@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap');

:root {
  /* Diality brand tokens */
  --blue:        #0066AC;
  --deep-blue:   #2B3E7F;
  --logo-blue:   #8BC6E8;
  --light-blue:  #D2E7F5;
  --white:       #FFFFFF;
  --dark-gray:   #313E48;
  --gray:        #768592;
  --light-gray:  #E6EDF2;
  --success:     #247D3E;
  --warning:     #FA921A;
  --danger:      #AE2628;

  /* Semantic aliases */
  --bg:          #E6EDF2;
  --bg-strong:   #F4F8FB;
  --panel:       #FFFFFF;
  --ink:         #313E48;
  --muted:       #768592;
  --accent:      #0066AC;
  --accent-2:    #2B3E7F;
  --line:        rgba(49, 62, 72, 0.12);

  /* Radius — style guide: cards 30px, buttons 12px, inputs 8px */
  --radius:      30px;
  --radius-btn:  12px;
  --radius-sm:   8px;

  /* Shadow */
  --shadow:      0 4px 20px rgba(43, 62, 127, 0.10);
  --shadow-sm:   0 2px 8px  rgba(43, 62, 127, 0.08);

  /* Spacing (8pt scale) */
  --sp-xs:  4px;
  --sp-sm:  8px;
  --sp-md:  16px;
  --sp-lg:  24px;
  --sp-xl:  32px;
  --sp-xxl: 48px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  font-family: Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  background: var(--bg);
}

.hidden { display: none !important; }

/* ── Eyebrow label ─────────────────────────────────────────────────────────── */
.eyebrow {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--logo-blue);
}

/* ── Login screen ──────────────────────────────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--sp-xl);
  background:
    linear-gradient(160deg, var(--deep-blue) 0%, #1a2d6b 60%, #0f1f4f 100%);
}

.login-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-lg);
  width: min(400px, calc(100% - 48px));
}

.login-logo {
  width: 200px;
  max-width: 100%;
}

.login-card {
  width: 100%;
  padding: var(--sp-xl) var(--sp-xl) var(--sp-lg);
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: 0 24px 64px rgba(0, 0, 20, 0.32);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-md);
  text-align: center;
}

.login-card h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--deep-blue);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.login-form input {
  width: 100%;
  height: 44px;
  padding: 0 var(--sp-md);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--bg-strong);
  color: var(--ink);
  outline: none;
  transition: border-color 0.12s;
}

.login-form input:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(0, 102, 172, 0.18);
}

.login-form button {
  margin-top: var(--sp-xs);
  width: 100%;
}

.login-hint-text {
  font-size: 0.85rem;
  color: var(--danger);
  margin: 0;
  min-height: 1.1em;
}

.login-challenge-hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0 0 var(--sp-xs);
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.primary {
  border: none;
  cursor: pointer;
  color: #fff;
  font-size: 0.95rem;
  font-weight: 500;
  padding: 0 var(--sp-lg);
  height: 44px;
  border-radius: var(--radius-btn);
  background: var(--blue);
  box-shadow: 0 4px 14px rgba(0, 102, 172, 0.28);
  transition: background 0.12s, box-shadow 0.12s;
}

.primary:hover {
  background: #0058a0;
  box-shadow: 0 6px 18px rgba(0, 102, 172, 0.38);
}

.primary:active {
  background: var(--deep-blue);
}

.primary:disabled {
  background: var(--gray);
  box-shadow: none;
  cursor: not-allowed;
}

/* ── Badge / pill ──────────────────────────────────────────────────────────── */
.badge,
.pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--light-blue);
  border: 1px solid rgba(0, 102, 172, 0.18);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--deep-blue);
}

.pill {
  background: var(--white);
  border-color: var(--line);
  color: var(--ink);
}

.pill.muted {
  color: var(--muted);
}

/* ── App shell layout ──────────────────────────────────────────────────────── */
.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
}

/* ── Sidebar ───────────────────────────────────────────────────────────────── */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: var(--sp-lg) var(--sp-md);
  background: var(--deep-blue);
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  margin-bottom: var(--sp-xl);
  padding-bottom: var(--sp-md);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.sidebar-brand-logo {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sidebar-logo {
  width: 130px;
  max-width: 100%;
}

.sidebar-app-title {
  font-size: 0.78rem;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.55);
  letter-spacing: 0.02em;
}

.nav {
  display: grid;
  gap: var(--sp-xs);
}

.nav-link {
  border: 1px solid transparent;
  background: transparent;
  border-radius: var(--radius-btn);
  padding: 11px var(--sp-md);
  text-align: left;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.75);
  transition: background 0.12s, color 0.12s;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.10);
  color: var(--white);
}

.nav-link.active {
  background: rgba(255, 255, 255, 0.18);
  color: var(--white);
  font-weight: 500;
  border-color: rgba(255, 255, 255, 0.08);
}

.sidebar-card {
  margin-top: auto;
  padding-top: var(--sp-md);
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.sidebar-card h3 {
  margin: 0 0 var(--sp-sm);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--logo-blue);
}

.sidebar-card p {
  margin: 0;
  font-size: 0.82rem;
  color: rgba(255, 255, 255, 0.6);
  line-height: 1.5;
}

/* ── Main content ──────────────────────────────────────────────────────────── */
.main {
  padding: var(--sp-lg) var(--sp-xl) var(--sp-xxl);
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-md);
  align-items: center;
  margin-bottom: var(--sp-lg);
  padding-bottom: var(--sp-md);
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 500;
  color: var(--deep-blue);
}

.topbar-pills {
  display: flex;
  gap: var(--sp-sm);
  align-items: center;
  flex-wrap: wrap;
}

.page { display: none; }
.page.active { display: block; }

/* ── Hero / overview ───────────────────────────────────────────────────────── */
.hero {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: var(--sp-lg);
  padding: var(--sp-lg);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: linear-gradient(135deg, var(--light-blue) 0%, var(--white) 60%);
  box-shadow: var(--shadow);
  margin-bottom: var(--sp-lg);
}

.hero h2 {
  margin: 0 0 var(--sp-sm);
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--deep-blue);
  line-height: 1.4;
}

.hero-copy p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-sm);
  align-content: start;
}

.metric-card {
  padding: var(--sp-md);
  border-radius: var(--radius-btn);
  background: var(--white);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  border-top-width: 3px;
}
.metric-card.accent-green  { border-top-color: var(--success); }
.metric-card.accent-red    { border-top-color: var(--danger); }
.metric-card.accent-orange { border-top-color: var(--warning); }
.metric-card.accent-blue   { border-top-color: var(--accent); }

/* ── Disabled analytics filter ─────────────────────────────────────────────── */
label.filter-disabled { opacity: 0.35; pointer-events: none; }

/* ── Cache staleness bar ───────────────────────────────────────────────────── */
.cache-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  padding: 6px var(--sp-md);
  margin-bottom: var(--sp-md);
  border-radius: var(--radius-sm);
  background: var(--light-blue);
  border: 1px solid rgba(0, 102, 172, 0.12);
  font-size: 0.82rem;
  color: var(--muted);
}
.cache-bar .cache-age { font-weight: 600; color: var(--ink); }
.cache-bar .btn-ghost  { margin-left: auto; }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  height: 28px;
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius-btn);
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  cursor: pointer;
  white-space: nowrap;
}
.btn-ghost:hover { background: var(--bg-strong); color: var(--ink); }

.metric-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--blue);
}

.metric-label {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 2px;
}

/* ── Dashboard grid ────────────────────────────────────────────────────────── */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-md);
}

/* ── Cards / panels ────────────────────────────────────────────────────────── */
.panel,
.result-card,
.capability-meta,
.sql-preview {
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel {
  padding: var(--sp-lg);
}

.panel-header {
  margin-bottom: var(--sp-md);
}

.panel-header h3 {
  margin: 0 0 4px;
  font-size: 1rem;
  font-weight: 500;
  color: var(--deep-blue);
}

.panel-header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
}

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  gap: var(--sp-md);
}

.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.four  { grid-template-columns: repeat(4, minmax(0, 1fr)); }

label {
  display: grid;
  gap: var(--sp-xs);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--dark-gray);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

input,
select,
button {
  font: inherit;
}

.btn-sm {
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  height: 30px;
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius-btn);
  background: var(--blue);
  color: var(--white);
  border: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn-sm:hover { background: var(--deep-blue); }
.btn-sm:disabled { opacity: 0.55; cursor: default; }

/* ── Loading indicator ─────────────────────────────────────── */
.loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px var(--sp-md);
  color: var(--muted);
  font-size: 0.9rem;
}

.spinner {
  display: inline-block;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border: 2px solid var(--light-blue);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Table row status tinting ──────────────────────────────── */
tr.row-failed td { background: rgba(174, 38, 40, 0.06); }
tr.row-failed:hover td { background: rgba(174, 38, 40, 0.10); }
tr.row-processing td { background: rgba(0, 102, 172, 0.05); }

.tabulator-row.row-failed .tabulator-cell       { background: rgba(174, 38, 40, 0.06); }
.tabulator-row.row-failed:hover .tabulator-cell { background: rgba(174, 38, 40, 0.10); }
.tabulator-row.row-processing .tabulator-cell   { background: rgba(0, 102, 172, 0.05); }

.action-cell { white-space: nowrap; display: flex; gap: 6px; align-items: center; }

/* ── Status badges ─────────────────────────────────────────────────────────── */
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border: 1px solid transparent;
  white-space: nowrap;
}
.status-badge.status-processed,
.status-badge.status-success,
.status-badge.status-succeeded,
.status-badge.status-pass       { background: #e8f5e9; color: #2e7d32; border-color: #a5d6a7; }
.status-badge.status-failed,
.status-badge.status-fail,
.status-badge.status-error      { background: #ffebee; color: #c62828; border-color: #ef9a9a; }
.status-badge.status-pending    { background: #fff8e1; color: #e65100; border-color: #ffe082; }
.status-badge.status-processing { background: #e3f2fd; color: #1565c0; border-color: #90caf9; }
.status-badge.status-canceled,
.status-badge.status-cancelled  { background: #f5f5f5; color: #616161; border-color: #e0e0e0; }

.btn-reprocess {
  background: transparent;
  color: var(--blue);
  border: 1px solid var(--blue);
}
.btn-reprocess:hover { background: var(--light-blue); }

/* ── Logout button ─────────────────────────────────────────── */
.btn-logout {
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  height: 34px;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-btn);
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn-logout:hover {
  background: var(--bg);
  border-color: rgba(49,62,72,0.25);
}

input,
select {
  width: 100%;
  height: 44px;
  padding: 0 13px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(49, 62, 72, 0.2);
  background: var(--white);
  color: var(--ink);
  font-size: 0.9rem;
}

input:focus,
select:focus {
  outline: 2px solid rgba(0, 102, 172, 0.20);
  border-color: var(--accent);
}

.form-actions {
  display: flex;
  gap: var(--sp-sm);
  align-items: center;
  flex-wrap: wrap;
  margin-top: var(--sp-md);
}

/* ── Result areas ──────────────────────────────────────────────────────────── */
.result-card,
.capability-meta,
.sql-preview {
  margin-top: var(--sp-md);
  padding: var(--sp-md);
}

.sql-preview pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.82rem;
  color: var(--deep-blue);
  margin: var(--sp-sm) 0 0;
}

/* ── Upload progress & success ──────────────────────────────────────────────── */
.upload-progress-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: var(--sp-sm) 0;
}
.upload-progress-label {
  font-size: 0.88rem;
  color: var(--ink);
}
.upload-progress-track {
  height: 8px;
  background: var(--line);
  border-radius: 4px;
  overflow: hidden;
}
.upload-progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.15s ease;
}
.upload-progress-pct {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
  text-align: right;
}
.upload-success {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-md);
  padding: var(--sp-sm) 0;
}
.upload-success-icon {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #27ae60;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
}
.upload-success-body {
  font-size: 0.9rem;
  color: var(--ink);
  line-height: 1.5;
}
.upload-success-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 4px;
  font-size: 0.82rem;
  color: var(--ink-2);
}

/* ── Tables ────────────────────────────────────────────────────────────────── */
.table-shell {
  overflow: auto;
  border-radius: var(--radius-btn);
  border: 1px solid var(--line);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--white);
}

th,
td {
  height: 44px;
  padding: 0 var(--sp-md);
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 0.875rem;
  vertical-align: middle;
}

th {
  background: var(--light-gray);
  font-weight: 500;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--dark-gray);
}

tr:last-child td { border-bottom: none; }

tr:hover td {
  background: var(--bg-strong);
}

/* ── Messages ──────────────────────────────────────────────────────────────── */
.message {
  padding: var(--sp-md);
  border-radius: var(--radius-sm);
  background: var(--light-gray);
  color: var(--muted);
  font-size: 0.9rem;
}

.message.error {
  background: rgba(174, 38, 40, 0.07);
  color: var(--danger);
}

/* ── Meta grid ─────────────────────────────────────────────────────────────── */
.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-sm) var(--sp-md);
  font-size: 0.9rem;
}

.muted-text { color: var(--muted); }

/* ── Chart panel ───────────────────────────────────────────────────────────── */
.chart-panel {
  margin-top: var(--sp-md);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chart-title-bar {
  display: flex;
  align-items: center;
  padding: var(--sp-sm) var(--sp-md);
  border-bottom: 1px solid var(--line);
}

.chart-title {
  font-size: 0.82rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.chart-canvas-wrapper {
  position: relative;
  height: 300px;
  padding: var(--sp-md);
}

/* ── Tabulator overrides — match app brand ────────────────────────────────── */
.tabulator {
  border-radius: var(--radius-btn);
  border-color: var(--line);
  background: var(--panel);
  font-family: Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 0.875rem;
  color: var(--ink);
  margin-top: var(--sp-md);
}

.tabulator-header {
  background: var(--light-gray);
  border-bottom-color: var(--line);
}

.tabulator-col {
  background: var(--light-gray);
  border-right-color: var(--line);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--dark-gray);
}

.tabulator-col:hover { background: var(--bg); }

.tabulator-row {
  background: var(--panel);
  border-bottom-color: var(--line);
  min-height: 44px;
  color: var(--ink);
}

.tabulator-row:hover,
.tabulator-row.tabulator-row-even:hover { background: var(--bg-strong); }

.tabulator-row.tabulator-row-even { background: var(--panel); }

.tabulator-footer {
  background: var(--light-gray);
  border-top-color: var(--line);
  color: var(--muted);
}

.tabulator-page {
  border-color: var(--line);
  color: var(--ink);
  border-radius: var(--radius-sm);
}

.tabulator-page:hover:not(.disabled) { background: var(--bg-strong); }
.tabulator-page.active { background: var(--accent); color: var(--white); border-color: var(--accent); }

input.tabulator-header-filter {
  background: var(--white);
  border-color: var(--line);
  color: var(--ink);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
}

/* ── Dark mode ─────────────────────────────────────────────────────────────── */

[data-theme="dark"] {
  --bg:        #0f1621;
  --bg-strong: #182030;
  --panel:     #1c2840;
  --ink:       #cdd9e6;
  --muted:     #7a90a8;
  --accent:    #4aacee;
  --accent-2:  #4870cc;
  --line:      rgba(255, 255, 255, 0.09);
  /* Override light-specific brand tokens used as backgrounds/fills */
  --light-blue: #1a3460;
  --light-gray: #1c2840;
  --dark-gray:  #a8bece;
  --shadow:    0 4px 24px rgba(0, 0, 0, 0.50);
  --shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.40);
}

/* Elements with var(--white) or var(--deep-blue) that need explicit dark overrides */

[data-theme="dark"] table                        { background: var(--panel); }
[data-theme="dark"] th                           { color: var(--muted); }

[data-theme="dark"] input,
[data-theme="dark"] select                       { background: var(--bg-strong); color: var(--ink);
                                                   border-color: rgba(255,255,255,0.14); }
[data-theme="dark"] input::placeholder           { color: var(--muted); }
[data-theme="dark"] input:focus,
[data-theme="dark"] select:focus                 { border-color: var(--accent);
                                                   outline-color: rgba(74,172,238,0.25); }

[data-theme="dark"] .pill                        { background: rgba(255,255,255,0.08);
                                                   border-color: rgba(255,255,255,0.12);
                                                   color: var(--ink); }
[data-theme="dark"] .pill.muted                  { color: var(--muted); }
[data-theme="dark"] .badge                       { background: var(--light-blue);
                                                   border-color: rgba(74,172,238,0.22);
                                                   color: #8ecef5; }

[data-theme="dark"] .panel-header h3             { color: var(--ink); }
[data-theme="dark"] .topbar h1                   { color: var(--ink); }
[data-theme="dark"] .sql-preview pre             { color: var(--accent); }

[data-theme="dark"] .hero                        { background: linear-gradient(135deg, var(--light-blue) 0%, var(--panel) 60%); }
[data-theme="dark"] .hero h2                     { color: var(--ink); }

[data-theme="dark"] .primary                     { background: var(--accent); }
[data-theme="dark"] .primary:hover               { background: var(--accent-2); }

[data-theme="dark"] .message                     { background: var(--bg-strong); }
[data-theme="dark"] .message.error               { background: rgba(174,38,40,0.15); }
[data-theme="dark"] tr.row-failed td             { background: rgba(174,38,40,0.14); }
[data-theme="dark"] tr.row-failed:hover td       { background: rgba(174,38,40,0.20); }
[data-theme="dark"] tr.row-processing td         { background: rgba(74,172,238,0.07); }

[data-theme="dark"] .tabulator-row.row-failed .tabulator-cell       { background: rgba(174,38,40,0.14); }
[data-theme="dark"] .tabulator-row.row-failed:hover .tabulator-cell { background: rgba(174,38,40,0.20); }
[data-theme="dark"] .tabulator-row.row-processing .tabulator-cell   { background: rgba(74,172,238,0.07); }

[data-theme="dark"] .status-badge.status-processed,
[data-theme="dark"] .status-badge.status-success,
[data-theme="dark"] .status-badge.status-succeeded,
[data-theme="dark"] .status-badge.status-pass       { background: rgba(46,125,50,0.22); color: #81c784; border-color: rgba(165,214,167,0.28); }
[data-theme="dark"] .status-badge.status-failed,
[data-theme="dark"] .status-badge.status-fail,
[data-theme="dark"] .status-badge.status-error      { background: rgba(198,40,40,0.22); color: #ef9a9a; border-color: rgba(239,154,154,0.28); }
[data-theme="dark"] .status-badge.status-pending    { background: rgba(230,81,0,0.22); color: #ffcc80; border-color: rgba(255,224,130,0.28); }
[data-theme="dark"] .status-badge.status-processing { background: rgba(21,101,192,0.22); color: #90caf9; border-color: rgba(144,202,249,0.28); }
[data-theme="dark"] .status-badge.status-canceled,
[data-theme="dark"] .status-badge.status-cancelled  { background: rgba(97,97,97,0.22); color: #bdbdbd; border-color: rgba(224,224,224,0.18); }

[data-theme="dark"] .metric-card { background: var(--panel); }

[data-theme="dark"] .cache-bar {
  background: var(--light-blue);
  border-color: rgba(74, 172, 238, 0.15);
}

[data-theme="dark"] .btn-reprocess               { border-color: var(--accent); color: var(--accent); }
[data-theme="dark"] .btn-reprocess:hover         { background: rgba(74,172,238,0.12); }

/* Tabulator dark mode overrides */
[data-theme="dark"] .tabulator                   { background: var(--panel); border-color: var(--line); color: var(--ink); }
[data-theme="dark"] .tabulator-header            { background: var(--bg-strong); border-bottom-color: var(--line); }
[data-theme="dark"] .tabulator-col               { background: var(--bg-strong); border-right-color: var(--line); color: var(--muted); }
[data-theme="dark"] .tabulator-col:hover         { background: var(--bg); }
[data-theme="dark"] .tabulator-row               { background: var(--panel); border-bottom-color: var(--line); color: var(--ink); }
[data-theme="dark"] .tabulator-row:hover,
[data-theme="dark"] .tabulator-row.tabulator-row-even:hover { background: var(--bg); }
[data-theme="dark"] .tabulator-row.tabulator-row-even { background: var(--panel); }
[data-theme="dark"] .tabulator-footer            { background: var(--bg-strong); border-top-color: var(--line); color: var(--muted); }
[data-theme="dark"] .tabulator-page              { border-color: var(--line); color: var(--ink); }
[data-theme="dark"] .tabulator-page:hover:not(.disabled) { background: var(--bg); }
[data-theme="dark"] .tabulator-page.active       { background: var(--accent); color: var(--bg); border-color: var(--accent); }
[data-theme="dark"] input.tabulator-header-filter { background: var(--bg-strong);
                                                    border-color: rgba(255,255,255,0.14);
                                                    color: var(--ink); }

/* ── Theme toggle button ───────────────────────────────────────────────────── */
.btn-theme {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: var(--radius-btn);
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}
.btn-theme:hover {
  background: var(--bg);
  border-color: rgba(49,62,72,0.25);
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 1023px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    gap: var(--sp-sm);
    padding: var(--sp-md);
  }

  .sidebar-brand {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
  }

  .nav {
    grid-auto-flow: column;
    grid-template-columns: none;
  }

  .sidebar-card {
    display: none;
  }

  .main {
    padding: var(--sp-md);
  }

  .hero,
  .dashboard-grid,
  .form-grid.three,
  .form-grid.four,
  .meta-grid {
    grid-template-columns: 1fr;
  }

  .hero-stats {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ── Chat panel ──────────────────────────────────────────────────────────────── */

.chat-panel {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 160px);
  min-height: 480px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-md);
  display: flex;
  flex-direction: column;
  gap: var(--sp-md);
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  margin-bottom: var(--sp-md);
}

.chat-bubble {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  gap: var(--sp-xs);
}

.chat-bubble.user {
  align-self: flex-end;
  align-items: flex-end;
}

.chat-bubble.assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.chat-bubble-label {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chat-bubble-body {
  padding: var(--sp-sm) var(--sp-md);
  border-radius: var(--radius-btn);
  font-size: 0.93rem;
  line-height: 1.55;
  word-break: break-word;
}

.chat-bubble.user .chat-bubble-body {
  background: var(--accent);
  color: var(--white);
  border-bottom-right-radius: 4px;
}

.chat-bubble.assistant .chat-bubble-body {
  background: var(--panel);
  color: var(--ink);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.chat-bubble-summary {
  margin-bottom: var(--sp-xs);
}

.chat-bubble-sql {
  margin-top: var(--sp-sm);
  font-size: 0.78rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.chat-bubble-sql pre {
  margin: var(--sp-xs) 0 0;
  padding: var(--sp-sm) var(--sp-md);
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  white-space: pre-wrap;
  word-break: break-all;
  border: 1px solid var(--line);
}

.chat-table-wrap {
  margin-top: var(--sp-sm);
  max-height: 260px;
  overflow-y: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
}

.chat-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.chat-table th {
  background: var(--bg-strong);
  color: var(--muted);
  text-align: left;
  padding: var(--sp-xs) var(--sp-sm);
  font-weight: 500;
  position: sticky;
  top: 0;
  white-space: nowrap;
}

.chat-table td {
  padding: var(--sp-xs) var(--sp-sm);
  border-top: 1px solid var(--line);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-table tr:hover td {
  background: var(--bg);
}

.chat-truncation-note {
  font-size: 0.78rem;
  color: var(--warning);
  margin-top: var(--sp-xs);
  font-style: italic;
}

.chat-spinner {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  color: var(--muted);
  font-size: 0.88rem;
  padding: var(--sp-sm) 0;
}

.chat-spinner-dot {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: chat-bounce 1.2s ease-in-out infinite;
}

.chat-spinner-dot:nth-child(2) { animation-delay: 0.2s; }
.chat-spinner-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes chat-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40%           { transform: translateY(-6px); opacity: 1; }
}

.chat-error {
  color: var(--danger);
  font-size: 0.88rem;
}

.chat-input-row {
  display: flex;
  gap: var(--sp-sm);
  align-items: flex-end;
}

.chat-textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: var(--sp-sm) var(--sp-md);
  font-family: inherit;
  font-size: 0.93rem;
  line-height: 1.5;
  background: var(--bg-strong);
  color: var(--ink);
  transition: border-color 0.15s;
}

.chat-textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.chat-send-btn {
  flex-shrink: 0;
  align-self: flex-end;
}

.chat-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--sp-sm);
}

.chat-hint {
  font-size: 0.75rem;
}

/* dark mode overrides for chat */
[data-theme="dark"] .chat-messages {
  background: var(--bg);
  border-color: var(--line);
}

[data-theme="dark"] .chat-bubble.assistant .chat-bubble-body {
  background: var(--panel);
}

[data-theme="dark"] .chat-bubble-sql pre {
  background: var(--bg);
}

[data-theme="dark"] .chat-table th {
  background: var(--bg-strong);
}

[data-theme="dark"] .chat-textarea {
  background: var(--bg-strong);
  color: var(--ink);
  border-color: var(--line);
}

/* ── Help modal ──────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-lg);
}

.modal-overlay.hidden {
  display: none;
}

.modal-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.22);
  width: 100%;
  max-width: 680px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-md) var(--sp-lg);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--ink-muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}

.modal-close:hover {
  background: var(--bg-strong);
  color: var(--ink);
}

.modal-body {
  overflow-y: auto;
  padding: var(--sp-lg);
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--sp-lg);
}

.help-section h3 {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 0 0 var(--sp-sm) 0;
}

.help-section h4 {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
  margin: var(--sp-sm) 0 4px 0;
}

.help-section p,
.help-section li {
  font-size: 0.88rem;
  color: var(--ink-light);
  line-height: 1.6;
}

.help-section ul,
.help-section ol {
  margin: 0;
  padding-left: 1.3em;
}

.help-section ul li,
.help-section ol li {
  margin-bottom: 3px;
}

.help-section kbd {
  display: inline-block;
  padding: 1px 6px;
  font-family: monospace;
  font-size: 0.82rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--bg-strong);
  color: var(--ink);
  line-height: 1.5;
}

.prompt-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.prompt-list li {
  margin: 0;
}

.prompt-chip {
  font-size: 0.8rem;
  background: var(--bg-strong);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 4px 12px;
  color: var(--ink-light);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  font-family: inherit;
  line-height: 1.4;
  text-align: left;
}

.prompt-chip:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.chat-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.btn-help {
  background: none;
  border: 1px solid var(--line);
  border-radius: 50%;
  width: 26px;
  height: 26px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.btn-help:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* dark mode overrides for modal */
[data-theme="dark"] .modal-header {
  border-color: var(--line);
}

[data-theme="dark"] .prompt-chip {
  background: var(--bg-strong);
  border-color: var(--line);
  color: var(--ink-light);
}

[data-theme="dark"] .prompt-chip:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

[data-theme="dark"] .help-section kbd {
  background: var(--bg);
  border-color: var(--line);
}

/* ── Cost Dashboard ──────────────────────────────────────────────────────── */

.cost-error {
  background: #fde8e8;
  color: #c0392b;
  border: 1px solid #f5c6cb;
  border-radius: var(--radius-sm);
  padding: var(--sp-sm) var(--sp-md);
  margin-bottom: var(--sp-md);
  font-size: 0.88rem;
}

.cost-cards {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-md);
  margin-bottom: var(--sp-lg);
}

.cost-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--sp-md) var(--sp-lg);
  flex: 1;
  min-width: 140px;
}

.cost-card-realtime {
  border-color: var(--accent);
}

.cost-card-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 6px;
}

.cost-card-value {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.02em;
}

.cost-panel {
  margin-bottom: var(--sp-lg);
  overflow: hidden;
}

/* ── Help / Query Guide ─────────────────────────────────────────────────────── */
.help-panel { overflow: visible; }
.help-panel-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-md); }
.help-content {
  padding: var(--sp-lg) var(--sp-xl);
  line-height: 1.7;
  max-width: 860px;
}
.help-content h1 { font-size: 1.5rem; margin: 0 0 var(--sp-md); }
.help-content h2 { font-size: 1.2rem; margin: var(--sp-xl) 0 var(--sp-sm); border-bottom: 1px solid var(--border); padding-bottom: var(--sp-xs); }
.help-content h3 { font-size: 1.05rem; margin: var(--sp-lg) 0 var(--sp-xs); }
.help-content h4 { font-size: 0.95rem; margin: var(--sp-md) 0 var(--sp-xs); font-weight: 600; }
.help-content p  { margin: 0 0 var(--sp-sm); }
.help-content ul, .help-content ol { margin: 0 0 var(--sp-sm); padding-left: 1.6em; }
.help-content li { margin-bottom: 0.25em; }
.help-content pre {
  background: #1e1e2e;
  color: #cdd9e6;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-md);
  overflow-x: auto;
  font-size: 0.82rem;
  line-height: 1.5;
  margin: var(--sp-sm) 0 var(--sp-md);
}
.help-content code {
  font-family: var(--font-mono, "JetBrains Mono", monospace);
  font-size: 0.85em;
  background: rgba(0,0,0,0.08);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}
.help-content pre code { background: none; color: inherit; padding: 0; font-size: inherit; }
.help-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  margin: var(--sp-sm) 0 var(--sp-md);
}
.help-content th, .help-content td {
  border: 1px solid var(--border);
  padding: 0.4em 0.7em;
  text-align: left;
}
.help-content th { background: var(--surface-alt, rgba(255,255,255,0.05)); font-weight: 600; }
.help-content blockquote {
  border-left: 3px solid var(--accent);
  margin: var(--sp-sm) 0;
  padding: var(--sp-xs) var(--sp-md);
  color: var(--ink-muted);
}

.cost-loading {
  padding: var(--sp-lg);
  color: var(--ink-muted);
  font-size: 0.88rem;
}

.cost-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.cost-table th {
  background: var(--bg-strong);
  font-weight: 600;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-muted);
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.cost-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  vertical-align: middle;
}

.cost-table tr:last-child td {
  border-bottom: none;
}

.cost-table td.num,
.cost-table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.cost-bar-col {
  width: 80px;
}

.cost-bar {
  height: 8px;
  background: var(--accent);
  border-radius: 4px;
  min-width: 2px;
  display: inline-block;
  opacity: 0.75;
}

.cost-total-row td {
  background: var(--bg-strong);
  font-size: 0.88rem;
}

.cost-svc-cell {
  white-space: nowrap;
}

.cost-footnote {
  font-size: 0.75rem;
  color: var(--ink-muted);
  padding: var(--sp-sm) var(--sp-md);
  margin: 0;
}

/* Daily sparkline */
.cost-sparkline {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: var(--sp-md) var(--sp-lg) var(--sp-sm);
  height: 100px;
  overflow-x: auto;
}

.cost-spark-bar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: default;
  flex-shrink: 0;
}

.cost-spark-bar {
  width: 22px;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  opacity: 0.7;
  transition: opacity 0.15s;
}

.cost-spark-bar-wrap:hover .cost-spark-bar {
  opacity: 1;
}

.cost-spark-label {
  font-size: 0.65rem;
  color: var(--ink-muted);
  white-space: nowrap;
}

/* dark mode overrides */
[data-theme="dark"] .cost-card {
  background: var(--panel);
}

[data-theme="dark"] .cost-table th {
  background: var(--bg-strong);
}

[data-theme="dark"] .cost-total-row td {
  background: var(--bg-strong);
}

[data-theme="dark"] .cost-error {
  background: #3d1010;
  color: #f1948a;
  border-color: #7b241c;
}

/* ── User Management ─────────────────────────────────────────────────────── */

.users-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.panel-header:has(.users-actions) {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  margin-top: 1rem;
}

.users-table th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 2px solid var(--border);
  color: var(--ink-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
}

.users-table td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.users-table tr:hover td {
  background: var(--bg-strong);
}

.user-status {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.user-status-confirmed        { background: #d4edda; color: #155724; }
.user-status-force-change-password { background: #fff3cd; color: #856404; }
.user-status-unconfirmed      { background: #f8d7da; color: #721c24; }
.user-status-reset-required   { background: #d1ecf1; color: #0c5460; }

.user-group-select {
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--ink);
  font-size: 0.85rem;
  cursor: pointer;
}

.user-delete-btn {
  background: transparent;
  border: 1px solid #dc3545;
  color: #dc3545;
  cursor: pointer;
  border-radius: 4px;
  padding: 0.2rem 0.6rem;
  font-size: 0.8rem;
  transition: background 0.15s, color 0.15s;
}

.user-delete-btn:hover {
  background: #dc3545;
  color: #fff;
}

.users-status {
  font-size: 0.875rem;
  padding: 0.4rem 0.75rem;
  border-radius: 4px;
  margin: 0.5rem 0;
}

.users-success { background: #d4edda; color: #155724; }
.users-error   { background: #f8d7da; color: #721c24; }

.modal-footer {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.users-modal-status {
  font-size: 0.85rem;
  color: #721c24;
  background: #f8d7da;
  padding: 0.4rem 0.75rem;
  border-radius: 4px;
  margin-top: 0.75rem;
}

[data-theme="dark"] .user-status-confirmed        { background: #1a3d25; color: #75d49b; }
[data-theme="dark"] .user-status-force-change-password { background: #3d2e00; color: #ffd166; }
[data-theme="dark"] .user-status-unconfirmed      { background: #3d1010; color: #f1948a; }
[data-theme="dark"] .user-status-reset-required   { background: #0a2a30; color: #72cfe3; }
[data-theme="dark"] .user-group-select            { background: var(--panel); border-color: var(--border); }
[data-theme="dark"] .users-success { background: #1a3d25; color: #75d49b; }
[data-theme="dark"] .users-error   { background: #3d1010; color: #f1948a; }
[data-theme="dark"] .users-modal-status { background: #3d1010; color: #f1948a; }

/* ── SQL Runner ───────────────────────────────────────────────────────────── */

.sql-runner-panel { display: flex; flex-direction: column; gap: 0; padding: 0; }

.sql-runner-toolbar {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; padding: 1.25rem 1.5rem 0.75rem;
  flex-wrap: wrap;
}
.sql-runner-subtitle { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.25rem; }
.sql-runner-actions  { display: flex; gap: 0.5rem; align-items: center; flex-shrink: 0; }

/* CodeMirror overrides */
.sql-editor-wrap { border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.sql-editor-wrap .CodeMirror {
  height: 220px;
  font-size: 0.875rem;
  font-family: "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;
  background: var(--panel);
  color: var(--text);
  border: none;
}
.sql-editor-wrap .CodeMirror-gutters   { background: var(--panel); border-right: 1px solid var(--border); }
.sql-editor-wrap .CodeMirror-linenumber { color: var(--text-muted); }
.sql-editor-wrap .CodeMirror-cursor    { border-left-color: var(--text); }
.sql-editor-wrap .CodeMirror-selected  { background: rgba(74, 172, 238, 0.25); }

/* Dark-mode CodeMirror syntax tokens */
[data-theme="dark"] .cm-keyword  { color: #e86b4f; }
[data-theme="dark"] .cm-string   { color: #98c379; }
[data-theme="dark"] .cm-number   { color: #d19a66; }
[data-theme="dark"] .cm-comment  { color: #5c6370; font-style: italic; }
[data-theme="dark"] .cm-operator { color: #56b6c2; }
[data-theme="dark"] .CodeMirror-hints { background: var(--panel); border: 1px solid var(--border); }
[data-theme="dark"] .CodeMirror-hint  { color: var(--text); }
[data-theme="dark"] .CodeMirror-hint-active { background: var(--primary); color: #fff; }

/* Results bar */
.sql-results-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: 0.6rem 1.25rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.sql-tab-row   { display: flex; gap: 0; }
.sql-tab {
  padding: 0.3rem 1rem; font-size: 0.82rem; font-weight: 500;
  border: 1px solid var(--border); background: transparent; color: var(--text-muted);
  cursor: pointer; transition: background 0.15s;
}
.sql-tab:first-child { border-radius: 4px 0 0 4px; }
.sql-tab:last-child  { border-radius: 0 4px 4px 0; border-left: none; }
.sql-tab-active { background: var(--primary); color: #fff; border-color: var(--primary); }

.sql-results-meta { display: flex; align-items: center; gap: 0.75rem; font-size: 0.8rem; }

/* Status / loading inside runner */
#sql-runner-status { padding: 0 1.25rem; }
#sql-runner-status:empty { padding: 0; }

/* Tabulator host */
#sql-runner-table { padding: 0 0 0.5rem; }
#sql-runner-table.hidden { display: none; }

/* Chart panel */
.sql-chart-panel { padding: 1rem 1.25rem 1.25rem; }
.sql-chart-panel.hidden { display: none; }
.sql-chart-config {
  display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: flex-end;
  margin-bottom: 1rem;
}
.sql-chart-config label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.8rem; min-width: 130px; }
.sql-chart-config label span { color: var(--text-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
.sql-chart-config select { font-size: 0.85rem; padding: 0.3rem 0.5rem; border: 1px solid var(--border); border-radius: 4px; background: var(--panel); color: var(--text); }
.sql-chart-canvas-wrap { position: relative; height: 340px; }

/* Security notice */
.sql-security-notice {
  margin: 0.75rem 1.25rem 1rem;
  padding: 0.55rem 0.9rem;
  font-size: 0.78rem;
  background: rgba(255, 193, 7, 0.1);
  border: 1px solid rgba(255, 193, 7, 0.35);
  border-radius: 4px;
  color: var(--text-muted);
}
.sql-security-notice strong { color: var(--text); }

[data-theme="dark"] .sql-security-notice { background: rgba(255, 193, 7, 0.07); }

/* Blocked-query error callout */
.sql-blocked-error {
  margin: 0.75rem 0;
  padding: 0.65rem 1rem;
  background: #fdf0f0; border: 1px solid #f5c6cb; border-radius: 4px;
  color: #721c24; font-size: 0.85rem;
}
[data-theme="dark"] .sql-blocked-error { background: #3d1010; border-color: #6b2222; color: #f1948a; }

