/* ============================================================
   CUSTAVS Control Plane — Design System
   Clean light admin. Indigo accent. Left-sidebar shell.
   No build step: plain CSS served from /public.
   ============================================================ */

/* ---------- Tokens ---------- */
:root {
  /* neutrals / surfaces */
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --surface-3: #f3f4f6;

  /* text */
  --text: #111827;
  --text-secondary: #4b5563;
  --muted: #6b7280;
  --faint: #9ca3af;

  /* borders */
  --line: #e6e8eb;
  --line-strong: #d5d8dd;

  /* accent (indigo) */
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-press: #3730a3;
  --accent-soft: #eef2ff;
  --accent-soft-border: #c7d2fe;
  --accent-contrast: #ffffff;

  /* status */
  --good: #059669;  --good-soft: #ecfdf5;  --good-border: #a7f3d0;
  --warn: #b45309;  --warn-soft: #fffbeb;  --warn-border: #fde68a;
  --bad:  #dc2626;  --bad-soft:  #fef2f2;  --bad-border:  #fecaca;
  --info: #0369a1;  --info-soft: #eff6ff;  --info-border: #bfdbfe;

  /* radii */
  --r-sm: 6px; --r: 8px; --r-md: 10px; --r-lg: 14px; --r-full: 999px;

  /* shadows */
  --shadow-xs: 0 1px 2px rgba(17,24,39,.05);
  --shadow-sm: 0 1px 3px rgba(17,24,39,.06), 0 1px 2px rgba(17,24,39,.04);
  --shadow-md: 0 6px 16px rgba(17,24,39,.08);
  --shadow-lg: 0 16px 40px rgba(17,24,39,.14);

  /* type */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, "Apple Color Emoji", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* metrics */
  --sidebar-w: 248px;
  --topbar-h: 60px;

  /* legacy aliases (older inline styles reference these) */
  --panel: var(--surface);
}

/* ---------- Reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; color: var(--text); }
p { margin: 0 0 12px; }
code { font-family: var(--mono); font-size: .86em; background: var(--surface-3); padding: 1px 5px; border-radius: 5px; }
pre {
  font-family: var(--mono); font-size: 12.5px; line-height: 1.55;
  background: #0f1729; color: #d7dce7; border: 1px solid #1f2a44;
  border-radius: var(--r); padding: 14px 16px; overflow: auto;
}
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #d7dbe0; border-radius: 999px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #c2c7ce; }

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  position: fixed; inset: 0 auto 0 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  z-index: 40;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px;
  height: var(--topbar-h); padding: 0 18px;
  border-bottom: 1px solid var(--line);
  font-weight: 700; letter-spacing: -0.02em; font-size: 15px; color: var(--text);
}
.sidebar .brand .logo {
  width: 26px; height: 26px; border-radius: 7px; flex: none;
  background: linear-gradient(135deg, var(--accent), #7c73f0);
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 13px;
  box-shadow: var(--shadow-sm);
}
.sidebar .brand .sub { font-size: 11px; font-weight: 500; color: var(--faint); letter-spacing: 0; }

.nav { flex: 1; overflow-y: auto; padding: 14px 12px; }
.nav-section { margin: 16px 8px 6px; font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); }
.nav-section:first-child { margin-top: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; margin: 1px 0;
  border-radius: var(--r); color: var(--text-secondary);
  font-weight: 500; font-size: 13.5px; line-height: 1;
  transition: background .12s ease, color .12s ease;
}
.nav-item:hover { background: var(--surface-3); color: var(--text); }
.nav-item svg { width: 18px; height: 18px; flex: none; stroke-width: 1.9; opacity: .8; }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item.active svg { opacity: 1; stroke-width: 2.1; }

.sidebar-footer { border-top: 1px solid var(--line); padding: 12px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: var(--r); }
.avatar {
  width: 32px; height: 32px; border-radius: var(--r-full); flex: none;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 700; font-size: 12px;
  border: 1px solid var(--accent-soft-border);
}
.user-chip .who { min-width: 0; }
.user-chip .who .name { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip .who .role { font-size: 11.5px; color: var(--faint); }

/* main column */
.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h); position: sticky; top: 0; z-index: 30;
  background: rgba(255,255,255,.86); backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 16px; padding: 0 24px;
}
.topbar .page-title { font-size: 15px; font-weight: 650; letter-spacing: -0.01em; }
.topbar .grow { flex: 1; }
.topbar .topbar-actions { display: flex; align-items: center; gap: 10px; }
.nav-toggle { display: none; }

.content { padding: 26px 24px 64px; width: 100%; max-width: 1180px; margin: 0 auto; }

/* ---------- Page header / toolbar ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-head .lead { color: var(--muted); font-size: 13.5px; margin-top: 4px; max-width: 62ch; }
.section-title { font-size: 14px; font-weight: 650; color: var(--text); margin: 26px 0 12px; }
.section-title:first-child { margin-top: 0; }

/* ---------- Buttons ---------- */
.btn, button, a.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  font-family: inherit; font-size: 13.5px; font-weight: 600; line-height: 1;
  padding: 8px 13px; border-radius: var(--r); cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  transition: background .12s, border-color .12s, box-shadow .12s, color .12s;
  white-space: nowrap;
}
.btn:hover, button:hover, a.btn:hover { background: var(--surface-3); border-color: var(--line-strong); color: var(--text); }
.btn svg, button svg { width: 15px; height: 15px; }
.btn-primary, button.btn-primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-contrast);
  box-shadow: var(--shadow-xs);
}
.btn-primary:hover, button.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn-danger, button.btn-danger { background: var(--surface); border-color: var(--bad-border); color: var(--bad); }
.btn-danger:hover, button.btn-danger:hover { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.btn-sm, button.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-3); }
/* inline text button */
.btn.link, button.link, a.link {
  background: none; border: none; padding: 0; color: var(--accent);
  font-weight: 600; font-size: inherit; box-shadow: none;
}
.btn.link:hover, button.link:hover { background: none; color: var(--accent-hover); text-decoration: underline; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 18px; box-shadow: var(--shadow-xs);
}
.card + .card { margin-top: 16px; }
.card-title { font-size: 14px; font-weight: 650; margin-bottom: 14px; }

/* ---------- Stat cards (KPIs) ---------- */
.cards, .stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat, .cards > .card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 16px 18px; box-shadow: var(--shadow-xs); }
.stat .k, .card .k, .stat-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.stat .v, .card .v, .stat-value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin-top: 7px; color: var(--text); }

/* ---------- Tables ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; box-shadow: var(--shadow-xs); }
table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; box-shadow: var(--shadow-xs); }
thead th {
  text-align: left; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); background: var(--surface-2); padding: 10px 14px; border-bottom: 1px solid var(--line);
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--line); font-size: 13.5px; color: var(--text-secondary); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: var(--surface-2); }
th[width], td.num { text-align: left; }
/* key/value detail table */
table.kv th { text-transform: none; letter-spacing: 0; color: var(--muted); font-weight: 600; width: 190px; background: var(--surface-2); }

/* ---------- Badges / status pills ---------- */
.badge, .pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: var(--r-full);
  font-size: 12px; font-weight: 600; line-height: 1.5;
  background: var(--surface-3); color: var(--text-secondary); border: 1px solid var(--line);
}
.badge-success { background: var(--good-soft); color: var(--good); border-color: var(--good-border); }
.badge-warning { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-border); }
.badge-danger  { background: var(--bad-soft);  color: var(--bad);  border-color: var(--bad-border); }
.badge-info    { background: var(--info-soft); color: var(--info); border-color: var(--info-border); }
.badge-accent  { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-soft-border); }
.badge .dot { width: 6px; height: 6px; border-radius: 999px; background: currentColor; }

/* ---------- Forms ---------- */
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
input, select, textarea {
  width: 100%; font-family: inherit; font-size: 13.5px; color: var(--text);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r);
  padding: 8px 11px; transition: border-color .12s, box-shadow .12s;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input[readonly] { background: var(--surface-3); color: var(--muted); cursor: not-allowed; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }
.field { margin-bottom: 14px; }
.form-grid { display: grid; gap: 14px; }
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin-bottom: 18px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); }
.filters label { margin-bottom: 5px; }
.filters .field, .filters > div { margin-bottom: 0; }

/* ---------- Alerts ---------- */
.alert, .notice {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 14px; border-radius: var(--r); margin-bottom: 18px;
  font-size: 13.5px; font-weight: 500; border: 1px solid transparent;
}
.notice { background: var(--good-soft); color: #065f46; border-color: var(--good-border); }
.alert  { background: var(--bad-soft);  color: #991b1b; border-color: var(--bad-border); }

/* ---------- Pagination ---------- */
.pager, .pagination { display: flex; gap: 12px; align-items: center; margin-top: 18px; font-size: 13px; }
.pager a, .pagination a {
  display: inline-flex; align-items: center; padding: 6px 12px;
  border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--surface); color: var(--text); font-weight: 600;
}
.pager a:hover, .pagination a:hover { background: var(--surface-3); }

/* ---------- Empty states ---------- */
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }

/* ---------- Helpers ---------- */
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.row { display: flex; gap: 12px; align-items: center; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.stack { display: grid; gap: 14px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.truncate { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* ---------- Auth (login) ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(1200px 500px at 50% -10%, #eef1f8, var(--bg)); padding: 24px; }
.auth-card { width: 380px; max-width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); padding: 30px 28px; }
.auth-card .brand { display: flex; align-items: center; gap: 11px; margin-bottom: 22px; }
.auth-card .brand .logo { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, var(--accent), #7c73f0); display: grid; place-items: center; color: #fff; font-weight: 800; box-shadow: var(--shadow-sm); }
.auth-card h1 { font-size: 18px; }
.auth-card .brand .sub { font-size: 12px; color: var(--faint); }
.auth-card .field { margin-bottom: 16px; }
.auth-card button[type=submit] { width: 100%; margin-top: 6px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 500; margin-bottom: 4px; }
.check input { width: auto; }

/* Grid of labelled checkboxes (roles, brands, permissions). */
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 4px 18px; margin-top: 4px; }
.check-grid-wide { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.check-grid .check { margin-bottom: 0; padding: 4px 2px; cursor: pointer; }
.check-grid .check span { color: var(--text-secondary); }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow-lg); }
  .nav-toggle-cb:checked ~ .app .sidebar { transform: translateX(0); }
  .main { margin-left: 0; }
  .nav-toggle { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: var(--r); border: 1px solid var(--line-strong); background: var(--surface); cursor: pointer; }
  .content { padding: 20px 16px 56px; }
}
.nav-toggle-cb { position: absolute; opacity: 0; pointer-events: none; }
