/* Empire Surplus Platform — neutral placeholder theme (spec §19).
   All colors are DESIGN TOKENS. The Empire black-and-gold palette is entered by the
   admin in the brand screen, NEVER hard-coded here. Dark is the flagship look. */
:root {
  /* Slate-blue-biased neutrals (chosen, not default grey) — deep, calm, fintech. */
  --bg: #090b10;
  --bg-2: #0e1219;            /* for the page gradient */
  --surface: #12161d;
  --surface-2: #1a2029;
  --surface-3: #212936;      /* hover / raised */
  --border: #262e3b;
  --border-soft: #1e2530;
  --hairline: rgba(255,255,255,.06); /* top-edge highlight for depth */
  --text: #eef1f7;
  --muted: #8f99a8;
  --primary: #4f86f7;
  --primary-2: #6aa5ff;      /* gradient partner */
  --primary-ink: #ffffff;
  --accent: #34d3ee;
  --ok: #2fbf71;
  --err: #f2545b;
  --warn: #f5a524;
  --radius: 12px;
  --radius-sm: 8px;
  --grad-primary: linear-gradient(180deg, var(--primary-2), var(--primary));
  /* subtle tinted fills for status pills/flashes (color-mix keeps them on-token) */
  --ok-bg: color-mix(in srgb, var(--ok) 14%, transparent);
  --err-bg: color-mix(in srgb, var(--err) 14%, transparent);
  --warn-bg: color-mix(in srgb, var(--warn) 14%, transparent);
  --primary-bg: color-mix(in srgb, var(--primary) 16%, transparent);
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 22px rgba(0,0,0,.28);
  --shadow-lg: 0 16px 50px rgba(0,0,0,.55);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  color: var(--text);
  /* Depth: a quiet slate gradient rather than a flat fill. */
  background: radial-gradient(1200px 600px at 78% -10%, color-mix(in srgb, var(--primary) 10%, transparent), transparent 60%), linear-gradient(180deg, var(--bg-2), var(--bg) 30%);
  background-attachment: fixed;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

header.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 12px 22px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--surface) 92%, var(--primary) 8%), var(--surface));
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 var(--hairline) inset, 0 6px 24px rgba(0,0,0,.25);
  position: sticky; top: 0; z-index: 60;
  backdrop-filter: saturate(1.1);
}
.brand { font-weight: 800; letter-spacing: -.2px; font-size: 16px; }
.brand small { color: var(--muted); font-weight: 400; }
nav.topnav { display: flex; gap: 6px; margin-left: auto; align-items: center; flex-wrap: wrap; }
nav.topnav a { color: var(--muted); padding: 6px 10px; border-radius: 8px; white-space: nowrap; transition: color .12s, background .12s; }
nav.topnav a.active { color: var(--text); background: var(--surface-2); }
nav.topnav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }

/* Admin dropdown (CSP-safe, no JS): a <details> menu that declutters the many admin links. */
.navmenu { position: relative; }
.navmenu > summary { list-style: none; cursor: pointer; color: var(--muted); padding: 6px 10px; border-radius: 8px; white-space: nowrap; }
.navmenu > summary::-webkit-details-marker { display: none; }
.navmenu[open] > summary, .navmenu > summary:hover { color: var(--text); background: var(--surface-2); }
.navmenu .menu {
  position: absolute; right: 0; top: 100%; margin-top: 6px; z-index: 70;
  display: grid; grid-template-columns: 1fr 1fr; gap: 2px; min-width: 320px; padding: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg);
}
.navmenu .menu a { color: var(--muted); padding: 7px 10px; border-radius: 7px; font-size: 14px; }
.navmenu .menu a:hover, .navmenu .menu a.active { color: var(--text); background: var(--surface-2); text-decoration: none; }

main { max-width: 1080px; margin: 24px auto; padding: 0 20px; }
h1 { font-size: 23px; margin: 0 0 4px; font-weight: 750; letter-spacing: -.4px; text-wrap: balance; }
h2 { font-size: 16px; margin: 24px 0 8px; font-weight: 650; letter-spacing: -.2px; }
p.sub { color: var(--muted); margin-top: 0; }

.card {
  background: linear-gradient(180deg, color-mix(in srgb, var(--surface) 88%, #fff 2%), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; margin-bottom: 16px;
  box-shadow: 0 1px 0 var(--hairline) inset, var(--shadow);
}
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.stat {
  background: linear-gradient(180deg, var(--surface-3), var(--surface-2));
  border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 16px 16px 14px;
  box-shadow: 0 1px 0 var(--hairline) inset;
}
.stat .n { font-size: 28px; font-weight: 750; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; margin-top: 2px; }

label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; letter-spacing: .02em; }
input, select, textarea {
  width: 100%; padding: 9px 11px; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm); font: inherit; transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent); }
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--muted) 70%, transparent); }

.btn {
  display: inline-block; padding: 9px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); cursor: pointer; font: inherit; font-weight: 500; line-height: 1.2;
  transition: border-color .12s, background .12s, transform .05s, box-shadow .12s;
}
.btn:hover { border-color: color-mix(in srgb, var(--primary) 60%, var(--border)); background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 30%, transparent); }
.btn.primary { background: var(--grad-primary); color: var(--primary-ink); border-color: transparent; box-shadow: 0 1px 0 rgba(255,255,255,.18) inset, 0 2px 10px color-mix(in srgb, var(--primary) 40%, transparent); }
.btn.primary:hover { filter: brightness(1.06); border-color: transparent; }
.btn.danger { color: var(--err); }
.btn.danger:hover { border-color: var(--err); background: var(--err-bg); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--muted); font-weight: 600; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
tbody tr.kbd-active { background: color-mix(in srgb, var(--primary) 16%, transparent); box-shadow: inset 3px 0 0 var(--primary); }
.tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; border: 1px solid var(--border); line-height: 1.5; }
.tag.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, var(--border)); background: var(--ok-bg); }
.tag.err { color: var(--err); border-color: color-mix(in srgb, var(--err) 45%, var(--border)); background: var(--err-bg); }
.tag.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, var(--border)); background: var(--warn-bg); }
.tag.muted { color: var(--muted); }

.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; border: 1px solid var(--border); }
.flash.success { border-color: color-mix(in srgb, var(--ok) 45%, var(--border)); color: var(--ok); background: var(--ok-bg); }
.flash.error { border-color: color-mix(in srgb, var(--err) 45%, var(--border)); color: var(--err); background: var(--err-bg); }
.flash.warn { border-color: color-mix(in srgb, var(--warn) 45%, var(--border)); color: var(--warn); background: var(--warn-bg); }

details.conn { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; margin: 8px 0; background: var(--surface-2); }
details.conn summary { cursor: pointer; font-weight: 600; }
.muted { color: var(--muted); }
.center { max-width: 380px; margin: 8vh auto; }
.codes { font-family: ui-monospace, monospace; background: var(--bg); padding: 12px; border-radius: 8px; border: 1px solid var(--border); }
.banner { background: var(--surface-2); border: 1px solid var(--warn); color: var(--warn); padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }

/* Address autocomplete dropdown (Admin → Company) */
.addr-suggest { position: fixed; z-index: 210; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-lg); max-height: 260px; overflow-y: auto; }
.addr-suggest[hidden] { display: none; }
.addr-opt { padding: 8px 11px; cursor: pointer; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.addr-opt:hover, .addr-opt.active { background: var(--surface-2); }

/* Logo lightbox (Admin → Company): large preview + header/letterhead mockups */
.lightbox { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.62); padding: 20px; }
.lightbox[hidden] { display: none; } /* id/display rules must not defeat the hidden attribute (see #ai-panel) */
.lightbox-panel { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 22px; max-width: 560px; width: 100%; max-height: 90vh; overflow: auto; box-shadow: var(--shadow-lg); }
.lightbox-close { position: absolute; top: 8px; right: 12px; background: none; border: 0; color: var(--muted); font-size: 26px; line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.lightbox-close:hover { color: var(--text); background: var(--surface-2); }
.lightbox-samples { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 14px; }
.lightbox-samples figure { margin: 0; }
.lightbox-samples figcaption { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.lb-dark { background: linear-gradient(180deg, color-mix(in srgb, var(--surface) 92%, var(--primary) 8%), var(--surface)); border: 1px solid var(--border); border-radius: 8px; padding: 12px; display: flex; align-items: center; min-height: 56px; }
.lb-white { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 12px; display: flex; align-items: center; justify-content: center; min-height: 56px; }
.lb-hdr { height: 30px; width: auto; }            /* exactly the header render size */
.lb-doc { max-height: 90px; max-width: 100%; }     /* letterhead size on documents */
.lb-full { background: var(--surface-2); border-radius: 8px; padding: 16px; display: flex; align-items: center; justify-content: center; }
.lb-big { max-width: 100%; max-height: 320px; }

/* Show/hide password toggle — a ghosted eyeball inside the field */
.pw-wrap { position: relative; display: block; }
.pw-wrap > input { width: 100%; padding-right: 42px; }
.pw-toggle { position: absolute; top: 50%; right: 6px; transform: translateY(-50%); background: none; border: 0; cursor: pointer; font-size: 15px; line-height: 1; opacity: .4; padding: 5px; border-radius: 6px; }
.pw-toggle:hover, .pw-toggle.on { opacity: 1; }
.pw-toggle:focus-visible { outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 30%, transparent); }

/* TOTP code-rotation countdown (2FA pages) */
.totp-countdown { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.totp-countdown .totp-bar { flex: 0 0 90px; height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.totp-countdown .totp-bar > span { display: block; height: 100%; width: 100%; background: var(--primary); transition: width .25s linear; }
.totp-countdown .totp-secs { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }
.totp-countdown.low .totp-bar > span { background: var(--warn); }
.totp-countdown.low .totp-secs { color: var(--warn); }

/* AI assistant widget */
#ai-fab { position: fixed; right: 20px; bottom: 20px; z-index: 50; width: 52px; height: 52px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--primary); color: #fff; font-size: 22px; cursor: pointer; box-shadow: 0 4px 16px rgba(0,0,0,.35); }
#ai-panel { position: fixed; right: 20px; bottom: 84px; z-index: 50; width: min(380px, calc(100vw - 40px)); height: min(520px, calc(100vh - 120px));
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; box-shadow: 0 8px 32px rgba(0,0,0,.45); }
#ai-panel[hidden] { display: none; } /* the id+display:flex above otherwise defeats the hidden attribute → panel couldn't close */
#ai-head { padding: 10px 14px; border-bottom: 1px solid var(--border); font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
#ai-head button { background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer; }
#ai-msgs { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.ai-bubble { padding: 8px 11px; border-radius: 10px; max-width: 85%; font-size: 14px; line-height: 1.45; white-space: normal; }
.ai-user { align-self: flex-end; background: var(--primary); color: #fff; }
.ai-assistant { align-self: flex-start; background: var(--surface-2); color: var(--text); }
.ai-pending { opacity: .6; }
#ai-form { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--border); }
#ai-form textarea { flex: 1; resize: none; }

/* Hover tooltips (learn-as-you-go bubbles) — positioned by public/app.js */
.tip-bubble {
  position: absolute;
  z-index: 9999;
  max-width: 300px;
  background: #0b0d10;
  color: #e9edf2;
  border: 1px solid #3a4150;
  border-radius: 8px;
  padding: 8px 11px;
  font-size: 12.5px;
  line-height: 1.4;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  animation: tip-fade 0.12s ease-out;
}
.tip-bubble[hidden] { display: none; }
@keyframes tip-fade { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }

/* Per-phone Call dropdown (§38): one button → choose browser softphone or phone bridge. */
.callwrap { position: relative; display: inline-block; }
.call-menu { position: absolute; left: 0; top: 100%; margin-top: 3px; z-index: 40;
  display: flex; flex-direction: column; gap: 4px; padding: 6px; min-width: 168px;
  background: var(--bg-elev, #1a1a1a); border: 1px solid rgba(255,255,255,.15);
  border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.4); }
.call-menu[hidden] { display: none; }
.call-menu .btn { width: 100%; text-align: left; }
/* Browser calling only appears once the softphone confirms it's configured + ready. */
body:not(.sf-ready) .call-browser-opt { display: none; }

/* Responsive: keep the header usable on small screens (the nav wraps + the admin menu goes full-width). */
@media (max-width: 820px) {
  header.topbar { flex-wrap: wrap; gap: 10px; padding: 10px 14px; }
  nav.topnav { width: 100%; margin-left: 0; flex-wrap: wrap; }
  .navmenu .menu { position: static; grid-template-columns: 1fr 1fr; min-width: 0; box-shadow: none; margin-top: 4px; }
  main { margin: 16px auto; }
  /* Wide data tables scroll within themselves instead of overflowing the page horizontally. */
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  th, td { white-space: nowrap; }
}

/* Phones: tighter gutters, stack the admin menu + any inline forms, comfortable tap targets. */
@media (max-width: 560px) {
  main { padding: 0 12px; margin: 12px auto; }
  h1 { font-size: 20px; }
  h2 { font-size: 15px; margin-top: 18px; }
  .card { padding: 14px; }
  .navmenu .menu { grid-template-columns: 1fr; }
  /* The header search box eats width on a phone — hide it; global search is a tap away via a page. */
  #globalnav-search { display: none; }
  /* Inline forms/rows stack so controls get full width and are easy to tap. */
  form.row, .row.stack-sm { flex-direction: column; align-items: stretch; }
  form.row > *, .row.stack-sm > * { width: 100%; }
  .btn, .btn.sm { padding: 9px 14px; font-size: 14px; } /* ≥40px tap targets */
  .navmenu > summary.acct { max-width: 46vw; overflow: hidden; text-overflow: ellipsis; }
}

/* Two-level nav: primary section tabs + a contextual sub-bar, with a settings gear + account menu. */
nav.topnav a.tab { font-size: 15px; font-weight: 500; padding: 7px 13px; }
nav.topnav a.tab.active { color: var(--text); background: color-mix(in srgb, var(--primary) 14%, transparent); box-shadow: inset 0 -2px 0 var(--primary); }
.iconbtn { color: var(--muted); padding: 6px 9px; border-radius: 8px; font-size: 16px; cursor: pointer; }
.iconbtn.active, .iconbtn:hover { color: var(--text); background: var(--surface-2); }
/* Green/yellow/red system-health light (header, all users) */
.statuslight { display: inline-flex; align-items: center; padding: 6px 8px; border-radius: 8px; }
.statuslight:hover { background: var(--surface-2); }
.statuslight .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 18%, transparent); }
.statuslight.green .dot { background: #22c55e; color: #22c55e; }
.statuslight.yellow .dot { background: #f59e0b; color: #f59e0b; }
.statuslight.red .dot { background: #ef4444; color: #ef4444; }
.statuslight.yellow .dot, .statuslight.red .dot { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 2px color-mix(in srgb, currentColor 20%, transparent); } 50% { box-shadow: 0 0 0 5px color-mix(in srgb, currentColor 8%, transparent); } }
@media (prefers-reduced-motion: reduce) { .statuslight .dot { animation: none; } }
.navmenu > summary.acct { font-size: 13px; }
.navmenu .menu.menu-1 { grid-template-columns: 1fr; min-width: 200px; }
.subbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 53px; z-index: 55; }
.subnav { max-width: 1080px; margin: 0 auto; padding: 8px 20px; display: flex; gap: 6px; flex-wrap: wrap; }
.subnav a { color: var(--muted); padding: 5px 12px; border-radius: 999px; font-size: 13px; }
.subnav a.active { color: var(--primary-ink); background: var(--grad-primary); border: 1px solid transparent; }
.subnav a:hover { color: var(--text); text-decoration: none; }
@media (max-width: 820px) { .subbar { position: static; } }

/* Clickable quick-view chips (Review workspace): jump to nearing-deadline / dropped deals. */
.quickview{display:inline-flex;align-items:center;gap:6px;padding:8px 13px;border-radius:999px;font-size:13px;font-weight:500;color:var(--muted);background:var(--surface-2);border:1px solid var(--border);transition:color .12s,background .12s,border-color .12s}
.quickview:hover{color:var(--text);border-color:color-mix(in srgb,var(--primary) 50%,var(--border));text-decoration:none}
.quickview.active{color:var(--text);background:var(--surface-3);box-shadow:0 1px 0 var(--hairline) inset}
.quickview.warn.active{border-color:color-mix(in srgb,var(--warn) 55%,var(--border));color:var(--warn);background:var(--warn-bg)}
.quickview.err.active{border-color:color-mix(in srgb,var(--err) 55%,var(--border));color:var(--err);background:var(--err-bg)}

/* Stat cards used as links (Dashboard summary → filtered lists). */
a.stat { display: block; text-decoration: none; color: inherit; transition: border-color .12s, transform .05s; }
a.stat:hover { border-color: color-mix(in srgb, var(--primary) 45%, var(--border)); text-decoration: none; transform: translateY(-1px); }
