/* Colors live here; change them in one place. Dark mode follows the device setting. */
:root {
  --bg: #f6f6f4; --panel: #ffffff; --text: #1d1d1b; --muted: #6b6b66; --line: #e3e2dd; --hover: #f0efeb;
  --accent: #2f5d8a; --accent-text: #ffffff; --danger: #a33a2c;
  --ordered: #8a6d1d; --ordered-bg: #fbf3dc; --shipping: #2f5d8a; --shipping-bg: #e3edf7;
  --delivered: #2e6b3a; --delivered-bg: #e2f1e5; --muted-bg: #ecebe7;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615; --panel: #1f1f1e; --text: #ecebe7; --muted: #9c9b95; --line: #33332f; --hover: #2a2a28;
    --accent: #6d9fd1; --accent-text: #0f1a26; --danger: #e07a6b;
    --ordered: #e3c46b; --ordered-bg: #3a3220; --shipping: #8fb7e0; --shipping-bg: #1f2d3b;
    --delivered: #8ccb98; --delivered-bg: #1f3324; --muted-bg: #2c2c2a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 4px; }
h3 { font-size: 15px; margin: 18px 0 8px; }

/* ---------- Top bar ---------- */
header { display: flex; align-items: center; gap: 12px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; }
.brand img { width: 26px; height: 26px; border-radius: 6px; }
.store-switch { padding: 5px 10px; border: 1px solid var(--line); border-radius: 99px; color: var(--text); text-decoration: none; font-weight: 600; font-size: 14px; }
.store-switch:empty { display: none; }
.store-switch::after { content: " ▾"; color: var(--muted); }
nav { display: flex; gap: 2px; margin-right: auto; }
nav a { padding: 6px 10px; border-radius: 6px; color: var(--muted); text-decoration: none; }
nav a.on { background: var(--bg); color: var(--text); font-weight: 600; }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; padding: 6px 10px; border-radius: 6px; color: var(--muted); }
.menu summary::-webkit-details-marker { display: none; }
.menu summary::after { content: " ▾"; }
.menu-body { position: absolute; right: 0; top: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px; min-width: 170px; box-shadow: 0 6px 20px rgb(0 0 0 / .12); display: flex; flex-direction: column; }
.menu-body a, .menu-body button { padding: 8px 10px; text-align: left; border: 0; background: none; font: inherit; color: var(--text); text-decoration: none; border-radius: 6px; cursor: pointer; }
.menu-body a:hover, .menu-body button:hover { background: var(--hover); }
@media (max-width: 640px) {
  nav { order: 5; width: 100%; margin-right: 0; }
  .brand span { display: none; }
  .menu { margin-left: auto; }
}

/* ---------- Layout ---------- */
main { padding: 20px; max-width: 1200px; margin: 0 auto; padding-bottom: max(20px, env(safe-area-inset-bottom)); }
@media (max-width: 640px) { main { padding: 14px 16px; } }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.pad { padding: 16px 18px; }
.split { display: grid; grid-template-columns: minmax(260px, 360px) 1fr; gap: 20px; align-items: start; }
.split > * { min-width: 0; }  /* let wide tables scroll inside the panel instead of stretching the page */@media (max-width: 760px) { .split { grid-template-columns: 1fr; } }
.bar { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; align-items: center; }
.bar .grow { flex: 1; }
.center { min-height: 70vh; display: grid; place-items: center; }
.stack > * + * { margin-top: 12px; }
.scroll { overflow-x: auto; }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); }
.meta { color: var(--muted); font-size: 13px; }
.err { color: var(--danger); min-height: 1.2em; margin: 6px 0 0; }

/* ---------- Controls ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  padding: 7px 13px; border-radius: 7px; font: inherit; cursor: pointer; text-decoration: none; }
.btn:hover:not(:disabled) { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .45; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--muted); text-decoration: underline; cursor: pointer; font: inherit; font-size: 13px; }
input, select { font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); color: var(--text); }
input[type=checkbox] { width: 17px; height: 17px; padding: 0; vertical-align: -3px; accent-color: var(--accent); }
input[type=number] { width: 86px; text-align: right; }
label { display: block; }
form label > input:not([type=checkbox]):not([type=radio]) { display: block; width: 100%; margin-top: 4px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.checks label { display: flex; gap: 6px; align-items: center; }

/* ---------- Sign-in screens ---------- */
.auth { width: 100%; max-width: 360px; padding: 26px; }
.auth .logo { width: 52px; height: 52px; border-radius: 12px; display: block; margin-bottom: 12px; }
.auth form > * + * { margin-top: 14px; }
.auth .btn { width: 100%; justify-content: center; padding: 10px; }

/* ---------- Store picker ---------- */
.stores { display: grid; gap: 10px; max-width: 520px; margin: 0 auto; }
.store-btn { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; font-size: 17px; font-weight: 600;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; color: var(--text); text-decoration: none; }
.store-btn:hover { background: var(--hover); }
.store-btn .meta { font-weight: 400; }

/* ---------- Orders ---------- */
.list { max-height: calc(100vh - 160px); overflow-y: auto; }
@media (max-width: 760px) { .list { max-height: none; } }
.row { padding: 11px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--hover); }
.row.sel { background: var(--shipping-bg); }
.row .top { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.pill { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; text-transform: capitalize; white-space: nowrap; background: var(--muted-bg); color: var(--muted); }
.pill.ordered { color: var(--ordered); background: var(--ordered-bg); }
.pill.shipping { color: var(--shipping); background: var(--shipping-bg); }
.pill.delivered { color: var(--delivered); background: var(--delivered-bg); }
.detail h2 { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; margin: 14px 0; flex-wrap: wrap; align-items: center; }
.totals { margin-top: 12px; text-align: right; color: var(--muted); }
.totals b { color: var(--text); }
.move-box { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.move-box select { width: auto; display: inline-block; margin: 0; }
.move-box .meta { width: 100%; }
.back { display: none; }
@media (max-width: 760px) {
  .split.has-detail .list-panel { display: none; }
  .split:not(.has-detail) .detail { display: none; }
  .back { display: inline-block; margin-bottom: 10px; }
}

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Admin ---------- */
.tabs { display: flex; gap: 4px; margin-bottom: 14px; }
.tabs button { border: 0; background: none; padding: 7px 12px; border-radius: 7px; font: inherit; color: var(--muted); cursor: pointer; }
.tabs button.on { background: var(--panel); color: var(--text); font-weight: 600; border: 1px solid var(--line); }
.roles { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.role { flex: 1 1 160px; display: flex; gap: 8px; align-items: flex-start; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.role:has(input:checked) { border-color: var(--accent); background: var(--shipping-bg); }
.role input { margin-top: 3px; accent-color: var(--accent); }
.role > span { display: flex; flex-direction: column; }
.items > details { border-bottom: 1px solid var(--line); }
.items > details:last-child { border-bottom: 0; }
.items summary { padding: 12px 16px; cursor: pointer; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; list-style: none; }
.items summary::-webkit-details-marker { display: none; }
.items summary:hover { background: var(--hover); }
.items summary .grow { flex: 1; min-width: 140px; }
.items .body { padding: 4px 16px 16px; }
.secret { font-family: ui-monospace, Consolas, monospace; font-size: 15px; background: var(--bg); border: 1px dashed var(--line);
  border-radius: 7px; padding: 10px 12px; word-break: break-all; user-select: all; }
.notice { background: var(--shipping-bg); border-radius: 10px; padding: 14px 16px; margin-bottom: 14px; }
.notice > * + * { margin-top: 8px; }

.narrow { max-width: 520px; margin: 0 auto; }
.ok { color: var(--delivered); font-weight: 600; margin: 0; }
select { width: 100%; margin-top: 4px; display: block; }

/* ---------- Setup page (/install) ---------- */
.setup { max-width: 600px; }
.setup > * + * { margin-top: 14px; }
.setup-head { display: flex; gap: 14px; align-items: center; margin: 8px 0 18px; }
.setup-logo { width: 56px; height: 56px; border-radius: 13px; }
.setup h2 { display: flex; align-items: center; gap: 10px; }
.num { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: var(--accent-text); font-size: 14px; flex: none; }
.btn.big { font-size: 17px; padding: 12px 22px; width: 100%; justify-content: center; }
.steps { margin: 0; padding-left: 22px; }
.steps li { margin: 8px 0; }
.inline-icon { width: 20px; height: 20px; vertical-align: -4px; color: var(--accent); }
.substep { border-top: 1px solid var(--line); padding-top: 12px; }
.copy-row { display: inline-flex; gap: 8px; align-items: center; margin: 4px 0; }
.copy-row code { font: 14px ui-monospace, Consolas, monospace; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; user-select: all; }
.copy-row .btn { padding: 3px 10px; font-size: 13px; }
.substep > * + * { margin-top: 8px; }

#toast { position: fixed; bottom: max(16px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 9px 15px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 10; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; }
