/* Base tokens. Brand colors come from /brand.css (per company). */
:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --line: #e3e8ef;
  --line-strong: #cbd3de;
  --ink: #16202e;
  --ink-2: #4b5563;
  --ink-3: #7b8592;
  --ok: #178a4c;
  --ok-soft: #e3f5ea;
  --warn: #b45309;
  --warn-soft: #fdf1df;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --sidebar-w: 248px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
}
a { color: var(--brand-primary); }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.05rem; font-weight: 650; }
p { margin: 0 0 0.75rem; }
.muted { color: var(--ink-3); }
.mono { font-family: var(--mono); font-size: 0.85em; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
svg.lucide { width: 1.1em; height: 1.1em; vertical-align: -0.2em; flex: none; }

/* Shell ------------------------------------------------------------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  background: var(--brand-primary);
  color: var(--brand-primary-ink);
  display: flex;
  flex-direction: column;
  padding: 1rem 0.75rem;
  gap: 0.5rem;
  position: sticky;
  top: 0;
  height: 100vh;
  flex: none;
}
.brand { display: block; padding: 0.25rem 0.5rem 0.75rem; }
.brand img { width: 100%; max-height: 72px; object-fit: contain; object-position: left center; filter: drop-shadow(0 1px 0 rgba(255,255,255,0.15)); background: #fff; border-radius: var(--radius-sm); padding: 0.5rem; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.55rem 0.7rem; border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.86); text-decoration: none; font-weight: 500; font-size: 0.95rem;
}
.nav-item:hover { background: rgba(255,255,255,0.10); color: #fff; }
.nav-item.active { background: var(--brand-accent); color: var(--brand-accent-ink); }
.nav-item.soon { opacity: 0.55; cursor: default; }
.nav-item small { margin-left: auto; font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.8; }
.nav-section { margin: 0.75rem 0.7rem 0.25rem; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.1em; opacity: 0.6; }
.sidebar-foot { margin-top: auto; padding: 0.75rem 0.7rem 0; display: flex; flex-direction: column; font-size: 0.8rem; opacity: 0.8; }
.sidebar-company { font-weight: 600; }
.sidebar-tagline { text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.7rem; color: var(--brand-accent); }

.shell-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.6rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.topbar-menu { display: none; }
.search {
  flex: 1; max-width: 640px; display: flex; align-items: center; gap: 0.5rem;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 0.35rem 0.9rem;
  color: var(--ink-3);
}
.search:focus-within { border-color: var(--brand-primary); box-shadow: 0 0 0 3px var(--brand-primary-soft); }
.search input { flex: 1; border: 0; background: transparent; font: inherit; color: var(--ink); outline: none; min-width: 0; }
.search kbd { font-family: var(--mono); font-size: 0.7rem; border: 1px solid var(--line-strong); border-radius: 4px; padding: 0 5px; color: var(--ink-3); }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 0.6rem; }
.topbar-user-name { font-weight: 600; font-size: 0.9rem; }
.page { padding: 1.5rem 1.25rem 3rem; max-width: 1280px; width: 100%; }
.footer { margin-top: auto; padding: 1rem 1.25rem; color: var(--ink-3); font-size: 0.8rem; border-top: 1px solid var(--line); }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head p { margin: 0.2rem 0 0; }

/* Cards, grids ------------------------------------------------------ */
.grid { display: grid; gap: 1rem; margin-bottom: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.2rem; margin-bottom: 1rem; }
.card-flush { padding: 0; overflow: hidden; }
.card-flush .card-head { padding: 0.9rem 1.2rem; border-bottom: 1px solid var(--line); margin: 0; }
.card-head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.75rem; color: var(--brand-primary); }
.card-actions { display: flex; gap: 0.5rem; margin-top: 0.75rem; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.25rem 1rem; margin: 0; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; font-weight: 600; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.9rem 1.1rem; display: flex; flex-direction: column; gap: 0.15rem; }
.stat-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); }
.stat-value { font-size: 1.6rem; font-weight: 700; }
.stat-value.small { font-size: 0.95rem; font-family: var(--mono); }
.stat-bad { border-color: var(--bad); background: var(--bad-soft); }
.empty { padding: 2.5rem 1rem; text-align: center; color: var(--ink-3); }
.empty svg.lucide { width: 2rem; height: 2rem; }
.roadmap { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.4rem; }
.roadmap li { display: flex; gap: 0.6rem; align-items: baseline; color: var(--ink-2); }
.roadmap li.done { color: var(--ink); }
.roadmap li.done svg.lucide { color: var(--ok); }
.roadmap strong { color: var(--ink); margin-right: 0.35rem; }

/* Tables ------------------------------------------------------------ */
.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.table th, .table td { text-align: left; padding: 0.6rem 0.9rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table thead th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); background: var(--surface-2); }
.table tbody tr:hover { background: var(--surface-2); }
.table-inner { margin-top: 0.4rem; }
.table-inner th, .table-inner td { padding: 0.25rem 0.5rem; border-bottom: 1px dashed var(--line); }
details > summary { cursor: pointer; color: var(--brand-primary); }
.pre { font-family: var(--mono); font-size: 0.75rem; white-space: pre-wrap; background: var(--surface-2); padding: 0.6rem; border-radius: var(--radius-sm); max-height: 300px; overflow: auto; }

/* Badges ------------------------------------------------------------ */
.badge { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px; font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.badge-muted { background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); }
.badge-insert { background: var(--ok-soft); color: var(--ok); }
.badge-update { background: var(--brand-accent-soft); color: var(--brand-accent); }
.badge-delete { background: var(--bad-soft); color: var(--bad); }

/* Forms ------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.9rem; }
.field label, .check { font-size: 0.88rem; font-weight: 600; color: var(--ink-2); }
input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="number"],
input[type="tel"], input[type="url"], select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 0.55rem 0.7rem; width: 100%; min-height: 42px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand-primary); box-shadow: 0 0 0 3px var(--brand-primary-soft); }
input[type="file"] { font: inherit; }
input[type="color"] { width: 42px; height: 42px; padding: 0; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: none; }
.color-row { display: flex; gap: 0.5rem; align-items: center; }
.color-row input[type="text"] { font-family: var(--mono); }
.has-error input, .has-error select { border-color: var(--bad); }
.error { color: var(--bad); font-size: 0.82rem; margin: 0; }
.help { color: var(--ink-3); font-size: 0.82rem; margin: 0; }
.check { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 1rem; font-weight: 500; }
.check input { width: 18px; height: 18px; accent-color: var(--brand-accent); }
.form-actions { display: flex; gap: 0.6rem; justify-content: flex-end; margin: 0.5rem 0 1rem; }
.filter-row select { min-width: 200px; }
.inline-form { display: inline-block; }
.brand-preview { display: flex; align-items: center; gap: 0.6rem; padding: 0.75rem; border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); margin-bottom: 0.9rem; flex-wrap: wrap; }
.swatch { width: 28px; height: 28px; border-radius: 6px; border: 1px solid rgba(0,0,0,0.1); }
.preview-text { font-weight: 700; font-size: 1.1rem; }
.logo-preview { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0.75rem; display: flex; justify-content: center; }
.logo-preview img { max-height: 80px; max-width: 100%; }

/* Buttons ----------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font: inherit; font-weight: 600; font-size: 0.92rem;
  padding: 0.55rem 0.95rem; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  cursor: pointer; text-decoration: none; min-height: 42px;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--brand-accent); border-color: var(--brand-accent); color: var(--brand-accent-ink); }
.btn-primary:hover { filter: brightness(0.95); background: var(--brand-accent); }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 0.3rem 0.6rem; min-height: 32px; font-size: 0.82rem; }
.icon-btn { border: 0; background: transparent; color: var(--ink-2); cursor: pointer; padding: 0.35rem; border-radius: var(--radius-sm); display: inline-flex; font: inherit; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

/* Flash ------------------------------------------------------------- */
.flashes { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }
.flash { display: flex; align-items: center; gap: 0.6rem; padding: 0.65rem 0.9rem; border-radius: var(--radius-sm); border: 1px solid; font-size: 0.92rem; }
.flash span { flex: 1; }
.flash-success { background: var(--ok-soft); border-color: #b7e2c7; color: var(--ok); }
.flash-error { background: var(--bad-soft); border-color: #f2b8b3; color: var(--bad); }
.flash-info { background: var(--brand-primary-soft); border-color: var(--line-strong); color: var(--brand-primary); }

/* Auth pages -------------------------------------------------------- */
body.auth { background: linear-gradient(160deg, var(--brand-primary) 0%, var(--brand-primary-deep) 100%); min-height: 100vh; }
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border-radius: 14px; padding: 2rem 1.75rem; box-shadow: 0 20px 50px rgba(0,0,0,0.25); }
.auth-logo { display: block; width: 100%; max-height: 110px; object-fit: contain; margin-bottom: 0.5rem; }
.auth-tagline { text-align: center; text-transform: uppercase; letter-spacing: 0.18em; font-size: 0.75rem; color: var(--brand-accent); font-weight: 700; margin-bottom: 1.5rem; }
.auth-foot { text-align: center; color: var(--ink-3); font-size: 0.78rem; margin: 1.25rem 0 0; }
.error-card { text-align: center; }
.error-card svg.lucide { width: 2.5rem; height: 2.5rem; color: var(--brand-accent); margin-bottom: 0.5rem; }
.error-card h1 { margin-bottom: 0.4rem; }

/* Responsive -------------------------------------------------------- */
@media (max-width: 960px) {
  .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 20; transform: translateX(-100%); transition: transform 0.18s ease; box-shadow: 0 0 40px rgba(0,0,0,0.3); }
  .sidebar.open { transform: translateX(0); }
  .topbar-menu { display: inline-flex; }
  .topbar { padding: 0.5rem 0.9rem; }
  .topbar-user-name { display: none; }
  .search kbd { display: none; }
  .page { padding: 1rem 0.9rem 3rem; }
  .table { font-size: 0.85rem; }
  .table th, .table td { padding: 0.5rem 0.6rem; }
}
