:root {
  --bg: #F3F2EE; --card: #FFFFFF; --card2: #FBFAF7; --ink: #1E2327; --muted: #5C6268; --line: #D9D6CE;
  --accent: #B85412; --accent-ink: #FFFFFF; --accent-soft: #FBEBDD; --dark: #1E2327;
  --chase: #B3261E; --chase-bg: #FBE6E3; --tight: #7A4B00; --tight-bg: #FFF1CC; --tight-bar: #E0A100;
  --ok: #4A545B; --ok-bar: #A9B0B5; --ok-bg: #ECEAE4; --done: #2F6B3F; --done-bg: #E3F1E6;
  --hold: #5C6268; --info: #1F5A8A; --info-bg: #E5EFF7;
  --shadow: 0 1px 2px rgba(30,35,39,.08), 0 2px 8px rgba(30,35,39,.06);
  --radius: 14px;
  --font: 'Public Sans', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --display: 'Oswald', 'Public Sans', system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14181B; --card: #1E2327; --card2: #232A2F; --ink: #F3F2EE; --muted: #A5ADB2; --line: #353D43;
    --accent: #F0913A; --accent-ink: #1E2327; --accent-soft: #3A2A1B;
    --chase: #FF8A80; --chase-bg: #3B1F1D; --tight: #FFD470; --tight-bg: #3A2F12; --tight-bar: #E0A100;
    --ok: #C3CACE; --ok-bar: #6B767D; --ok-bg: #262D32; --done: #8FD19E; --done-bg: #1D3022; --hold: #A5ADB2; --info: #8CC2EE; --info-bg: #1C2C3A;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 17px; line-height: 1.4; }
body { min-height: 100vh; min-height: 100dvh; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { font-family: var(--display); font-weight: 600; letter-spacing: .2px; margin: 0; line-height: 1.15; }
h1 { font-size: 28px; } h2 { font-size: 22px; } h3 { font-size: 18px; }
.muted { color: var(--muted); } .small { font-size: 14px; } .tiny { font-size: 12.5px; } .strong { font-weight: 600; }
.hide { display: none !important; }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- shell ---------- */
.shell { display: flex; flex-direction: column; min-height: 100dvh; }
.topbar { position: sticky; top: 0; z-index: 20; background: var(--dark); color: #F3F2EE; display: flex; align-items: center; gap: 12px; padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); }
.brand { font-family: var(--display); font-weight: 600; font-size: 20px; letter-spacing: .5px; }
.brand b { color: #F0913A; }
.topbar .grow { flex: 1; }
.who { font-size: 14px; color: #CFD4D7; display: flex; align-items: center; gap: 8px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #5FBF7A; display: inline-block; }
.dot.off { background: #E0A100; }
.demo-banner { background: var(--info-bg); color: var(--info); font-size: 14px; padding: 6px 16px; display: flex; gap: 8px; align-items: center; }
.demo-banner select, .demo-banner button { width: auto; min-height: 34px; font-size: 14px; padding: 2px 8px; border-radius: 8px; border: 1px solid var(--info); background: transparent; color: var(--info); }
main { flex: 1; padding: 16px; padding-bottom: calc(96px + env(safe-area-inset-bottom)); max-width: 1100px; width: 100%; margin: 0 auto; }
.nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 25; background: var(--card); border-top: 1px solid var(--line); display: flex; padding-bottom: env(safe-area-inset-bottom); }
.nav button { flex: 1; background: none; border: 0; padding: 9px 4px 8px; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: 12.5px; font-weight: 600; min-height: 58px; position: relative; }
.nav button svg { width: 24px; height: 24px; }
.nav button.on { color: var(--accent); }
.nav .badge-n { position: absolute; top: 4px; left: calc(50% + 8px); background: var(--chase); color: #fff; border-radius: 999px; font-size: 11px; min-width: 18px; height: 18px; line-height: 18px; text-align: center; padding: 0 5px; }
@media (min-width: 900px) {
  .shell { padding-left: 92px; }
  .nav { top: 0; bottom: 0; right: auto; width: 92px; flex-direction: column; border-top: 0; border-right: 1px solid var(--line); padding-top: 64px; }
  .nav button { flex: 0 0 auto; min-height: 76px; }
  main { padding-bottom: 40px; }
}

/* ---------- common bits ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head .date { color: var(--muted); font-size: 15px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 12px 16px; font-weight: 600; min-height: 48px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.dark { background: var(--dark); color: #F3F2EE; border-color: var(--dark); }
.btn.danger { color: var(--chase); border-color: var(--chase); }
.btn.small { min-height: 38px; padding: 7px 12px; font-size: 15px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 8px 14px; font-weight: 600; font-size: 15px; min-height: 40px; }
.chip.on { background: var(--dark); color: #F3F2EE; border-color: var(--dark); }
.chip .n { opacity: .65; margin-left: 4px; font-weight: 500; }
.pill { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 10px; font-size: 13px; font-weight: 600; background: var(--ok-bg); color: var(--ok); white-space: nowrap; }
.pill.chase { background: var(--chase-bg); color: var(--chase); }
.pill.tight { background: var(--tight-bg); color: var(--tight); }
.pill.done { background: var(--done-bg); color: var(--done); }
.pill.info { background: var(--info-bg); color: var(--info); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.pill.hold { background: var(--ok-bg); color: var(--hold); }
.empty { text-align: center; padding: 36px 12px; color: var(--muted); }
.empty b { display: block; font-family: var(--display); font-size: 20px; color: var(--ink); margin-bottom: 4px; }
.section-title { display: flex; align-items: center; gap: 10px; margin: 22px 0 10px; }
.section-title h2 { font-size: 20px; }
.section-title .count { background: var(--ok-bg); border-radius: 999px; padding: 1px 10px; font-weight: 600; font-size: 14px; }
.section-title.chase h2 { color: var(--chase); } .section-title.tight h2 { color: var(--tight); }

/* ---------- board ---------- */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.tile { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); padding: 12px 10px; text-align: left; box-shadow: var(--shadow); border-top-width: 6px; }
.tile .big { font-family: var(--display); font-size: 40px; line-height: 1; font-weight: 600; }
.tile .lbl { font-weight: 600; font-size: 14.5px; margin-top: 4px; }
.tile.chase { border-top-color: var(--chase); } .tile.chase .big { color: var(--chase); }
.tile.tight { border-top-color: var(--tight-bar); } .tile.tight .big { color: var(--tight); }
.tile.ok { border-top-color: var(--ok-bar); }
.tile.on { outline: 3px solid var(--ink); outline-offset: 1px; }
.alerts { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.alert { border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 8px 12px; font-size: 14.5px; font-weight: 600; display: inline-flex; gap: 8px; align-items: center; min-height: 40px; }
.alert b { font-family: var(--display); font-size: 18px; }
.order { display: block; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px 12px 18px; position: relative; overflow: hidden; margin-bottom: 10px; }
.order::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 7px; background: var(--ok-bar); }
.order.chase::before { background: var(--chase); } .order.tight::before { background: var(--tight-bar); }
.order.done::before { background: var(--done); } .order.draft::before, .order.hold::before { background: var(--line); }
.order .top { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.order .po { font-family: var(--display); font-weight: 600; font-size: 20px; letter-spacing: .3px; }
.order .due { margin-left: auto; font-weight: 600; text-align: right; }
.order .why { font-size: 14.5px; margin-top: 4px; }
.order.chase .why { color: var(--chase); font-weight: 600; } .order.tight .why { color: var(--tight); font-weight: 600; }
.order .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; align-items: center; }
.stagebar { display: flex; gap: 3px; height: 8px; margin-top: 9px; }
.stagebar i { flex: 1; border-radius: 3px; background: var(--line); }
.stagebar i.s-unit4 { background: #8FA3B0; } .stagebar i.s-painters { background: #C79A5C; } .stagebar i.s-back { background: #7FA98A; }
.stagebar i.s-booked { background: #3E8E5A; } .stagebar i.s-gone, .stagebar i.s-delivered { background: #2F6B3F; } .stagebar i.s-draft { background: var(--line); }
.lines-mini { font-size: 14px; color: var(--muted); margin-top: 6px; }

/* ---------- work view ---------- */
.tabs { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px 12px; padding: 2px 16px 8px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: 0 0 auto; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 8px 14px; font-weight: 600; min-height: 52px; text-align: center; }
.tab .n { display: block; font-family: var(--display); font-size: 20px; line-height: 1.1; }
.tab .t { font-size: 13px; color: var(--muted); }
.tab.on { background: var(--dark); border-color: var(--dark); color: #F3F2EE; } .tab.on .t { color: #CFD4D7; }
.group { margin-bottom: 14px; }
.group-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; padding: 0 2px 6px; }
.group-head .po { font-family: var(--display); font-weight: 600; font-size: 19px; }
.line { display: flex; gap: 12px; align-items: center; padding: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; }
.line .main { flex: 1; min-width: 0; }
.line .code { font-weight: 700; letter-spacing: .2px; }
.line .desc { font-size: 14.5px; color: var(--muted); }
.line .qty { font-family: var(--display); font-size: 22px; min-width: 38px; text-align: right; }
.line.sel { outline: 3px solid var(--accent); outline-offset: -1px; }
.check { width: 28px; height: 28px; border-radius: 8px; border: 2px solid var(--line); background: var(--card); flex: 0 0 auto; display: grid; place-items: center; padding: 0; }
.check.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.check svg { width: 18px; height: 18px; }
.actionbar { position: fixed; left: 0; right: 0; bottom: calc(60px + env(safe-area-inset-bottom)); z-index: 24; padding: 10px 16px; background: var(--dark); color: #F3F2EE; display: flex; gap: 10px; align-items: center; justify-content: space-between; box-shadow: 0 -4px 16px rgba(0,0,0,.2); }
@media (min-width: 900px) { .actionbar { left: 92px; bottom: 0; } }

/* ---------- forms & modals ---------- */
.overlay { position: fixed; inset: 0; z-index: 40; background: rgba(20,24,27,.55); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 760px; max-height: 94dvh; overflow: auto; border-radius: 20px 20px 0 0; padding: 16px; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
@media (min-width: 900px) { .overlay { align-items: center; } .sheet { border-radius: 20px; max-height: 90vh; } }
.sheet-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.sheet-head .grow { flex: 1; }
.x { border: 0; background: var(--card); width: 44px; height: 44px; border-radius: 12px; font-size: 22px; line-height: 1; border: 1px solid var(--line); }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > label, .lbl { font-size: 14px; font-weight: 600; color: var(--muted); }
input[type=text], input[type=number], input[type=date], input[type=email], input[type=password], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 11px 12px; min-height: 48px; font-size: 17px; }
input:focus, select:focus, textarea:focus { outline: 3px solid var(--accent-soft); border-color: var(--accent); }
textarea { min-height: 84px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .grid3 { grid-template-columns: 1fr 1fr; } }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 15.5px; }
.kv dt { color: var(--muted); font-weight: 600; } .kv dd { margin: 0; }
.callout { border-radius: 12px; padding: 10px 12px; font-size: 15px; margin: 10px 0; background: var(--info-bg); color: var(--info); }
.callout.warn { background: var(--tight-bg); color: var(--tight); } .callout.bad { background: var(--chase-bg); color: var(--chase); }
.callout.tip { background: var(--accent-soft); color: var(--ink); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: var(--card); padding: 10px 8px; font-weight: 600; min-height: 48px; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; } .seg button.on { background: var(--dark); color: #F3F2EE; }
.opt { display: block; width: 100%; text-align: left; border: 2px solid var(--line); background: var(--card); border-radius: 14px; padding: 14px; margin-bottom: 10px; }
.opt.rec { border-color: var(--accent); } .opt .t { font-family: var(--display); font-size: 21px; font-weight: 600; }
.table { width: 100%; border-collapse: collapse; font-size: 15px; }
.table th { text-align: left; font-size: 13px; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line); }
.table td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table td.num, .table th.num { text-align: right; }
.hist { font-size: 14.5px; }
.hist li { padding: 7px 0; border-bottom: 1px solid var(--line); list-style: none; }
.hist ul { padding: 0; margin: 0; }
.toast { position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(30px); opacity: 0; pointer-events: none; z-index: 60; background: var(--dark); color: #F3F2EE; border-radius: 14px; padding: 12px 16px; display: flex; gap: 14px; align-items: center; transition: .2s; max-width: 92vw; box-shadow: 0 6px 24px rgba(0,0,0,.3); }
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.show button { pointer-events: auto; }
.toast.error { background: var(--chase); color: #fff; }
.toast button { background: #F0913A; border: 0; border-radius: 10px; color: #1E2327; font-weight: 700; padding: 8px 14px; min-height: 40px; }
.auth { max-width: 440px; margin: 0 auto; padding: 36px 20px; }
.auth h1 { margin-bottom: 6px; }
.big-input { font-size: 22px; letter-spacing: 3px; text-transform: uppercase; text-align: center; }
.search { margin-bottom: 10px; }
.sheet-doc { background: #fff; color: #1E2327; border: 1px solid var(--line); border-radius: 8px; padding: 22px; font-size: 15px; }
.sheet-doc h2 { font-size: 24px; margin-bottom: 4px; }
.sheet-doc table { width: 100%; border-collapse: collapse; margin: 12px 0; }
.sheet-doc th, .sheet-doc td { border: 1px solid #bbb; padding: 6px 8px; text-align: left; }
@media print {
  body * { visibility: hidden; }
  .sheet-doc, .sheet-doc * { visibility: visible; }
  .sheet-doc { position: absolute; left: 0; top: 0; width: 100%; border: 0; }
}
.sync-spin { opacity: .6; }
a { color: var(--accent); }

.grid2 > *, .grid3 > * { min-width: 0; }
input[type=date] { min-width: 0; max-width: 100%; }
