/* ===================================================================
 * FFlirtyGo Ops Invoicing — Design System
 * Matches /opt/fflirtygo/dashboard/index.html (Command Center) tokens
 * Dark theme. Mobile-first. WCAG AA contrast.
 * =================================================================== */

:root {
  /* ---- Surface ---- */
  --bg:               #0b0c10;
  --bg-elev:          #12131b;
  --bg-elev-2:        #181924;
  --bg-input:         #0f1018;
  --border:           #252636;
  --border-subtle:    #1a1b25;
  --border-strong:    #3a3b48;

  /* ---- Text ---- */
  --text:             #e2e4ea;
  --text-2:           #a8aab5;
  --text-3:           #6b6d78;
  --text-4:           #4a4b56;

  /* ---- Brand / Status ---- */
  --ok:               #34d399;
  --warn:             #fbbf24;
  --err:              #f87171;
  --info:             #60a5fa;
  --accent:           #a78bfa;     /* secondary accent (target/lavender) */
  --accent-2:         #f97316;     /* tertiary accent (orange/spend) */

  --ok-bg:            rgba(52, 211, 153, 0.10);
  --warn-bg:          rgba(251, 191, 36, 0.10);
  --err-bg:           rgba(248, 113, 113, 0.10);
  --info-bg:          rgba(96, 165, 250, 0.10);

  /* ---- Type ---- */
  --font:             'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono:             'JetBrains Mono', 'SF Mono', Consolas, monospace;

  --t-xs:   11px;
  --t-sm:   12px;
  --t-base: 13px;
  --t-md:   14px;
  --t-lg:   16px;
  --t-xl:   20px;
  --t-2xl:  26px;

  /* ---- Spacing (4px base) ---- */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-8: 32px;
  --s-10: 40px;

  /* ---- Radius ---- */
  --r-sm: 4px;
  --r:    6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-pill: 9999px;

  /* ---- Shadow ---- */
  --shadow:    0 4px 20px rgba(0,0,0,.5);
  --shadow-sm: 0 2px 8px rgba(0,0,0,.4);

  /* ---- Motion ---- */
  --t-fast: 120ms ease;
  --t-base: 180ms ease;

  color-scheme: dark;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: var(--t-base); line-height: 1.5; min-height: 100%; }
input[type=date], input[type=datetime-local], select, textarea { color-scheme: dark; }

::-webkit-scrollbar       { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2a2b38; border-radius: 3px; }

a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font: inherit; }

/* ---------- Skip link (a11y) ---------- */
.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--info); color: var(--bg);
  padding: var(--s-2) var(--s-4); border-radius: 0 0 var(--r) 0;
  font-weight: 600;
}
.skip-link:focus { left: 0; }

/* ---------- Layout shell ---------- */
.shell { display: grid; grid-template-rows: auto 1fr; min-height: 100vh; }

.topbar {
  display: flex; align-items: center; gap: var(--s-6);
  padding: var(--s-3) var(--s-5);
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}
.topbar__brand {
  display: flex; align-items: center; gap: var(--s-3);
  font-weight: 700; font-size: var(--t-md); letter-spacing: .3px;
  color: var(--text);
}
.topbar__brand img {
  height: 22px; width: auto;
  filter: invert(1) brightness(1.4);   /* black wordmark on dark bg */
}
.topbar__brand small { color: var(--text-3); font-weight: 400; }
.auth__logo {
  display: block; margin: 0 auto var(--s-5);
  height: 40px; width: auto;
  filter: invert(1) brightness(1.4);
}
.topbar__nav { display: flex; gap: var(--s-1); flex: 1; }
.topbar__nav a {
  color: var(--text-2); padding: var(--s-2) var(--s-3); border-radius: var(--r);
  font-weight: 500; text-decoration: none; transition: var(--t-fast);
}
.topbar__nav a:hover { background: var(--bg-elev-2); color: var(--text); }
.topbar__nav a.active { background: var(--bg-elev-2); color: var(--text); }
.topbar__user { color: var(--text-2); font-size: var(--t-sm); }
.topbar__user a { color: var(--text-3); margin-left: var(--s-2); }

.main { padding: var(--s-5); max-width: 1600px; margin: 0 auto; width: 100%; }

@media (max-width: 720px) {
  .topbar { padding: var(--s-2) var(--s-3); flex-wrap: wrap; gap: var(--s-2); }
  .main { padding: var(--s-3); }
}

/* ---------- Banner (active OOS, status, etc.) ---------- */
.banner {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-4);
  background: var(--bg-elev); border: 1px solid var(--border);
  border-left: 3px solid var(--info);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
  margin-bottom: var(--s-4);
  font-size: var(--t-sm);
}
.banner--ok   { border-left-color: var(--ok); }
.banner--warn { border-left-color: var(--warn); }
.banner--err  { border-left-color: var(--err); }
.banner__meta { color: var(--text-2); }
.banner__meta strong { color: var(--text); font-weight: 600; }

/* ---------- Cards ---------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-5);
}
.card + .card { margin-top: var(--s-4); }
.card__head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--s-4); gap: var(--s-3);
}
.card__title { font-size: var(--t-md); font-weight: 600; color: var(--text); }
.card__sub { color: var(--text-3); font-size: var(--t-sm); }

/* ---------- Toolbar (filters above tables) ---------- */
.toolbar {
  display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center;
  padding: var(--s-3); background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--r-md); margin-bottom: var(--s-3);
}
.toolbar__sep { width: 1px; height: 18px; background: var(--border); margin: 0 var(--s-2); }
.toolbar__spacer { flex: 1; }

/* ---------- Inputs ---------- */
.field { display: flex; flex-direction: column; gap: var(--s-1); }
.field__label { font-size: var(--t-sm); color: var(--text-2); font-weight: 500; }
.field__hint  { font-size: var(--t-xs); color: var(--text-3); }
.field__error { font-size: var(--t-xs); color: var(--err); }

.input, .select, .textarea {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: var(--s-2) var(--s-3);
  font-family: inherit; font-size: var(--t-base);
  min-height: 36px;
  transition: border-color var(--t-fast), background var(--t-fast);
  width: 100%;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--info); background: var(--bg);
}
.input--mono { font-family: var(--mono); }
.input--invalid { border-color: var(--err); }
.input::placeholder { color: var(--text-4); }

.textarea { min-height: 100px; resize: vertical; font-family: var(--mono); font-size: var(--t-sm); }

.checkbox { width: 16px; height: 16px; accent-color: var(--info); cursor: pointer; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  background: var(--bg-elev-2); color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r); padding: var(--s-2) var(--s-3);
  font-weight: 500; font-size: var(--t-sm); cursor: pointer;
  min-height: 36px;
  transition: all var(--t-fast);
  text-decoration: none;
}
.btn:hover:not(:disabled) { border-color: var(--border-strong); background: #1f2030; }
.btn:focus-visible { outline: 2px solid var(--info); outline-offset: 2px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn--primary {
  background: var(--info); border-color: var(--info); color: #06121f;
  font-weight: 600;
}
.btn--primary:hover:not(:disabled) { background: #7eb8ff; border-color: #7eb8ff; }

.btn--danger {
  background: var(--err); border-color: var(--err); color: #1a0606;
  font-weight: 600;
}
.btn--danger:hover:not(:disabled) { background: #fa9999; border-color: #fa9999; }

.btn--ghost { background: transparent; }
.btn--sm { min-height: 28px; padding: var(--s-1) var(--s-2); font-size: var(--t-xs); }
.btn--lg { min-height: 44px; padding: var(--s-3) var(--s-5); font-size: var(--t-md); }
.btn--wide { width: 100%; }
.btn[aria-busy="true"] { pointer-events: none; opacity: .7; }

/* ---------- Pills / chips ---------- */
.pill {
  display: inline-flex; align-items: center; gap: var(--s-1);
  background: var(--bg-elev-2); color: var(--text-2);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  padding: 2px 10px;
  font-size: var(--t-xs); font-weight: 500;
  white-space: nowrap;
}
.pill--ok   { background: var(--ok-bg);   color: var(--ok);   border-color: rgba(52,211,153,.3); }
.pill--warn { background: var(--warn-bg); color: var(--warn); border-color: rgba(251,191,36,.3); }
.pill--err  { background: var(--err-bg);  color: var(--err);  border-color: rgba(248,113,113,.3); }
.pill--info { background: var(--info-bg); color: var(--info); border-color: rgba(96,165,250,.3); }

/* Filter chip (toggleable) */
.chip {
  display: inline-flex; align-items: center; gap: var(--s-1);
  background: transparent; color: var(--text-2);
  border: 1px solid var(--border); border-radius: var(--r-pill);
  padding: var(--s-1) var(--s-3); font-size: var(--t-xs); font-weight: 500;
  cursor: pointer; user-select: none; transition: all var(--t-fast);
}
.chip:hover { color: var(--text); border-color: var(--border-strong); }
.chip[aria-pressed="true"] {
  background: var(--info-bg); color: var(--info); border-color: rgba(96,165,250,.4);
}

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--bg-elev); }
.table { width: 100%; border-collapse: collapse; font-size: var(--t-sm); }
.table th, .table td { padding: var(--s-2) var(--s-3); text-align: left; vertical-align: middle; }
.table thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--bg-elev-2); color: var(--text-2);
  font-size: var(--t-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
  user-select: none;
}
.table thead th[data-sortable] {
  cursor: pointer; padding-right: 18px; position: relative;
}
.table thead th[data-sortable]:hover { color: var(--text); }
.table thead th[data-sortable]::after {
  content: "⇅"; position: absolute; right: 6px; opacity: .35; font-size: 9px;
}
.table thead th[data-sort-dir="asc"]::after  { content: "↑"; opacity: 1; color: var(--info); }
.table thead th[data-sort-dir="desc"]::after { content: "↓"; opacity: 1; color: var(--info); }
.table tbody tr { border-bottom: 1px solid var(--border-subtle); transition: background var(--t-fast); }
.table tbody tr:hover { background: var(--bg-elev-2); }
.table tbody tr:last-child { border-bottom: 0; }
.table tbody tr.is-blocked { background: rgba(248,113,113,.04); }
.table tbody tr.is-blocked:hover { background: rgba(248,113,113,.07); }
.table tbody tr.is-check-address { background: rgba(251,191,36,.06); }
.table tbody tr.is-check-address:hover { background: rgba(251,191,36,.1); }
.table tbody tr.is-error { background: rgba(248,113,113,.07); border-left: 3px solid var(--err); }
.table tbody tr.is-error:hover { background: rgba(248,113,113,.12); }
.table tbody tr.is-selected { background: var(--info-bg); }
.table .num { font-family: var(--mono); text-align: right; white-space: nowrap; }
.table .order-no { font-family: var(--mono); font-weight: 500; color: var(--text); }
.table th.col-actions, .table td.col-actions { text-align: right; }
.table th.col-checkbox, .table td.col-checkbox { width: 32px; padding-right: 0; }

.empty-state {
  padding: var(--s-10) var(--s-4); text-align: center; color: var(--text-3);
}
.empty-state__title { color: var(--text-2); font-size: var(--t-md); margin-bottom: var(--s-2); }

/* ---------- Selection bar (sticky) ---------- */
.selbar {
  position: sticky; bottom: var(--s-4); z-index: 10;
  display: flex; align-items: center; gap: var(--s-3);
  background: var(--bg-elev-2); border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4); margin-top: var(--s-4);
  box-shadow: var(--shadow);
}
.selbar__count { color: var(--text); font-weight: 600; }
.selbar__meta  { color: var(--text-3); font-size: var(--t-sm); }
.selbar__spacer { flex: 1; }

/* ---------- Auth screen ---------- */
.auth { display: grid; place-items: center; min-height: 100vh; padding: var(--s-4); }
.auth__card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: var(--s-8); width: 100%; max-width: 360px;
  box-shadow: var(--shadow);
}
.auth__brand { font-weight: 700; font-size: var(--t-xl); margin-bottom: var(--s-1); }
.auth__sub   { color: var(--text-3); font-size: var(--t-sm); margin-bottom: var(--s-6); }
.auth__field + .auth__field { margin-top: var(--s-3); }

/* ---------- Dialog / modal ---------- */
.dialog-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 50;
  display: grid; place-items: center; padding: var(--s-4);
}
.dialog {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: var(--s-6);
  width: 100%; max-width: 540px; box-shadow: var(--shadow);
}
.dialog__title  { font-size: var(--t-lg); font-weight: 600; margin-bottom: var(--s-2); }
.dialog__body   { color: var(--text-2); font-size: var(--t-sm); margin-bottom: var(--s-5); line-height: 1.6; }
.dialog__actions { display: flex; gap: var(--s-2); justify-content: flex-end; }

/* ---------- Progress / spinner ---------- */
.progress { height: 4px; background: var(--bg-elev-2); border-radius: var(--r-pill); overflow: hidden; }
.progress__bar { height: 100%; background: var(--info); transition: width var(--t-base); }

.spinner {
  width: 14px; height: 14px;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
  * { transition: none !important; animation: none !important; }
}

/* ---------- Stat tile ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--s-3); margin-bottom: var(--s-4); }
.stat {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: var(--s-4);
}
.stat__label { color: var(--text-3); font-size: var(--t-xs); text-transform: uppercase; letter-spacing: .5px; margin-bottom: var(--s-1); }
.stat__value { color: var(--text); font-size: var(--t-2xl); font-family: var(--mono); font-weight: 500; }
.stat__delta { font-size: var(--t-xs); margin-top: var(--s-1); }
.stat__delta--up   { color: var(--ok); }
.stat__delta--down { color: var(--err); }

/* ---------- Detail rows (sub-row under selected order) ---------- */
.subrow { background: var(--bg-elev-2); }
.subrow td { padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--border-subtle); font-size: var(--t-sm); color: var(--text-2); }
.subrow .kv { display: inline-block; margin-right: var(--s-4); }
.subrow .kv b { color: var(--text); font-weight: 500; }

/* ---------- Code blocks ---------- */
code, pre { font-family: var(--mono); font-size: var(--t-sm); }
pre {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--r);
  padding: var(--s-3); overflow-x: auto;
}

/* ---------- Utilities ---------- */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.gap-1 { gap: var(--s-1); } .gap-2 { gap: var(--s-2); } .gap-3 { gap: var(--s-3); } .gap-4 { gap: var(--s-4); }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-1 { flex: 1; }
.w-full { width: 100%; }
.text-2 { color: var(--text-2); }
.text-3 { color: var(--text-3); }
.text-mono { font-family: var(--mono); }
.text-sm { font-size: var(--t-sm); }
.text-xs { font-size: var(--t-xs); }
.text-right { text-align: right; }
.mt-2 { margin-top: var(--s-2); } .mt-3 { margin-top: var(--s-3); } .mt-4 { margin-top: var(--s-4); }
.mb-2 { margin-bottom: var(--s-2); } .mb-3 { margin-bottom: var(--s-3); } .mb-4 { margin-bottom: var(--s-4); }
.hidden { display: none; }

/* HTMX swap indicator */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-flex; }
.htmx-request.htmx-indicator { display: inline-flex; }
