:root {
  --paper: #E9ECE8;
  --surface: #FFFFFF;
  --ink: #1E2731;
  --muted: #5D6873;
  --line: #D4D9D3;
  --accent: #F2C12E;       /* safety yellow */
  --accent-ink: #1E2731;
  --danger: #B3402A;
  --radius: 6px;
  --font: "Barlow", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-display: "Barlow Condensed", "Arial Narrow", "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #161C22; --surface: #1F2730; --ink: #E7EAE6; --muted: #9AA4AD;
    --line: #34404B; --danger: #E2775F; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 400 16px/1.5 var(--font); }
a { color: inherit; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 20px; }
main.wrap { padding-bottom: 60px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
code { font-size: .9em; background: var(--paper); padding: 1px 5px; border-radius: 3px; word-break: break-all; }

/* Top bar */
.topbar { background: #1E2731; color: #fff; border-bottom: 4px solid var(--accent); }
.topbar-in { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 60px; flex-wrap: wrap; }
.brand { font: 700 22px/1 var(--font-display); text-decoration: none; letter-spacing: .01em; }
.topbar nav { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; padding: 8px 0; }
.topbar nav a:not(.btn) { text-decoration: none; opacity: .85; }
.topbar nav a:not(.btn):hover { opacity: 1; text-decoration: underline; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; font: 600 15px/1 var(--font);
  padding: 10px 16px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-primary:hover { background: #E3B11C; border-color: transparent; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--muted); text-decoration: underline; cursor: pointer; }
.danger { color: var(--danger); }

/* Notices */
.notice { margin: 20px 0 0; padding: 12px 16px; background: var(--surface); border-left: 4px solid var(--accent); border-radius: var(--radius); }
.notice.error { border-left-color: var(--danger); }
.notice h1 { margin-top: 0; }

/* Hero: the total, and the two charts */
.hero { display: grid; grid-template-columns: 1fr 1.2fr 1.4fr; gap: 20px; margin: 28px 0 24px; }
.hero > * { background: var(--surface); border-radius: var(--radius); padding: 22px; }
.hero-main { background: #1E2731; color: #fff; display: flex; flex-direction: column; justify-content: flex-end; }
.hero-label { margin: 0; color: #B9C2CA; }
.hero-value { margin: 4px 0 6px; font: 700 clamp(48px, 6vw, 76px)/.95 var(--font-display); color: var(--accent); font-variant-numeric: tabular-nums; }
.hero-sub { margin: 0; color: #D7DDE2; }
.hero-warn { margin: 14px 0 0; padding-top: 12px; border-top: 1px solid #3A4754; color: #F5D67A; font-size: 15px; }
.chart h2 { margin: 0 0 14px; font: 700 20px/1.2 var(--font-display); }
.chart-body { display: flex; gap: 18px; align-items: center; }
.donut { width: 140px; height: 140px; flex: none; }
.donut circle { transition: stroke-width .15s; }
.donut circle:hover { stroke-width: 40; }
.legend { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 0; font-size: 14px; max-height: 190px; overflow-y: auto; }
.legend li { display: grid; grid-template-columns: 12px 1fr auto 38px; gap: 8px; align-items: start; padding: 4px 0; }
.swatch { width: 12px; height: 12px; border-radius: 2px; margin-top: 5px; }
.lg-name small { display: block; color: var(--muted); font-size: 12px; line-height: 1.2; }
.lg-val, .lg-pct { text-align: right; font-variant-numeric: tabular-nums; }
.lg-pct { color: var(--muted); }

/* Empty state */
.empty { background: var(--surface); border-radius: var(--radius); padding: 40px; max-width: 640px; }
.empty h2 { margin-top: 0; font: 700 28px/1.15 var(--font-display); }
.empty p { color: var(--muted); }

/* Filters */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.filters input[type=search] { flex: 1 1 260px; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 9px 11px; width: 100%; font-weight: 400; }
.filters select { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--ink); }
.clear { color: var(--muted); }
.result-line, .none { color: var(--muted); margin: 8px 0 12px; }

/* Items table */
.table-wrap { background: var(--surface); border-radius: var(--radius); overflow-x: auto; }
table.items { width: 100%; border-collapse: collapse; font-size: 15px; }
.items th { text-align: left; font-weight: 600; color: var(--muted); padding: 12px 14px; border-bottom: 2px solid var(--line); white-space: nowrap; }
.items td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.items tbody tr { cursor: pointer; }
.items tbody tr:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.items .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.items .strong { font-weight: 600; }
.c-name a { font-weight: 600; text-decoration: none; }
.c-name a:hover { text-decoration: underline; }
.c-name small { display: block; color: var(--muted); }
.c-thumb { width: 64px; }
.c-thumb img, .nothumb { width: 44px; height: 44px; object-fit: cover; border-radius: 4px; display: block; }
.nothumb { background: repeating-linear-gradient(45deg, var(--line) 0 4px, transparent 4px 8px); }
.c-files { text-align: center; }
.missing { color: var(--muted); font-size: 13px; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 3px; font-size: 13px; font-weight: 600;
  background: color-mix(in srgb, var(--c) 16%, transparent); border-left: 3px solid var(--c); white-space: nowrap; }

/* Item page */
.back { margin: 24px 0 4px; }
.back a { color: var(--muted); }
.page-title { font: 700 clamp(30px, 4vw, 42px)/1.1 var(--font-display); margin: 0 0 20px; }
.item-form fieldset { background: var(--surface); border: 0; border-radius: var(--radius); padding: 20px 22px 22px; margin: 0 0 16px;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px 20px; }
.item-form legend { float: left; width: 100%; grid-column: 1 / -1; font: 700 20px/1.2 var(--font-display); padding: 0; margin-bottom: 2px; }
.item-form label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 15px; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: 1 / -1; }
.req { font-weight: 400; color: var(--muted); font-size: 13px; }
.hint { font-weight: 400; font-size: 13px; color: var(--muted); }
.drop input[type=file] { padding: 18px; border-style: dashed; cursor: pointer; }
.files { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; }
.files li { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.file-prev { display: block; aspect-ratio: 1; border-radius: 4px; overflow: hidden; background: var(--paper); }
.file-prev img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pdf { display: grid; place-items: center; height: 100%; font: 700 24px var(--font-display); color: var(--danger); }
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.files .link { align-self: flex-start; font-size: 13px; }
.actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.cancel { color: var(--muted); }
.push { margin-left: auto; }

/* Backup page */
.prose { background: var(--surface); border-radius: var(--radius); padding: 24px 28px; max-width: 720px; }
.prose h2 { font: 700 22px/1.2 var(--font-display); margin: 28px 0 6px; }
.prose p { margin: 0 0 12px; }

/* Responsive */
@media (max-width: 1000px) {
  .hero { grid-template-columns: 1fr 1fr; }
  .hero-main { grid-column: 1 / -1; }
}
@media (max-width: 700px) {
  .hero { grid-template-columns: 1fr; }
  .chart-body { flex-direction: column; align-items: stretch; }
  .donut { align-self: center; }
  .legend { max-height: none; }
  .item-form fieldset { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .filters select { flex: 1 1 45%; }
  /* table becomes stacked rows */
  .items thead { display: none; }
  .items, .items tbody, .items tr, .items td { display: block; }
  .items tr { display: grid; grid-template-columns: 56px 1fr auto; gap: 2px 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .items td { padding: 0; border: 0; }
  .items .c-thumb { grid-row: span 3; width: auto; }
  .items .c-name { grid-column: 2; }
  .items td[data-l="Replace for"] { grid-column: 3; grid-row: 1; }
  .items td[data-l="Type"] { grid-column: 2; }
  .items td[data-l="Category"], .items td[data-l="Location"] { display: none; }
  .items td[data-l="Paid"], .items .c-files { display: none; }
  .items td[data-l="Resale"] { grid-column: 3; grid-row: 2; font-size: 14px; }
  .push { margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Sign in, setup, account */
.inline { display: inline; margin: 0; }
.navlink { background: none; border: 0; padding: 0; font: inherit; color: inherit; opacity: .85; cursor: pointer; }
.navlink:hover { opacity: 1; text-decoration: underline; }
.auth { max-width: 440px; margin: 48px auto 0; }
.auth .notice { margin: 0 0 16px; }
.auth-form { display: flex; flex-direction: column; gap: 16px; background: var(--surface); padding: 24px; border-radius: var(--radius); }
.prose .auth-form { padding: 0; max-width: 420px; }
.auth-form label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 15px; }
.auth-form .btn { align-self: flex-start; }

/* Resale total and per-item ticks */
.resale-bar { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; background: #2E7D4F; color: #fff;
  font-weight: 700; border-radius: 10px; padding: 14px 20px; margin-bottom: 12px; }
.rb-label { font-weight: 700; }
.rb-value { font: 700 28px/1 var(--font-display); font-variant-numeric: tabular-nums; }
.rb-note { font-size: 14px; font-weight: 700; }
.rb-err { flex-basis: 100%; font-size: 14px; background: #fff; color: var(--danger); padding: 4px 8px; border-radius: 4px; }
.th-hint { font-weight: 400; font-size: 12px; }
.rs-toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; vertical-align: middle; line-height: 1; }
.rs-check { display: block; width: 18px; height: 18px; margin: 0; padding: 0; border: 0; flex: none;
  accent-color: var(--ink); cursor: pointer; }
.rs-amt { display: block; line-height: 18px; min-width: 10ch; text-align: right; }
.items td.excluded .rs-amt { color: var(--muted); text-decoration: line-through; }
@media (max-width: 700px) {
  .th-hint { display: none; }
}

/* Item numbers */
.c-no { white-space: nowrap; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.item-no { color: var(--muted); font-weight: 600; font-size: .6em; vertical-align: middle; margin-right: 6px; }
@media (max-width: 700px) {
  .items td.c-no { grid-column: 2; grid-row: 1; font-size: 12px; }
  .items .c-name { grid-row: 2; }
  .items td[data-l="Type"] { grid-row: 3; }
  .items .c-thumb { grid-row: span 3; }
}
