/* ==========================================================================
   ZED CRM — design system
   --------------------------------------------------------------------------
   Same family as Zed Payroll / Chat / Leads (warm near-black + ZED orange) so
   all in-house tools read as one product. Two deliberate departures, both
   because this is an operational screen people stare at for a full shift:

   1. The canvas is lifted off pure black (#0f1115) with layered surfaces.
      Pure black + bright text at 8h/day is genuinely fatiguing.
   2. Orange is reserved for BRAND and PRIMARY ACTIONS only — never for status.
      In the old CRM everything was blue-on-navy, so nothing stood out. Here
      status has its own unambiguous palette, because reading status at a
      glance IS the job.
   ========================================================================== */

:root {
  --bg:        #0f1115;
  --surface:   #161920;
  --surface-2: #1d212a;
  --border:    #2a2f3a;
  --border-lit:#3a4150;

  --text:      #e8eaed;
  --text-dim:  #9aa3b2;
  --text-mute: #6b7484;

  --accent:      #ef8a2b;   /* ZED orange — brand + primary actions */
  --accent-soft: rgba(239,138,43,.14);
  --accent-hover:#ff9d45;

  /* Status palette — each one distinct at a glance, even side by side */
  --st-new:      #8b95a7;   /* SALE_MADE  — unclaimed, neutral */
  --st-progress: #4d9fff;   /* IN_PROCESS — someone is on it */
  --st-review:   #f5b13d;   /* REVIEW     — needs agent action (the money lever) */
  --st-done:     #35c9a5;   /* PROCESSED  — awaiting supplier verification */
  --st-good:     #3ecf7a;   /* CONFIRMED  — revenue */
  --st-warn:     #ff8f5a;   /* PIN_WRONG  */
  --st-bad:      #f2545b;   /* CANCELED   */
  --st-call:     #a97bff;   /* CALL_BACK  */

  --team-zeds: #4d9fff;
  --team-zedx: #3ecf7a;

  --radius:   10px;
  --radius-lg:14px;
  --shadow:   0 4px 24px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 0 20px; height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 40;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; letter-spacing: .01em; white-space: nowrap; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; flex: none;
  background: linear-gradient(135deg, var(--accent), #c96a15);
  display: grid; place-items: center; color: #fff; font-size: 13px; font-weight: 800;
}
.brand small { color: var(--text-mute); font-weight: 500; font-size: 11px; display: block; letter-spacing: .02em; }

.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.nav a {
  color: var(--text-dim); font-size: 13px; font-weight: 500;
  padding: 7px 13px; border-radius: 8px; white-space: nowrap;
}
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a.active { color: var(--text); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border-lit); }
.nav a .count {
  display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 99px;
  font-size: 11px; font-weight: 700; background: var(--accent-soft); color: var(--accent);
}

/* team badge — instant "whose data am I looking at" */
.team-badge {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 600; color: var(--text-dim);
  padding: 5px 11px; border-radius: 99px; border: 1px solid var(--border);
  background: var(--bg); white-space: nowrap;
}
.team-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--team-zeds); }
.team-dot.green { background: var(--team-zedx); }
.team-dot.grey  { background: var(--text-mute); }

.who { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.who .role { text-transform: uppercase; letter-spacing: .05em; font-size: 10px; color: var(--text-mute); }

/* ---------- layout ---------- */
.wrap { max-width: 1500px; margin: 0 auto; padding: 22px 20px 90px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 20px; font-weight: 650; letter-spacing: -.01em; }
.page-head p { margin: 3px 0 0; color: var(--text-dim); font-size: 13px; }

/* ---------- stat cards ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 22px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 15px 16px; position: relative; overflow: hidden;
}
.stat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--st-new); }
.stat .n { font-size: 26px; font-weight: 700; line-height: 1.1; letter-spacing: -.02em; }
.stat .l { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .06em; margin-top: 5px; }
.stat .sub { font-size: 11px; color: var(--text-mute); margin-top: 3px; }
.stat.new::before      { background: var(--st-new); }
.stat.progress::before { background: var(--st-progress); }
.stat.review::before   { background: var(--st-review); }
.stat.done::before     { background: var(--st-done); }
.stat.good::before     { background: var(--st-good); }
.stat.warn::before     { background: var(--st-warn); }
.stat.bad::before      { background: var(--st-bad); }
/* Roll-up totals sit visually apart from the per-status cards — they're the
   yardstick you check the individual statuses against, not another status. */
.stat.rollup { background: var(--surface-2); border-color: var(--border-lit); }
.stat.rollup::before { background: var(--accent); }
.stat.rollup .n { color: var(--text); }
.stat.rollup.done::before { background: var(--st-done); }
.stat.rollup.done .n { color: var(--st-done); }
.stat.good .n { color: var(--st-good); }
.stat.review .n { color: var(--st-review); }
.stat.bad .n  { color: var(--st-bad); }

/* ---------- panels & tables ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; margin-bottom: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.panel-head h2 { margin: 0; font-size: 14px; font-weight: 650; }
.panel-body { padding: 16px; }

.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
/* NOTE: .tablewrap sets overflow-x:auto, which per spec forces overflow-y to
   `auto` as well — making it a scroll container. A sticky `th` therefore
   positions relative to THAT container, not the viewport, so `top: 56px`
   (the topbar height) pushed the header 56px down and it sat on top of the
   first row, hiding it. `top: 0` keeps the header where it belongs. */
th {
  text-align: left; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-mute); padding: 10px 14px; border-bottom: 1px solid var(--border);
  background: var(--surface); position: sticky; top: 0; z-index: 5;
}
td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover td { background: rgba(255,255,255,.022); }
tbody tr:last-child td { border-bottom: none; }
.t-strong { font-weight: 600; }
.t-dim { color: var(--text-dim); }
.t-mute { color: var(--text-mute); font-size: 12px; }
.t-mono { font-family: "SF Mono", ui-monospace, Menlo, monospace; font-size: 12px; }
.t-right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ---------- status pills ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 99px; font-size: 11px; font-weight: 650;
  white-space: nowrap; letter-spacing: .01em;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.pill.new      { color: var(--st-new);      background: rgba(139,149,167,.14); }
.pill.progress { color: var(--st-progress); background: rgba(77,159,255,.14); }
.pill.review   { color: var(--st-review);   background: rgba(245,177,61,.15); }
.pill.done     { color: var(--st-done);     background: rgba(53,201,165,.14); }
.pill.good     { color: var(--st-good);     background: rgba(62,207,122,.15); }
.pill.warn     { color: var(--st-warn);     background: rgba(255,143,90,.15); }
.pill.bad      { color: var(--st-bad);      background: rgba(242,84,91,.15); }
.pill.call     { color: var(--st-call);     background: rgba(169,123,255,.15); }

/* ---------- buttons ---------- */
button, .btn {
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  border-radius: 8px; padding: 8px 15px; border: 1px solid transparent;
  background: var(--accent); color: #14161a; transition: background .12s, border-color .12s;
}
button:hover, .btn:hover { background: var(--accent-hover); color: #14161a; }
button:disabled { opacity: .45; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border-lit); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); border-color: var(--text-mute); }
.btn-sm { padding: 5px 11px; font-size: 12px; border-radius: 7px; }
.btn-good { background: var(--st-good); color: #08130d; }
.btn-good:hover { background: #5ddb92; color: #08130d; }
.btn-warn { background: var(--st-warn); color: #1a0d06; }
.btn-warn:hover { background: #ffa473; color: #1a0d06; }
.btn-bad  { background: var(--st-bad); color: #fff; }
.btn-bad:hover { background: #ff6b71; color: #fff; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 13px; }
.field label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-dim); }
input, select, textarea {
  font: inherit; font-size: 14px; width: 100%;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border-lit); border-radius: 8px; padding: 9px 11px;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder, textarea::placeholder { color: var(--text-mute); }
textarea { resize: vertical; min-height: 90px; line-height: 1.55; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 14px; }
.hint { font-size: 11px; color: var(--text-mute); margin-top: -8px; margin-bottom: 12px; }

.toolbar { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; min-width: 150px; padding: 7px 10px; font-size: 13px; }

/* ---------- empty state ---------- */
.empty { padding: 52px 20px; text-align: center; color: var(--text-mute); }
.empty .icon { font-size: 30px; opacity: .35; margin-bottom: 10px; }
.empty h3 { margin: 0 0 5px; font-size: 14px; color: var(--text-dim); font-weight: 600; }
.empty p { margin: 0; font-size: 13px; }

/* ---------- sticky notes: always one keystroke away ---------- */
.notes-fab {
  position: fixed; right: 22px; bottom: 22px; z-index: 60;
  width: 50px; height: 50px; border-radius: 50%; border: none;
  background: var(--accent); color: #14161a; font-size: 21px;
  box-shadow: var(--shadow); display: grid; place-items: center; padding: 0;
}
.notes-fab:hover { background: var(--accent-hover); transform: translateY(-1px); }
.notes-panel {
  position: fixed; right: 0; top: 0; bottom: 0; width: 400px; max-width: 92vw; z-index: 70;
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: -8px 0 40px rgba(0,0,0,.45);
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .18s ease;
}
.notes-panel.open { transform: translateX(0); }
.notes-head { display: flex; align-items: center; justify-content: space-between; padding: 15px 16px; border-bottom: 1px solid var(--border); }
.notes-head h3 { margin: 0; font-size: 14px; font-weight: 650; }
.notes-head .close { background: none; border: none; color: var(--text-mute); font-size: 22px; cursor: pointer; padding: 0 4px; }
.notes-head .close:hover { color: var(--text); background: none; }
.notes-panel textarea {
  flex: 1; border: none; border-radius: 0; background: transparent;
  padding: 16px; font-size: 14px; line-height: 1.65; resize: none;
}
.notes-panel textarea:focus { box-shadow: none; border-color: transparent; }
.notes-foot { padding: 9px 16px; border-top: 1px solid var(--border); font-size: 11px; color: var(--text-mute); display: flex; justify-content: space-between; }
.notes-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 65; opacity: 0; pointer-events: none; transition: opacity .18s; }
.notes-backdrop.open { opacity: 1; pointer-events: auto; }

/* ---------- toast ---------- */
.toasts { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--surface-2); border: 1px solid var(--border-lit); color: var(--text);
  padding: 10px 17px; border-radius: 99px; font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow); animation: rise .2s ease;
}
.toast.good { border-color: var(--st-good); color: var(--st-good); }
.toast.bad  { border-color: var(--st-bad);  color: var(--st-bad); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 370px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 30px; box-shadow: var(--shadow); }
.login-card .brand { justify-content: center; margin-bottom: 6px; font-size: 17px; }
.login-card .tag { text-align: center; color: var(--text-mute); font-size: 12px; margin-bottom: 24px; }
.login-card button { width: 100%; padding: 10px; margin-top: 6px; }
.err { background: rgba(242,84,91,.12); border: 1px solid rgba(242,84,91,.4); color: #ff9096; padding: 9px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; }

/* ---------- misc ---------- */
.sale-detail dt { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-mute); margin-top: 12px; }
.sale-detail dd { margin: 3px 0 0; font-size: 14px; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.claimed-by { font-size: 11px; color: var(--st-progress); }
.age { font-size: 11px; color: var(--text-mute); }
.age.stale { color: var(--st-review); font-weight: 600; }

@media (max-width: 820px) {
  .topbar { height: auto; flex-wrap: wrap; padding: 10px 14px; gap: 10px; }
  th { position: static; }
  .wrap { padding: 16px 12px 90px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
