:root {
  --bg: #f7f5f1;
  --surface: #ffffff;
  --text: #24211d;
  --muted: #6f6a62;
  --line: #e2ddd4;
  --accent: #0f6e6a;
  --accent-text: #ffffff;
  --warn-bg: #fdf1d8;
  --warn-text: #7a5300;
  --ok-bg: #dff3e7;
  --ok-text: #14613a;
  --bad-bg: #fbe3e1;
  --bad-text: #93261c;
  --info-bg: #e3eef6;
  --info-text: #1d5479;
  --neutral-bg: #eeebe5;
  --radius: 10px;
  --series-cur: #2a78d6;  /* dashboard: chosen period (reference palette slot 1) */
  --series-cmp: #eb6834;  /* dashboard: comparison period (slot 2) */
  --up: #14613a;
  --down: #93261c;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1a18;
    --surface: #262421;
    --text: #efeae2;
    --muted: #a8a196;
    --line: #3b3833;
    --accent: #3fb3ac;
    --accent-text: #10201f;
    --warn-bg: #43341a;
    --warn-text: #f3cf8a;
    --ok-bg: #1d3a2a;
    --ok-text: #9fe0ba;
    --bad-bg: #472421;
    --bad-text: #f5b4ad;
    --info-bg: #1f3442;
    --info-text: #a8d3ef;
    --neutral-bg: #33302b;
    --series-cur: #3987e5;
    --series-cmp: #d95926;
    --up: #9fe0ba;
    --down: #f5b4ad;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 Heebo, "Segoe UI", Arial, sans-serif;
}
.rainbow {
  height: 4px;
  background: linear-gradient(to left, #d9534f, #f0a13c, #e9cf4a, #4fb06d, #3f8fc9, #8c63c4);
}
h1, h2, h3 { margin: 0; font-weight: 700; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
a { color: var(--accent); }

/* layout */
.topbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; margin-inline-end: 12px; }
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a {
  padding: 6px 12px; border-radius: 8px; text-decoration: none; color: var(--text); font-weight: 500;
}
.nav a[aria-current="page"] { background: var(--accent); color: var(--accent-text); }
.page { max-width: 980px; margin: 0 auto; padding: 16px; }
.page.wide { max-width: 1180px; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px;
}
.card > h2 { margin-bottom: 12px; }

/* forms */
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); font-weight: 500; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; min-height: 40px;
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
input[type="tel"], input[inputmode="numeric"], input[inputmode="decimal"] { direction: ltr; text-align: right; }
textarea { min-height: 70px; resize: vertical; }
button {
  font: inherit; font-weight: 500; cursor: pointer; border-radius: 8px; min-height: 40px; padding: 8px 14px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.link { border: 0; background: none; color: var(--accent); padding: 4px 6px; min-height: 0; text-decoration: underline; }
button.danger { color: var(--bad-text); }
button:disabled { opacity: .55; cursor: default; }
.segmented { display: flex; flex-wrap: wrap; gap: 6px; }
.segmented button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

/* notices */
.notice { padding: 8px 12px; border-radius: 8px; font-size: 14px; margin-top: 10px; }
.notice.warn { background: var(--warn-bg); color: var(--warn-text); }
.notice.ok { background: var(--ok-bg); color: var(--ok-text); }
.notice.info { background: var(--info-bg); color: var(--info-text); }
.notice.bad { background: var(--bad-bg); color: var(--bad-text); }
.pill {
  display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: 13px; font-weight: 500; white-space: nowrap;
  background: var(--neutral-bg); color: var(--text);
}
.pill.ok { background: var(--ok-bg); color: var(--ok-text); }
.pill.warn { background: var(--warn-bg); color: var(--warn-text); }
.pill.bad { background: var(--bad-bg); color: var(--bad-text); }
.pill.info { background: var(--info-bg); color: var(--info-text); }
.muted { color: var(--muted); font-size: 14px; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.toast {
  position: fixed; bottom: 20px; inset-inline-start: 50%; transform: translateX(50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; z-index: 50; max-width: 90vw;
}

/* order lines */
.line { border-top: 1px solid var(--line); padding: 12px 0; }
.line:first-of-type { border-top: 0; padding-top: 0; }
.line-row { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr) 70px 100px 40px; align-items: end; }
.line-details { margin-top: 8px; display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr) 170px; }
.line-details.single { grid-template-columns: minmax(0, 1fr); }
.line-remove { padding: 0; min-width: 40px; }
.combo { position: relative; }
.combo-list {
  position: absolute; z-index: 20; inset-inline: 0; top: 100%; margin: 4px 0 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  max-height: 280px; overflow: auto; box-shadow: 0 6px 20px rgba(0,0,0,.15);
}
.combo-list li { padding: 7px 9px; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; gap: 12px; }
.combo-list li[aria-selected="true"], .combo-list li:hover { background: var(--neutral-bg); }
.combo-list .price { color: var(--muted); white-space: nowrap; font-size: 14px; }
.totals { display: flex; justify-content: flex-end; gap: 18px; flex-wrap: wrap; padding-top: 10px; border-top: 1px solid var(--line); margin-top: 10px; }
.totals strong { font-size: 18px; }
.savebar {
  position: sticky; bottom: 0; background: var(--bg); padding: 10px 0; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  border-top: 1px solid var(--line); z-index: 10;
}

/* orders list */
.filters { display: grid; gap: 10px; grid-template-columns: minmax(180px, 2fr) repeat(3, minmax(130px, 1fr)); margin-bottom: 12px; }
.orders { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.orders th { text-align: right; font-size: 13px; color: var(--muted); font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.orders td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.orders tr.row { cursor: pointer; }
.orders tr.row:hover { background: var(--neutral-bg); }
.orders tr.detail > td { background: var(--bg); padding: 14px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.detail-grid { display: grid; gap: 12px; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
.item { display: grid; grid-template-columns: minmax(0, 1fr) 190px; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
pre.notes { white-space: pre-wrap; font: inherit; margin: 0; }

/* login */
.login { max-width: 380px; margin: 8vh auto; padding: 0 16px; }
.login form { display: grid; gap: 12px; }

@media (max-width: 720px) {
  .line-row { grid-template-columns: minmax(0, 1fr) 64px 84px 40px; gap: 6px; }
  .line-details { grid-template-columns: minmax(0, 1fr); }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .search { grid-column: 1 / -1; }
  .detail-grid, .item { grid-template-columns: minmax(0, 1fr); }
  .orders thead { display: none; }
  .orders, .orders tbody, .orders tr, .orders td { display: block; width: 100%; }
  .orders tr.row { padding: 10px 12px; border-bottom: 1px solid var(--line); }
  .orders tr.row td { border: 0; padding: 1px 0; }
  .orders tr.row td:empty { display: none; }
  .orders td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: 13px; }
}

/* ---------- Monday-style board ---------- */
a.button {
  display: inline-flex; align-items: center; min-height: 40px; padding: 8px 14px; border-radius: 8px;
  text-decoration: none; font-weight: 500; border: 1px solid var(--line); color: var(--text); background: var(--surface);
}
a.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.page.board { max-width: none; padding: 16px 20px; }
.board-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.board-tools { display: flex; gap: 8px; margin-inline-start: auto; flex-wrap: wrap; }
.board-tools input { width: 260px; }
.board-tools select { width: auto; }
.group { margin-bottom: 22px; }
.group-head {
  border: 0; background: none; padding: 4px 0; min-height: 0; font-size: 18px; font-weight: 700;
  display: flex; align-items: center; gap: 8px;
}
.group-head:hover { border: 0; }
.caret { font-size: 14px; width: 14px; }
.group-count { color: var(--muted); font-size: 13px; font-weight: 400; }
.table-wrap { overflow-x: auto; border-radius: 8px; }
.board-table {
  width: 100%; min-width: 1050px; border-collapse: separate; border-spacing: 0; background: var(--surface);
  border: 1px solid var(--line); border-inline-start: 6px solid var(--group); border-radius: 8px;
}
.board-table th {
  font-size: 13px; font-weight: 500; color: var(--muted); padding: 7px 8px; text-align: center;
  border-bottom: 1px solid var(--line); background: var(--surface); white-space: nowrap;
}
.board-table th.col-name, .board-table th.col-items, .board-table th.col-notes { text-align: right; }
.board-table td {
  padding: 4px 8px; border-bottom: 1px solid var(--line); border-inline-start: 1px solid var(--line);
  height: 40px; vertical-align: middle; text-align: center; font-size: 14px;
}
.board-table td:first-child { border-inline-start: 0; }
.board-table tbody tr:hover td { background: var(--neutral-bg); }
.board-table tr.cancelled td { opacity: .5; text-decoration: line-through; }
.board-table tfoot td { border-bottom: 0; height: 34px; }
.col-name { text-align: right !important; min-width: 190px; }
.col-items { text-align: right !important; max-width: 280px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.col-notes { max-width: 220px; padding: 0 !important; }
.col-status { width: 170px; padding: 0 !important; }
.col-payment, .col-delivery { width: 140px; padding: 0 !important; }
.col-phone { width: 120px; white-space: nowrap; }
.col-total { width: 100px; }
.col-date { width: 90px; }
.name-link {
  border: 0; background: none; padding: 0; min-height: 0; font-weight: 500; color: var(--text); text-align: right;
}
.name-link:hover { color: var(--accent); text-decoration: underline; border: 0; }
.id { margin-inline-start: 6px; font-size: 12px; }
.chip {
  width: 100%; height: 40px; min-height: 0; border: 0; border-radius: 0; padding: 0 8px;
  font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip:hover { filter: brightness(.94); border: 0; }
.cell-text {
  width: 100%; height: 40px; min-height: 0; border: 0; border-radius: 0; background: none; text-align: right;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; color: var(--text);
}
.cell-text:hover { border: 0; background: var(--neutral-bg); }

.popover {
  position: absolute; z-index: 60; background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.2); padding: 10px; max-width: min(340px, 94vw);
}
.picker { display: grid; gap: 6px; width: 220px; max-height: 60vh; overflow: auto; }
.picker .chip { height: 34px; border-radius: 4px; }
.pay-pop, .notes-pop { display: grid; gap: 8px; width: 300px; max-width: 100%; }
.grid.tight { gap: 8px; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }

.panel {
  position: fixed; top: 0; bottom: 0; inset-inline-end: 0; width: min(560px, 100vw); z-index: 40;
  background: var(--bg); border-inline-start: 1px solid var(--line); box-shadow: 0 0 40px rgba(0,0,0,.18);
  display: flex; flex-direction: column;
}
.panel-top {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 18px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.panel-close { min-height: 34px; padding: 4px 10px; }
.panel-body { overflow: auto; padding: 14px 18px 40px; }
.panel-sec { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; }
.panel-sec h3 { font-size: 15px; margin-bottom: 8px; }
.panel-sec > .field, .panel-sec > label.field { margin-top: 8px; }
.panel-item { display: grid; grid-template-columns: minmax(0, 1fr) 170px; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.panel-item .chip { height: 34px; border-radius: 4px; }
.panel-sec > div > .chip { width: auto; height: 28px; border-radius: 4px; display: inline-block; padding: 0 10px; }
ul.plain { list-style: none; padding: 0; margin: 6px 0 0; display: grid; gap: 4px; font-size: 14px; }

@media (max-width: 720px) {
  .page.board { padding: 12px; }
  .board-tools { margin-inline-start: 0; width: 100%; }
  .board-tools input { width: 100%; }
  .panel-item { grid-template-columns: minmax(0, 1fr); }
}

/* type filter tabs */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.tab {
  --tab: var(--accent);
  border-radius: 99px; min-height: 36px; padding: 5px 14px; display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 500;
}
.tab::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--tab); }
.tab[aria-selected="true"] { background: var(--tab); border-color: var(--tab); color: #fff; }
.tab[aria-selected="true"]::before { background: #fff; }
.tab-count { font-size: 12px; font-weight: 400; opacity: .8; }
.col-type { width: 130px; padding: 0 !important; }
.col-address { max-width: 200px; min-width: 140px; padding: 0 !important; }

.items-pop { display: grid; gap: 8px; width: 360px; max-width: 100%; }
.items-pop h3 { font-size: 14px; margin: 0; }
.item-list { display: grid; gap: 2px; max-height: 200px; overflow: auto; }
.item-row { display: flex; justify-content: space-between; gap: 8px; align-items: center; padding: 4px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.items-pop .combo-list { position: static; max-height: 200px; box-shadow: none; }
.subhead td { background: var(--bg) !important; text-align: right !important; font-weight: 500; color: var(--muted); height: 30px; padding: 0 10px !important; }
.products-table { min-width: 1000px; }
.products-table td { padding: 0 !important; }
.products-table td.num .cell-text { text-align: center; }
.products-table td:not(:has(.cell-text)) { padding: 4px 8px !important; }
.pcol-name { min-width: 300px; }
.pcol-size { min-width: 150px; }
.neg { color: var(--bad-text); }
label.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
label.check input { width: auto; min-height: 0; }

.add-row td { padding: 0 !important; text-align: right !important; }
.add-input { border: 0; border-radius: 0; background: transparent; min-height: 40px; padding: 0 12px; }
.add-input:focus { background: var(--surface); }
.col-phone .cell-text { text-align: center; }

.col-date { padding: 0 !important; }
.col-date .cell-text { text-align: center; }

/* undo + bulk actions */
.toast { display: flex; align-items: center; gap: 12px; }
.toast-undo { min-height: 30px; padding: 2px 12px; background: transparent; color: inherit; border: 1px solid currentColor; }
.col-select { width: 36px; padding: 0 !important; }
.col-select input { width: 16px; min-height: 0; height: 16px; cursor: pointer; }
.board-table tr.selected td { background: var(--info-bg); }
.bulkbar {
  position: fixed; bottom: 18px; inset-inline-start: 50%; transform: translateX(50%); z-index: 30;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0,0,0,.18); padding: 10px 14px;
}

/* deals waiting too long */
.col-date.overdue { background: #e2445c; }
.col-date.overdue .cell-text { color: #fff; font-weight: 500; }
.board-table tbody tr:hover td.col-date.overdue { background: #c93a50; }

.site-tag { margin-inline-start: 6px; font-size: 11px; padding: 0 6px; border-radius: 99px; background: var(--info-bg); color: var(--info-text); white-space: nowrap; }

.site-sync { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sync-info { font-size: 13px; }

/* amount editor (products sum / shipping) */
.money-pop { display: flex; flex-direction: column; gap: 8px; min-width: 200px; }
.money-pop label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.money-pop input { font-size: 16px; padding: 6px 8px; direction: ltr; text-align: right; }

.health .notice { margin: 0 0 8px; }
.health .notice .link { font-weight: 700; }

/* customers screen */
.cust-stats { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; min-width: 130px; }
.stat-value { font-size: 20px; font-weight: 700; }
.panel .cust-stats .stat { min-width: 100px; padding: 8px 12px; }
.panel .cust-stats .stat-value { font-size: 16px; }
.small { font-size: 13px; }
.customers-table td { white-space: nowrap; }
.customers-table td.col-name { white-space: normal; min-width: 160px; }
.history-table td.col-items { white-space: normal; text-align: right; }
.history-table .pill { margin-inline-start: 6px; }
.more-btn { margin: 10px auto 0; display: block; }

/* dashboard */
.dash-filters select, .dash-filters input { width: auto; }
.dash-range { display: flex; align-items: center; gap: 6px; }
.dash-range[hidden] { display: none; }
.dash-body.loading { opacity: .5; transition: opacity .2s; }
.kpis .kpi { flex: 1 1 160px; }
.kpi-cmp { margin-top: 4px; }
.up { color: var(--up); font-weight: 600; }
.down { color: var(--down); font-weight: 600; }
.dash-caption { margin: 0 0 12px; }
.dash-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.dash-sec h3 { margin-bottom: 6px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 6px; color: var(--muted); }
.legend > span { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 14px; height: 4px; border-radius: 2px; }
.sw.cur { background: var(--series-cur); }
.sw.cmp { background: var(--series-cmp); }
.chart-wrap { position: relative; }
.trend { width: 100%; height: auto; display: block; overflow: visible; direction: ltr; }
.trend .grid { stroke: var(--line); stroke-width: 1; }
.trend .axis { stroke: var(--muted); stroke-width: 1; }
.trend .tick { fill: var(--muted); font-size: 12px; font-family: inherit; }
.trend .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.trend .line.cur { stroke: var(--series-cur); }
.trend .line.cmp { stroke: var(--series-cmp); }
.trend .dot { stroke: var(--surface); stroke-width: 2; }
.trend .dot.cur { fill: var(--series-cur); }
.trend .dot.cmp { fill: var(--series-cmp); }
.trend .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.trend .hit { fill: transparent; cursor: crosshair; }
.chart-tip { position: absolute; top: 4px; width: 230px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13px; box-shadow: 0 4px 14px rgba(0,0,0,.12); pointer-events: none; }
.tip-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.chart-table { margin-top: 8px; }
.chart-table summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) 110px; gap: 4px 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.bar-label { grid-column: 1 / -1; }
.bar-track { display: flex; flex-direction: column; gap: 3px; justify-content: center; }
.bar { height: 10px; border-start-end-radius: 4px; border-end-end-radius: 4px; min-width: 2px; }
.bar.cur { background: var(--series-cur); }
.bar.cmp { background: var(--series-cmp); height: 6px; }
.bar-value { text-align: left; font-weight: 600; }
.dash-sec { min-width: 0; }
.dash-sec .board-table td.col-name { white-space: normal; text-align: right; }
.dash .board-table { min-width: 0; --group: var(--line); }
.history-table { min-width: 480px; --group: var(--line); }

/* two-step login */
.code-input { font-size: 24px; letter-spacing: 6px; text-align: center; }
.enroll-qr { display: block; width: 200px; height: 200px; margin: 10px auto; background: #fff; padding: 8px; border-radius: 8px; }
.enroll-steps { padding-inline-start: 20px; margin: 8px 0; font-size: 14px; }
.enroll-steps li { margin-bottom: 4px; }
.enroll-secret { display: block; word-break: break-all; padding: 6px; background: var(--neutral-bg); border-radius: 6px; }
.login .link { justify-self: start; }
