:root {
  --paper: #e9e3d7;
  --surface: #fbf9f6;
  --ink: #1c1915;
  --muted: #5e564e;
  --line: #e3dacd;
  --line-strong: #d3c9b8;
  --sidebar: #17211c;
  --stamp: #a33b24;
  --stamp-dark: #842f1c;
  --pine: #1f5c3c;
  --pine-soft: #e5f2ea;
  --warn: #8a5a10;
  --danger: #8d2e22;
  --danger-soft: #f8e6e3;
  --shadow: 0 16px 40px rgba(48, 32, 14, 0.06);
  --display: "Fraunces", "Palatino Linotype", serif;
  --body: "Outfit", "Segoe UI", sans-serif;
  color-scheme: light;
}

*,
*::before,
*::after { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.45;
  background:
    radial-gradient(ellipse at top left, rgba(255, 255, 255, 0.65), transparent 46%),
    var(--paper);
}

body:has(dialog[open]) { overflow: hidden; }

button,
input,
textarea,
select { font: inherit; color: inherit; }

button:disabled { cursor: progress; opacity: 0.7; }

p,
h1,
h2 { margin: 0; }

:focus { outline: none; }

:focus-visible {
  outline: 2px solid var(--stamp);
  outline-offset: 2px;
}

.sidebar :focus-visible { outline-color: #f0c2b6; }

::placeholder { color: #9a9186; }

::selection { background: #f0cfc6; }

code {
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.06);
  font-size: 0.9em;
}

.skip {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 80;
  padding: 8px 12px;
  border-radius: 8px;
  background: white;
  color: var(--ink);
}

.skip:focus { top: 12px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 22px 16px;
  background: var(--sidebar);
  color: #e7eee9;
}

.brand,
.login-brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 0 8px;
}

.mark {
  display: grid;
  flex: none;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1.5px solid #e7b2a4;
  border-radius: 50%;
  color: #f0c2b6;
  font-family: var(--display);
  font-size: 22px;
}

.brand strong,
.login-brand strong {
  display: block;
  font-size: 15px;
  font-weight: 600;
}

.brand span,
.login-brand span {
  display: block;
  color: #b7c4bb;
  font-size: 13px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 26px;
}

.nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 10px;
  color: #d5e0d8;
  text-decoration: none;
}

.nav a:hover { background: rgba(255, 255, 255, 0.05); }

.nav a.is-active {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.count {
  min-width: 1.5em;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 12px;
  text-align: center;
}

.is-active .count {
  background: var(--stamp);
  color: white;
}

.side-foot { margin-top: auto; }

.side-stat {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
}

.side-stat span { color: #b7c4bb; font-size: 13px; }

.side-stat strong {
  font-family: var(--display);
  font-size: 22px;
  font-weight: 560;
}

.side-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 8px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.side-user strong {
  display: block;
  font-size: 14px;
  font-weight: 600;
}

.side-user span {
  display: block;
  color: #9aada3;
  font-size: 12px;
}

.side-user-actions {
  display: flex;
  flex: none;
  gap: 10px;
  align-items: center;
}

.side-user-actions form { margin: 0; }

.side-user-actions a,
.side-user-actions button {
  padding: 0;
  border: none;
  background: none;
  color: #f0c2b6;
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
}

.side-user-actions a:hover,
.side-user-actions button:hover { text-decoration: underline; }

.content {
  min-width: 0;
  max-width: 1180px;
  padding: 28px 32px 64px;
}

.print-only { display: none; }

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px 24px;
  margin-bottom: 22px;
}

.eyebrow {
  color: var(--stamp);
  font-size: 13px;
  font-weight: 600;
}

h1,
.dialog-head h2,
.empty h2,
.stat-value {
  font-family: var(--display);
  font-weight: 560;
  letter-spacing: -0.03em;
}

h1 { font-size: clamp(32px, 4vw, 46px); }

.lede {
  max-width: 48ch;
  margin-top: 8px;
  color: var(--muted);
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  appearance: none;
  padding: 10px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: white;
  color: var(--ink);
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.btn:hover { background: #f3eee6; }

.btn-primary {
  border-color: var(--stamp);
  background: var(--stamp);
  color: white;
}

.btn-primary:hover { background: var(--stamp-dark); }

.btn-block { width: 100%; }

.btn-small {
  padding: 6px 10px;
  font-size: 13px;
}

.btn-pine {
  border-color: transparent;
  background: var(--pine-soft);
  color: var(--pine);
}

.btn-pine:hover { background: #d5ebdd; }

.btn-danger {
  border-color: transparent;
  background: transparent;
  color: var(--danger);
}

.btn-danger:hover { background: var(--danger-soft); }

.btn-danger-fill {
  border-color: var(--danger);
  background: var(--danger);
  color: white;
}

.btn-danger-fill:hover { background: #74261c; }

.btn.is-on {
  border-color: var(--ink);
  background: var(--ink);
  color: white;
}

.icon-btn {
  display: grid;
  flex: none;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: white;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: white;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.chip span {
  color: var(--muted);
  font-size: 12px;
}

.chip:hover { background: #f3eee6; }

.chip.is-on {
  border-color: var(--sidebar);
  background: var(--sidebar);
  color: white;
}

.chip.is-on span { color: #b7c4bb; }

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  background: #ece7df;
  color: #3d3731;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.search { flex: 1; }

.search input,
.field input,
.field textarea,
.field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d5cdc0;
  border-radius: 10px;
  background: white;
}

.field input[readonly],
.field select:disabled {
  background: #f3eee6;
  color: var(--muted);
}

.search input { width: min(440px, 100%); }

.field textarea {
  min-height: 96px;
  resize: vertical;
}

[aria-invalid="true"] {
  border-color: var(--danger);
  background: #fff8f6;
}

.result-line,
.muted,
.field-help,
.hint,
.secondary,
.stat-foot,
.stat-label {
  color: var(--muted);
}

.result-line,
.field-help,
.hint,
.secondary,
.stat-foot,
.stat-label { font-size: 13px; }

.field-help,
.hint { margin-top: 6px; }

.hint.warn { color: var(--warn); }

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 14px;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f3eee6;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

tbody td { border-top: 1px solid var(--line); }

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.primary { font-weight: 600; }

.secondary { margin-top: 2px; }

.clamp {
  display: -webkit-box;
  max-width: 280px;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.stock {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  white-space: nowrap;
}

.table-empty { color: var(--muted); text-align: center; }

.pill {
  display: inline-flex;
  flex: none;
  align-items: center;
  width: max-content;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}

.pill.ok { background: var(--pine-soft); color: var(--pine); }
.pill.low { background: #f8efd8; color: var(--warn); }
.pill.out { background: var(--danger-soft); color: var(--danger); }
.pill.note { background: #ece7df; color: #4e473f; }

.detail td { background: #f7f3eb; }

.detail-head,
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.detail-box h2,
.panel h2 {
  font-family: var(--display);
  font-size: 20px;
  font-weight: 560;
}

.mini-list,
.plain-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.mini-list { display: flex; flex-direction: column; gap: 8px; }

.mini-list li,
.plain-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
}

.plain-list li {
  justify-content: space-between;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.stack { display: flex; flex-direction: column; }

.empty {
  padding: 48px 20px;
  border: 1px dashed #d2c8b8;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.45);
  text-align: center;
}

.empty-kicker {
  margin-bottom: 6px;
  color: var(--stamp);
  font-size: 13px;
  font-weight: 600;
}

.empty h2 { margin-bottom: 8px; font-size: 32px; }

.empty p {
  max-width: 42ch;
  margin: 0 auto 16px;
  color: var(--muted);
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.stat {
  padding: 16px 16px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.stat:nth-child(1) { border-top: 3px solid #23483a; }
.stat:nth-child(2) { border-top: 3px solid #1c1915; }
.stat:nth-child(3) { border-top: 3px solid var(--stamp); }
.stat:nth-child(4) { border-top: 3px solid #a56b2b; }

.stat-value {
  margin: 8px 0 4px;
  font-size: 40px;
  line-height: 1.05;
}

.panels {
  display: grid;
  grid-template-columns: 0.9fr 1.2fr;
  gap: 12px;
  margin-top: 12px;
}

.panel {
  padding: 16px 18px 8px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel.wide { margin-top: 12px; }

.panel .muted { margin-bottom: 12px; }

.panel.form-grid { padding-bottom: 18px; }

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: 12px;
}

a.btn { display: inline-block; }

.narrow { max-width: 520px; }

.inline {
  color: var(--stamp);
  font-size: 14px;
  font-weight: 600;
}

.dialog {
  width: min(580px, calc(100vw - 28px));
  max-height: min(88vh, 820px);
  padding: 0;
  overflow: auto;
  border: none;
  border-radius: 18px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 70px rgba(28, 25, 21, 0.28);
}

.dialog::backdrop { background: rgba(23, 22, 18, 0.48); }

.dialog-body { padding: 20px; }

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.dialog-head h2 { font-size: 30px; }

.dialog-text { line-height: 1.5; }

.form-error {
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger);
}

.form-grid .form-error { margin-bottom: 0; }

.form-error:empty { display: none; }

.form-grid { display: grid; gap: 14px; }

.field { display: flex; flex-direction: column; }

.field label { margin-bottom: 6px; font-size: 13px; font-weight: 600; }

.form-split { display: grid; gap: 14px; }

.check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
}

.check input {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: #17211c;
}

.check strong { display: block; }

.check small {
  display: block;
  color: var(--muted);
  font-weight: 400;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.dialog-text + .dialog-actions { margin-top: 18px; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  z-index: 50;
  max-width: min(92vw, 440px);
  padding: 12px 16px;
  border-radius: 999px;
  background: #17211c;
  color: white;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(12px);
  transition: 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error { background: var(--danger); }

.file-form { margin: 0; }

.file-form .btn { cursor: pointer; }

.file-form .btn:focus-within {
  outline: 2px solid var(--stamp);
  outline-offset: 2px;
}

.login-card.wide { width: min(560px, 100%); }

.login-card hr {
  width: 100%;
  margin: 4px 0;
  border: none;
  border-top: 1px solid var(--line);
}

.login-card .lede { margin: 0 0 16px; }

textarea.code {
  width: 100%;
  margin: 12px 0;
  padding: 10px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  font-family: Consolas, monospace;
  font-size: 13px;
}

.side-user-actions a[aria-current] { text-decoration: underline; }

.login {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px 16px;
}

.login-card {
  width: min(420px, 100%);
  padding: 28px 26px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-brand {
  margin: -28px -26px 22px;
  padding: 18px 26px;
  border-radius: 20px 20px 0 0;
  background: var(--sidebar);
  color: #e7eee9;
}

.login-card h1 {
  margin-bottom: 16px;
  font-size: 32px;
}

.notice {
  padding: 12px 14px;
  border-radius: 12px;
  background: #f8efd8;
  color: #5c3d0a;
  line-height: 1.5;
}

@media (min-width: 560px) {
  .form-split { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 980px) {
  .stats,
  .panels { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }

  .table-wrap {
    overflow: visible;
    border: none;
    background: transparent;
    box-shadow: none;
  }

  table,
  tbody,
  tr { display: block; width: 100%; }

  table { min-width: 0; }

  thead { display: none; }

  tbody tr {
    margin-bottom: 12px;
    padding: 6px 0;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--surface);
    box-shadow: var(--shadow);
  }

  tbody td {
    display: grid;
    grid-template-columns: 104px minmax(0, 1fr);
    column-gap: 12px;
    align-items: start;
    padding: 8px 14px;
    border-top: none;
  }

  tbody td > * { grid-column: 2; }

  tbody td > .pill,
  tbody td > .tag { justify-self: start; }

  tbody td[data-label]::before {
    content: attr(data-label);
    grid-column: 1;
    grid-row: 1 / span 3;
    padding-top: 1px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
  }

  td.num { text-align: left; }

  .stock {
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }

  .clamp { max-width: none; }

  td.actions,
  td.table-empty { display: block; }

  .row-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
    white-space: normal;
  }

  tr.detail {
    padding: 0;
    border: none;
    background: transparent;
    box-shadow: none;
  }

  tr.detail td { display: block; }

  .sidebar {
    position: sticky;
    z-index: 20;
    height: auto;
    padding: 12px;
  }

  .nav { flex-direction: row; flex-wrap: wrap; margin-top: 14px; }

  .nav a { flex: 1; justify-content: center; gap: 8px; }

  .side-foot { margin-top: 12px; }

  .side-stat { display: none; }

  .side-user { padding-top: 10px; }

  .content { padding: 18px 14px 48px; }

  .topbar { align-items: stretch; flex-direction: column; }
}

@media (max-width: 640px) {
  .stats,
  .panels { grid-template-columns: 1fr; }

  .empty h2 { font-size: 26px; }

  .stat-value { font-size: 34px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  .sidebar,
  .top-actions,
  .toolbar,
  .row-actions,
  .skip,
  .toast,
  .dialog { display: none !important; }

  .print-only { display: block; margin-bottom: 8px; font-weight: 600; }

  .app { display: block; }

  body { background: white; }

  .content { max-width: none; padding: 0; }

  .table-wrap { border: none; box-shadow: none; }

  table { min-width: 0; }

  a { color: inherit; text-decoration: none; }
}
