:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #d9dee6;
  --text: #1a1f2b;
  --muted: #64707f;
  --accent: #6a4bc8;
  --accent-ink: #ffffff;
  --pos: #1f8a4c;
  --neg: #c0392b;
  --warn: #b8860b;
  --shadow: 0 1px 3px rgba(20, 25, 40, 0.08);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c;
    --surface: #1b1f2a;
    --surface-2: #232836;
    --border: #313848;
    --text: #e7ebf2;
    --muted: #97a2b3;
    --accent: #9b83e6;
    --accent-ink: #14121f;
    --pos: #4ecb7d;
    --neg: #ef6a5c;
    --warn: #e0a800;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; font-weight: 600; }

/* Layout */
header.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem .9rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
header.topbar .brand { font-weight: 700; font-size: 1.05rem; }
header.topbar .brand small { color: var(--muted); font-weight: 500; }
header.topbar .spacer { flex: 1; }
header.topbar .who { color: var(--muted); font-size: .85rem; }

nav.tabs {
  display: flex; gap: .25rem; overflow-x: auto; padding: .4rem .6rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 49px; z-index: 19;
}
nav.tabs button {
  flex: 0 0 auto; border: none; background: transparent; color: var(--muted);
  padding: .45rem .7rem; border-radius: 8px; font-weight: 600; font-size: .9rem; cursor: pointer;
}
nav.tabs button.active { background: var(--accent); color: var(--accent-ink); }

main { padding: 1rem; max-width: 1100px; margin: 0 auto; }
section.view { display: none; }
section.view.active { display: block; }

/* Cards & grid */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem;
}
.grid { display: grid; gap: 1rem; }
@media (min-width: 720px) { .grid.cols-2 { grid-template-columns: 1fr 1fr; } .grid.cols-3 { grid-template-columns: repeat(3,1fr);} }

.stat { display: flex; flex-direction: column; gap: .1rem; }
.stat .label { color: var(--muted); font-size: .8rem; }
.stat .value { font-size: 1.5rem; font-weight: 700; }

/* Forms */
label { display: block; font-size: .82rem; color: var(--muted); margin: .5rem 0 .2rem; font-weight: 600; }
input, select, textarea {
  width: 100%; padding: .55rem .6rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); color: var(--text); font-size: 1rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
input:disabled, select:disabled, textarea:disabled { opacity: .55; cursor: not-allowed; background: var(--surface); }
hr.sep { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }
.row { display: grid; gap: .6rem; }
@media (min-width: 560px) { .row.two { grid-template-columns: 1fr 1fr; } .row.three { grid-template-columns: 1fr 1fr 1fr; } }

button.btn {
  appearance: none; border: none; border-radius: 9px; cursor: pointer;
  padding: .6rem 1rem; font-weight: 700; font-size: .95rem;
  background: var(--accent); color: var(--accent-ink);
}
button.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
button.btn.ghost { background: transparent; color: var(--accent); }
button.btn:disabled { opacity: .5; cursor: default; }
.btnrow { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .75rem; }

/* Tables */
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .02em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.pos { color: var(--pos); } .neg { color: var(--neg); } .warn { color: var(--warn); }
tr.total td { font-weight: 700; border-top: 2px solid var(--border); }

.pill { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .72rem; font-weight: 700; }
.pill.open { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.pill.paid { background: color-mix(in srgb, var(--pos) 20%, transparent); color: var(--pos); }
.pill.overdue { background: color-mix(in srgb, var(--neg) 22%, transparent); color: var(--neg); }

.muted { color: var(--muted); }
.hint { font-size: .8rem; color: var(--muted); margin-top: .3rem; }
.toast {
  position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 10px;
  box-shadow: var(--shadow); z-index: 50; font-weight: 600; max-width: 90vw;
}
.center { min-height: 70vh; display: grid; place-items: center; }
.authbox { width: min(380px, 92vw); }

/* Budget meters */
.meter .meter-nums { margin: .2rem 0 .5rem; }
.meter .meter-spend { font-size: 1.6rem; font-weight: 800; }
.bar { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.bar-fill { height: 100%; border-radius: 999px; transition: width .3s ease; }
.bar-fill.pos { background: var(--pos); }
.bar-fill.warn { background: var(--warn); }
.bar-fill.neg { background: var(--neg); }
.meter-rem { margin-top: .4rem; font-weight: 700; font-size: .9rem; }
.meter-sub { margin-top: .3rem; font-size: .78rem; }

/* Buttons — small variants */
.btn.sm, .step { padding: .3rem .6rem; font-size: .82rem; }
.btnrow.tight { margin-top: .4rem; gap: .35rem; }
.btn.ghost.sm.neg { color: var(--neg); }

/* Catalog chips */
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 999px; padding: .4rem .7rem; font-size: .85rem; font-weight: 600; cursor: pointer;
}
.chip.custom { border-style: dashed; color: var(--accent); }

/* Order lines */
.lines { display: flex; flex-direction: column; gap: .5rem; }
.line { display: grid; grid-template-columns: 1fr auto auto auto auto; gap: .4rem; align-items: center; }
.line .ln-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.line .ln-mid { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.line .ln-qty { display: flex; align-items: center; gap: .2rem; flex-wrap: wrap; }
.line .ln-qty input { width: 3rem; text-align: center; padding: .35rem .2rem; }
.ln-unit { font-size: .78rem; color: var(--muted); font-weight: 600; }
.ln-unit-in { width: 3.4rem; padding: .3rem .3rem; font-size: .82rem; }
.line .ln-price { width: 5.5rem; padding: .35rem .3rem; }
.line .ln-set { display: flex; align-items: center; gap: .2rem; }
.ln-dollar { color: var(--muted); font-weight: 700; }
.ln-setamt { width: 6rem; padding: .35rem .3rem; }
.step.mode { font-size: .72rem; padding: .3rem .45rem; }
.line .ln-total { font-variant-numeric: tabular-nums; font-weight: 700; text-align: right; }
.line.setmode .ln-total { display: none; }
.step { border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 8px; cursor: pointer; font-weight: 700; }
.step.del { color: var(--neg); }
.checks { display: flex; gap: 1rem; padding-top: .3rem; }
.chk { display: inline-flex; align-items: center; gap: .3rem; margin: 0; color: var(--text); font-weight: 600; }
.chk input { width: auto; }

/* Totals */
.totals .trow, .card .trow { display: flex; justify-content: space-between; padding: .25rem 0; }
.totals .trow.grand { border-top: 2px solid var(--border); margin-top: .3rem; padding-top: .5rem; font-weight: 800; font-size: 1.1rem; }

/* Timeline */
.tl-row { padding: .7rem .8rem; }
.tl-meta { font-size: .82rem; margin-bottom: .2rem; }
.tl-badge { display: inline-block; padding: .05rem .45rem; border-radius: 999px; font-size: .68rem; font-weight: 800; text-transform: uppercase; letter-spacing: .03em; }
.tl-badge.order { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--accent); }
.tl-badge.note { background: color-mix(in srgb, var(--warn) 22%, transparent); color: var(--warn); }
.tl-badge.photo { background: color-mix(in srgb, var(--pos) 22%, transparent); color: var(--pos); }
.tl-body { margin: .1rem 0; }
.tl-note { font-size: .85rem; font-style: italic; }
.photos { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .4rem; }
.photos img { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }

/* Orders list */
.day-head { display: flex; justify-content: space-between; align-items: baseline; font-weight: 800; margin: 1rem 0 .4rem; padding-bottom: .2rem; border-bottom: 2px solid var(--border); }
.order-row .order-top { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.order-breakdown { font-size: .8rem; margin-top: .2rem; }

/* Catalog + users editors */
.cat-list { display: flex; flex-direction: column; gap: .4rem; }
.cat-row { display: grid; grid-template-columns: 1.4fr .7fr .6fr .8fr auto auto auto; gap: .4rem; align-items: center; }
.cat-row.add { grid-template-columns: 1.4fr .7fr .6fr .8fr auto auto; margin-top: .6rem; border-top: 1px dashed var(--border); padding-top: .6rem; }
.cat-row.head { font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; }
.cat-row.head span { padding-left: .1rem; }
.cat-row.inactive input { opacity: .55; }
@media (max-width: 620px) { .cat-row, .cat-row.add { grid-template-columns: 1fr 1fr; } .cat-row.head { display: none; } }
.user-row { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; padding: .45rem 0; border-bottom: 1px solid var(--border); }
.user-row.inactive > span:first-child { opacity: .55; }
.user-tags { display: inline-flex; gap: .35rem; align-items: center; }
.user-row .btnrow.tight { margin-top: 0; }
.card.sub { background: var(--surface-2); }

/* Report */
.report-head { margin-bottom: .8rem; }
.report-summary { white-space: pre-wrap; padding: .6rem .8rem; background: var(--surface-2); border-radius: 10px; margin-bottom: 1rem; }
.report-tl-head { margin-top: 1.2rem; }
.report-entry { border-left: 3px solid var(--border); padding: .4rem 0 .6rem .8rem; margin: .2rem 0; }
.re-time { font-size: .8rem; color: var(--muted); margin-bottom: .2rem; }
.re-lines { margin: .3rem 0; padding-left: 1.1rem; font-size: .88rem; }
.report-photos { gap: .6rem; }
.report-photos figure { margin: 0; }
.report-photos img { width: 220px; height: auto; max-height: 300px; object-fit: contain; border-radius: 8px; border: 1px solid var(--border); }
.report-photos figcaption { font-size: .72rem; margin-top: .2rem; }

@media print {
  header.topbar, nav.tabs, .noprint, button { display: none !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  .report-entry { break-inside: avoid; }
  .report-photos img { width: 2.4in; }
}
