/* QueryGate design system — buildless, single stylesheet. */

:root {
  /* Brand: calm blue/teal */
  --brand: #0891b2;
  --brand-600: #0e7490;
  --brand-700: #155e75;
  --brand-weak: #ecfeff;
  --brand-weak-2: #cffafe;

  /* Neutrals */
  --app-bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #475569;
  --text-subtle: #94a3b8;

  /* Semantic */
  --ok: #15803d;        --ok-bg: #dcfce7;
  --warn: #b45309;      --warn-bg: #fef3c7;
  --error: #b91c1c;     --error-bg: #fee2e2;
  --info: #1d4ed8;      --info-bg: #dbeafe;

  /* Spacing scale (8pt) */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;

  /* Type scale */
  --fs-xs: 12px; --fs-sm: 13px; --fs-base: 14px; --fs-md: 15px;
  --fs-lg: 18px; --fs-xl: 22px; --fs-2xl: 28px;

  --r-sm: 6px; --r: 8px; --r-lg: 12px; --r-full: 999px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow-md: 0 6px 20px rgba(15, 23, 42, .10);

  --sidebar-w: 232px;
}

* { box-sizing: border-box; }
.skip { position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--surface); color: var(--text); padding: 8px 12px;
  border: 1px solid var(--border); border-radius: var(--r-sm); }
.skip:focus { left: 8px; top: 8px; }
html, body { height: 100%; }
body {
  margin: 0;
  font: var(--fs-md)/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--app-bg);
}
a { color: var(--brand-600); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .brand {
  display: flex; align-items: center; gap: var(--s2);
  padding: var(--s4) var(--s4) var(--s3);
  font-size: var(--fs-lg); font-weight: 700; color: var(--text);
}
.sidebar .brand:hover { text-decoration: none; }
.brand-mark { width: 24px; height: 24px; border-radius: 6px; display: block; }
.nav { padding: var(--s2); overflow-y: auto; flex: 1; }
.nav-group { margin-top: var(--s4); }
.nav-group-label {
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-subtle); padding: var(--s2) var(--s3) var(--s1);
}
.nav a {
  display: flex; align-items: center; gap: var(--s2);
  padding: var(--s2) var(--s3); margin: 2px 0;
  border-radius: var(--r-sm); color: var(--text-muted);
  font-size: var(--fs-base); font-weight: 500; border-left: 3px solid transparent;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active {
  background: var(--brand-weak); color: var(--brand-700);
  border-left-color: var(--brand); font-weight: 600;
}
.nav .ico { width: 18px; text-align: center; opacity: .9; }

.user-menu {
  border-top: 1px solid var(--border); padding: var(--s3) var(--s4);
  display: flex; align-items: center; gap: var(--s2); font-size: var(--fs-sm);
}
.user-menu .who { flex: 1; min-width: 0; }
.user-menu .who b { display: block; color: var(--text); }
.user-menu .who span { color: var(--text-subtle); font-size: var(--fs-xs); }

/* ---------- Content ---------- */
.content { min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s5); border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.breadcrumb { color: var(--text-subtle); font-size: var(--fs-sm); }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb .sep { margin: 0 var(--s1); color: var(--border-strong); }
.hamburger { display: none; background: none; border: 0; font-size: 20px; cursor: pointer; color: var(--text); }

main { padding: var(--s5); max-width: 1120px; }
main.auth { max-width: none; min-height: 100vh; display: flex; justify-content: center;
  align-items: flex-start; padding: 9vh var(--s4) var(--s4); }
.auth-box { width: 100%; max-width: 380px; }
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--s4); margin-bottom: var(--s5);
}
.page-head h1 { font-size: var(--fs-xl); margin: 0; }
.page-head .sub { color: var(--text-muted); font-size: var(--fs-sm); margin-top: 2px; }
.page-actions { display: flex; gap: var(--s2); flex-shrink: 0; }

h2 { font-size: var(--fs-lg); margin: var(--s5) 0 var(--s3); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: var(--s5); margin-bottom: var(--s4);
  box-shadow: var(--shadow);
}
.card h2 { margin-top: 0; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--s4); }

/* ---------- Forms ---------- */
label { display: block; font-size: var(--fs-sm); font-weight: 600; color: var(--text-muted); margin: var(--s3) 0 var(--s1); }
label .req { color: var(--error); }
input, select, textarea {
  width: 100%; padding: 9px 11px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-weak-2);
}
textarea { min-height: 96px; font-family: ui-monospace, "Cascadia Code", monospace; font-size: var(--fs-sm); }
.field-hint { font-size: var(--fs-xs); color: var(--text-subtle); margin-top: var(--s1); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--s2) var(--s4); }
.form-actions { margin-top: var(--s4); display: flex; gap: var(--s2); }

/* ---------- Buttons ---------- */
.btn, button {
  display: inline-flex; align-items: center; gap: var(--s2);
  background: var(--brand); color: #fff; border: 1px solid var(--brand);
  padding: 8px 14px; border-radius: var(--r-sm);
  font: inherit; font-weight: 600; font-size: var(--fs-base);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .12s, border-color .12s, box-shadow .12s;
}
.btn:hover, button:hover { background: var(--brand-600); border-color: var(--brand-600); text-decoration: none; }
.btn:focus-visible, button:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--brand-weak-2); }
.btn-secondary {
  background: var(--surface); color: var(--text); border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn-ghost { background: transparent; color: var(--brand-700); border-color: transparent; }
.btn-ghost:hover { background: var(--brand-weak); }
.btn-danger { background: var(--surface); color: var(--error); border-color: #fecaca; }
.btn-danger:hover { background: var(--error-bg); border-color: #fca5a5; }
.btn-sm { padding: 5px 10px; font-size: var(--fs-sm); }
.btn-block { width: 100%; justify-content: center; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: var(--fs-base); }
thead th {
  position: sticky; top: 0; background: var(--surface-2); z-index: 1;
  text-align: left; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-subtle); font-weight: 700; padding: var(--s2) var(--s3); border-bottom: 1px solid var(--border);
}
tbody td { padding: 10px var(--s3); border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td .row-actions { display: flex; gap: var(--s2); justify-content: flex-end; }
.t-right { text-align: right; }
.mono { font-family: ui-monospace, monospace; }

/* ---------- Badges / pills ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: var(--r-full);
  font-size: var(--fs-xs); font-weight: 600; line-height: 1.7;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-error { background: var(--error-bg); color: var(--error); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-neutral { background: #e2e8f0; color: var(--text-muted); }
.badge.plain::before { display: none; }
.env-dev { background: #e2e8f0; color: #475569; }
.env-test { background: var(--info-bg); color: var(--info); }
.env-prod { background: #ffe4e6; color: #be123c; }

/* ---------- Flash ---------- */
.flashes { margin-bottom: var(--s4); display: flex; flex-direction: column; gap: var(--s2); }
.flash { padding: 10px 14px; border-radius: var(--r); font-size: var(--fs-base); border: 1px solid transparent; }
.flash.ok { background: var(--ok-bg); color: var(--ok); border-color: #bbf7d0; }
.flash.error { background: var(--error-bg); color: var(--error); border-color: #fecaca; }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: var(--s7) var(--s5); color: var(--text-muted); }
.empty .empty-ico { font-size: 30px; opacity: .5; }
.empty h3 { margin: var(--s3) 0 var(--s1); color: var(--text); font-size: var(--fs-lg); }
.empty p { margin: 0 auto var(--s4); max-width: 420px; font-size: var(--fs-sm); }

/* ---------- Misc ---------- */
.muted { color: var(--text-muted); font-size: var(--fs-sm); }
.subtle { color: var(--text-subtle); font-size: var(--fs-xs); }
code { background: var(--surface-2); border: 1px solid var(--border); padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.token-box {
  display: flex; align-items: center; gap: var(--s2);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: var(--s2) var(--s3); font-family: ui-monospace, monospace; word-break: break-all;
}
.token-box .tk { flex: 1; }
details summary { cursor: pointer; }
.audit-full { white-space: pre-wrap; margin: 6px 0 0; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--r-sm); padding: var(--s2); max-width: 520px; }
.result-wrap { overflow-x: auto; }
.checklist { max-height: 360px; overflow-y: auto; border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: var(--s1); }
.check-row { display: flex; align-items: center; gap: var(--s2); padding: 6px 8px;
  border-radius: var(--r-sm); font-size: var(--fs-base); }
.check-row:hover { background: var(--surface-2); }
.check-row input { width: auto; }
.toolbar { display: flex; gap: var(--s2); align-items: center; margin-bottom: var(--s2); }
.toolbar input[type="search"] { max-width: 280px; }
.toolbar .check-row { white-space: nowrap; }
.tabs { display: flex; gap: var(--s1); border-bottom: 1px solid var(--border); margin-bottom: var(--s5); }
.tabs a {
  padding: var(--s2) var(--s3); color: var(--text-muted); font-weight: 600; font-size: var(--fs-base);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--brand-700); border-bottom-color: var(--brand); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--s4); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s4); box-shadow: var(--shadow); }
.stat .n { font-size: var(--fs-2xl); font-weight: 700; }
.stat .l { color: var(--text-subtle); font-size: var(--fs-sm); }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 40; width: var(--sidebar-w);
    transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-md);
  }
  .app.nav-open .sidebar { transform: translateX(0); }
  .hamburger { display: inline-block; }
  .scrim { display: none; position: fixed; inset: 0; background: rgba(15,23,42,.4); z-index: 30; }
  .app.nav-open .scrim { display: block; }
}
