/* Martin Co. theme. Tokens are copied from design/DESIGN.md; components follow design/mockups/. */

:root {
  --bg: #F7F8FA;
  --card: #FFFFFF;
  --line: #E5E7EB;
  --line-soft: #F0F1F3;
  --th: #F9FAFB;
  --col: #EEF0F3;          /* board column */
  --primary: #1F4FD8;
  --primary-hover: #163BA6;
  --primary-tint: #EAF1FE;
  --text: #111827;
  --text-2: #374151;
  --text-3: #4B5563;
  --muted: #5B6270;
  --faint: #6B7280;      /* 4.4:1 on #F3F4F6, enough for icons and placeholders */
  --input-line: #D1D5DB;
  --flag-row: #FFFBFA;
  --flag-line: #F5C2BE;

  --r-card: 14px;
  --r-btn: 10px;
  --r-btn-sm: 8px;
  --side: 248px;

  --sans: "IBM Plex Sans Thai", Inter, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

/* tone = whose turn it is */
.t-gray   { --tbg: #F1F2F4; --tfg: #3F4654; --tbar: #6B7280; }
.t-blue   { --tbg: #EAF1FE; --tfg: #1F4FD8; --tbar: #1F4FD8; }
.t-violet { --tbg: #F1EEFC; --tfg: #5B3FC4; --tbar: #6E56CF; }
.t-green  { --tbg: #E8F6EE; --tfg: #16794A; --tbar: #16A34A; }
.t-amber  { --tbg: #FFF4E5; --tfg: #8A4B00; --tbar: #E58A00; }
.t-red    { --tbg: #FDECEC; --tfg: #B42318; --tbar: #D92D20; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); }
a:hover { color: var(--primary-hover); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid rgb(31 79 216 / .35); outline-offset: 2px; }
.mono { font-family: var(--mono); font-weight: 500; }
.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg.i { flex: none; }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100vh; }
.side {
  width: var(--side); flex: none; background: var(--card); border-right: 1px solid var(--line);
  padding: 24px 16px; display: flex; flex-direction: column; gap: 24px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; text-decoration: none; color: var(--text); }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; background: var(--primary); display: grid; place-items: center; }
.brand b { display: block; font-size: 16px; font-weight: 700; }
.brand small { display: block; font-size: 12px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 10px; height: 40px; padding: 0 10px; border-radius: 9px;
  font-size: 14px; font-weight: 500; color: var(--text-2); text-decoration: none; white-space: nowrap;
}
.nav a:hover { background: var(--bg); color: var(--text); }
.nav a[aria-current="page"] { background: var(--primary); color: #FFF; font-weight: 600; }
.nav a[aria-current="page"]:hover { background: var(--primary-hover); color: #FFF; }
.nav a[aria-current="page"] .count { background: rgb(255 255 255 / .2); color: #FFF; }
.count { margin-left: auto; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: #F1F2F4; color: #3F4654; }
.count.warn { background: #FDECEC; color: #B42318; }
.side-user { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 12px 8px 0; border-top: 1px solid var(--line); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary-tint); color: var(--primary); font-weight: 600; font-size: 13px; display: grid; place-items: center; flex: none; }
.side-user b { display: block; font-size: 14px; font-weight: 500; }
.side-user small { display: block; font-size: 12px; color: var(--muted); }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); }
.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #16A34A; }
.live.off::before { background: #D92D20; }

/* dark-blue sidebar: white text and icons, the selected item in the primary blue */
.side { --side-bg: #0E0C32; --side-line: rgb(255 255 255 / .12); background: var(--side-bg); border-color: var(--side-line); color: #FFF; }
.side .brand { color: #FFF; }
.side .brand-mark { background: #FFF; }
.side .brand-mark svg { stroke: var(--primary); }
.side .brand small, .side .side-user small, .side .live { color: rgb(255 255 255 / .72); }
.side .nav a { color: rgb(255 255 255 / .86); }
.side .nav a:hover { background: rgb(255 255 255 / .08); color: #FFF; }
.side .nav a[aria-current="page"] { background: var(--primary); color: #FFF; }
.side .nav a[aria-current="page"]:hover { background: #2A5BE6; }
.side .count { background: rgb(255 255 255 / .14); color: #FFF; }
.side .count.warn { background: #FDECEC; color: #B42318; }
.side .side-user { border-top-color: var(--side-line); }
.side .avatar { background: rgb(255 255 255 / .14); color: #FFF; }
.side :focus-visible { outline-color: rgb(255 255 255 / .6); }

.main { flex: 1; min-width: 0; padding: 28px 32px 48px; display: flex; flex-direction: column; gap: 20px; max-width: 1304px; }
.main.wide { max-width: none; }

/* ---------- page header ---------- */
.head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.head-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.eyebrow { font-size: 13px; color: var(--muted); }
h1 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -.5px; line-height: 1.25; }
h1.big { font-size: 30px; }
.sub { font-size: 14px; color: var(--muted); }
.head-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
h2 { margin: 0; font-size: 18px; font-weight: 600; }
h2.sm { font-size: 17px; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px;
  border-radius: var(--r-btn); border: 1px solid var(--input-line); background: var(--card); color: var(--text);
  font-size: 14px; font-weight: 500; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--th); color: var(--text); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #FFF; font-weight: 600; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #FFF; }
.btn-danger { background: #B42318; border-color: #B42318; color: #FFF; font-weight: 600; }
.btn-danger:hover { background: #8F1C13; color: #FFF; }
.btn-md { height: 36px; padding: 0 14px; border-radius: 9px; font-size: 13px; min-width: 120px; }
.btn-sm { height: 32px; padding: 0 12px; border-radius: var(--r-btn-sm); font-size: 12px; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-icon { width: 32px; height: 32px; padding: 0; border: 0; background: transparent; border-radius: 8px; color: var(--text-3); display: inline-grid; place-items: center; }
.btn-icon:hover { background: var(--bg); }

.search { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-btn); min-width: 240px; }
.search.sm { height: 38px; }
.search:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgb(31 79 216 / .12); }
.search input { border: 0; outline: none; background: transparent; flex: 1; min-width: 0; font-size: 14px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 12px; border: 1px solid var(--line);
  border-radius: var(--r-btn); background: var(--card); font-size: 13px; color: var(--text-2); white-space: nowrap;
}
.chip.on { border-color: var(--primary); background: var(--primary-tint); color: var(--primary); font-weight: 500; }
.chip.sm { height: 32px; border-radius: 8px; }
.chip.dark { background: var(--text); border-color: var(--text); color: #FFF; }

.seg { display: inline-flex; padding: 3px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-btn); }
.seg.soft { background: var(--bg); }
.seg > * { display: inline-flex; align-items: center; height: 32px; padding: 0 14px; border-radius: 8px; border: 0; background: transparent; color: var(--text-2); font-size: 13px; font-weight: 500; text-decoration: none; }
.seg > [aria-current="page"], .seg > [aria-pressed="true"] { background: var(--primary-tint); color: var(--primary); font-weight: 600; }
.seg.soft > [aria-pressed="true"] { background: var(--card); }

/* dropdown menus (details/summary) */
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-pop {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 20; min-width: 210px; background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(17, 24, 39, .10); padding: 6px;
}
.menu-pop.right { left: auto; right: 0; }
.menu-pop label, .menu-pop button {
  display: flex; align-items: center; gap: 10px; width: 100%; height: 36px; padding: 0 8px; border-radius: 7px;
  font-size: 13px; cursor: pointer; border: 0; background: transparent; text-align: left; white-space: nowrap;
}
.menu-pop label:hover, .menu-pop button:hover { background: var(--bg); }
.menu-pop button[aria-pressed="true"] { color: var(--primary); font-weight: 600; }

/* ---------- cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card); }
.card.clip { overflow: hidden; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.card-head .sub { font-size: 13px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.toolbar-group { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.card-foot { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.kpi { background: var(--tbg); border: 1px solid var(--line); border-radius: var(--r-card); padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kpi-label { font-size: 13px; font-weight: 500; color: var(--text-2); }
.kpi-icon { width: 30px; height: 30px; border-radius: 8px; background: #FFF; color: var(--tfg); display: grid; place-items: center; }
.kpi-value { font-size: 32px; font-weight: 700; letter-spacing: -.5px; line-height: 1.2; }
.kpi-sub { font-size: 12px; color: var(--text-3); }

/* ---------- badges ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--tbg); color: var(--tfg);
}
.pill.lg { height: 26px; min-width: 132px; }
.pill.sm { height: 22px; padding: 0 8px; font-size: 11px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--tbar); flex: none; display: inline-block; }
.dot.sm { width: 7px; height: 7px; }
.plat { display: inline-flex; align-items: center; height: 24px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.plat-tiktok_shop { background: #111827; color: #FFF; }
.plat-tiktok_chat { background: #FFF; color: #111827; border: 1px solid #111827; }
.plat-line { background: #E7F7EC; color: #0B7A35; }
.plat-shopee { background: #FFF1EC; color: #C2410C; }
.carrier { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 5px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.carrier.lg { height: 24px; padding: 0 9px; border-radius: 6px; font-size: 12px; }
.c-flash { background: #FFF7CC; color: #6B5400; }
.c-kerry { background: #FFEDE0; color: #9A3D00; }
.c-jt { background: #FDECEC; color: #B42318; }
.c-thaipost { background: #EAF1FE; color: #1F4FD8; }
.c-tiktok { background: #111827; color: #FFF; }
.owner-chip { display: inline-flex; align-items: center; height: 24px; padding: 0 10px; border-radius: 6px; background: var(--tbg); color: var(--tfg); font-size: 12px; font-weight: 600; white-space: nowrap; }
.delay { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 6px; font-size: 11px; font-weight: 600; background: #FFF4E5; color: #8A4B00; margin-left: 8px; }

.bar { display: flex; gap: 3px; }
.bar span { flex: 1; height: 7px; border-radius: 2px; background: var(--line); }
.bar span.on { background: var(--tbar); }
.bar.thick span { height: 8px; border-radius: 3px; }
.bar.thin span { height: 6px; }
.prod { display: flex; flex-direction: column; gap: 4px; min-width: 104px; }
.prod small { font-size: 11px; color: var(--text-3); }

.level { flex: 1; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.level > div { height: 100%; background: var(--tbar); }

/* ---------- tables ---------- */
.scroll-x { overflow-x: auto; position: relative; }
table.grid { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
table.grid th { background: var(--th); padding: 10px 8px; font-weight: 600; color: var(--text-3); text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.grid td { padding: 0 8px; height: 58px; border-bottom: 1px solid var(--line-soft); background: var(--card); vertical-align: middle; }
table.grid tbody tr:last-child td { border-bottom: 0; }
table.grid tr.flag td { background: var(--flag-row); }
table.grid tbody tr:hover td { background: #FAFBFC; }
table.grid tbody tr.flag:hover td { background: #FFF6F5; }
table.grid tbody tr:focus-visible { outline: none; }
table.grid tbody tr:focus-visible td { box-shadow: inset 0 2px 0 var(--primary), inset 0 -2px 0 var(--primary); }
table.grid .num { text-align: right; }
table.grid th:first-child, table.grid td:first-child { padding-left: 16px; }
table.grid th:last-child, table.grid td:last-child { padding-right: 16px; }
table.grid.plain td { height: 52px; }
table.grid.compact td { height: 46px; }
table.grid.nohead th { background: transparent; }
.sticky-0, .sticky-1, .sticky-2 { position: sticky; z-index: 1; }
th.sticky-0, th.sticky-1, th.sticky-2 { z-index: 2; }
.sticky-0 { left: 0; width: 40px; min-width: 40px; }
.sticky-1 { left: 40px; width: 96px; min-width: 96px; }
.sticky-2 { left: 136px; width: 160px; min-width: 160px; box-shadow: 1px 0 0 var(--line); }
table.grid th.sticky-0, table.grid td.sticky-0 { padding: 0 12px; }
.stack { display: flex; flex-direction: column; gap: 2px; align-items: flex-start; }
.stack.g4 { gap: 4px; }
.id-link { font-family: var(--mono); font-weight: 500; font-size: 12px; color: var(--primary); background: none; border: 0; padding: 0; text-decoration: none; cursor: pointer; text-align: left; }
.id-link:hover { text-decoration: underline; }
.tiny { font-size: 11px; color: var(--muted); }
.note { font-size: 11px; color: var(--text-3); white-space: nowrap; }
.note.red { color: #B42318; }
.nowrap { white-space: nowrap; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); font-size: 14px; }
.track { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.track .mono { font-size: 11px; color: var(--text-2); }
.copy { width: 22px; height: 22px; border: 0; background: transparent; color: var(--faint); border-radius: 5px; display: inline-grid; place-items: center; padding: 0; }
.copy:hover { background: var(--bg); color: var(--text-2); }
.pager { display: flex; gap: 4px; }
.pager button { min-width: 32px; height: 32px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); font-size: 13px; }
.pager button[aria-current="page"] { background: var(--primary); border-color: var(--primary); color: #FFF; font-weight: 600; }

/* ---------- Orders: status summary ---------- */
.stages { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.stage-btn { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); text-align: left; }
.stage-btn .row { display: flex; align-items: center; gap: 8px; }
.stage-btn b { font-size: 14px; font-weight: 600; }
.stage-btn strong { margin-left: auto; font-size: 18px; font-weight: 700; }
.stage-btn small { font-size: 11px; color: var(--text-3); }
.stage-btn.flagbox { background: #FDECEC; border-color: var(--flag-line); }
.stage-btn[aria-pressed="true"] { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }

/* ---------- Today ---------- */
.inbox-row { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; padding: 14px 20px; border-bottom: 1px solid var(--line-soft); }
.inbox-row:last-child { border-bottom: 0; }
.inbox-main { flex: 1 1 280px; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.inbox-main .who { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; }
.inbox-main .who .mono { font-size: 13px; color: var(--primary); }
.inbox-main .who b { font-size: 14px; font-weight: 600; }
.inbox-main .detail { font-size: 13px; color: var(--muted); }
.inbox-when { font-size: 12px; color: var(--muted); min-width: 72px; }
.section { display: flex; flex-direction: column; gap: 12px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.section-head a { font-size: 13px; font-weight: 500; }
.snaps { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.snap { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 10px; text-align: left; }
.snap:hover { border-color: #C9CED6; }
.snap-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.snap-top .mono { font-size: 12px; color: var(--primary); }
.snap-top span:last-child { font-size: 12px; font-weight: 600; color: var(--text-2); }
.snap .name { font-size: 14px; font-weight: 500; }
.snap .pill { align-self: flex-start; }

/* ---------- Board ---------- */
.board { display: grid; grid-template-columns: repeat(4, minmax(260px, 1fr)); gap: 16px; min-width: 1100px; }
.col { background: var(--col); border-radius: var(--r-card); padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.col-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 6px; }
.col-head > div { display: flex; align-items: center; gap: 8px; }
.col-head h2 { font-size: 14px; }
.col-count { font-size: 12px; font-weight: 600; color: var(--text-3); background: #FFF; border-radius: 999px; padding: 1px 8px; }
.col-owner { font-size: 11px; color: var(--text-3); }
.kcard { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 10px; text-align: left; width: 100%; }
.kcard.flag { border-color: var(--flag-line); }
.kcard:hover { border-color: #C9CED6; }
.kcard-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.kcard-top .mono { font-size: 12px; color: var(--primary); }
.kcard .name { font-size: 14px; font-weight: 600; display: block; }
.kcard .item { font-size: 12px; color: var(--muted); display: block; }
.kcard-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding-top: 8px; border-top: 1px solid var(--line-soft); font-size: 11px; color: var(--text-3); }
.kcard-foot span { display: inline-flex; align-items: center; gap: 5px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-more { font-size: 12px; color: var(--text-3); text-align: center; padding: 4px; }

/* ---------- Shipments ---------- */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 16px; border-bottom: 1px solid var(--line); }
.tabs button { display: inline-flex; align-items: center; gap: 8px; height: 46px; padding: 0 12px; border: 0; background: transparent; font-size: 13px; font-weight: 500; color: var(--text-2); }
.tabs button[aria-selected="true"] { color: var(--primary); font-weight: 600; box-shadow: inset 0 -2px 0 var(--primary); }
.tabs button[aria-selected="true"] .count { background: var(--primary-tint); color: var(--primary); }
.journey { display: flex; align-items: center; }
.journey .ln { width: 18px; height: 2px; background: #111827; flex: none; }
.journey .ln.todo { height: 0; background: none; border-top: 2px dashed var(--input-line); }
.journey .st { width: 24px; height: 24px; border-radius: 50%; display: inline-grid; place-items: center; flex: none; background: #F3F4F6; color: var(--faint); }
.journey .st.done { background: #111827; color: #FFF; }
.journey .st.now { background: #FFF; color: var(--primary); border: 2px solid var(--primary); }
.journey .st.now.problem { color: #D92D20; border-color: #D92D20; }
.legend { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--text-3); }
.legend b { color: var(--text-2); font-weight: 600; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Inventory ---------- */
.buy { background: var(--card); border: 1px solid #F7D9A8; border-radius: var(--r-card); overflow: hidden; }
.buy-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; background: #FFFAF2; border-bottom: 1px solid #F7D9A8; }
.buy-head > div { display: flex; align-items: center; gap: 10px; }
.buy-head .sub { font-size: 13px; color: #6B4A12; }
table.grid.buy-t th { background: transparent; border-bottom: 0; }
table.grid.buy-t td { border-bottom: 0; border-top: 1px solid var(--line-soft); }

/* ---------- Bot log ---------- */
.chat { display: flex; flex-direction: column; gap: 10px; padding: 16px 20px; }
.msg { display: flex; gap: 10px; align-items: flex-start; max-width: 720px; }
.msg.hoya { margin-left: auto; flex-direction: row-reverse; text-align: right; }
.msg .bubble { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; font-size: 13px; }
.msg.hoya .bubble { background: #E7F7EC; border-color: #CDEBD6; }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.msg .avatar { width: 28px; height: 28px; font-size: 11px; }

/* ---------- dialog & forms ---------- */
dialog.sheet {
  width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; border: 1px solid var(--line);
  border-radius: 16px; background: var(--card); color: var(--text); box-shadow: 0 20px 40px -8px rgb(17 24 39 / .18);
}
dialog.sheet.narrow { width: min(520px, calc(100vw - 32px)); }
dialog.sheet::backdrop { background: rgb(17 24 39 / .4); }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 24px 16px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { font-size: 20px; }
.sheet-body { padding: 20px 24px; display: flex; flex-direction: column; gap: 20px; }
.sheet-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px; border-top: 1px solid var(--line); }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px 20px; }
.facts dt { font-size: 12px; color: var(--muted); }
.facts dd { margin: 2px 0 0; font-size: 14px; font-weight: 500; }
.panel { border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.panel.red { border-color: var(--flag-line); background: var(--flag-row); }
.panel h3 { margin: 0; font-size: 15px; font-weight: 600; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: var(--text-2); }
.field input, .field select, .field textarea {
  height: 40px; padding: 0 12px; border: 1px solid var(--input-line); border-radius: 9px; background: #FFF; font-size: 14px; font-weight: 400; color: var(--text);
}
.field textarea { height: 72px; padding: 8px 12px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgb(31 79 216 / .12); }
.field small { font-weight: 400; color: var(--muted); font-size: 12px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.timeline li { display: grid; grid-template-columns: 92px 1fr; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
.timeline li:last-child { border-bottom: 0; }
.timeline time { color: var(--muted); font-size: 12px; }
.timeline .who { color: var(--muted); font-size: 12px; }
.timeline li.undone { opacity: .5; text-decoration: line-through; }
.legs { display: flex; flex-direction: column; gap: 8px; }
.leg { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-size: 13px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.leg .mono { font-size: 12px; }
.err { color: #B42318; font-size: 13px; }
.warn-list { margin: 0; padding-left: 18px; font-size: 13px; color: #8A4B00; }

#toast {
  position: fixed; inset: auto auto 24px 50%; margin: 0; border: 0; transform: translateX(-50%); z-index: 60; display: flex; align-items: center; gap: 12px;
  background: #111827; color: #FFF; padding: 10px 12px 10px 16px; border-radius: 12px; font-size: 14px; box-shadow: 0 8px 24px rgb(17 24 39 / .25);
  max-width: calc(100vw - 32px);
}
#toast:not(:popover-open) { display: none; }
#toast.error { background: #B42318; }
#toast button { background: rgb(255 255 255 / .14); border: 0; color: #FFF; height: 30px; padding: 0 12px; border-radius: 8px; font-weight: 600; font-size: 13px; }

/* ---------- phones ---------- */
@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .side { width: auto; height: auto; position: static; border-right: 0; border-bottom: 1px solid var(--line); padding: 14px 16px 10px; gap: 12px; }
  .nav { flex-direction: row; overflow-x: auto; gap: 4px; margin: 0 -16px; padding: 0 16px 4px; scrollbar-width: none; }
  .nav a { height: 36px; flex: none; }
  .nav a .count { margin-left: 4px; }
  .side-user { display: none; }
  .main { padding: 20px 16px 40px; gap: 16px; }
  h1, h1.big { font-size: 24px; }
  .search { min-width: 0; flex: 1 1 100%; }
  .head-actions { width: 100%; }
  .card-head, .inbox-row { padding-left: 16px; padding-right: 16px; }
  .kpi-value { font-size: 28px; }
  .sheet-head, .sheet-body, .sheet-foot { padding-left: 16px; padding-right: 16px; }
  .menu-pop { max-width: calc(100vw - 32px); }
  /* three sticky columns would fill a phone; keep the checkbox and order number */
  .sticky-1 { position: static; }
  .sticky-2 { left: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* order sheet: route, pinned error / unsaved bar */
.route { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.route li { border: 1px solid var(--line); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); min-width: 0; }
.route li b { font-weight: 600; color: inherit; }
.route li span { overflow-wrap: anywhere; }
.route li.leg { border-style: dashed; }
.route li.done { background: var(--bg); }
.route li.here { border: 2px solid var(--primary); color: var(--primary); background: #EEF3FF; }
@media (max-width: 760px) { .route { grid-template-columns: repeat(2, 1fr); } }
.sheet-bar { position: sticky; top: 0; z-index: 5; display: flex; flex-direction: column; }
.sheet-bar .bar-err { background: #FEF3F2; color: #B42318; border-bottom: 1px solid #FECDCA; padding: 10px 24px; font-weight: 500; display: flex; gap: 8px; align-items: center; }
.sheet-bar .bar-save { background: #FFFAEB; border-bottom: 1px solid #FEDF89; padding: 10px 24px; display: flex; gap: 8px; align-items: center; }
.sheet-bar .bar-save span { margin-right: auto; }
.msg.focus .bubble { outline: 3px solid #F04438; }
/* follows the screen while the user scrolls the log */
.review-pop { position: fixed; top: 16px; right: 24px; width: min(420px, calc(100vw - 32px)); z-index: 20; border: 1px solid #FECDCA; background: #FFF; border-radius: 12px; padding: 14px 16px; box-shadow: 0 8px 24px rgb(16 24 40 / .12); display: flex; flex-direction: column; gap: 10px; }

/* bot page chat log: scrolls inside, newest at the bottom */
[data-chat-log] { max-height: 560px; overflow-y: auto; }
.chat-orders { border-bottom: 1px solid var(--line); max-height: 320px; overflow-y: auto; }
.sheet-bar .bar-save.warn { background: #FEF3F2; border-bottom-color: #FECDCA; color: #912018; }
.timeline li.follow > div { color: var(--muted); }
.mode-dev { background: #F79009; color: #FFF; border-radius: 4px; padding: 0 5px; font-size: 10px; font-weight: 700; margin-left: 4px; }
/* edit a leg's parcel number: opens inline under the leg, never off screen */
.leg-edit { margin-left: auto; }
.leg-edit[open] { flex-basis: 100%; margin-left: 0; display: flex; flex-direction: column; gap: 8px; }
.leg-edit[open] > summary { align-self: flex-end; }
.th-sort { all: unset; cursor: pointer; font: inherit; color: inherit; white-space: nowrap; }
.th-sort:hover { color: var(--primary); }
.th-sort:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
/* sign in */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.linkish { all: unset; cursor: pointer; text-decoration: underline; color: inherit; }
