/* ============================================================
   TadTech Document Engine — design system v2
   Dark navy sidebar · Teal accent · White content area
   ============================================================ */

:root {
  /* ── Palette ─────────────────────────────────────────── */
  --ink-900: #0C1628;
  --ink-800: #12203A;
  --ink-700: #1A2D45;
  --ink-600: #243850;
  --ink-line: #253548;

  --bg: #EEF2F7;
  --surface: #FFFFFF;
  --surface-2: #F6F9FC;
  --surface-3: #EEF2F7;
  --line: #E1E8F0;
  --line-strong: #C8D5E3;

  --text: #111827;
  --text-2: #546274;
  --text-3: #8C9BAD;
  --text-inv: #EBF0F8;
  --text-inv-2: #7E98B4;

  --accent: #0E8A99;
  --accent-600: #0A7381;
  --accent-700: #085F6B;
  --accent-50: #E0F5F7;
  --accent-100: #B3E7EC;

  --success: #1A9C5B;  --success-50: #E6F7EE;
  --warning: #C07A10;  --warning-50: #FDF3E0;
  --error:   #CC3C3C;  --error-50:   #FBE8E8;
  --purple:  #7C3AED;  --purple-50:  #F3EEFF;

  /* ── Aliases for backward-compat ───────────────────── */
  --fg: var(--text);
  --muted: var(--text-2);

  /* ── Radius / elevation / motion ───────────────────── */
  --r-xs: 6px;  --r-sm: 8px;  --r: 12px;  --r-lg: 16px;  --r-pill: 999px;
  --shadow-1: 0 1px 3px rgba(12,22,40,.06), 0 1px 2px rgba(12,22,40,.04);
  --shadow-2: 0 4px 16px rgba(12,22,40,.10), 0 1px 4px rgba(12,22,40,.06);
  --shadow-3: 0 20px 60px rgba(8,16,32,.28), 0 4px 16px rgba(8,16,32,.12);
  --ring: 0 0 0 3px rgba(14,138,153,.3);
  --t-fast: 120ms cubic-bezier(.4,0,.2,1);
  --t: 200ms cubic-bezier(.4,0,.2,1);

  --font-display: "Space Grotesk", "Segoe UI Semibold", system-ui, sans-serif;
  --font-ui: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;

  --sidebar-w: 260px;
}

/* ── Reset ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-ui);
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -.01em;
  margin: 0;
}
a { color: var(--accent-600); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }
code, kbd, .mono { font-family: var(--font-mono); }

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

/* ── Sidebar ────────────────────────────────────────── */
.sidebar {
  background: var(--ink-900);
  color: var(--text-inv);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--ink-line);
  z-index: 40;
  overflow: hidden;
}

/* Brand / logo */
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 16px;
  border-bottom: 1px solid var(--ink-line);
  flex: none;
}
.brand-mark {
  width: 36px; height: 36px; flex: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-700));
  display: grid; place-items: center; color: #fff;
  box-shadow: 0 2px 8px rgba(14,138,153,.4);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 14.5px; color: #fff; }
.brand-sub { font-size: 11px; color: var(--text-inv-2); letter-spacing: .02em; }

/* Nav */
.nav {
  padding: 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow-y: auto;
  flex: 1;
}
.nav::-webkit-scrollbar { width: 4px; }
.nav::-webkit-scrollbar-track { background: transparent; }
.nav::-webkit-scrollbar-thumb { background: var(--ink-600); border-radius: 4px; }

.nav-section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-inv-2);
  padding: 10px 10px 4px;
  opacity: .7;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  color: var(--text-inv-2);
  font-weight: 500;
  font-size: 13.5px;
  border: none;
  background: none;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background var(--t-fast), color var(--t-fast);
}
.nav-item svg { width: 17px; height: 17px; flex: none; }
.nav-item:hover { background: var(--ink-700); color: var(--text-inv); }
.nav-item.active {
  background: linear-gradient(90deg, var(--accent), var(--accent-600));
  color: #fff;
  box-shadow: var(--shadow-1);
}
.nav-item.active svg { opacity: 1; }

/* Sidebar foot */
.sidebar-foot {
  padding: 12px 10px;
  border-top: 1px solid var(--ink-line);
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Sidebar: user info widget */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  background: var(--ink-800);
  border: 1px solid var(--ink-line);
}
.sidebar-avatar {
  width: 32px; height: 32px; flex: none;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-700));
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px; color: #fff;
}
.sidebar-user-info { min-width: 0; flex: 1; }
.sidebar-user-name { font-size: 12.5px; font-weight: 600; color: var(--text-inv); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: 10.5px; color: var(--text-inv-2); text-transform: capitalize; }

/* Sidebar: tenant context chip */
.sidebar-tenant {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  background: rgba(14,138,153,.14);
  border: 1px solid rgba(14,138,153,.28);
  cursor: pointer;
  transition: background var(--t-fast);
}
.sidebar-tenant:hover { background: rgba(14,138,153,.24); }
.sidebar-tenant-label { font-size: 9.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--accent-100); font-weight: 700; display: block; }
.sidebar-tenant-name { font-size: 12.5px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-tenant-caret { color: var(--accent-100); flex: none; margin-left: auto; }

/* Sidebar: health */
.health-card { background: var(--ink-800); border: 1px solid var(--ink-line); border-radius: var(--r-sm); padding: 10px; display: flex; flex-direction: column; gap: 7px; }
.health-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-inv-2); }
.health-row .health-val { margin-left: auto; color: var(--text-inv); font-weight: 500; font-size: 11.5px; }
.health-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex: none; }
.health-dot.ok  { background: var(--success); box-shadow: 0 0 0 2px rgba(26,156,91,.25); }
.health-dot.warn { background: var(--warning); box-shadow: 0 0 0 2px rgba(192,122,16,.25); }
.health-dot.err  { background: var(--error);   box-shadow: 0 0 0 2px rgba(204,60,60,.25); }
.ver { color: var(--text-inv-2); font-size: 10.5px; text-align: center; font-family: var(--font-mono); margin: 2px 0 0; opacity: .6; }

/* Logout button (reuse nav-item style) */
#logoutBtn.nav-item { opacity: .75; }
#logoutBtn.nav-item:hover { opacity: 1; background: var(--error-50); color: var(--error); }

/* ── Main column ─────────────────────────────────────── */
.main { display: flex; flex-direction: column; min-width: 0; height: 100vh; overflow: hidden; }

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
  height: 60px;
  flex: none;
}
.topbar-title h1 { font-size: 18px; font-weight: 600; }
.page-sub { color: var(--text-2); font-size: 12px; margin: 1px 0 0; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.env-pill {
  font-size: 12px; color: var(--text-2);
  background: var(--surface-2); border: 1px solid var(--line);
  padding: 5px 12px; border-radius: var(--r-pill); font-weight: 500;
}
.key-status {
  display: flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 500;
  background: var(--surface); border: 1px solid var(--line);
  padding: 5px 12px; border-radius: var(--r-pill); box-shadow: var(--shadow-1);
  cursor: pointer; transition: border-color var(--t-fast);
}
.key-status:hover { border-color: var(--accent); }

.menu-btn { display: none; }
.icon-btn {
  width: 36px; height: 36px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--surface);
  cursor: pointer; display: grid; place-items: center;
  color: var(--text-2); transition: var(--t-fast);
}
.icon-btn:hover { color: var(--text); border-color: var(--line-strong); }
.icon-btn-danger:hover { color: var(--error); background: var(--error-50); border-color: #E9C4C4; }

/* ── Content area ────────────────────────────────────── */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 28px;
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(14,138,153,.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(14,138,153,.035) 1px, transparent 1px);
  background-size: 40px 40px;
  outline: none;
}
.view { max-width: 1100px; margin: 0 auto; animation: rise var(--t) both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.section { margin-bottom: 24px; }
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; margin-bottom: 14px;
}
.section-head h2 { font-size: 15px; }
.muted { color: var(--text-2); }
.eyebrow { font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); font-weight: 700; }

/* ── Login-page state ────────────────────────────────── */
.app.state-login { grid-template-columns: 1fr; }
.app.state-login .sidebar,
.app.state-login .topbar { display: none !important; }
.app.state-login .main { height: 100vh; overflow: hidden; }
.app.state-login .content {
  padding: 0;
  background-color: var(--ink-900);
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(14,138,153,.18) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(14,138,153,.12) 0%, transparent 50%);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Login card ──────────────────────────────────────── */
.login-wrap { width: 100%; max-width: 440px; padding: 20px; }
.login-card {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: 0 32px 80px rgba(0,0,0,.45), 0 4px 16px rgba(0,0,0,.2);
  padding: 36px;
  border: 1px solid rgba(255,255,255,.04);
}
.login-brand { text-align: center; margin-bottom: 28px; }
.login-logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 56px; height: 56px; border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent-700));
  box-shadow: 0 8px 24px rgba(14,138,153,.45);
  margin-bottom: 14px;
}
.login-title { font-family: var(--font-display); font-size: 22px; font-weight: 700; color: var(--text); margin: 0 0 4px; }
.login-sub { font-size: 13px; color: var(--text-2); margin: 0; }
.login-footer { text-align: center; margin-top: 20px; font-size: 11.5px; color: rgba(255,255,255,.28); }

/* ── Cards ───────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
}
.card-pad { padding: 18px; }
.card-accent-t { border-top: 3px solid var(--accent); }
.card-accent-success { border-top: 3px solid var(--success); }
.card-accent-warning { border-top: 3px solid var(--warning); }
.card-accent-purple  { border-top: 3px solid var(--purple); }

.grid { display: grid; gap: 14px; }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }

/* ── Stat tiles ──────────────────────────────────────── */
.stat { display: flex; flex-direction: column; gap: 5px; padding: 18px; }
.stat .stat-top { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.stat .stat-top svg { width: 15px; height: 15px; color: var(--accent); }
.stat .stat-val { font-family: var(--font-display); font-size: 32px; font-weight: 700; line-height: 1.1; color: var(--text); }
.stat .stat-sub { font-size: 12px; color: var(--text-3); }

/* ── Quick action cards ──────────────────────────────── */
.qa-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.qa-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 16px 18px;
  cursor: pointer; transition: all var(--t-fast);
  display: flex; align-items: flex-start; gap: 12px;
}
.qa-card:hover { border-color: var(--accent); box-shadow: var(--shadow-2); transform: translateY(-2px); }
.qa-icon {
  width: 38px; height: 38px; border-radius: 11px;
  background: var(--accent-50); color: var(--accent-700);
  display: flex; align-items: center; justify-content: center; flex: none;
}
.qa-icon.success { background: var(--success-50); color: var(--success); }
.qa-icon.warning { background: var(--warning-50); color: var(--warning); }
.qa-icon.purple  { background: var(--purple-50);  color: var(--purple); }
.qa-title { font-weight: 600; font-size: 13.5px; margin-bottom: 2px; }
.qa-desc  { font-size: 11.5px; color: var(--text-2); line-height: 1.4; }

/* ── Welcome banner ──────────────────────────────────── */
.welcome-banner {
  background: linear-gradient(120deg, var(--accent-700) 0%, var(--accent) 100%);
  border-radius: var(--r-lg); padding: 22px 26px;
  color: #fff; margin-bottom: 22px;
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
}
.welcome-banner h2 { color: #fff; font-size: 19px; margin-bottom: 3px; }
.welcome-banner p  { color: rgba(255,255,255,.78); font-size: 13px; margin: 0; }
.welcome-actions   { display: flex; gap: 10px; flex-wrap: wrap; margin-left: auto; }
.btn-inv { background: rgba(255,255,255,.18); color: #fff; border-color: rgba(255,255,255,.25); }
.btn-inv:hover { background: rgba(255,255,255,.28); }

/* ── Tenant-prompt (select tenant first) ─────────────── */
.tenant-prompt {
  display: flex; flex-direction: column; align-items: center;
  text-align: center; padding: 52px 32px;
  background: var(--surface); border: 1.5px dashed var(--line-strong);
  border-radius: var(--r-lg); max-width: 500px; margin: 5vh auto 0;
}
.tenant-prompt-icon {
  width: 56px; height: 56px; border-radius: 16px;
  background: var(--accent-50); color: var(--accent-700);
  display: flex; align-items: center; justify-content: center; margin: 0 auto 16px;
}
.tenant-prompt h2 { font-size: 18px; margin-bottom: 8px; }
.tenant-prompt p  { color: var(--text-2); font-size: 13.5px; margin: 0 0 20px; max-width: 360px; }

/* ── Template card ───────────────────────────────────── */
.tpl-card { display: flex; flex-direction: column; padding: 16px; transition: transform var(--t-fast), box-shadow var(--t-fast), border-color var(--t-fast); }
.tpl-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); border-color: var(--line-strong); }
.tpl-card .tpl-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.tpl-card h4 { font-size: 14.5px; line-height: 1.3; }
.tpl-key { font-family: var(--font-mono); font-size: 11px; color: var(--text-2); margin-top: 3px; }
.tpl-meta { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.tpl-actions { display: flex; gap: 6px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); flex-wrap: wrap; }

/* ── Pills / badges ──────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 700; padding: 3px 9px;
  border-radius: var(--r-pill); background: var(--surface-2);
  color: var(--text-2); border: 1px solid var(--line);
}
.pill-accent  { background: var(--accent-50);  color: var(--accent-700);  border-color: var(--accent-100); }
.pill-ok      { background: var(--success-50); color: var(--success);     border-color: var(--success-50); }
.pill-warn    { background: var(--warning-50); color: var(--warning);     border-color: var(--warning-50); }
.pill-err     { background: var(--error-50);   color: var(--error);       border-color: var(--error-50); }
.pill-count   { background: var(--ink-700);    color: var(--text-inv);    border: none; }
.pill-purple  { background: var(--purple-50);  color: var(--purple);      border-color: var(--purple-50); }

/* Status badges (documents) */
.status {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: var(--r-pill);
}
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-generated     { background: var(--success-50); color: var(--success); }
.status-generated_no_pdf { background: var(--warning-50); color: var(--warning); }
.status-draft         { background: var(--surface-2); color: var(--text-3); border: 1px solid var(--line); }
.status-failed        { background: var(--error-50);   color: var(--error); }
.status-archived      { background: var(--surface-2);  color: var(--text-3); opacity: .7; }

/* ── Data table ──────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th {
  text-align: left; padding: 10px 14px;
  font-size: 10.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-2);
  border-bottom: 2px solid var(--line); background: var(--surface-2);
}
.data-table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--surface-2); }

/* ── Chips ───────────────────────────────────────────── */
.chip {
  font-family: var(--font-mono); font-size: 11px;
  background: var(--accent-50); color: var(--accent-700);
  padding: 2px 7px; border-radius: 5px; border: 1px solid var(--accent-100);
}
.chip.none { background: var(--surface-2); color: var(--text-3); border-color: var(--line); font-family: var(--font-ui); font-style: italic; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }

/* ── Buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font-size: 13px; font-weight: 600; padding: 9px 15px;
  border-radius: var(--r-sm); border: 1px solid transparent;
  cursor: pointer; transition: var(--t-fast); white-space: nowrap;
  font-family: inherit;
}
.btn svg { width: 15px; height: 15px; }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn-primary   { background: var(--accent);   color: #fff; border-color: var(--accent);   box-shadow: var(--shadow-1); }
.btn-primary:hover { background: var(--accent-600); border-color: var(--accent-600); }
.btn-secondary { background: var(--surface);  color: var(--text); border-color: var(--line-strong); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent-700); }
.btn-ghost     { background: transparent; color: var(--text-2); border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger    { background: var(--surface);  color: var(--error); border-color: #E4C0C0; }
.btn-danger:hover { background: var(--error-50); }
.btn-inv       { background: rgba(255,255,255,.15); color: #fff; border-color: rgba(255,255,255,.25); }
.btn-inv:hover { background: rgba(255,255,255,.25); }
.btn-sm        { padding: 6px 11px; font-size: 12px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn-block     { width: 100%; }

/* ── Forms ───────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label, .label { font-size: 12.5px; font-weight: 600; color: var(--text); }
.field .hint { font-size: 11.5px; color: var(--text-2); font-weight: 400; }
.input,
input[type=text],
input[type=password],
input[type=email],
input[type=tel],
input[type=date],
input[type=number],
input[type=search],
select, textarea {
  width: 100%; font-family: inherit; font-size: 13.5px; color: var(--text);
  padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background: var(--surface); transition: border-color var(--t-fast), box-shadow var(--t-fast);
  appearance: none;
}
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23546274' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }
textarea { resize: vertical; min-height: 80px; }
.input:focus, input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.input-mono { font-family: var(--font-mono); font-size: 12.5px !important; }
.input-group { display: flex; gap: 8px; }
.input-group .input { flex: 1; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.req-star { color: var(--error); }

/* Dropzone */
.dropzone {
  border: 1.5px dashed var(--line-strong); border-radius: var(--r);
  padding: 20px; text-align: center; color: var(--text-2);
  background: var(--surface-2); transition: var(--t-fast); cursor: pointer;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-50); color: var(--accent-700); }
.dropzone strong { color: var(--text); }
.dropzone .fname { margin-top: 8px; font-family: var(--font-mono); font-size: 12px; color: var(--accent-700); }

/* ── Tables ──────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-1); }
table.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; font-size: 10.5px; letter-spacing: .05em;
  text-transform: uppercase; color: var(--text-3); font-weight: 700;
  padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--surface-2);
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--surface-2); }

/* ── Tabs ────────────────────────────────────────────── */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tab { background: none; border: none; padding: 10px 14px; font-size: 13.5px; font-weight: 600; color: var(--text-2); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; transition: var(--t-fast); }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent-700); border-bottom-color: var(--accent); }

/* ── Search bar ──────────────────────────────────────── */
.search { position: relative; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--text-3); pointer-events: none; }
.search input { padding-left: 34px; width: 280px; }

/* ── Code blocks ─────────────────────────────────────── */
.code {
  position: relative; background: var(--ink-800); color: #C9D8EF;
  border-radius: var(--r); padding: 14px 16px;
  font-family: var(--font-mono); font-size: 12.5px; line-height: 1.65;
  overflow-x: auto; white-space: pre; border: 1px solid var(--ink-line);
}
.code .copy-btn { position: absolute; top: 8px; right: 8px; }
.copy-btn { position: relative; }
.endpoint { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.method { font-family: var(--font-mono); font-weight: 700; font-size: 11px; padding: 3px 8px; border-radius: 6px; letter-spacing: .03em; }
.m-get    { background: var(--accent-50);  color: var(--accent-700); }
.m-post   { background: #E7F0FB;           color: #1D4ED8; }
.m-patch  { background: var(--warning-50); color: var(--warning); }
.m-delete { background: var(--error-50);   color: var(--error); }
.path-mono { font-family: var(--font-mono); font-size: 13px; color: var(--text); }

/* ── States ──────────────────────────────────────────── */
.empty { text-align: center; padding: 48px 24px; color: var(--text-2); }
.empty-ic {
  width: 50px; height: 50px; margin: 0 auto 14px; border-radius: 14px;
  display: grid; place-items: center; background: var(--accent-50); color: var(--accent);
}
.empty h3 { font-size: 16px; color: var(--text); margin-bottom: 6px; }
.empty p { font-size: 13.5px; max-width: 360px; margin: 0 auto; }

.error-box {
  background: var(--error-50); border: 1px solid #E4C0C0;
  color: #8B2020; padding: 14px 16px; border-radius: var(--r);
  display: flex; gap: 10px; align-items: flex-start;
}
.error-box svg { color: var(--error); flex: none; width: 18px; height: 18px; margin-top: 1px; }

.notice {
  padding: 10px 14px; border-radius: var(--r-sm);
  font-size: 13px; line-height: 1.5; margin-bottom: 10px;
  display: flex; gap: 8px; align-items: flex-start;
}
.notice svg { width: 16px; height: 16px; flex: none; margin-top: 1px; }
.notice-ok   { background: var(--success-50); color: #146C40; }
.notice-warn { background: var(--warning-50); color: #8A5A06; }
.notice-err  { background: var(--error-50);   color: #8B2020; }
.notice-info { background: var(--accent-50);  color: var(--accent-700); }

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, #E8EFF7 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--r-sm);
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.35); border-top-color: #fff;
  border-radius: 50%; animation: spin .65s linear infinite; display: inline-block;
}
.spinner.dark { border-color: rgba(14,138,153,.3); border-top-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toasts ──────────────────────────────────────────── */
.toast-stack { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 90; }
.toast {
  display: flex; align-items: center; gap: 10px;
  background: var(--ink-800); color: #fff;
  padding: 11px 16px; border-radius: var(--r); box-shadow: var(--shadow-3);
  font-size: 13.5px; font-weight: 500;
  min-width: 240px; max-width: 360px;
  animation: toastIn var(--t) both;
  border: 1px solid var(--ink-line);
}
.toast svg { width: 17px; height: 17px; flex: none; }
.toast.ok   svg { color: #4DD49A; }
.toast.err  svg { color: #F08080; }
.toast.info svg { color: #6FD3DE; }
@keyframes toastIn { from { opacity: 0; transform: translateX(18px); } to { opacity: 1; transform: none; } }

/* ── Tabs ────────────────────────────────────────────── */
.tab-bar { display: flex; gap: 4px; border-bottom: 1.5px solid var(--line); margin-bottom: 14px; }
.tab-btn {
  background: none; border: none; cursor: pointer;
  padding: 7px 14px; font-size: 13px; font-weight: 500; color: var(--text-2);
  border-bottom: 2px solid transparent; margin-bottom: -1.5px;
  transition: color var(--t-fast), border-color var(--t-fast);
  border-radius: var(--r) var(--r) 0 0;
}
.tab-btn:hover  { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* ── Modal ───────────────────────────────────────────── */
.overlay { position: fixed; inset: 0; background: rgba(8,16,32,.55); z-index: 50; animation: fade var(--t-fast) both; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  position: fixed; z-index: 60; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - 60px);
  overflow-y: auto;
  background: var(--surface); border-radius: var(--r-lg);
  box-shadow: var(--shadow-3);
  animation: pop var(--t) both;
}
@keyframes pop { from { opacity: 0; transform: translate(-50%, -46%) scale(.97); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }

/* ── Schema / KV ─────────────────────────────────────── */
.schema-row { display: grid; grid-template-columns: 1.1fr 1.4fr .9fr auto; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.kv { display: grid; grid-template-columns: 175px 1fr; gap: 5px 14px; font-size: 13px; }
.kv dt { color: var(--text-2); font-weight: 500; }
.kv dd { margin: 0; word-break: break-word; }

/* ── Integration cards ───────────────────────────────── */
.int-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.int-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 18px;
  display: flex; flex-direction: column; gap: 10px;
  transition: box-shadow var(--t-fast), border-color var(--t-fast);
}
.int-card:hover { box-shadow: var(--shadow-2); border-color: var(--line-strong); }
.int-card-head { display: flex; align-items: center; gap: 12px; }
.int-icon {
  width: 42px; height: 42px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; flex: none;
}
.int-icon-teal   { background: var(--accent-50);  color: var(--accent-700); }
.int-icon-purple { background: var(--purple-50);  color: var(--purple); }
.int-icon-blue   { background: #EBF3FF;           color: #1D4ED8; }
.int-icon-green  { background: var(--success-50); color: var(--success); }
.int-icon-orange { background: var(--warning-50); color: var(--warning); }
.int-icon-navy   { background: var(--ink-700);    color: var(--text-inv); }
.int-name { font-weight: 700; font-size: 15px; }
.int-desc { font-size: 12.5px; color: var(--text-2); line-height: 1.5; flex: 1; }
.int-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: var(--r-pill);
}
.int-badge-live    { background: var(--success-50); color: var(--success); }
.int-badge-soon    { background: var(--warning-50); color: var(--warning); }
.int-badge-planned { background: var(--surface-2);  color: var(--text-3); border: 1px solid var(--line); }
.int-connected-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); }

/* ── Audit log ───────────────────────────────────────── */
.audit-filter {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; margin-bottom: 16px;
  padding: 12px 14px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r);
}
.audit-filter select { width: auto; min-width: 150px; }
.audit-filter input  { width: auto; min-width: 200px; }
.audit-filter label  { font-size: 12px; font-weight: 600; color: var(--text-2); white-space: nowrap; }
.audit-action {
  font-family: var(--font-mono); font-size: 11.5px;
  background: var(--surface-2); padding: 2px 8px;
  border-radius: 5px; border: 1px solid var(--line);
  color: var(--text); white-space: nowrap;
}

/* ── Field editor ─────────────────────────────────────── */
.fe-wrap { display: flex; flex-direction: column; gap: 4px; }
.fe-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.fe-list { display: flex; flex-direction: column; gap: 6px; }
.fe-empty { display: flex; align-items: flex-start; gap: 8px; padding: 14px; background: var(--warning-50); border-radius: var(--r); color: var(--warning); font-size: 13px; line-height: 1.5; }
.fe-row { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; }
.fe-row-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.fe-row-extra { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.fe-row-btns { display: flex; gap: 2px; margin-left: auto; }
.fe-key-input { font-family: var(--font-mono); font-size: 12px !important; }
.fe-req-label { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-2); cursor: pointer; white-space: nowrap; }
.fe-req-label input { width: 15px; height: 15px; accent-color: var(--accent); }
.fe-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; cursor: help; }
.fe-dot-green  { background: var(--success); }
.fe-dot-yellow { background: var(--warning); }
.fe-dot-grey   { background: var(--line-strong); }
.fe-warn { color: var(--warning); font-size: 11px; margin-top: 4px; }
.fe-tok-example { display: inline-block; background: var(--accent-50); color: var(--accent-700); font-family: var(--font-mono); font-size: 13px; padding: 2px 8px; border-radius: 4px; }
.fe-guide { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 16px; margin-top: 14px; font-size: 12.5px; color: var(--text-2); }
.fe-guide p { margin: 4px 0; }
.fe-guide strong { color: var(--text); }

/* ── Generate form ───────────────────────────────────── */
.gen-field { margin-bottom: 12px; }

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 270px;
    transform: translateX(-100%); transition: transform var(--t);
    box-shadow: none;
  }
  .sidebar.open { transform: none; box-shadow: var(--shadow-3); }
  .menu-btn { display: grid; }
  .content { padding: 16px; }
  .search input { width: 100%; }
  .env-pill { display: none; }
  .field-row { grid-template-columns: 1fr; }
  .schema-row { grid-template-columns: 1fr 1fr; }
  .qa-grid { grid-template-columns: 1fr 1fr; }
  .int-grid { grid-template-columns: 1fr; }
  .welcome-banner { flex-direction: column; align-items: flex-start; }
  .welcome-actions { margin-left: 0; }
  .kv { grid-template-columns: 140px 1fr; }
}
@media (max-width: 500px) {
  .qa-grid { grid-template-columns: 1fr; }
  .login-card { padding: 24px 20px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* ── A11y ────────────────────────────────────────────── */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.nav-item:focus-visible, .tab:focus-visible { outline-offset: -2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ── Switch / toggle ─────────────────────────────────── */
.switch { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; cursor: pointer; user-select: none; }
.switch input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ── Misc ────────────────────────────────────────────── */
hr.divider { border: none; border-top: 1px solid var(--line); margin: 16px 0; }
.code-snippet {
  font-family: var(--font-mono); font-size: 11.5px;
  background: var(--surface-2); padding: 2px 7px;
  border-radius: 4px; border: 1px solid var(--line);
  color: var(--text); display: inline-block;
}
