/* Smart Link — admin theme (ink & brass) */

@font-face { font-family: 'Fraunces Disp'; font-weight: 500; font-style: normal; font-display: swap; src: url('../fonts/fraunces-500.woff2') format('woff2'); }
@font-face { font-family: 'Fraunces Disp'; font-weight: 600; font-style: normal; font-display: swap; src: url('../fonts/fraunces-600.woff2') format('woff2'); }
@font-face { font-family: 'Plex UI'; font-weight: 400; font-style: normal; font-display: swap; src: url('../fonts/plexsans-400.woff2') format('woff2'); }
@font-face { font-family: 'Plex UI'; font-weight: 500; font-style: normal; font-display: swap; src: url('../fonts/plexsans-500.woff2') format('woff2'); }
@font-face { font-family: 'Plex UI'; font-weight: 600; font-style: normal; font-display: swap; src: url('../fonts/plexsans-600.woff2') format('woff2'); }
@font-face { font-family: 'Plex Data'; font-weight: 400; font-style: normal; font-display: swap; src: url('../fonts/plexmono-400.woff2') format('woff2'); }
@font-face { font-family: 'Plex Data'; font-weight: 500; font-style: normal; font-display: swap; src: url('../fonts/plexmono-500.woff2') format('woff2'); }

:root {
  --ink-950: #0e1013;
  --ink-800: #16191d;
  --ink-700: #1e2227;
  --ink-600: #2a2f35;
  --paper-50: #f6f2ea;
  --paper-0: #fffdf9;
  --paper-200: #e7ded0;
  --paper-300: #d8ccb6;
  --brass-500: #b8874a;
  --brass-600: #9c6f39;
  --brass-700: #7c5928;
  --brass-200: #e9d3ae;
  --success: #4f8f5b;
  --warning: #b9862f;
  --danger: #b6503f;

  --bg-page: var(--paper-50);
  --bg-card: var(--paper-0);
  --bg-rail: #ffffff;
  --bg-hover: rgba(30, 24, 14, 0.03);
  --border-soft: var(--paper-200);
  --border-strong: var(--paper-300);
  --text-primary: #211d16;
  --text-secondary: #6b6459;
  --text-muted: #948c7c;
  --accent: var(--brass-600);
  --accent-text: var(--brass-700);
  --accent-tint: var(--brass-200);
  --shadow-card: 0 1px 2px rgba(30, 24, 14, 0.04);
  --danger-tint: rgba(182, 80, 63, 0.1);
  --success-tint: rgba(79, 143, 91, 0.1);
  --warning-tint: rgba(185, 134, 47, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-page: var(--ink-950);
    --bg-card: var(--ink-800);
    --bg-rail: #131619;
    --bg-hover: rgba(255, 255, 255, 0.03);
    --border-soft: var(--ink-700);
    --border-strong: var(--ink-600);
    --text-primary: #eee9df;
    --text-secondary: #a39c8d;
    --text-muted: #726b5e;
    --accent: var(--brass-500);
    --accent-text: #d7ad74;
    --accent-tint: rgba(184, 135, 74, 0.14);
    --shadow-card: none;
    --danger-tint: rgba(224, 122, 105, 0.12);
    --success-tint: rgba(111, 179, 124, 0.12);
    --warning-tint: rgba(214, 168, 92, 0.12);
  }
}
:root[data-theme="dark"] {
  --bg-page: var(--ink-950);
  --bg-card: var(--ink-800);
  --bg-rail: #131619;
  --bg-hover: rgba(255, 255, 255, 0.03);
  --border-soft: var(--ink-700);
  --border-strong: var(--ink-600);
  --text-primary: #eee9df;
  --text-secondary: #a39c8d;
  --text-muted: #726b5e;
  --accent: var(--brass-500);
  --accent-text: #d7ad74;
  --accent-tint: rgba(184, 135, 74, 0.14);
  --shadow-card: none;
  --danger-tint: rgba(224, 122, 105, 0.12);
  --success-tint: rgba(111, 179, 124, 0.12);
  --warning-tint: rgba(214, 168, 92, 0.12);
}
:root[data-theme="light"] {
  --bg-page: var(--paper-50);
  --bg-card: var(--paper-0);
  --bg-rail: #ffffff;
  --bg-hover: rgba(30, 24, 14, 0.03);
  --border-soft: var(--paper-200);
  --border-strong: var(--paper-300);
  --text-primary: #211d16;
  --text-secondary: #6b6459;
  --text-muted: #948c7c;
  --accent: var(--brass-600);
  --accent-text: var(--brass-700);
  --accent-tint: var(--brass-200);
  --shadow-card: 0 1px 2px rgba(30, 24, 14, 0.04);
  --danger-tint: rgba(182, 80, 63, 0.1);
  --success-tint: rgba(79, 143, 91, 0.1);
  --warning-tint: rgba(185, 134, 47, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: 'Plex UI', system-ui, sans-serif;
  overflow-x: hidden;
}

a { color: inherit; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

::selection { background: var(--accent-tint); color: var(--text-primary); }

::placeholder { color: var(--text-muted); }

/* ── Layout shell ───────────────────────────── */

:root { --rail-width: 240px; }

.rail {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--rail-width);
  height: 100vh;
  background: var(--bg-rail);
  border-right: 1px solid var(--border-soft);
  padding: 26px 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 30px;
  z-index: 1000;
  transition: transform 0.25s ease;
  overflow-y: auto;
}

.rail-brand {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-soft);
}
.rail-brand .mark {
  font-family: 'Fraunces Disp', serif;
  font-weight: 600;
  font-size: 21px;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 10px;
}
.rail-brand .mark img {
  width: 26px; height: 26px; border-radius: 6px; object-fit: cover;
}
.rail-brand .mark em {
  font-style: normal;
  color: var(--accent-text);
}
.rail-brand .tag {
  margin-top: 6px;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.rail-nav { display: grid; gap: 2px; }
.rail-nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-left: 2px solid transparent;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
  border-radius: 0 3px 3px 0;
}
.rail-nav a .nav-label { display: flex; align-items: center; gap: 10px; }
.rail-nav a .dot {
  width: 4px; height: 4px; border-radius: 50%;
  background: var(--border-strong);
  flex-shrink: 0;
}
.rail-nav a:hover { background: var(--bg-hover); color: var(--text-primary); }
.rail-nav a.active {
  color: var(--text-primary);
  border-left-color: var(--accent);
  background: var(--accent-tint);
}
.rail-nav a.active .dot { background: var(--accent); }

.rail-nav a .badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent-tint);
  color: var(--accent-text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: 'Plex Data', monospace;
  font-size: 11px;
}

.rail-group-label {
  margin: 16px 0 4px;
  padding: 0 12px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.rail-foot {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border-soft);
}
.rail-foot a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  border-radius: 3px;
}
.rail-foot a:hover { color: var(--text-primary); background: var(--bg-hover); }

.main {
  margin-left: var(--rail-width);
  min-height: 100vh;
  padding: 30px 40px 56px;
}
.main > .main-inner {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

.toggle {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border-soft);
  border-radius: 3px;
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  z-index: 1100;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(14, 16, 19, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 900;
}
.overlay.active { opacity: 1; pointer-events: auto; }

@media (max-width: 900px) {
  .rail { transform: translateX(-100%); width: min(280px, 86vw); }
  .rail.active { transform: translateX(0); }
  .main { margin-left: 0; padding: 78px 16px 28px; }
  .toggle { display: inline-flex; align-items: center; justify-content: center; }
}

/* ── Account menu ───────────────────────────── */

.account-shell {
  position: fixed;
  top: 18px;
  right: 26px;
  z-index: 1200;
}
.account-trigger {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
  padding: 8px 12px;
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  box-shadow: var(--shadow-card);
}
.account-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent-tint);
  color: var(--accent-text);
  display: inline-flex; align-items: center; justify-content: center;
  font-family: 'Fraunces Disp', serif;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
}
.account-copy { min-width: 0; display: grid; gap: 1px; text-align: left; }
.account-copy strong { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-copy span { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-caret { margin-left: auto; color: var(--text-muted); font-size: 11px; flex-shrink: 0; }

.account-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(300px, calc(100vw - 24px));
  padding: 8px;
  border-radius: 4px;
  border: 1px solid var(--border-soft);
  background: var(--bg-card);
  box-shadow: 0 12px 32px rgba(14,16,19,0.16);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-6px);
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.account-shell.open .account-dropdown { opacity: 1; pointer-events: auto; transform: translateY(0); }

.account-card { padding: 12px; }
.account-card-top { display: flex; align-items: center; gap: 10px; padding-bottom: 12px; border-bottom: 1px solid var(--border-soft); margin-bottom: 6px; }
.account-card .account-avatar { width: 40px; height: 40px; font-size: 15px; }
.account-meta strong { display: block; font-size: 13px; margin-bottom: 2px; }
.account-meta span { display: block; color: var(--text-muted); font-size: 11.5px; line-height: 1.4; word-break: break-word; }

.account-links { display: grid; gap: 2px; }
.account-links a {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 10px; border-radius: 3px; color: var(--text-primary);
  text-decoration: none; font-size: 12.5px; font-weight: 500;
}
.account-links a:hover { background: var(--bg-hover); }

@media (max-width: 900px) {
  .account-shell { top: 14px; right: 14px; left: 66px; }
  .account-trigger { width: 100%; min-width: 0; }
  .account-dropdown { width: 100%; }
}

/* ── Page chrome ────────────────────────────── */

.topline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 36px;
}
.search {
  border: none;
  border-bottom: 1px solid var(--border-strong);
  background: transparent;
  padding: 8px 2px;
  font-family: 'Plex UI', sans-serif;
  font-size: 13px;
  color: var(--text-primary);
  width: min(320px, 100%);
  outline: none;
}
.search:focus { border-color: var(--accent); }

.hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  margin-bottom: 34px;
  flex-wrap: wrap;
}
.hero-super {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-text);
  margin-bottom: 6px;
}
.hero h1 {
  margin: 0;
  font-family: 'Fraunces Disp', serif;
  font-weight: 600;
  font-size: 32px;
  letter-spacing: -0.015em;
  text-wrap: balance;
}
.hero p {
  margin: 8px 0 0;
  max-width: 60ch;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.6;
}
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ── Buttons ────────────────────────────────── */

.btn {
  font-family: 'Plex UI', sans-serif;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 10px 16px;
  border-radius: 3px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid transparent;
  line-height: 1.2;
}
.btn-primary { background: var(--accent); color: var(--paper-0); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-text); border-color: var(--accent-text); }
.btn-ghost { background: transparent; color: var(--text-primary); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--bg-hover); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-tint); }
.btn-sm { padding: 7px 12px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── KPI ledger ─────────────────────────────── */

.ledger {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  border-top: 1px solid var(--border-strong);
  border-bottom: 1px solid var(--border-strong);
  margin-bottom: 36px;
}
.ledger-item {
  padding: 20px 22px;
  border-left: 1px solid var(--border-soft);
}
.ledger-item:first-child { border-left: none; }
.ledger-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.ledger-value {
  margin-top: 10px;
  font-family: 'Plex Data', monospace;
  font-variant-numeric: tabular-nums;
  font-size: 28px;
  font-weight: 500;
  letter-spacing: -0.01em;
}
.ledger-delta { margin-top: 6px; font-size: 12px; color: var(--text-muted); }
.ledger-delta.up { color: var(--success); }
.ledger-delta.warn { color: var(--warning); }

@media (max-width: 720px) {
  .ledger { grid-template-columns: repeat(2, 1fr); }
  .ledger-item:nth-child(2n+1) { border-left: none; }
  .ledger-item:nth-child(n+3) { border-top: 1px solid var(--border-soft); }
}

/* ── Panels, tables ─────────────────────────── */

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: 4px;
  box-shadow: var(--shadow-card);
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border-soft);
  flex-wrap: wrap;
}
.panel-head h2 {
  margin: 0;
  font-family: 'Fraunces Disp', serif;
  font-weight: 600;
  font-size: 18px;
}
.panel-head p { margin: 4px 0 0; font-size: 12.5px; color: var(--text-muted); }
.panel-head .count { font-family: 'Plex Data', monospace; font-size: 12px; color: var(--text-muted); }
.panel-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.panel-body { padding: 22px 24px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  padding: 12px 24px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
}
thead th.num, tbody td.num { text-align: right; }
thead th.right, tbody td.right { text-align: right; }
tbody td {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13.5px;
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }
.num { font-family: 'Plex Data', monospace; font-variant-numeric: tabular-nums; }

.row-title { font-weight: 600; }
.row-sub { display: block; margin-top: 2px; font-size: 12px; color: var(--text-muted); }

.empty-row, .empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13.5px;
}
.empty-state strong { display: block; margin-bottom: 8px; font-family: 'Fraunces Disp', serif; font-size: 22px; font-weight: 600; color: var(--text-primary); }
.empty-state p { margin: 0 auto; max-width: 52ch; line-height: 1.7; }
.empty-state .hero-actions { justify-content: center; margin-top: 18px; }

/* ── Status / badges ────────────────────────── */

.status { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-secondary); }
.status .sw { width: 6px; height: 6px; border-radius: 50%; background: var(--success); flex-shrink: 0; }
.status.neutral .sw { background: var(--border-strong); }
.status.warn .sw { background: var(--warning); }
.status.danger .sw { background: var(--danger); }

.tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.tag-accent { background: var(--accent-tint); color: var(--accent-text); }
.tag-neutral { background: var(--bg-hover); color: var(--text-secondary); }
.tag-danger { background: var(--danger-tint); color: var(--danger); }
.tag-success { background: var(--success-tint); color: var(--success); }
.tag-warning { background: var(--warning-tint); color: var(--warning); }

/* ── Forms ──────────────────────────────────── */

.field { display: grid; gap: 7px; margin-bottom: 18px; }
.field label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.field small { font-size: 12px; color: var(--text-muted); }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 18px; }
.field.full { grid-column: 1 / -1; }

input:not([type]), input[type="text"], input[type="email"], input[type="password"],
input[type="search"], input[type="url"], input[type="number"], input[type="date"],
select, textarea {
  box-sizing: border-box;
  width: 100%;
  height: 44px;
  padding: 0 13px;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: 'Plex UI', sans-serif;
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.15s ease;
}

textarea { height: auto; padding: 11px 13px; }

input[type="password"]::-ms-reveal,
input[type="password"]::-ms-clear {
  display: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 110px; resize: vertical; }

.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }

button {
  font-family: 'Plex UI', sans-serif;
}

/* ── Flash / alerts ─────────────────────────── */

.flash {
  margin-bottom: 20px;
  padding: 13px 16px;
  border-radius: 3px;
  border: 1px solid var(--border-soft);
  font-size: 13.5px;
}
.flash.success { background: var(--success-tint); border-color: var(--success); color: var(--text-primary); }
.flash.error { background: var(--danger-tint); border-color: var(--danger); color: var(--text-primary); }

/* ── Pagination ─────────────────────────────── */

.pagination { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pagination a, .pagination span {
  min-width: 34px; height: 34px; padding: 0 10px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 3px; text-decoration: none; font-size: 12.5px; font-weight: 600;
  font-family: 'Plex Data', monospace;
}
.pagination a { border: 1px solid var(--border-soft); color: var(--text-primary); }
.pagination a:hover { border-color: var(--accent); }
.pagination .current { background: var(--accent); color: var(--paper-0); }
.pagination .disabled, .pagination .ellipsis { color: var(--text-muted); }

/* ── Ledger / KPI grid used on secondary pages ─ */

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1px; background: var(--border-soft); border: 1px solid var(--border-soft); margin-bottom: 32px; }
.stat-tile { background: var(--bg-card); padding: 18px 20px; }
.stat-tile .ledger-label { display: block; }
.stat-tile .ledger-value { display: block; }
