/* LASER Dark for the CRM.
   Values are copied from Payment_Portal static/css/laser.css and DESIGN.md ("LASER Ledger",
   origin/main 2026-11-03). Keep them in step with that repo rather than tuning them here.
   This file is the only stylesheet; templates carry no inline styles (the CSP forbids them). */

:root {
  --laser-primary: #00E5FF;
  --laser-primary-dark: #00B8D4;
  --laser-primary-active: #0093AB;
  --laser-secondary: #7C4DFF;

  --ground: #0A0A0A;
  --surface: #1A1A1A;
  --surface-raised: #222222;
  --chrome: #0D0D0D;

  --text: #FFFFFF;
  --text-2: rgba(255, 255, 255, 0.7);
  --text-muted: rgba(255, 255, 255, 0.55);
  --text-disabled: rgba(255, 255, 255, 0.4);

  --hairline: rgba(0, 229, 255, 0.2);
  --divider: rgba(0, 229, 255, 0.15);
  --control-border: rgba(0, 229, 255, 0.5);
  --wash-4: rgba(0, 229, 255, 0.04);
  --wash-8: rgba(0, 229, 255, 0.08);
  --wash-12: rgba(0, 229, 255, 0.12);

  --success: #00E676; --success-wash: rgba(0, 230, 118, 0.12);
  --warning: #FFD740; --warning-wash: rgba(255, 215, 64, 0.12);
  --danger:  #FF5252; --danger-wash:  rgba(255, 82, 82, 0.12);
  --info:    #448AFF; --info-wash:    rgba(68, 138, 255, 0.12);
  --neutral-wash: rgba(255, 255, 255, 0.08);

  --glass-sheen: rgba(255, 255, 255, 0.045);
  --glass-filter: blur(20px) saturate(160%);
  --glass-border: rgba(255, 255, 255, 0.16);
  --glass-edge: inset 0 1px 0 rgba(255, 255, 255, 0.22), 0 12px 40px rgba(0, 0, 0, 0.40);

  --font: Nunito, Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --fs-page-title: 1.5rem;
  --fs-section: 0.9375rem;
  --fs-body: 0.875rem;
  --fs-label: 0.75rem;
  --fs-metric: 1.75rem;
  --fs-input: 16px;

  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 24px; --s-6: 32px; --s-7: 48px;
  --h-button: 32px; --h-button-sm: 26px; --h-input: 36px; --h-row: 36px; --h-touch: 44px;
  --r-sm: 6px; --r-button: 8px; --r-input: 12px; --r-card: 12px; --r-pill: 999px;

  --sidebar-w: 240px;
  --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 100%; }
body {
  font-family: var(--font);
  font-size: var(--fs-body);
  line-height: 1.5;
  color: var(--text);
  min-height: 100vh;
  /* Blueprint grid on top, then cyan / violet / cyan aurora: what the glass frosts over. */
  background-color: var(--ground);
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.028) 1px, transparent 1px),
    radial-gradient(52rem 34rem at 8% -6%, rgba(0, 229, 255, 0.18), transparent 58%),
    radial-gradient(46rem 32rem at 96% 6%, rgba(124, 77, 255, 0.16), transparent 60%),
    radial-gradient(44rem 30rem at 46% 104%, rgba(0, 229, 255, 0.10), transparent 62%);
  background-size: 44px 44px, 44px 44px, auto, auto, auto;
  background-attachment: fixed;
  background-repeat: repeat, repeat, no-repeat, no-repeat, no-repeat;
}

a { color: var(--laser-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--laser-primary); outline-offset: 2px; }

.num, .data-table td.num, .kpi-value, .fact-value.num { font-variant-numeric: tabular-nums lining-nums; }
.muted { color: var(--text-muted); }
.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; }

* { scrollbar-width: thin; scrollbar-color: rgba(0, 229, 255, 0.25) transparent; }

/* ─── Shell ─────────────────────────────────────────────────────────────── */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--chrome);
  border-right: 1px solid var(--hairline);
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
}
.sidebar-brand {
  display: flex; align-items: center; gap: var(--s-2);
  height: 56px; padding: 0 var(--s-4);
  border-bottom: 1px solid var(--divider);
  color: var(--text); font-weight: 700; font-size: 1rem; letter-spacing: -0.01em;
}
.sidebar-brand:hover { text-decoration: none; }
.brand-mark { color: var(--laser-primary); font-weight: 800; letter-spacing: 0.08em; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: var(--s-3) var(--s-2); display: flex; flex-direction: column; gap: 2px; }
.nav-section {
  font-size: var(--fs-label); font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted); padding: var(--s-3) var(--s-3) var(--s-1);
}
.nav-item {
  display: flex; align-items: center; justify-content: space-between;
  height: var(--h-button); padding: 0 var(--s-3);
  border-radius: var(--r-sm);
  color: var(--text-2); font-size: var(--fs-body);
  transition: background var(--transition), color var(--transition);
}
.nav-item:hover { background: var(--wash-4); color: var(--laser-primary); text-decoration: none; }
.nav-item[aria-current="page"] {
  background: var(--wash-4); color: var(--laser-primary); font-weight: 600;
  box-shadow: inset 3px 0 0 var(--laser-primary);
}
.nav-count { font-size: var(--fs-label); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.sidebar-footer { border-top: 1px solid var(--divider); padding: var(--s-3) var(--s-4); display: flex; flex-direction: column; gap: var(--s-2); }
.sidebar-user { font-size: var(--fs-label); color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { flex: 1; min-width: 0; padding: var(--s-5); display: flex; flex-direction: column; gap: var(--s-4); }
.main > * { max-width: 1600px; width: 100%; }

/* ─── Page header ───────────────────────────────────────────────────────── */

.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap; }
.page-header-text { display: flex; flex-direction: column; gap: var(--s-1); min-width: 0; }
.page-title { font-size: var(--fs-page-title); font-weight: 600; letter-spacing: -0.01em; line-height: 1.2; overflow-wrap: anywhere; }
.page-title .count { color: var(--text-muted); font-weight: 400; font-size: var(--fs-section); margin-left: var(--s-2); }
.breadcrumb { font-size: var(--fs-label); color: var(--text-2); }
.page-actions { display: flex; gap: var(--s-2); flex-wrap: wrap; }

/* ─── Cards (glass) ─────────────────────────────────────────────────────── */

.section-card {
  background: var(--glass-sheen);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-card);
  box-shadow: var(--glass-edge);
  overflow: hidden;
  min-width: 0;
}
.section-card-head {
  display: flex; align-items: center; gap: var(--s-2);
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--divider);
}
.section-card-title { font-size: var(--fs-section); font-weight: 600; }
.section-card-title a { color: var(--text); }
.section-card-count { color: var(--text-muted); font-size: var(--fs-label); font-variant-numeric: tabular-nums; }
.section-card-actions { margin-left: auto; display: flex; gap: var(--s-2); }
.section-card-body { padding: var(--s-4); }
.section-card-foot { padding: var(--s-2) var(--s-4); border-top: 1px solid var(--divider); font-size: var(--fs-label); }

/* ─── KPI tiles ─────────────────────────────────────────────────────────── */

.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr)); gap: var(--s-3); }
.kpi {
  display: flex; flex-direction: column; gap: var(--s-1);
  min-height: 84px; padding: var(--s-3) var(--s-4);
  background: var(--glass-sheen);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-card);
  color: var(--text);
}
a.kpi:hover { text-decoration: none; border-color: var(--control-border); }
.kpi-label { font-size: var(--fs-label); font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-2); }
.kpi-value { font-size: var(--fs-metric); font-weight: 600; line-height: 1.2; }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-1);
  height: var(--h-button); padding: 0 var(--s-3);
  border-radius: var(--r-button);
  border: 1px solid var(--hairline);
  background: var(--surface-raised); color: var(--text);
  font: inherit; font-size: var(--fs-body); font-weight: 600; white-space: nowrap;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.btn:hover { background: var(--wash-8); text-decoration: none; }
.btn--primary { background: var(--laser-primary); border-color: var(--laser-primary); color: var(--ground); }
.btn--primary:hover { background: var(--laser-primary-dark); border-color: var(--laser-primary-dark); }
.btn--primary:active { background: var(--laser-primary-active); }
.btn--danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn--danger:hover { background: var(--danger-wash); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn--ghost:hover { background: var(--wash-4); color: var(--text); }
.btn--sm { height: var(--h-button-sm); padding: 0 var(--s-2); font-size: var(--fs-label); }
.btn--block { width: 100%; }
@media (pointer: coarse), (max-width: 640px) { .btn { height: var(--h-touch); } }

/* ─── Fields ────────────────────────────────────────────────────────────── */

.field { display: flex; flex-direction: column; gap: var(--s-1); min-width: 0; }
.field-label { font-size: var(--fs-label); font-weight: 600; color: var(--text-2); letter-spacing: 0.04em; }
.field-hint { font-size: var(--fs-label); color: var(--text-muted); }
.field-msg-error { font-size: var(--fs-label); color: var(--danger); }
.field-input, .field-select, .field-textarea {
  width: 100%;
  height: var(--h-input); padding: 0 var(--s-3);
  border-radius: var(--r-input);
  border: 1px solid var(--control-border);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: var(--fs-input); line-height: 1;
}
.field-textarea { height: auto; min-height: 96px; padding: var(--s-2) var(--s-3); line-height: 1.5; resize: vertical; }
.field-input:focus, .field-select:focus, .field-textarea:focus { outline: none; border-color: var(--laser-primary); box-shadow: 0 0 0 1px var(--laser-primary); }
.field-input[readonly] { background: transparent; border-style: dashed; color: var(--text-2); }
.field-select {
  appearance: none; -webkit-appearance: none;
  padding-right: 32px; text-overflow: ellipsis;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.field.has-error .field-input, .field.has-error .field-select, .field.has-error .field-textarea { border-color: var(--danger); }
.field-resolved { font-size: var(--fs-label); color: var(--text-2); min-height: 1.2em; }
@media (pointer: coarse), (max-width: 640px) { .field-input, .field-select { height: var(--h-touch); } }

.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr)); gap: var(--s-4) var(--s-5); }
.form-grid .field--wide { grid-column: 1 / -1; }
.form-group-title {
  grid-column: 1 / -1;
  font-size: var(--fs-label); font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted);
  padding-top: var(--s-2); border-top: 1px solid var(--divider);
}
.form-group-title:first-child { border-top: 0; padding-top: 0; }
.form-actions { display: flex; gap: var(--s-2); padding: var(--s-3) var(--s-4); border-top: 1px solid var(--divider); }

/* ─── Toolbar (filters above the table) ─────────────────────────────────── */

.toolbar { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: flex-end; padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--divider); }
.toolbar .field { flex: 0 1 200px; }
.toolbar .field--search { flex: 1 1 220px; }
.toolbar .field-select { max-width: 240px; }

/* ─── Data table ────────────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; }
.table-wrap--scroll { max-height: 420px; overflow-y: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  position: sticky; top: 0; z-index: 1;
  background: var(--chrome);
  padding: 6px var(--s-4);
  font-size: var(--fs-label); font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--text-muted); text-align: left; white-space: nowrap;
  border-bottom: 1px solid var(--hairline);
}
.data-table th button.sort { all: unset; cursor: pointer; display: inline-flex; gap: var(--s-1); align-items: center; }
.data-table th button.sort:focus-visible { outline: 2px solid var(--laser-primary); outline-offset: 2px; }
.data-table th[aria-sort] { color: var(--laser-primary); }
.data-table td {
  padding: 6px var(--s-4); height: var(--h-row);
  border-bottom: 1px solid var(--divider);
  overflow-wrap: break-word; word-break: normal;
}
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover td { background: var(--wash-4); }
.data-table .num { text-align: right; }
.data-table td.first a { font-weight: 600; }
.lookup-link { color: var(--text-2); }
.lookup-link:hover { color: var(--laser-primary); }

.empty-state { padding: var(--s-6) var(--s-4); text-align: center; color: var(--text-2); }
.empty-state .hint { display: block; margin-top: var(--s-1); color: var(--text-muted); font-size: var(--fs-label); }

/* ─── Pager ─────────────────────────────────────────────────────────────── */

.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-2); padding: var(--s-2) var(--s-4); border-top: 1px solid var(--divider); font-size: var(--fs-label); color: var(--text-2); }
.pager-controls { display: flex; gap: var(--s-2); align-items: center; }

/* ─── Badges ────────────────────────────────────────────────────────────── */

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 20px; padding: 0 var(--s-2);
  border-radius: var(--r-pill);
  font-size: var(--fs-label); font-weight: 600; white-space: nowrap;
  background: var(--neutral-wash); color: var(--text-2);
}
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge--success { background: var(--success-wash); color: var(--success); }
.badge--warning { background: var(--warning-wash); color: var(--warning); }
.badge--error { background: var(--danger-wash); color: var(--danger); }
.badge--info { background: var(--info-wash); color: var(--info); }

/* ─── Notes / flash messages ────────────────────────────────────────────── */

.note {
  background: var(--surface-raised);
  border: 1px solid var(--hairline);
  border-left: 3px solid var(--info);
  border-radius: var(--r-button);
  padding: var(--s-3) var(--s-4);
}
.note--success { border-left-color: var(--success); }
.note--warning { border-left-color: var(--warning); }
.note--error { border-left-color: var(--danger); }

/* ─── Facts (read-only detail grid) ─────────────────────────────────────── */

.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr)); gap: var(--s-3) var(--s-5); }
.fact { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.fact--wide { grid-column: 1 / -1; }
.fact-label { font-size: var(--fs-label); font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-muted); }
.fact-value { overflow-wrap: anywhere; }

/* ─── Layout helpers ────────────────────────────────────────────────────── */

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr)); gap: var(--s-4); align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); gap: var(--s-4); align-items: start; }
.dash { display: grid; grid-template-columns: minmax(260px, 320px) 1fr; gap: var(--s-4); align-items: start; }
.stack { display: flex; flex-direction: column; gap: var(--s-4); min-width: 0; }

.list { list-style: none; }
.list li { border-bottom: 1px solid var(--divider); }
.list li:last-child { border-bottom: 0; }
.list a, .list .row { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); min-height: var(--h-row); padding: 6px var(--s-4); color: var(--text); }
.list a:hover { background: var(--wash-4); text-decoration: none; color: var(--laser-primary); }
.list .meta { display: flex; gap: var(--s-1); flex-shrink: 0; }
.list--scroll { max-height: 60vh; overflow-y: auto; }
.list-filter { padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--divider); }

/* ─── Dialog ────────────────────────────────────────────────────────────── */

dialog.confirm {
  margin: auto; max-width: 440px; width: calc(100% - 32px);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--hairline); border-radius: var(--r-button);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
dialog.confirm::backdrop { background: rgba(0, 0, 0, 0.6); }
.dialog-body { padding: var(--s-4); display: flex; flex-direction: column; gap: var(--s-2); }
.dialog-title { font-size: var(--fs-section); font-weight: 600; }
.dialog-foot { display: flex; justify-content: flex-end; gap: var(--s-2); padding: var(--s-3) var(--s-4); border-top: 1px solid var(--divider); }

/* ─── Auth pages (login / denied) ───────────────────────────────────────── */

.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--s-4); }
.auth-card { width: 100%; max-width: 400px; text-align: center; }
.auth-card .section-card-body { display: flex; flex-direction: column; gap: var(--s-4); align-items: center; padding: var(--s-6) var(--s-5); }
.auth-brand { font-size: var(--fs-page-title); font-weight: 700; letter-spacing: -0.01em; }
.auth-card p { color: var(--text-2); }

/* ─── Responsive ────────────────────────────────────────────────────────── */

.menu-toggle { display: none; }
@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; border-right: 0; border-bottom: 1px solid var(--hairline); }
  .sidebar-nav, .sidebar-footer { display: none; }
  .sidebar.open .sidebar-nav, .sidebar.open .sidebar-footer { display: flex; }
  .sidebar-brand { justify-content: space-between; }
  .menu-toggle { display: inline-flex; }
  .main { padding: var(--s-4); }
  .dash { grid-template-columns: 1fr; }
}

/* ─── Accessibility opt-outs, applied at the token ──────────────────────── */

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  :root { --glass-sheen: var(--surface); --glass-edge: none; }
}
@media (prefers-reduced-transparency: reduce) {
  :root { --glass-sheen: var(--surface); --glass-filter: none; --glass-edge: none; --glass-border: var(--hairline); }
  body { background-image: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
@media (forced-colors: active) {
  .badge::before { background: CanvasText; }
}
@media print {
  :root { --glass-sheen: #fff; --glass-filter: none; --glass-edge: none; }
  body { background: #fff; color: #000; }
  .sidebar, .page-actions, .toolbar, .pager, .form-actions { display: none; }
}

/* ─── Small additions ───────────────────────────────────────────────────── */

.sidebar-brand-link { color: var(--text); }
.sidebar-brand-link:hover { text-decoration: none; }
.data-table th .sort-link { color: inherit; }
.data-table th .sort-link:hover { color: var(--laser-primary); text-decoration: none; }
.page-actions form { display: contents; }
.data-table td.num, .data-table td.date { white-space: nowrap; }
.date { font-variant-numeric: tabular-nums lining-nums; }
.fact-value.long { white-space: pre-line; }
