/* ====================== БАЗА ====================== */
:root {
  --bg: #0f172a;
  --bg-2: #1e293b;
  --bg-3: #334155;
  --text: #f1f5f9;
  --text-2: #94a3b8;
  --accent: #6366f1;
  --accent-2: #8b5cf6;
  --green: #10b981;
  --red: #ef4444;
  --yellow: #f59e0b;
  --blue: #3b82f6;
  --card: #1e293b;
  --border: #334155;
  --shadow: 0 4px 20px rgba(0,0,0,.25);
  --radius: 14px;
  --radius-sm: 8px;
  --transition: .2s ease;
}

[data-theme="light"] {
  --bg: #f8fafc;
  --bg-2: #ffffff;
  --bg-3: #e2e8f0;
  --text: #0f172a;
  --text-2: #64748b;
  --card: #ffffff;
  --border: #e2e8f0;
  --shadow: 0 4px 20px rgba(0,0,0,.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ====================== ЛЕЙАУТ ====================== */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  padding: 24px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 32px;
  padding: 0 8px;
}

.logo-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid;
  place-items: center;
  font-size: 18px;
}

.nav { display: flex; flex-direction: column; gap: 4px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-weight: 500;
  transition: all var(--transition);
  cursor: pointer;
}

.nav-item:hover {
  background: var(--bg-3);
  color: var(--text);
  text-decoration: none;
}

.nav-item.active {
  background: var(--accent);
  color: #fff;
}

.nav-icon { font-size: 18px; width: 22px; text-align: center; }

.main {
  padding: 32px;
  max-width: 1400px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28px;
  flex-wrap: wrap;
  gap: 16px;
}

.page-title {
  font-size: 28px;
  font-weight: 700;
}

.page-subtitle {
  color: var(--text-2);
  font-size: 14px;
  margin-top: 4px;
}

/* ====================== КАРТОЧКИ ====================== */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  transition: transform var(--transition), box-shadow var(--transition);
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(0,0,0,.35);
}

.card-label {
  color: var(--text-2);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 8px;
}

.card-value {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.2;
}

.card-value.green { color: var(--green); }
.card-value.red { color: var(--red); }
.card-value.yellow { color: var(--yellow); }
.card-value.blue { color: var(--blue); }

.card-hint {
  font-size: 12px;
  color: var(--text-2);
  margin-top: 6px;
}

/* ====================== КНОПКИ ====================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-2); }

.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-3); color: var(--text); }

.btn-danger {
  background: var(--red);
  color: #fff;
}
.btn-danger:hover { opacity: .85; }

.btn-icon {
  padding: 6px 10px;
  font-size: 13px;
}

/* ====================== ФОРМА ====================== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; color: var(--text-2); font-weight: 500; }

.field input,
.field select,
.field textarea,
.input {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border var(--transition);
}

.field input:focus,
.field select:focus,
.input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ====================== ТАБЛИЦА ====================== */
.table-wrap {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  margin-bottom: 24px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th, td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  background: var(--bg-3);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-2);
}

tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-3); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge-green { background: rgba(16,185,129,.15); color: var(--green); }
.badge-red { background: rgba(239,68,68,.15); color: var(--red); }
.badge-yellow { background: rgba(245,158,11,.15); color: var(--yellow); }
.badge-blue { background: rgba(59,130,246,.15); color: var(--blue); }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--bg-3);
  font-size: 12px;
}

.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
}

/* ====================== ГРАФИКИ ====================== */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}

.chart-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.chart-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}

.chart-container { position: relative; height: 300px; }

/* ====================== МОДАЛКА ====================== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  border: 1px solid var(--border);
}

.modal-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ====================== SQL ====================== */
.sql-editor {
  width: 100%;
  min-height: 140px;
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text);
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 14px;
  line-height: 1.6;
  resize: vertical;
}

.sql-editor:focus { outline: none; border-color: var(--accent); }

.sql-result {
  margin-top: 20px;
  overflow-x: auto;
}

/* ====================== ТОСТЫ ====================== */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-weight: 500;
  transform: translateY(100px);
  opacity: 0;
  transition: all .3s ease;
  z-index: 200;
}

.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { border-left: 4px solid var(--green); }
.toast.error { border-left: 4px solid var(--red); }

/* ====================== АДАПТИВ ====================== */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    top: auto;
    height: auto;
    padding: 10px 12px;
    border-right: none;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    overflow-x: auto;
    z-index: 50;
  }
  .logo { display: none; }
  .nav { flex-direction: row; gap: 4px; }
  .nav-item { flex-direction: column; font-size: 10px; padding: 8px 10px; gap: 2px; white-space: nowrap; }
  .nav-icon { font-size: 18px; }
  .main { padding: 20px 16px 90px; }
  .page-title { font-size: 22px; }
  .charts-grid { grid-template-columns: 1fr; }
}

/* ====================== СКРОЛЛБАР ====================== */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ====================== LOADER ====================== */
.loader {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--text-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.empty {
  padding: 40px;
  text-align: center;
  color: var(--text-2);
}