/* iTraffic 26 design system — single source of truth for all component styles. */

:root {
  --bg: #0b0d10;
  --surface: #14171c;
  --surface-2: #1a1e24;
  --text: #e8e7e4;
  --text-dim: #8a8e96;
  --text-muted: #5e6166;
  --accent: #e8a030;
  --accent-soft: rgba(232, 160, 48, 0.12);
  --border: #232830;
  --border-strong: #2c323b;

  --success: #80d0a0;
  --success-soft: rgba(64, 180, 120, 0.12);
  --warning: var(--accent);
  --warning-soft: var(--accent-soft);
  --danger: #f08070;
  --danger-soft: rgba(232, 80, 60, 0.12);

  --radius: 6px;
  --radius-sm: 4px;
  --shadow-sm: 0 1px 0 rgba(0,0,0,0.3);
}

*, *::before, *::after { box-sizing: border-box; }
html { scrollbar-gutter: stable; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  text-wrap: pretty;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  text-wrap: balance;
  margin: 0 0 0.5em;
  letter-spacing: -0.005em;
}
h1 { font-size: 1.7rem; }
h2 { font-size: 1.05rem; }
code, pre, .mono { font-family: 'JetBrains Mono', ui-monospace, monospace; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.5rem 0; }

/* Default shell — used by login/forgot/reset (no sidebar). */
.shell { max-width: 960px; margin: 0 auto; padding: 4rem 1.5rem; }

/* Default form-control styling — dark theme everywhere unless overridden. */
input[type="text"], input[type="number"], input[type="date"], input[type="email"],
input[type="password"], input[type="search"], input[type="tel"], input[type="url"],
input[type="time"], input[type="datetime-local"], input:not([type]),
select, textarea {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.6rem;
  font: inherit;
  font-size: 0.88rem;
  line-height: 1.4;
  transition: border-color 0.12s ease;
}
input[type="text"]:focus, input[type="number"]:focus, input[type="date"]:focus,
input[type="email"]:focus, input[type="password"]:focus, input[type="search"]:focus,
input[type="tel"]:focus, input[type="url"]:focus, input[type="time"]:focus,
input[type="datetime-local"]:focus, input:not([type]):focus,
select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
}
textarea { resize: vertical; min-height: 4rem; }
input::placeholder, textarea::placeholder { color: var(--text-muted); }
select {
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='%238a8e96' d='M0 0l5 6 5-6z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
  padding-right: 1.6rem;
}
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }

/* App shell — sidebar + main, horizontally centered as a single unit. */
.app {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
  max-width: 1400px;
  margin: 0 auto;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}
.app .main { padding: 2rem 2rem 4rem; min-width: 0; }

/* Mobile topbar — hidden by default, shown ≤860px. */
.mobile-topbar { display: none; }
.nav-scrim { display: none; }

@media (max-width: 860px) {
  body { overflow-x: hidden; }
  .mobile-topbar {
    display: flex; align-items: center; gap: 0.6rem;
    position: sticky; top: 0; z-index: 30;
    padding: 0.5rem 0.9rem;
    background: var(--surface); border-bottom: 1px solid var(--border);
    height: 52px;
  }
  .mobile-topbar .hamburger {
    display: inline-flex; flex-direction: column; justify-content: space-between;
    width: 36px; height: 28px; padding: 4px;
    background: transparent; border: 0; cursor: pointer;
  }
  .mobile-topbar .hamburger span {
    display: block; height: 2px; width: 100%; background: var(--text); border-radius: 1px;
    transition: transform 0.2s ease, opacity 0.15s ease;
  }
  .mobile-topbar .hamburger[aria-expanded="true"] span:nth-child(1) { transform: translateY(8px) rotate(45deg); }
  .mobile-topbar .hamburger[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
  .mobile-topbar .hamburger[aria-expanded="true"] span:nth-child(3) { transform: translateY(-8px) rotate(-45deg); }
  .mobile-topbar .mobile-brand { display: inline-flex; align-items: baseline; gap: 0.3rem; color: var(--text); }
  .mobile-topbar .brand-name { font-family: 'Fraunces', serif; font-weight: 600; font-size: 1.1rem; color: var(--text); }
  .mobile-topbar .brand-version { font-family: 'JetBrains Mono', monospace; font-size: 0.7rem; color: var(--accent); letter-spacing: 0.06em; }

  .app { grid-template-columns: 1fr; border: 0; max-width: none; }
  .app .main { padding: 1rem 1rem 3rem; }
}

/* Touch targets: 44px min on mobile. */
@media (max-width: 860px) {
  button, .action-link, .sidebar a { min-height: 40px; }
  input, select, textarea { font-size: 16px; }  /* prevents iOS zoom-on-focus */
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.1rem 0 1rem;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  font-size: 0.92rem;
}
.sidebar .brand {
  display: flex; align-items: baseline; gap: 0.4rem;
  padding: 0 1.2rem 0.9rem; margin-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.sidebar .brand:hover { text-decoration: none; }
.sidebar .brand:hover .brand-name { color: var(--accent); }
.sidebar .brand-name {
  font-family: 'Fraunces', serif; font-weight: 600; font-size: 1.2rem; letter-spacing: -0.01em; color: var(--text);
}
.sidebar .brand-version {
  font-family: 'JetBrains Mono', monospace; font-weight: 500; font-size: 0.72rem; color: var(--accent); letter-spacing: 0.06em;
}
.sidebar-search { padding: 0.4rem 1rem 0.6rem; }
.sidebar-search input {
  width: 100%;
  padding: 0.45rem 0.7rem;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font: inherit; font-size: 0.85rem;
  transition: border-color 0.12s ease;
}
.sidebar-search input:focus { outline: none; border-color: var(--accent); }
.sidebar-section {
  padding: 0.8rem 1rem 0.2rem;
  font-family: 'JetBrains Mono', monospace; font-weight: 500;
  font-size: 0.66rem; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--text-muted);
}
.sidebar a {
  display: flex; align-items: center; gap: 0.55rem;
  padding: 0.42rem 1rem;
  color: var(--text); text-decoration: none;
  border-left: 2px solid transparent;
  transition: background 0.1s ease, color 0.1s ease, border-color 0.1s ease;
}
.sidebar a:hover { background: var(--surface-2); color: var(--accent); text-decoration: none; }
.sidebar a[aria-current="page"] {
  color: var(--accent); background: var(--accent-soft); border-left-color: var(--accent);
}
.sidebar .footer-block {
  margin-top: auto; padding: 0.9rem 1rem 0;
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 0.4rem;
}
.sidebar .who {
  font-size: 0.78rem; color: var(--text-dim);
  display: flex; flex-direction: column; gap: 0.1rem;
}
.sidebar .who strong { color: var(--text); font-weight: 500; font-size: 0.86rem; }
.sidebar .who .role { font-family: 'JetBrains Mono', monospace; font-size: 0.7rem; }
.sidebar .signout {
  font-size: 0.82rem; color: var(--text-dim); padding: 0.3rem 0;
}
.sidebar .signout:hover { color: var(--danger); background: transparent; border-left-color: transparent; }

/* Legacy .topnav-search input kept so the JS shortcut keeps working on any old page. */
.topnav-search input { display: none; }

/* ---------- Buttons ---------- */
.btn, button.btn, a.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.55rem 1rem; border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  font: inherit; font-size: 0.88rem; font-weight: 500; cursor: pointer; line-height: 1;
  text-decoration: none;
  transition: all 0.1s ease;
}
.btn:hover { border-color: var(--border-strong); background: var(--surface-2); }
.btn-primary { background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-danger { color: var(--danger); border-color: rgba(232,80,60,0.3); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.8rem; }
.btn-icon-only { padding: 0.3rem 0.5rem; }

/* Header action button — small outline next to a heading */
.action-link {
  font-size: 0.85rem; font-family: 'Inter', sans-serif; font-weight: 500;
  padding: 0.35rem 0.9rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); background: transparent;
}
.action-link:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.action-link.primary { background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 600; }
.action-link.primary:hover { filter: brightness(1.08); color: var(--bg); }

/* ---------- Form fields ---------- */
.edit-form { max-width: 760px; }
.edit-form fieldset {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.4rem; margin-bottom: 1.4rem;
  background: var(--surface);
}
.edit-form legend {
  padding: 0 0.5rem; color: var(--text-dim); font-size: 0.78rem;
  letter-spacing: 0.05em; text-transform: uppercase;
}
.edit-form label {
  display: block; font-size: 0.82rem; color: var(--text-dim);
  margin: 0.9rem 0 0.3rem;
}
.edit-form input[type=text],
.edit-form input[type=date],
.edit-form input[type=number],
.edit-form input[type=password],
.edit-form input[type=email],
.edit-form select,
.edit-form textarea {
  width: 100%; padding: 0.55rem 0.7rem;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font: inherit; font-size: 0.92rem;
  transition: border-color 0.12s ease;
}
.edit-form textarea { resize: vertical; min-height: 5rem; font-family: inherit; }
.edit-form input:focus, .edit-form select:focus, .edit-form textarea:focus {
  outline: none; border-color: var(--accent);
}
.edit-form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.edit-form .row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
@media (max-width: 600px) { .edit-form .row, .edit-form .row-3 { grid-template-columns: 1fr; } }
.edit-form .checkbox-row {
  display: flex; gap: 1.4rem; align-items: center; margin-top: 0.6rem; flex-wrap: wrap;
}
.edit-form .checkbox-row label {
  display: inline-flex; gap: 0.4rem; align-items: center;
  margin: 0; color: var(--text); font-size: 0.92rem;
}
.edit-form .actions { display: flex; gap: 0.7rem; align-items: center; margin-top: 1rem; }
.edit-form button[type=submit] {
  padding: 0.6rem 1.4rem; background: var(--accent); color: var(--bg);
  border: 0; border-radius: var(--radius-sm);
  font: inherit; font-weight: 600; cursor: pointer;
}
.edit-form .cancel { color: var(--text-dim); }
.edit-form .err { color: var(--danger); font-size: 0.82rem; margin-top: 0.3rem; }

/* ---------- Cards / sections ---------- */
.detail-section, .card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.2rem 1.4rem; margin-bottom: 1.4rem;
}
.detail-section h2, .card h2 {
  font-size: 0.95rem; font-family: 'Inter', sans-serif; font-weight: 600;
  color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em;
  margin: 0 0 0.8rem;
}

.kv {
  display: grid; grid-template-columns: 140px 1fr;
  gap: 0.45rem 1rem; font-size: 0.9rem;
}
.kv .k { color: var(--text-dim); }

.body-text { line-height: 1.55; color: var(--text); white-space: pre-wrap; }

.meta { color: var(--text-dim); font-size: 0.82rem; }

.crumbs { color: var(--text-dim); font-size: 0.85rem; margin-bottom: 0.4rem; }
.crumbs a { color: var(--text-dim); }
.crumbs a:hover { color: var(--text); }

/* ---------- Tables ---------- */
.lineitems {
  width: 100%; border-collapse: collapse; font-size: 0.9rem;
}
.lineitems th {
  text-align: left; font-weight: 500;
  color: var(--text-dim); border-bottom: 1px solid var(--border);
  padding: 0.55rem 0.6rem;
  font-size: 0.74rem; letter-spacing: 0.06em; text-transform: uppercase;
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.lineitems td { padding: 0.65rem 0.6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.lineitems tbody tr { transition: background 0.08s ease; }
.lineitems tbody tr:hover td { background: rgba(232, 160, 48, 0.025); }
.lineitems .right { text-align: right; }
.lineitems tfoot td { font-weight: 600; border-top: 1px solid var(--border); border-bottom: 0; }

/* ---------- Pills ---------- */
.pill {
  display: inline-block;
  padding: 0.15rem 0.55rem; border-radius: 999px;
  background: rgba(255,255,255,0.06); color: var(--text-dim);
  font-size: 0.72rem; font-weight: 500; letter-spacing: 0.02em;
  vertical-align: middle;
}
.pill.success, .pill.ok, .pill.active, .pill.paid, .pill.approved {
  background: var(--success-soft); color: var(--success);
}
.pill.warning, .pill.warn, .pill.pending, .pill.potential {
  background: var(--warning-soft); color: var(--warning);
}
.pill.danger, .pill.lost, .pill.unpaid, .pill.overdue {
  background: var(--danger-soft); color: var(--danger);
}
.pill.muted, .pill.draft, .pill.done, .pill.completed {
  background: rgba(160,160,170,0.08); color: var(--text-dim);
}

/* ---------- Sidecar lists ---------- */
.sidecar-list {
  font-size: 0.88rem; list-style: none; padding: 0; margin: 0;
}
.sidecar-list li {
  padding: 0.5rem 0; border-bottom: 1px solid var(--border);
}
.sidecar-list li:last-child { border-bottom: 0; }
.sidecar-list .meta { font-size: 0.78rem; }

/* ---------- Tiles (dashboard / KPI) ---------- */
.dash-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem; margin-bottom: 2rem;
}
.tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem 1.2rem;
}
.tile .label { color: var(--text-dim); font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.06em; }
.tile .value { font-family: 'Fraunces', serif; font-size: 1.7rem; font-weight: 600; margin-top: 0.3rem; line-height: 1.1; }
.tile .sub { color: var(--text-dim); font-size: 0.78rem; margin-top: 0.25rem; }
.tile.accent .value { color: var(--accent); }
.tile.danger .value { color: var(--danger); }
.tile.success .value { color: var(--success); }

/* ---------- Filter bar ---------- */
.filter-bar { display: flex; gap: 0.6rem; margin-bottom: 1.4rem; flex-wrap: wrap; align-items: center; }
.filter-bar input, .filter-bar select {
  padding: 0.55rem 0.7rem; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font: inherit; font-size: 0.88rem;
}
.filter-bar input:focus, .filter-bar select:focus { outline: none; border-color: var(--accent); }
.filter-bar button[type=submit] {
  padding: 0.55rem 1.1rem; background: var(--accent); color: var(--bg);
  border: 0; border-radius: var(--radius-sm); font: inherit; font-weight: 600; cursor: pointer;
}
.filter-bar .clear {
  background: transparent; color: var(--text-dim);
  border: 1px solid var(--border); padding: 0.55rem 0.9rem;
  border-radius: var(--radius-sm); text-decoration: none;
}

/* ---------- Pager ---------- */
.pager { margin-top: 1.6rem; display: flex; gap: 0.6rem; align-items: center; color: var(--text-dim); font-size: 0.88rem; }
.pager a, .pager span {
  padding: 0.35rem 0.7rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.pager a { color: var(--text); }
.pager .current { color: var(--accent); border-color: var(--accent); }

/* ---------- Flash messages ---------- */
.flash {
  padding: 0.7rem 0.9rem; border-radius: var(--radius-sm);
  margin-bottom: 1rem; font-size: 0.88rem;
  display: flex; align-items: center; justify-content: space-between; gap: 0.6rem;
  transition: opacity 0.4s ease, transform 0.4s ease, max-height 0.4s ease, padding 0.4s ease, margin 0.4s ease;
}
.flash.success { background: var(--success-soft); border: 1px solid rgba(64,180,120,0.3); color: var(--success); }
.flash.warning { background: var(--warning-soft); border: 1px solid rgba(232,160,48,0.3); color: var(--warning); }
.flash.danger,
.flash.csrf, .flash.error { background: var(--danger-soft); border: 1px solid rgba(232,80,60,0.3); color: var(--danger); }
.flash.muted { background: rgba(255,255,255,0.04); border: 1px solid var(--border); color: var(--text-dim); }
.flash.is-dismissing { opacity: 0; transform: translateY(-4px); max-height: 0; padding-top: 0; padding-bottom: 0; margin-bottom: 0; overflow: hidden; }

/* ---------- Empty state ---------- */
.empty {
  text-align: center; padding: 3rem 1.5rem;
  color: var(--text-dim);
  border: 1px dashed var(--border); border-radius: var(--radius);
  background: rgba(255,255,255,0.015);
}
.empty .empty-icon {
  display: block; margin: 0 auto 0.7rem; opacity: 0.4;
}
.empty .empty-title {
  font-family: 'Fraunces', serif; font-size: 1.05rem; color: var(--text);
  margin-bottom: 0.3rem; font-weight: 500;
}
.empty .empty-sub { font-size: 0.88rem; margin-bottom: 1.2rem; }

/* ---------- Galleries ---------- */
.gallery {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.7rem;
}
.gallery a {
  display: block; border: 1px solid var(--border); border-radius: var(--radius-sm);
  overflow: hidden; background: var(--bg);
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.gallery a:hover { border-color: var(--accent); transform: translateY(-1px); text-decoration: none; }
.gallery img { width: 100%; height: 130px; object-fit: cover; display: block; }
.gallery .caption {
  padding: 0.4rem 0.5rem; font-size: 0.78rem; color: var(--text-dim);
}

/* ---------- Login card (auth pages) ---------- */
.login-card {
  max-width: 400px; margin: 6rem auto; padding: 2.5rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}
.login-card h1 { font-size: 1.6rem; margin-bottom: 0.4rem; }
.login-card .lead { color: var(--text-dim); font-size: 0.9rem; margin-bottom: 1.8rem; }
.login-card label {
  display: block; font-size: 0.82rem; color: var(--text-dim);
  margin: 1rem 0 0.35rem; letter-spacing: 0.02em;
}
.login-card input {
  width: 100%; padding: 0.7rem 0.9rem;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font: inherit; font-size: 0.95rem;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-card button {
  width: 100%; margin-top: 1.6rem; padding: 0.7rem;
  background: var(--accent); color: var(--bg);
  border: 0; border-radius: var(--radius-sm);
  font: inherit; font-weight: 600; cursor: pointer;
}
.login-card button:hover { filter: brightness(1.08); }
.login-card .alert {
  margin-top: 1rem; padding: 0.7rem 0.9rem;
  background: var(--danger-soft); border: 1px solid rgba(232,80,60,0.3);
  border-radius: var(--radius-sm); color: var(--danger); font-size: 0.88rem;
}
.login-card .alert.success {
  background: var(--success-soft); border-color: rgba(64,180,120,0.3); color: var(--success);
}
.login-card .footer-link { text-align: center; margin-top: 1.4rem; font-size: 0.85rem; }
.login-card .footer-link a { color: var(--text-dim); }

/* ---------- Footer ---------- */
.footer {
  color: var(--text-dim); font-size: 0.8rem;
  margin-top: 4rem; padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

/* ---------- Misc ---------- */
.muted { color: var(--text-dim); }
.dim { color: var(--text-muted); }

/* ---------- Cmd-K palette ---------- */
.palette-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(5, 7, 10, 0.65);
  backdrop-filter: blur(2px);
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 12vh;
  opacity: 0; pointer-events: none;
  transition: opacity 0.15s ease;
}
.palette-backdrop.is-open { opacity: 1; pointer-events: auto; }
.palette {
  width: min(560px, 90vw);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  display: flex; flex-direction: column;
  max-height: 60vh;
  overflow: hidden;
  transform: translateY(-4px);
  transition: transform 0.15s ease;
}
.palette-backdrop.is-open .palette { transform: translateY(0); }
.palette-input {
  width: 100%;
  padding: 0.95rem 1.2rem;
  background: transparent; color: var(--text);
  border: 0; border-bottom: 1px solid var(--border);
  font: inherit; font-size: 1.05rem; font-family: 'Fraunces', serif;
}
.palette-input:focus { outline: none; }
.palette-input::placeholder { color: var(--text-muted); }
.palette-results { overflow-y: auto; padding: 0.4rem 0; }
.palette-section {
  padding: 0.5rem 1.2rem 0.2rem;
  font-size: 0.66rem; font-family: 'JetBrains Mono', monospace;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.1em;
}
.palette-item {
  display: grid; grid-template-columns: 70px 1fr auto;
  gap: 0.8rem; align-items: center;
  padding: 0.55rem 1.2rem;
  color: var(--text); cursor: pointer; text-decoration: none;
  font-size: 0.92rem;
}
.palette-item .kind {
  font-family: 'JetBrains Mono', monospace; font-size: 0.7rem;
  color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em;
}
.palette-item .label { color: var(--text); font-weight: 500; }
.palette-item .sublabel { color: var(--text-dim); font-size: 0.78rem; }
.palette-item .key {
  font-family: 'JetBrains Mono', monospace; font-size: 0.7rem;
  color: var(--text-muted);
  border: 1px solid var(--border); padding: 0.05rem 0.4rem; border-radius: 3px;
}
.palette-item.is-active, .palette-item:hover {
  background: var(--accent-soft); text-decoration: none;
}
.palette-item.is-active .label { color: var(--accent); }
.palette-empty {
  padding: 1.5rem 1.2rem; color: var(--text-dim); font-size: 0.88rem; text-align: center;
}
.palette-hint {
  border-top: 1px solid var(--border);
  padding: 0.55rem 1.2rem;
  font-size: 0.74rem; color: var(--text-muted);
  display: flex; gap: 1.2rem; justify-content: space-between;
  font-family: 'JetBrains Mono', monospace;
}

/* ---------- Project tabs ---------- */
.tabs {
  display: flex; gap: 0; border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem; flex-wrap: wrap;
}
.tabs a {
  padding: 0.7rem 1.1rem;
  color: var(--text-dim); text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-size: 0.9rem; font-weight: 500;
  transition: color 0.1s ease, border-color 0.1s ease;
}
.tabs a:hover { color: var(--text); }
.tabs a.is-active {
  color: var(--accent); border-bottom-color: var(--accent);
}
.tabs a .count {
  display: inline-block; margin-left: 0.35rem;
  padding: 0.05rem 0.4rem; border-radius: 999px;
  background: rgba(255,255,255,0.06); color: var(--text-dim);
  font-size: 0.72rem; font-family: 'JetBrains Mono', monospace; line-height: 1.4;
}
.tabs a.is-active .count { background: var(--accent-soft); color: var(--accent); }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* Print stylesheet — pared-down view of invoices/proposals/briefs/leads. */
@media print {
    body { background: #fff; color: #000; }
    .app { display: block; max-width: none; margin: 0; }
    .sidebar, .topbar, .filter-bar, .crumbs, .pager, .chip-row, .flash,
    .proj-actions, form.edit-form, .actions, button, .action-link,
    .collab form, .collab .pill, .collab h2, .collab h3,
    [data-no-print], .empty-cta { display: none !important; }
    main { padding: 0; }
    h1, h2 { color: #000; page-break-after: avoid; }
    .detail-section { border: 0; padding: 0; margin: 0 0 1rem; box-shadow: none; }
    .detail-section h2 { border-bottom: 1px solid #ccc; padding-bottom: 0.2rem; margin-bottom: 0.5rem; }
    table.lineitems { border-collapse: collapse; width: 100%; }
    table.lineitems th, table.lineitems td { border-bottom: 1px solid #ccc; padding: 0.3rem 0.5rem; }
    table.lineitems thead th { border-bottom: 2px solid #000; }
    a, a:visited { color: #000; text-decoration: none; }
    .body-text, .kv { color: #000; }
    img { max-width: 100% !important; page-break-inside: avoid; }
}

/* ---------- Responsive: tables, forms, detail blocks ---------- */
@media (max-width: 860px) {
  /* Tables: horizontal scroll wrapper for any table that overflows. */
  table.lineitems { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
  table.lineitems th, table.lineitems td { white-space: nowrap; }

  /* Detail kv: stack rows. */
  .kv { grid-template-columns: 1fr !important; gap: 0.2rem 0; }
  .kv .k { color: var(--text-dim); font-size: 0.78rem; margin-top: 0.4rem; }

  /* Filter bar: wrap and stretch. */
  .filter-bar { flex-wrap: wrap; gap: 0.4rem; }
  .filter-bar input, .filter-bar select { min-width: 0; width: 100%; max-width: none; }
  .filter-bar input[type="text"] { flex: 1 1 100%; }

  /* Crumbs: smaller. */
  .crumbs { font-size: 0.78rem; }

  /* Detail section padding. */
  .detail-section { padding: 0.9rem; }

  /* Project actions row wraps. */
  .proj-actions { flex-wrap: wrap; gap: 0.4rem; }

  /* Headings: keep title + inline buttons readable when wrapped. */
  h1 { font-size: 1.5rem; line-height: 1.2; }
  h1 .pill, h1 .action-link, h1 form { display: inline-block; margin-left: 0; }

  /* Side-by-side layouts that should stack. */
  div[style*="grid-template-columns:2fr 1fr"] { grid-template-columns: 1fr !important; }

  /* Calendar: shrink cells, hide pad days, allow grid to scroll. */
  .cal-grid { grid-template-columns: repeat(7, minmax(46px, 1fr)); }
  .cal-day { min-height: 70px; padding: 0.25rem 0.3rem; }
  .cal-day .num { font-size: 0.7rem; }
  .cal-event { font-size: 0.66rem; padding: 0.1rem 0.3rem; }
  .cal-event .pill { display: none; }  /* save space; color of dot below conveys kind */

  /* Media grid: tighter on small screens. */
  .media-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)) !important; gap: 0.5rem; }

  /* Footer */
  .footer { font-size: 0.72rem; padding: 1.5rem 0 0; }
}

/* Tablet: keep sidebar visible but slimmer. */
@media (min-width: 861px) and (max-width: 1024px) {
  .app { grid-template-columns: 200px 1fr; }
  .sidebar { font-size: 0.86rem; }
  .sidebar a { padding: 0.36rem 0.85rem; }
  .app .main { padding: 1.4rem 1.4rem 3rem; }
}

/* Mobile sidebar drawer — must come AFTER the base .sidebar rules to win the cascade. */
@media (max-width: 860px) {
  .sidebar {
    position: fixed; top: 0; left: 0;
    width: 260px; height: 100vh; z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 0 0 0 1px var(--border);
  }
  .sidebar.is-open { transform: translateX(0); }
  .nav-scrim {
    position: fixed; inset: 0; z-index: 35;
    background: rgba(0,0,0,0.45);
    border: 0; padding: 0;
  }
  .nav-scrim[hidden] { display: none; }
}

/* ---------- Upload zone ---------- */
.upload-zone .upload-drop {
  display: flex; align-items: center; justify-content: center;
  border: 2px dashed var(--border); border-radius: var(--radius-sm);
  padding: 1.5rem 1rem; text-align: center; cursor: pointer;
  background: var(--surface-2); color: var(--text-dim);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.upload-zone .upload-drop:hover,
.upload-zone .upload-drop.is-drop { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.upload-zone .upload-drop strong { color: var(--text); }
.upload-zone .upload-filename { align-self: center; }
