:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e2230;
  --border: #2a2f3d;
  --text: #e6e9f0;
  --muted: #8b93a7;
  --accent: #4f8cff;
  --green: #34c98e;
  --red: #f0616d;
  --orange: #f5a95c;
  --purple: #a78bfa;
}

/* ---- Light mode ---- */
:root[data-theme="light"] {
  --bg: #f3f5f9;
  --panel: #ffffff;
  --panel-2: #e9edf4;
  --border: #d5dbe7;
  --text: #1c2434;
  --muted: #63708a;
  --accent: #2f6de0;
  --green: #128a5c;
  --red: #d43f4f;
  --orange: #c96f1a;
  --purple: #7a5cd6;
}
:root[data-theme="light"] .badge.new { background: #dbe5ff; color: #2f56c4; }
:root[data-theme="light"] .badge.confirmed { background: #d3f2e4; color: #0f7a50; }
:root[data-theme="light"] .badge.no_answer.na-1 { background: #ffeccd; color: #9a6414; }
:root[data-theme="light"] .badge.no_answer.na-2 { background: #ffdda8; color: #8a5203; }
:root[data-theme="light"] .badge.no_answer.na-3 { background: #ffc97e; color: #7a4300; }
:root[data-theme="light"] .badge.postponed { background: #d5e8fb; color: #1d6fc2; }
:root[data-theme="light"] .badge.cancelled { background: #fbdadd; color: #c22736; }
:root[data-theme="light"] .badge.didnt_order { background: #1c2434; color: #ffffff; border: 1px solid #1c2434; }
:root[data-theme="light"] tbody tr.row-didnt_order { background: rgba(28, 36, 52, 0.10); }
:root[data-theme="light"] .badge.shipped { background: #d3ecf8; color: #146d99; }
:root[data-theme="light"] .badge.delivered { background: #d3f2e4; color: #0f7a50; }
:root[data-theme="light"] .badge.returned { background: #fbdadd; color: #c22736; }
:root[data-theme="light"] .statusmenu .mi-na1 { color: #b07514; }
:root[data-theme="light"] .statusmenu .mi-na2 { color: #9a5f07; }
:root[data-theme="light"] .statusmenu .mi-na3 { color: #855000; }
:root[data-theme="light"] .statusmenu .mi-blue { color: #1d6fc2; }
:root[data-theme="light"] .statusmenu { box-shadow: 0 10px 30px rgba(30, 40, 70, 0.18); }
:root[data-theme="light"] .msg.err { background: #fbdadd; color: #b02231; }
:root[data-theme="light"] .msg.ok { background: #d3f2e4; color: #0f7a50; }
:root[data-theme="light"] .msg.warn { background: #ffeccd; color: #9a6414; }
:root[data-theme="light"] button.good { color: #ffffff; }

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

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

button {
  font: inherit;
  color: inherit;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.good { background: var(--green); border-color: var(--green); color: #08281b; font-weight: 600; }
button.danger { background: transparent; border-color: var(--red); color: var(--red); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }

/* ---- Login ---- */
.login-wrap { display: grid; place-items: center; min-height: 100vh; }
.login-card {
  width: 340px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px;
}
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card p { color: var(--muted); font-size: 13px; margin-bottom: 12px; }
.login-card button { width: 100%; margin-top: 16px; }

/* ---- Layout ---- */
header {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
header .logo { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 9px; }
header .logo span { color: var(--accent); }
/* The OrderDesk icon already carries its own blue tile and rounded corners —
   it needs no plate behind it, in either theme. */
header .brandmark { height: 32px; width: 32px; display: block; }
nav { display: flex; gap: 6px; }
nav button { border: none; background: transparent; color: var(--muted); padding: 7px 12px; }
nav button.active { background: var(--panel-2); color: var(--text); border-radius: 8px; }
header .spacer { flex: 1; }
header .who { color: var(--muted); font-size: 13px; }

main { padding: 20px 24px; width: 100%; }

/* ---- Toolbar / filters ---- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar input[type="search"] { width: 240px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border); background: var(--panel); border-radius: 999px;
  padding: 5px 12px; font-size: 13px; color: var(--muted); cursor: pointer;
}
.chip.active { border-color: var(--accent); color: var(--text); background: var(--panel-2); }
.chip b { color: var(--text); }

/* ---- Orders table ---- */
.tablewrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: start; padding: 8px 7px; border-bottom: 1px solid var(--border); white-space: nowrap; font-size: 13px; }
th:first-child, td:first-child { padding-left: 12px; }
/* Selection column leads the row, just before the status badge. */
th.selcol, td.selcol { text-align: center; padding-inline: 12px 4px; width: 1%; }
th { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.03em; }
tbody tr { cursor: pointer; }
/* Whole row tinted by status — the badge color, spread across the section */
tbody tr.row-confirmed { background: rgba(52, 201, 142, 0.08); }
tbody tr.row-no_answer.na-1 { background: rgba(242, 197, 131, 0.07); }
tbody tr.row-no_answer.na-2 { background: rgba(245, 169, 92, 0.13); }
tbody tr.row-no_answer.na-3 { background: rgba(255, 139, 38, 0.20); }
tbody tr.row-postponed { background: rgba(88, 166, 240, 0.09); }
tbody tr.row-cancelled { background: rgba(240, 97, 109, 0.10); }
tbody tr.row-didnt_order { background: rgba(0, 0, 0, 0.45); }
tbody tr.row-shipped { background: rgba(88, 196, 240, 0.07); }
tbody tr.row-delivered { background: rgba(52, 201, 142, 0.05); }
tbody tr.row-returned { background: rgba(240, 97, 109, 0.06); }
tbody tr:hover { background: var(--panel-2); }
td.wrap { white-space: normal; max-width: 190px; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.new { background: #2a3550; color: #9db8ff; }
.badge.confirmed { background: #14382a; color: var(--green); }
/* No answer: darker & hotter with each attempt */
.badge.no_answer.na-1 { background: #3a2d18; color: #f2c583; }
.badge.no_answer.na-2 { background: #4d340e; color: #f5a95c; }
.badge.no_answer.na-3 { background: #613608; color: #ff8b26; }
.badge.postponed { background: #16324d; color: #58a6f0; }
.badge.cancelled { background: #40222a; color: var(--red); cursor: help; }
.badge.didnt_order { background: #000000; color: #b8bfce; border: 1px solid #3a3f4c; }
.badge.shipped { background: #123344; color: #58c4f0; }
.badge.delivered { background: #14382a; color: var(--green); }
.badge.returned { background: #40222a; color: var(--red); }

/* ---- Modal ---- */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: grid; place-items: center; z-index: 10; padding: 20px;
}
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  width: min(720px, 100%); max-height: 90vh; overflow-y: auto; padding: 24px;
}
.modal h2 { font-size: 17px; margin-bottom: 2px; }
.modal .sub { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 18px; }
.timeline { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 10px; }
.timeline h3 { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.timeline .ev { font-size: 12.5px; color: var(--muted); padding: 3px 0; }
.timeline .ev b { color: var(--text); font-weight: 600; }
.timeline .ev-time { float: inline-end; }

.langsel { width: auto; padding: 7px 8px; }

/* ---- Profit breakdown ---- */
.pf-line { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.pf-line span:last-child { font-variant-numeric: tabular-nums; }
.pf-earn {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 12px; padding: 12px 14px; border-radius: 10px;
  background: rgba(52, 201, 142, 0.12); color: var(--green);
  font-weight: 700; font-size: 17px;
}
.pf-earn.pf-loss { background: rgba(240, 97, 109, 0.12); color: var(--red); }
.pf-sub { border-bottom: none; color: var(--muted); font-size: 12.5px; }

/* Special-offer orders: product name in heavy bold so the team spots them */
td.offer-bold { font-weight: 800; color: var(--text); }

/* ---- Offer switcher in the order form ---- */
.offers { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.offer-chip {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  text-align: start; padding: 8px 12px; max-width: 260px;
}
.offer-chip .offer-name { font-size: 12.5px; white-space: normal; }
.offer-chip .offer-price { font-size: 13px; font-weight: 700; color: var(--green); }
.offer-chip.active { border-color: var(--accent); background: var(--panel); box-shadow: 0 0 0 1px var(--accent) inset; }

/* ---- Delivery price line in the order form ---- */
.pricebox { margin-top: 8px; display: flex; gap: 14px; flex-wrap: wrap; }
.price-line { font-size: 13px; color: var(--muted); }
.price-line b { color: var(--green); font-size: 14px; }
.price-hint { font-size: 12.5px; color: var(--muted); }

/* Settings section headings — group the cards (Store / Delivery / …) */
.set-group { font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted);
  margin: 26px 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.set-group:first-child { margin-top: 4px; }

/* ---- Settings / cards ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 20px; }
.card h2 { font-size: 15px; margin-bottom: 4px; }
.card .sub { color: var(--muted); font-size: 12.5px; margin-bottom: 8px; }
.card .status-ok { color: var(--green); font-size: 12.5px; }
.card .status-warn { color: var(--orange); font-size: 12.5px; }
.card button { margin-top: 12px; }

/* ---- Status dropdown menu ---- */
.badge-btn { cursor: pointer; user-select: none; }
.badge-btn:hover { filter: brightness(1.25); }
.statusmenu {
  position: fixed; z-index: 50; min-width: 170px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 6px; display: flex; flex-direction: column; gap: 2px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
}
.statusmenu button {
  border: none; background: transparent; text-align: start;
  padding: 8px 12px; border-radius: 6px; font-size: 13px; font-weight: 600;
}
.statusmenu button:hover { background: var(--panel); border: none; }
.statusmenu .mi-green { color: var(--green); }
.statusmenu .mi-na1 { color: #f2c583; }
.statusmenu .mi-na2 { color: #f5a95c; }
.statusmenu .mi-na3 { color: #ff8b26; }
.statusmenu .mi-blue { color: #58a6f0; }
.statusmenu .mi-red { color: var(--red); }
.statusmenu .mi-black { color: var(--text); }

/* ---- Bulk action bar ---- */
.bulkbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--panel-2); border: 1px solid var(--accent); border-radius: 10px;
  padding: 10px 14px; margin-bottom: 12px; font-size: 13.5px;
}
.bulk-hint { color: var(--muted); font-size: 12.5px; }
.rowcheck, #selectAll { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

/* ---- Stats tiles ---- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 16px; }
.tile { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; }
.tile-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.tile-value { font-size: 28px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.tile-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
/* Who confirmed the order, under its status badge. */
.byline { font-size: 11px; color: var(--muted); margin-top: 3px; max-width: 120px;
  overflow: hidden; text-overflow: ellipsis; }

/* ---- Product research Board ---- */
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px; align-items: flex-start; }
.bcolumn { flex: 0 0 260px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; }
.bcolumn-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
.bcolumn-head b { color: var(--muted); font-weight: 600; margin-inline-start: 4px; }
.bcol-add { padding: 0 8px; font-size: 16px; line-height: 1.6; }
.bcolumn-body { min-height: 60px; padding: 10px; display: flex; flex-direction: column; gap: 10px; transition: background .15s; border-radius: 0 0 12px 12px; }
.bcolumn-body.drop-over { background: var(--panel-2); outline: 2px dashed var(--accent); outline-offset: -4px; }
.bcard { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; cursor: grab; }
.bcard:active { cursor: grabbing; }
.bcard.dragging { opacity: .45; }
.bcard-thumb { width: 100%; height: 120px; object-fit: cover; display: block; background: var(--bg); }
.bcard-thumb.none { display: grid; place-items: center; font-size: 30px; color: var(--muted); }
.bcard-body { padding: 8px 10px 10px; }
.bcard-name { font-weight: 600; font-size: 13.5px; line-height: 1.25; }
.bcard-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; font-size: 12px; color: var(--muted); }
.btag { background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; font-size: 11px; color: var(--text); }
.bverdict { border-radius: 999px; padding: 1px 8px; font-size: 11px; font-weight: 600; }
.bverdict.v-winner { background: rgba(52,201,142,.15); color: var(--green); }
.bverdict.v-killed { background: rgba(240,97,109,.15); color: var(--red); }
.bverdict.v-needs_more_testing { background: rgba(245,169,92,.15); color: var(--orange); }

/* Product editor modal */
.modal.pmodal { width: min(760px, 100%); max-height: 90vh; padding: 0; display: flex; flex-direction: column; overflow: hidden; }
.pmodal .modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.pmodal .modal-head h2 { margin: 0; }
.pmodal .modal-scroll { overflow-y: auto; padding: 16px 20px; }
.pmodal .modal-foot { display: flex; gap: 8px; align-items: center; padding: 14px 20px; border-top: 1px solid var(--border); }
.pm-section { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin: 18px 0 10px; }
.pm-section:first-child { margin-top: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .field.span2 { grid-column: 1 / -1; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.money-input { display: flex; gap: 6px; }
.money-input input { flex: 1; }
.money-input select { width: auto; }
.dims-input { display: flex; gap: 6px; align-items: center; }
.dims-input input { width: 100%; }
.dims-input span { color: var(--muted); }
.linkrow { display: flex; gap: 6px; margin-bottom: 6px; }
.linkrow .lk-label { flex: 0 0 130px; }
.linkrow .lk-url { flex: 1; }
.iconbtn { padding: 4px 9px; }
.pm-add { margin-top: 4px; font-size: 13px; }
.pm-media { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 8px; margin-bottom: 10px; }
.pm-mitem { position: relative; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.pm-mitem img { width: 100%; height: 90px; object-fit: cover; display: block; }
.pm-mitem .m-del { position: absolute; top: 3px; inset-inline-end: 3px; background: rgba(0,0,0,.6); border-color: transparent; color: #fff; padding: 1px 6px; }
.pm-vlink { display: grid; place-items: center; height: 90px; background: var(--panel-2); }
.pm-vlink a { color: var(--accent); font-size: 12px; text-decoration: none; }
.pm-media-add { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---- Find Product: Telegram panel ---- */
.tgqr { display: block; margin-top: 6px; border-radius: 10px; background: #fff; padding: 8px; width: 200px; }
.tgtoggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.tgtoggle input { width: auto; }
.tgprogress { margin-top: 12px; }
.tgbar { height: 8px; border-radius: 999px; background: var(--panel-2); overflow: hidden; margin-bottom: 6px; }
.tgbar-fill { height: 100%; background: var(--accent); transition: width .4s; }

/* ---- Find Product ---- */
.finddrop { border: 2px dashed var(--border); border-radius: 12px; padding: 26px; margin-top: 12px;
  text-align: center; cursor: pointer; transition: border-color .15s, background .15s; }
.finddrop:hover, .finddrop.over { border-color: var(--accent); background: var(--panel-2); }
.finddrop-icon { font-size: 26px; margin-bottom: 6px; }
.findquery { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.findquery img { height: 74px; width: 74px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.findgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-top: 16px; }
.findcard { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.findcard img { width: 100%; height: 160px; object-fit: cover; display: block; background: var(--panel-2); }
.findcard-noimg { height: 160px; display: grid; place-items: center; color: var(--muted); background: var(--panel-2); }
.findcard-body { padding: 9px 11px 11px; }
.findcard-match { font-weight: 700; font-size: 15px; color: var(--muted); }
.findcard-match.warm { color: var(--orange); }
.findcard-match.hot { color: var(--green); }
.findcard-price { font-size: 13px; margin-top: 2px; }
.findcard-channel { font-size: 12px; color: var(--muted); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.findcard-link { display: inline-block; margin-top: 7px; font-size: 12.5px; color: var(--accent); text-decoration: none; }
.findcard-link:hover { text-decoration: underline; }

/* ---- Confirmation / delivery dials ---- */
.dialbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.dialbar .chip { font: inherit; font-size: 13px; }
.dials { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 16px; margin-bottom: 18px; }
.dial { display: flex; align-items: center; gap: 18px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; }
.donut { width: 120px; height: 120px; flex: none; transform: rotate(-90deg); }
.donut-track { fill: none; stroke: var(--border); stroke-width: 14; }
.donut-arc { fill: none; stroke-width: 14; }
.donut-centre, .donut-sub { transform: rotate(90deg); transform-origin: 60px 60px;
  text-anchor: middle; fill: var(--text); }
.donut-centre { font-size: 26px; font-weight: 700; }
.donut-sub { font-size: 10px; fill: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.dial-body { min-width: 0; }
.dial-body h3 { margin: 0 0 6px; font-size: 13px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
/* Whose numbers these are — right on the circle. */
.dial-who { color: var(--text); background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 2px 9px; margin-inline-start: 6px;
  text-transform: none; letter-spacing: 0; font-size: 12px; }
.dial-big { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.dial-big span { font-size: 13px; font-weight: 500; color: var(--muted); }
.dial-count { font-size: 14px; margin: 2px 0 8px; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 1px 0; }
.legend-row i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend-row span { color: var(--muted); }
.legend-row b { margin-inline-start: auto; font-variant-numeric: tabular-nums; }
.dial-note { color: var(--muted); font-size: 12px; margin-top: 8px; }

/* ---- Product stock / remaining / mode (Stats table) ---- */
.stockinput { width: 74px; padding: 5px 8px; text-align: end; font-variant-numeric: tabular-nums; }
.modebtn { padding: 4px 11px; font-size: 12px; font-weight: 600; border-radius: 999px; white-space: nowrap; }
.modebtn.testing { border-color: var(--orange); color: var(--orange); background: rgba(245, 169, 92, 0.10); }
.modebtn.launched { border-color: var(--green); color: var(--green); background: rgba(52, 201, 142, 0.10); }
.modebtn:hover { filter: brightness(1.15); }
/* "Testing" tag on the admin's own order rows (agents never see these rows) */
.testtag { display: inline-block; margin-inline-start: 6px; padding: 1px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700; white-space: nowrap; color: var(--orange);
  border: 1px solid var(--orange); background: rgba(245, 169, 92, 0.10); vertical-align: middle; }
.rem-cell { font-variant-numeric: tabular-nums; }
.rem-cell.rem-ok b { color: var(--green); }
.rem-cell.rem-low b { color: var(--orange); }
.rem-cell.rem-out b { color: var(--red); }

.statnote { color: var(--muted); font-size: 12.5px; margin-top: 10px; }
.hidebtn { padding: 3px 10px; font-size: 12px; }
.hiddenwrap { margin-top: 18px; }
.hiddenwrap summary { color: var(--muted); font-size: 13px; cursor: pointer; margin-bottom: 8px; }
.hiddenwrap summary:hover { color: var(--text); }

.msg { margin: 10px 0; padding: 10px 12px; border-radius: 8px; font-size: 13px; }
.msg.err { background: #40222a; color: var(--red); }
.msg.ok { background: #14382a; color: var(--green); }
.msg.warn { background: #3d2f1b; color: var(--orange); }

/* ---- Customer history dot (green = good, red = bad, dark red = super bad) ---- */
.cust-dot {
  display: inline-block; min-width: 20px; text-align: center;
  border-radius: 999px; padding: 1px 7px; font-size: 11px; font-weight: 800;
  margin-inline-start: 6px; color: #ffffff; cursor: help; vertical-align: middle;
}
.cust-dot.good { background: #128a5c; }
.cust-dot.bad { background: #d43f4f; }
.cust-dot.superbad { background: #7a0c16; box-shadow: 0 0 0 1px #ff8b8b inset; }
.cust-dot.neutral { background: #5f6b81; }

/* "20/6" pair badge: green delivered / red returned, border = verdict */
.cust-pair {
  display: inline-block; border-radius: 999px; padding: 1px 8px;
  font-size: 11.5px; font-weight: 800; margin-inline-start: 6px;
  background: rgba(0, 0, 0, 0.35); cursor: help; vertical-align: middle;
  border: 1.5px solid transparent; color: var(--muted);
}
:root[data-theme="light"] .cust-pair { background: rgba(28, 36, 52, 0.07); }
.cust-pair .cp-g { color: #22b57f; }
.cust-pair .cp-r { color: #ff5d6b; }
:root[data-theme="light"] .cust-pair .cp-g { color: #0f7a50; }
:root[data-theme="light"] .cust-pair .cp-r { color: #c22736; }
.cust-pair.good { border-color: #128a5c; }
.cust-pair.warn { border-color: #c96f1a; }
.cust-pair.bad { border-color: #d43f4f; }
.cust-pair.superbad { border-color: #7a0c16; background: rgba(122, 12, 22, 0.35); }

/* ---- Click-to-call ---- */
.phone-link { color: var(--accent); text-decoration: none; white-space: nowrap; }
.phone-link:hover { text-decoration: underline; }
.callbtn { padding: 7px 10px; flex-shrink: 0; }

/* ---- Team performance ---- */
.agtitle { font-size: 15px; margin: 0; }
.agentwrap .tablewrap { margin-top: 4px; }

.empty { text-align: center; color: var(--muted); padding: 48px 0; }

/* ---- Team chat ---- */
.navbadge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--red); color: #fff; font-size: 11px; font-weight: 700; vertical-align: middle;
}
.chat { display: flex; gap: 14px; height: calc(100vh - 130px); }
.chat-list { flex: 0 0 280px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; overflow-y: auto; }
.chat-list-head { padding: 12px 14px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border-bottom: 1px solid var(--border); }
.chat-contact { width: 100%; text-align: start; border: none; border-bottom: 1px solid var(--border); background: transparent; border-radius: 0; padding: 11px 14px; display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: center; }
.chat-contact:hover { background: var(--panel-2); border-color: var(--border); }
.chat-contact.active { background: var(--panel-2); }
.cc-name { font-weight: 600; font-size: 14px; }
.cc-off { font-weight: 400; font-size: 11px; color: var(--muted); }
.cc-preview { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cc-badges { grid-column: 2; grid-row: 1 / span 2; display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.navbadge.problem { background: var(--orange); }

/* Problem report cards */
.chat-problem { align-self: stretch; max-width: 100%; border-radius: 12px; padding: 12px 14px; border: 1px solid; }
.chat-problem.open { background: rgba(240, 97, 109, .12); border-color: var(--red); }
.chat-problem.resolved { background: rgba(52, 201, 142, .12); border-color: var(--green); }
.cp-head { font-weight: 700; font-size: 13px; margin-bottom: 6px; }
.chat-problem.open .cp-head { color: var(--red); }
.chat-problem.resolved .cp-head { color: var(--green); }
.cp-desc { font-size: 14px; line-height: 1.4; white-space: pre-wrap; word-break: break-word; }
.cp-phone { margin-top: 8px; font-size: 14px; }
.cp-meta { display: flex; gap: 10px; align-items: center; margin-top: 8px; }
.cp-by { font-size: 12px; color: var(--muted); }
.cp-fixed { margin-top: 6px; font-size: 12.5px; color: var(--green); }
.cp-actions { margin-top: 10px; }

/* Problem form (shown above the composer for agents) */
.chat-problem-form { border-top: 1px solid var(--border); background: rgba(240, 97, 109, .06); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.chat-problem-form[hidden] { display: none; }
.cpf-title { font-weight: 700; font-size: 13px; color: var(--red); }
.chat-problem-form textarea { resize: vertical; }
.cpf-actions { display: flex; gap: 8px; justify-content: flex-end; }
.chat-problem-btn { flex: none; width: 44px; padding: 8px 0; text-align: center; font-size: 16px; border-color: var(--red); color: var(--red); }
.chat-problem-btn:hover { background: rgba(240, 97, 109, .12); border-color: var(--red); }
.chat-thread { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.chat-thread .empty { margin: auto; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.chat-back { display: none; padding: 4px 11px; }
.chat-scroll { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.chat-msg { display: flex; flex-direction: column; max-width: 78%; }
.chat-msg.mine { align-self: flex-end; align-items: flex-end; }
.chat-msg.theirs { align-self: flex-start; align-items: flex-start; }
.chat-bubble { padding: 9px 13px; border-radius: 14px; font-size: 14px; line-height: 1.4; word-break: break-word; white-space: pre-wrap; }
.chat-msg.theirs .chat-bubble { background: var(--panel-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat-msg.mine .chat-bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.chat-bubble audio { display: block; max-width: 230px; height: 40px; }
.chat-time { font-size: 10.5px; color: var(--muted); margin-top: 3px; }
.chat-report { align-self: center; max-width: 92%; background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.chat-report pre { font: inherit; white-space: pre-wrap; margin: 0; font-size: 13.5px; line-height: 1.5; }
.chat-report .chat-time { display: block; text-align: end; margin-top: 6px; }
.chat-compose { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-top: 1px solid var(--border); }
.chat-compose #chatInput { flex: 1; }
.chat-mic { flex: none; width: 44px; padding: 8px 0; text-align: center; font-size: 16px; }
.chat-mic.recording { background: var(--red); border-color: var(--red); color: #fff; }
.chat-rectime { font-variant-numeric: tabular-nums; font-weight: 600; }
.chat-recdot { width: 10px; height: 10px; border-radius: 50%; background: var(--red); animation: cblink 1s infinite; }
@keyframes cblink { 50% { opacity: .3; } }

/* ---- Live courier-status badge (list + order pop-up) ---- */
.cstatus { display: inline-block; padding: 3px 11px; border-radius: 999px; font-size: 12px; font-weight: 700;
  color: #fff; background: var(--tc); border: none; cursor: pointer; white-space: nowrap; line-height: 1.5; }
.cstatus:hover { filter: brightness(1.12); box-shadow: 0 0 0 2px color-mix(in srgb, var(--tc) 35%, transparent); }
.cstrack { font-size: 11px; color: var(--muted); margin-top: 3px; font-variant-numeric: tabular-nums; }
.cstatus-row { margin: 8px 0 4px; }

/* ---- Delivery history popup (opened from the badge) ---- */
.trackmodal { width: min(460px, 100%); }
.trackmodal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.trackmodal-head h2 { font-size: 17px; margin: 0; }
.track-loading { color: var(--muted); font-size: 13px; }
.track-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.track-title { font-weight: 700; font-size: 14px; }
.track-badge { color: #fff; background: var(--tc); border-radius: 999px; padding: 3px 12px;
  font-size: 12.5px; font-weight: 700; }
.track-meta { color: var(--muted); font-size: 12px; margin-inline-start: auto; }
.track-line { display: flex; flex-direction: column; gap: 0; }
.track-step { display: flex; gap: 12px; position: relative; padding-bottom: 14px; }
.track-step:last-child { padding-bottom: 0; }
/* the vertical connector between dots */
.track-step:not(:last-child)::before { content: ''; position: absolute; inset-inline-start: 6px; top: 16px;
  bottom: 0; width: 2px; background: var(--border); }
.track-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--tc); flex: none; margin-top: 2px;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--tc) 25%, transparent); z-index: 1; }
.track-stepbody { min-width: 0; }
.track-step.now .track-label { font-weight: 700; }
.track-label { font-size: 13.5px; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.track-time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.track-sits { margin-top: 4px; display: flex; flex-direction: column; gap: 3px; }
.track-sit { font-size: 12.5px; color: var(--muted); background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 4px 9px; }

/* Mobile-only "select all" — the desktop header checkbox is hidden on phones */
.selectall-m { display: none; }

@media (max-width: 640px) {
  main { padding: 12px 12px 40px; }

  /* Chat becomes single-pane: agent list OR the open thread */
  .chat { height: calc(100vh - 230px); min-height: 360px; gap: 0; }
  .chat-list { flex: 1 1 auto; }
  .chat.viewing .chat-list { display: none; }
  .chat:not(.viewing) .chat-thread { display: none; }
  .chat-back { display: inline-block; }

  .selectall-m {
    display: flex; align-items: center; gap: 10px;
    background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
    padding: 11px 14px; margin-bottom: 10px; font-size: 14px; font-weight: 600;
    cursor: pointer; user-select: none;
  }
  .selectall-m input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
  .grid2, .form-grid { grid-template-columns: 1fr; }
  .modal { padding: 18px; }
  .overlay { padding: 10px; }

  /* ---- Header: compact, and the nav wraps so EVERY tab is reachable ---- */
  header { flex-wrap: wrap; gap: 8px 12px; padding: 10px 14px; }
  header .logo { font-size: 15px; }
  header .brandmark { height: 28px; width: 28px; }
  header .spacer { display: none; }
  /* Nav drops to its own full-width row and wraps onto as many lines as needed */
  nav { order: 5; width: 100%; flex-wrap: wrap; gap: 6px; }
  nav button { padding: 8px 12px; font-size: 14px; }
  header .who { font-size: 12px; order: 1; }
  header .langsel { order: 2; }
  header #themeBtn { order: 3; }
  header #logoutBtn { order: 4; }

  /* ---- Toolbar: full-width search so it's easy to tap ---- */
  .toolbar { gap: 8px; }
  .toolbar .spacer { display: none; }
  .toolbar input[type="search"] { width: 100%; }
  .toolbar #daysFilter { flex: 1; }
  .toolbar #newOrderBtn, .toolbar #syncBtn { flex: 1; }

  /* ---- Orders: the wide table becomes one tappable card per order ---- */
  .orders-wrap { background: transparent; border: none; border-radius: 0; overflow: visible; }
  .orders-table, .orders-table tbody { display: block; width: 100%; }
  .orders-table thead { display: none; }
  .orders-table tbody tr {
    display: block; position: relative;
    background: var(--panel); border: 1px solid var(--border);
    border-radius: 12px; margin-bottom: 10px; padding: 2px 0;
  }
  .orders-table td {
    display: flex; justify-content: space-between; align-items: center; gap: 14px;
    white-space: normal; border: none; border-bottom: 1px solid var(--border);
    padding: 9px 14px; font-size: 14px; text-align: end; min-height: 40px;
  }
  .orders-table td:last-child { border-bottom: none; }
  .orders-table td::before {
    content: attr(data-label); flex: none; text-align: start;
    color: var(--muted); font-size: 11.5px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.03em;
  }
  .orders-table td.wrap { max-width: none; }
  /* Status is the card's header: badge on the left, big, no label */
  .orders-table td.statuscell {
    justify-content: flex-start; padding: 12px 14px 10px 14px; padding-inline-end: 44px;
    background: rgba(255, 255, 255, 0.02);
  }
  .orders-table td.statuscell::before { content: none; }
  .orders-table td.statuscell .badge { font-size: 13.5px; padding: 4px 12px; }
  .orders-table .byline { max-width: none; margin-inline-start: 8px; }
  /* Selection checkbox tucks into the card's top corner (admins only) */
  .orders-table td.selcol {
    position: absolute; top: 12px; inset-inline-end: 12px; padding: 0; border: none; min-height: 0;
  }
  .orders-table td.selcol::before { content: none; }
  .orders-table .rowcheck { width: 22px; height: 22px; }
  /* The phone and total are what agents reach for — make them pop */
  .orders-table td[data-label="#"] { font-size: 12.5px; color: var(--muted); }
  .orders-table .phone-link { font-size: 15px; font-weight: 600; }
}
