:root {
  --paper: #F2F0E6;
  --paper-raised: #FBFAF5;
  --ink: #1C2321;
  --ink-soft: #4B534F;
  --brass: #B8863B;
  --brass-deep: #93692B;
  --ledger-green: #3D6B5C;
  --alert: #B3453A;
  --line: #D9D3C4;
  --line-strong: #C3BBA6;
  --radius: 3px;
  --font-display: 'Zilla Slab', Georgia, serif;
  --font-body: 'IBM Plex Sans', -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
}

button, input, select { font-family: inherit; font-size: inherit; }

/* ---------- header ---------- */

.shopfront {
  background: var(--ink);
  color: var(--paper);
  border-bottom: 3px solid var(--brass);
}

.shopfront-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 28px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-mark {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  background: var(--brass);
  color: var(--ink);
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
}

.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 18px; line-height: 1.1; }
.brand-sub { font-size: 12.5px; color: #C8CFC9; letter-spacing: 0.02em; }

.tabs { display: flex; gap: 4px; margin-left: auto; }

.tab {
  background: transparent;
  border: 1px solid transparent;
  color: #D8DAD4;
  padding: 8px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 500;
}

.tab.active { background: var(--paper-raised); color: var(--ink); }
.tab:not(.active):hover { border-color: rgba(255,255,255,0.25); }

.freshness {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: #D8DAD4;
  border-left: 1px solid rgba(255,255,255,0.2);
  padding-left: 18px;
}

.freshness-dot { width: 9px; height: 9px; border-radius: 50%; background: #7A8079; }
.freshness-dot.fresh { background: #5B9279; }
.freshness-dot.stale { background: var(--brass); }
.freshness-dot.old { background: var(--alert); }

/* ---------- layout ---------- */

main { max-width: 1180px; margin: 0 auto; padding: 28px 24px 60px; }

.view { display: none; }
.view.active { display: block; }

/* ---------- stat row ---------- */

.stat-row { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 18px; margin-bottom: 26px; }

.stat-card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px 18px;
  position: relative;
}

.stat-card.hero {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.stat-card.hero .stat-label,
.stat-card.hero .stat-date { color: #B9C1BB; }

.stat-label { font-size: 12.5px; text-transform: none; color: var(--ink-soft); font-weight: 500; }
.stat-date { font-size: 12px; color: var(--ink-soft); margin-top: 2px; margin-bottom: 10px; }

.stat-value {
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 600;
  line-height: 1;
}

.stat-card.hero .stat-value { font-size: 42px; color: var(--brass); }

.stat-sub { margin-top: 8px; font-size: 13px; font-family: var(--font-mono); color: var(--ink-soft); }
.stat-card.hero .stat-sub { color: #C8CFC9; }

/* ---------- panels ---------- */

.panel-row { display: grid; grid-template-columns: 1fr 1.2fr; gap: 18px; }

.panel {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 18px;
}

.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; border-bottom: 1px dashed var(--line-strong); padding-bottom: 10px; }
.panel-head h2 { font-family: var(--font-display); font-size: 18px; margin: 0; font-weight: 600; }

.seg { display: flex; gap: 2px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 2px; }
.seg-btn { background: transparent; border: none; padding: 5px 12px; border-radius: 2px; cursor: pointer; color: var(--ink-soft); font-size: 13px; }
.seg-btn.active { background: var(--ink); color: var(--paper); }

.dept-bars { display: flex; flex-direction: column; gap: 10px; }

.dept-row { display: grid; grid-template-columns: 120px 1fr auto; align-items: center; gap: 10px; }
.dept-name { font-size: 13.5px; }
.dept-track { background: var(--paper); border: 1px solid var(--line); border-radius: 2px; height: 10px; overflow: hidden; }
.dept-fill { background: var(--ledger-green); height: 100%; }
.dept-value { font-family: var(--font-mono); font-size: 13px; text-align: right; min-width: 90px; }

.empty-note { color: var(--ink-soft); font-size: 13.5px; }

/* ---------- report ---------- */

.report-controls { display: flex; flex-wrap: wrap; gap: 16px; align-items: end; margin-bottom: 18px; }
.report-controls label { display: flex; flex-direction: column; font-size: 12.5px; color: var(--ink-soft); gap: 4px; }
.report-controls input, .report-controls select {
  border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 7px 10px; background: var(--paper);
}

.btn {
  background: var(--ink); color: var(--paper); border: none;
  padding: 9px 18px; border-radius: var(--radius); cursor: pointer; font-weight: 500;
}
.btn:hover { background: #2B3531; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line-strong); }
.btn.ghost:hover { border-color: var(--ink); }

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-family: var(--font-mono); font-size: 13.5px; }
thead th {
  text-align: right; font-family: var(--font-body); font-weight: 600; font-size: 12.5px;
  color: var(--ink-soft); border-bottom: 2px solid var(--ink); padding: 8px 10px;
}
thead th:first-child, tbody td:first-child { text-align: left; font-family: var(--font-body); }
tbody td { text-align: right; padding: 7px 10px; border-bottom: 1px dashed var(--line); }
tfoot td { text-align: right; padding: 10px; font-weight: 600; border-top: 2px solid var(--ink); }
tfoot td:first-child { text-align: left; font-family: var(--font-body); }

/* ---------- upload ---------- */

.hint { color: var(--ink-soft); font-size: 13.5px; margin-top: -6px; margin-bottom: 18px; max-width: 62ch; }

.upload-drop {
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 34px 20px;
  text-align: center;
  position: relative;
  background: var(--paper);
}
.upload-drop input[type=file] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%;
}
.upload-drop-text { color: var(--ink-soft); font-size: 14px; }
.upload-drop-text strong { color: var(--ink); }

.upload-status { margin-top: 14px; font-size: 13.5px; color: var(--ink-soft); }
.upload-status.error { color: var(--alert); }
.upload-status.ok { color: var(--ledger-green); }

.upload-preview { margin-top: 22px; border-top: 1px dashed var(--line-strong); padding-top: 18px; }
.upload-preview h3 { font-family: var(--font-display); font-size: 16px; margin: 0 0 10px; }
.upload-preview h4 { font-size: 14px; margin: 0 0 6px; }

.date-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--paper); border: 1px solid var(--line-strong); border-radius: var(--radius);
  padding: 5px 10px; margin: 0 8px 8px 0; font-family: var(--font-mono); font-size: 13px;
}

.duplicate-box { margin-top: 16px; background: #F7EFE3; border: 1px solid var(--brass); border-radius: var(--radius); padding: 14px 16px; }
.duplicate-row { display: flex; align-items: center; gap: 14px; padding: 6px 0; font-size: 13.5px; }
.duplicate-row .ddate { font-family: var(--font-mono); min-width: 110px; }
.duplicate-row select { border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 4px 8px; background: var(--paper-raised); }

.hidden { display: none !important; }

footer { text-align: center; color: var(--ink-soft); font-size: 12px; padding: 20px 0 30px; }

@media (max-width: 820px) {
  .stat-row { grid-template-columns: 1fr; }
  .panel-row { grid-template-columns: 1fr; }
  .shopfront-inner { gap: 14px; }
  .freshness { border-left: none; padding-left: 0; }
}
