/* SnoutCover Admin - design system v2 (professional admin dashboard).
   Brand tokens per spec section 9; loaded by index.html, order.html, thread.html, login.html.
   All tokens live here only - never re-declare in page <style> blocks. */

:root {
  --blue: #0040FF;
  --blue-ink: #0031C4;
  --blue-tint: #E7EDFF;
  --card-blue: #DBECFF;
  --bg: #F6F8FB;
  --surface: #FFFFFF;
  --text: #47506B;
  --muted: #8A94A6;
  --heading: #0B1220;
  --positive: #109441;
  --positive-tint: #E1F3E8;
  --negative: #B30021;
  --negative-tint: #FBE9EC;
  --warning: #D98900;
  --warning-tint: #FBF0DA;
  --gray-tint: #EDF0F4;
  --hairline: rgba(15, 23, 42, 0.07);
  --shadow-card: 0 1px 2px rgba(16, 24, 40, 0.05), 0 2px 8px rgba(16, 24, 40, 0.06);
  --shadow-float: 0 8px 30px rgba(16, 24, 40, 0.16);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); }
html { -webkit-tap-highlight-color: transparent; }
body {
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 15px;
  color: var(--text);
  padding: 12px 16px 64px;
  max-width: 680px;
  margin: 0 auto;
  -webkit-font-smoothing: antialiased;
  touch-action: pan-y;
}
a, button, input, .chip, .icon-btn, .drawer-link, .zone-jump-link {
  -webkit-tap-highlight-color: transparent;
}
:focus:not(:focus-visible) { outline: none; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
h1, h2, h3 { font-family: 'Cal Sans', 'Inter', sans-serif; color: var(--heading); margin: 0; }
h1 { font-size: 21px; letter-spacing: 0.01em; }
a { color: var(--blue); }
.back { display: inline-block; margin-bottom: 12px; font-size: 14px; color: var(--blue); text-decoration: none; font-weight: 600; }

/* ---------- Header ---------- */
header.top { padding: 6px 0 10px; }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand svg { width: 30px; height: 25px; overflow: visible; display: block; }
.brand h1 { white-space: nowrap; }
.actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.updated { color: var(--muted); font-size: 11.5px; margin-top: 8px; }
.icon-btn {
  background: var(--surface); border: 1px solid var(--hairline); border-radius: 12px;
  width: 38px; height: 38px; display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; box-shadow: var(--shadow-card); color: var(--heading); flex-shrink: 0;
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.icon-btn:disabled { opacity: 0.55; }

/* ---------- Sticky nav ---------- */
nav.zone-nav {
  position: sticky; top: 0; z-index: 30;
  display: flex; gap: 6px; overflow-x: auto; align-items: center;
  background: var(--bg); padding: 10px 16px;
  margin: 0 -16px;
  scrollbar-width: none;
}
nav.zone-nav::-webkit-scrollbar { display: none; }
nav.zone-nav a {
  flex-shrink: 0; padding: 8px 14px; border-radius: 999px;
  background: var(--surface); color: var(--heading); border: 1px solid var(--hairline);
  font-size: 13px; font-weight: 600; text-decoration: none; white-space: nowrap;
  box-shadow: var(--shadow-card);
}
nav.zone-nav a.active { background: var(--blue); color: #fff; border-color: var(--blue); }

/* ---------- Zones ---------- */
section.zone { display: none; }
section.zone.active { display: block; animation: zoneIn 0.18s ease; }
@keyframes zoneIn { from { opacity: 0; transform: translateX(8px); } to { opacity: 1; transform: translateX(0); } }
@media (prefers-reduced-motion: reduce) { section.zone.active { animation: none; } }

/* Flashed briefly on a target card/chart/tile after a jump-link scrolls to it */
.flash-highlight { animation: flashHighlight 1.4s ease; border-radius: 20px; }
.chart.flash-highlight { border-radius: 16px; }
@keyframes flashHighlight {
  0% { box-shadow: 0 0 0 3px var(--blue-tint); }
  65% { box-shadow: 0 0 0 3px var(--blue-tint); }
  100% { box-shadow: none; }
}
h2.zone-title { font-size: 19px; margin: 26px 0 10px; display: flex; align-items: center; gap: 9px; }
h2.zone-title .z-icon {
  width: 30px; height: 30px; border-radius: 10px; background: var(--blue-tint); color: var(--blue);
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
h2.zone-title .z-icon svg { width: 16px; height: 16px; }
h2.zone-title small { font-family: 'Inter', sans-serif; font-weight: 500; font-size: 12px; color: var(--muted); margin-left: auto; text-align: right; }
h3.zone-sub {
  font-family: 'Inter', sans-serif; font-weight: 700; font-size: 11.5px;
  color: var(--muted); margin: 16px 2px 7px; text-transform: uppercase; letter-spacing: 0.06em;
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border-radius: 20px; padding: 14px 16px; margin-bottom: 10px;
  box-shadow: var(--shadow-card);
}
.card.hero { background: var(--card-blue); box-shadow: none; border-radius: 24px; }
.card.flag { background: var(--warning-tint); box-shadow: none; }
.card.gray { background: var(--surface); border-radius: 24px; }
.unavailable { color: var(--muted); font-size: 13px; font-style: italic; padding: 4px 0; }

/* ---------- Brief (digest) ---------- */
.brief-row { display: flex; gap: 10px; align-items: flex-start; padding: 7px 0; }
.brief-row + .brief-row { border-top: 1px solid rgba(11, 18, 32, 0.06); }
.brief-row.clickable { cursor: pointer; }
.brief-row.clickable:active { opacity: 0.75; }
.brief-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; }
.brief-dot.red { background: var(--negative); }
.brief-dot.amber { background: var(--warning); }
.brief-dot.green { background: var(--positive); }
.brief-dot.blue { background: var(--blue); }
.brief-dot.gray { background: var(--muted); }
.brief-text { font-size: 14px; line-height: 1.45; color: var(--heading); flex: 1; min-width: 0; }
.brief-text b { font-weight: 700; }
.brief-chev { color: var(--muted); font-size: 18px; font-weight: 400; flex-shrink: 0; align-self: center; margin-left: 2px; }
.brief-label { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--blue-ink); margin-bottom: 4px; }

/* ---------- KPIs ---------- */
.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
@media (min-width: 560px) { .kpi-grid { grid-template-columns: repeat(4, 1fr); } }
.kpi { background: var(--surface); border-radius: 20px; padding: 13px 14px; box-shadow: var(--shadow-card); }
.kpi .v { font-family: 'Cal Sans', 'Inter', sans-serif; font-size: 25px; color: var(--heading); line-height: 1.1; }
.kpi .l { font-size: 12px; color: var(--muted); margin-top: 3px; font-weight: 500; }
.kpi .d { font-size: 11.5px; font-weight: 700; margin-top: 4px; }
.kpi .d.up { color: var(--positive); }
.kpi .d.down { color: var(--negative); }
.kpi .d.flat { color: var(--muted); }
a.zone-jump-link { -webkit-tap-highlight-color: transparent; }
a.zone-jump-link .kpi { transition: transform 0.1s ease, box-shadow 0.1s ease; }
a.zone-jump-link:active .kpi { transform: scale(0.97); }

/* ---------- Action queue ---------- */
.aq-group { margin-bottom: 4px; }
.aq-group:last-child { margin-bottom: 0; }
.aq-group-title { font-size: 11.5px; font-weight: 700; color: var(--blue-ink); text-transform: uppercase; letter-spacing: 0.05em; padding: 12px 0 4px; }
.aq-group:first-child .aq-group-title { padding-top: 0; }
.action-item {
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--hairline);
}
.action-item:last-child { border-bottom: none; }
.action-item .label { font-weight: 600; color: var(--heading); font-size: 14px; }
.action-item .sub { font-size: 12px; color: var(--text); margin-top: 2px; line-height: 1.4; }
/* Text block fills the row; the status pill sits on the title line so subtext
   gets the full card width instead of wrapping beside a badge column. */
.action-item > div:first-child, .order-row > div:first-child { flex: 1; min-width: 0; }
/* nowrap: the pill must never fall to its own left-aligned line when the name
   is long - the label wraps internally instead, the pill stays pinned right. */
.label-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 4px 10px; flex-wrap: nowrap; }
.label-row .label { min-width: 0; flex: 1 1 auto; overflow-wrap: break-word; word-break: break-word; }
.label-row .badge { margin-top: 1px; flex-shrink: 0; }
.label-row .badges { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; flex-shrink: 0; max-width: 55%; }
a.drawer-link .action-item::after, a.drawer-link .order-row::after {
  content: '\203A'; color: var(--muted); font-size: 18px; font-weight: 400; flex-shrink: 0; margin-left: -2px;
}

/* ---------- Badges / status pills ---------- */
.badge {
  font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  white-space: nowrap; flex-shrink: 0; display: inline-block;
}
.badge.red { background: var(--negative); color: #fff; }
.badge.amber { background: var(--warning); color: #fff; }
.badge.green { background: var(--positive); color: #fff; }
.badge.blue { background: var(--blue); color: #fff; }
.badge.gray { background: var(--gray-tint); color: #5B6472; }
.badge.t-blue { background: var(--blue-tint); color: var(--blue-ink); }
.badge.t-green { background: var(--positive-tint); color: #0B6B30; }
.badge.t-amber { background: var(--warning-tint); color: #92620A; }
.badge.t-red { background: var(--negative-tint); color: var(--negative); }
.badge.outline { background: var(--surface); color: var(--blue); box-shadow: inset 0 0 0 1.5px var(--blue); }

/* ---------- Chips + search (orders) ---------- */
.filter-row { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 10px; }
.chip {
  background: var(--surface); border-radius: 999px; padding: 8px 13px;
  font-size: 12.5px; font-weight: 600; color: var(--heading);
  display: flex; align-items: center; gap: 6px; border: 1px solid var(--hairline); cursor: pointer;
  font-family: 'Inter', sans-serif; box-shadow: var(--shadow-card);
}
.chip .count { color: var(--blue); font-weight: 700; }
.chip.active { background: var(--blue); color: #fff; border-color: var(--blue); }
.chip.active .count { color: #fff; }
.search-input {
  width: 100%; padding: 11px 15px; border-radius: 14px; border: 1px solid var(--hairline);
  font-size: 15px; font-family: 'Inter', sans-serif; margin-bottom: 10px;
  background: var(--surface); box-shadow: var(--shadow-card); color: var(--heading);
}
.search-input:focus { outline: 2px solid var(--blue); outline-offset: -1px; }
.orders-count { font-size: 12px; color: var(--muted); margin: 0 2px 8px; }
.order-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--hairline);
}
.order-row:last-child { border-bottom: none; }
.order-row .label { font-weight: 600; color: var(--heading); font-size: 14px; }
.order-row .sub { font-size: 12px; color: var(--text); margin-top: 2px; }

/* ---------- Key-value rows ---------- */
.row { display: flex; justify-content: space-between; padding: 7px 0; font-size: 14px; gap: 12px; }
.row .k { color: var(--text); }
.row .v { font-weight: 600; color: var(--heading); text-align: right; }
.row.bordered { border-bottom: 1px solid var(--hairline); }
.row.bordered:last-child { border-bottom: none; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--blue); display: inline-block; margin-right: 6px; }
.order-tag { display: inline-block; font-size: 11px; color: var(--blue); font-weight: 600; margin-top: 3px; }

/* ---------- Stat grids ---------- */
.totals-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.totals-grid .stat { font-size: 21px; font-weight: 700; color: var(--heading); font-family: 'Cal Sans', 'Inter', sans-serif; }
.totals-grid .stat-label { font-size: 12px; color: var(--muted); margin-top: 1px; }
.prepare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.prepare-grid .stat { font-size: 27px; font-weight: 700; color: var(--heading); font-family: 'Cal Sans', 'Inter', sans-serif; }
.prepare-grid .stat-label { font-size: 12px; color: var(--muted); margin-top: 1px; }

/* ---------- Label bars ---------- */
.breakdown-group + .breakdown-group { margin-top: 16px; }
.breakdown-group h3 { margin: 0 0 8px; font-size: 13px; }
.bar-row { margin-bottom: 8px; }
.bar-row:last-child { margin-bottom: 0; }
.bar-label-row { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; margin-bottom: 3px; }
.bar-label-row .name { font-weight: 600; color: var(--heading); }
.bar-label-row .count { color: var(--muted); flex-shrink: 0; font-weight: 600; }
.bar-track { background: var(--gray-tint); border-radius: 4px; height: 8px; overflow: hidden; }
.bar-fill { background: var(--blue); height: 100%; border-radius: 4px; min-width: 4px; }
.bar-more { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ---------- SVG charts ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .chart-title { font-size: 13px; font-weight: 700; color: var(--heading); margin-bottom: 8px; font-family: 'Inter', sans-serif; }
.chart + .chart { margin-top: 22px; }
.chart path.bar { transition: fill 0.12s ease; }
.chart path.bar.hover { fill: var(--blue-ink); }
.chart rect[data-idx] { cursor: pointer; }
.chart-tip {
  position: fixed; z-index: 60; pointer-events: none;
  background: rgba(11, 18, 32, 0.88); color: #fff; border-radius: 8px;
  padding: 6px 9px; font-size: 12px; line-height: 1.4; white-space: nowrap;
  transform: translate(-50%, calc(-100% - 10px)); display: none;
}

/* ---------- Global client search overlay ---------- */
.search-overlay {
  position: fixed; inset: 0; z-index: 70; background: var(--bg);
  padding: 14px 16px; overflow-y: auto; display: none;
}
.search-overlay.open { display: block; }
.search-overlay .search-head { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; position: sticky; top: 0; background: var(--bg); padding: 2px 0 8px; }
.search-overlay .search-head input { margin-bottom: 0; flex: 1; }
.search-result { display: block; text-decoration: none; color: inherit; }
.search-result .card { margin-bottom: 8px; padding: 12px 14px; }
.search-hint { color: var(--muted); font-size: 13px; text-align: center; padding: 24px 0; }

/* ---------- Detail views (order/thread + drawer) ---------- */
.reason { font-size: 13.5px; line-height: 1.5; background: var(--bg); border-radius: 12px; padding: 10px 12px; margin-top: 10px; color: var(--text); }
.notion-link { display: inline-block; margin-top: 10px; background: var(--blue); color: #fff; text-decoration: none; font-weight: 600; font-size: 13px; padding: 9px 15px; border-radius: 12px; }
.notion-link.secondary { background: var(--gray-tint); color: var(--heading); }
.track-link { color: var(--blue); text-decoration: none; font-weight: 600; }
.msg { padding: 8px 0; border-bottom: 1px solid var(--hairline); }
.msg:last-child { border-bottom: none; }
.msg .label { font-weight: 600; color: var(--heading); font-size: 14px; }
.msg .sub { font-size: 12px; color: var(--text); }
.thread-block { background: var(--surface); border-radius: 20px; padding: 14px 16px; margin-bottom: 12px; box-shadow: var(--shadow-card); }
.thread-block.highlight { outline: 2px solid var(--blue); }
.thread-block h3 { font-size: 15px; margin: 0 0 10px; }
.msg-full { background: var(--bg); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; }
.msg-full:last-child { margin-bottom: 0; }
.msg-full.mine { background: var(--blue-tint); }
.msg-head { display: flex; justify-content: space-between; gap: 8px; font-size: 11.5px; color: var(--muted); margin-bottom: 6px; }
.msg-head .from { font-weight: 700; color: var(--heading); }
.msg-body { font-size: 14px; line-height: 1.55; white-space: pre-wrap; color: var(--text); word-break: break-word; }
.msg-body.clamp { max-height: 150px; overflow: hidden; position: relative; }
.msg-body.clamp::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 40px; background: linear-gradient(transparent, var(--bg)); }
.msg-full.mine .msg-body.clamp::after { background: linear-gradient(transparent, var(--blue-tint)); }
.msg-expand { background: none; border: none; color: var(--blue); font-weight: 700; font-size: 12px; cursor: pointer; padding: 4px 0 0; font-family: 'Inter', sans-serif; }

/* ---------- Drawer / sidebar ---------- */
.drawer-overlay { position: fixed; inset: 0; background: rgba(11, 18, 32, 0.45); opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 40; }
.drawer-overlay.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; left: 0; right: 0; bottom: 0; top: 7vh; background: var(--bg); z-index: 50;
  box-shadow: var(--shadow-float); transition: transform 0.25s ease; overflow-y: auto;
  border-radius: 24px 24px 0 0; transform: translateY(100%); padding: 16px 16px 40px;
}
.drawer.open { transform: translateY(0); }
.drawer-close { position: sticky; top: -16px; display: flex; justify-content: flex-end; margin: -16px -16px 4px; background: linear-gradient(var(--bg) 70%, transparent); padding: 12px 16px 8px; z-index: 1; }
.drawer-close button { background: var(--surface); border: 1px solid var(--hairline); border-radius: 999px; width: 34px; height: 34px; font-size: 16px; cursor: pointer; color: var(--heading); box-shadow: var(--shadow-card); }
@media (min-width: 720px) {
  .drawer { left: auto; right: 0; top: 0; bottom: 0; width: 440px; border-radius: 0; transform: translateX(100%); }
  .drawer.open { transform: translateX(0); }
}

/* ---------- Login ---------- */
form.auth { width: 100%; max-width: 320px; text-align: center; }
form.auth h1 { font-size: 20px; margin: 0 0 8px; }
form.auth p.hint { font-size: 13px; margin: 0 0 20px; }
form.auth input {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--hairline);
  font-size: 16px; font-family: 'Inter', sans-serif; margin-bottom: 12px; background: var(--surface);
}
form.auth input#code { letter-spacing: 6px; text-align: center; font-weight: 600; }
form.auth button {
  width: 100%; padding: 12px; border-radius: 12px; border: none; background: var(--blue);
  color: #fff; font-weight: 600; font-size: 15px; font-family: 'Inter', sans-serif; cursor: pointer;
}
form.auth button:disabled { opacity: 0.6; }
form.auth button.secondary { background: none; color: var(--blue); margin-top: 4px; font-weight: 500; font-size: 13px; padding: 6px; }
form.auth .error { color: var(--negative); font-size: 13px; margin-bottom: 12px; min-height: 16px; }
.hidden { display: none; }

footer { text-align: center; color: var(--muted); font-size: 12px; margin-top: 36px; }
