:root {
  --ink: #1b1f1d;
  --paper: #efe9dc;
  --panel: #fffdf8;
  --line: #d7d0c2;
  --sidebar: #24312c;
  --sidebar-text: #e4ece7;
  --sidebar-muted: #9aada4;
  --accent: #2f6f5e;
  --accent-hover: #245a4c;
  --action: #c45c26;
  --action-hover: #a84c1e;
  --danger: #8f2d2d;
  --muted: #5d6560;
  --focus: #1f6feb;
  --shadow: 0 1px 2px rgba(28, 32, 30, 0.06);
  --radius: 10px;
  --sidebar-width: 232px;
  font-family: "Segoe UI", "Source Sans 3", "Liberation Sans", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  line-height: 1.45;
  min-height: 100vh;
}

a { color: var(--accent); }
a:hover { color: var(--accent-hover); }

.skip {
  position: absolute;
  left: -999px;
  top: 0;
}
.skip:focus {
  left: 12px;
  top: 12px;
  background: #fff;
  padding: 8px 12px;
  z-index: 50;
}

.app {
  display: flex;
  min-height: 100vh;
}

#nav-toggle { position: absolute; left: -999px; }

.nav-toggle {
  display: none;
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 30;
  background: var(--sidebar);
  color: #fff;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 600;
  cursor: pointer;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding: 20px 14px 16px;
}

.brand {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: #fff;
  text-decoration: none;
  padding: 4px 10px 18px;
}
.brand:hover { color: #fff; }
.brand-sub {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--sidebar-muted);
  margin-top: 4px;
}

.sidebar nav {
  flex: 1;
}
.menu {
  list-style: none;
  margin: 0;
  padding: 0;
}
.menu a {
  display: block;
  color: var(--sidebar-text);
  text-decoration: none;
  padding: 9px 12px;
  border-radius: 8px;
  margin-bottom: 2px;
}
.menu a:hover,
.menu a.active {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.sidebar-foot {
  padding: 12px 10px 0;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 0.8rem;
  color: var(--sidebar-muted);
}
.sidebar-foot button,
.sidebar-foot .linkish {
  background: none;
  border: 0;
  color: var(--sidebar-text);
  padding: 8px 0;
  cursor: pointer;
  font: inherit;
  text-decoration: none;
  display: inline-block;
}
.sidebar-foot button:hover { color: #fff; }

.content {
  flex: 1;
  padding: 28px 32px 48px;
  min-width: 0;
}

h1 {
  font-size: 1.45rem;
  font-weight: 650;
  margin: 0 0 4px;
}
.lede {
  color: var(--muted);
  margin: 0 0 22px;
}

.flash,
.errors {
  background: #f8e6e4;
  border: 1px solid #e3b7b2;
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.notice {
  background: #e7f2ec;
  border: 1px solid #b7d2c6;
  color: var(--accent-hover);
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.errors ul { margin: 0; padding-left: 18px; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.card .label {
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.card .value {
  font-size: 1.25rem;
  font-weight: 650;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
.card.warn .value { color: var(--action); }
.card.ok .value { color: var(--accent); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.panel h2 {
  font-size: 1rem;
  margin: 0 0 12px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 22px;
}

.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  min-height: 44px;
}
.btn:hover { background: var(--accent-hover); color: #fff; }
.btn.secondary {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn.secondary:hover { background: #f6f3ec; color: var(--ink); }
.btn.action { background: var(--action); }
.btn.action:hover { background: var(--action-hover); color: #fff; }
.btn.danger { background: var(--danger); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px 18px;
}
label, .field-label {
  display: block;
  font-size: 0.86rem;
  font-weight: 650;
  margin-bottom: 4px;
}
.hint {
  display: block;
  font-weight: 400;
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 4px;
}
input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid #cfc8ba;
  border-radius: 8px;
  font: inherit;
  background: #fff;
  min-height: 42px;
}
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus, .btn:focus, a:focus {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-weight: 500;
  margin: 8px 0;
}
.check input { margin-top: 3px; width: auto; min-height: 0; }

.guest {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.guest-box {
  width: 100%;
  max-width: 440px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px 26px 24px;
  box-shadow: var(--shadow);
}
.guest-box h1 { margin-bottom: 6px; }
.steps {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 18px;
}
.stack { display: flex; flex-direction: column; gap: 12px; }
.muted { color: var(--muted); }
.empty {
  color: var(--muted);
  font-size: 0.95rem;
  margin: 0;
}
.version {
  margin-top: 28px;
  color: var(--muted);
  font-size: 0.8rem;
}

.table-wrap { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
.table th, .table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.table th { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-actions { white-space: nowrap; }
.row-actions a { margin-left: 8px; }

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px 12px;
  margin-bottom: 18px;
  align-items: end;
}
.filter-go { padding-bottom: 2px; }
.year-pick {
  grid-template-columns: minmax(180px, 280px) auto;
  max-width: 420px;
}
.tax-note { margin: -8px 0 22px; }

.form-grid .wide { grid-column: 1 / -1; }
.file-btn { position: relative; overflow: hidden; cursor: pointer; }
.file-btn input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  min-height: 44px;
}
.receipt-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}
.receipt-preview img,
.receipt-current {
  max-width: min(100%, 420px);
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 8px;
}
.sticky-save {
  position: sticky;
  bottom: 0;
  background: var(--paper);
  padding: 12px 0;
}
.inline-rename {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.inline-rename input[type="text"] { min-width: 160px; }

.items-table th:nth-child(2),
.items-table td.qty { width: 5.5rem; }
.items-table th:nth-child(3),
.items-table td.num { width: 8rem; }
.items-table input { min-height: 38px; }
.extra-actions { margin-top: 12px; margin-bottom: 0; }
.pay-form { margin-top: 16px; }
.linkish {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  min-height: 0;
  text-decoration: underline;
}
.row-actions form { display: inline; }
.invoice-toolbar .actions { margin-bottom: 16px; }
.invoice-toolbar .actions form { margin: 0; }
.invoice-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 18px;
}
.invoice-status {
  font-weight: 700;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.invoice-status.warn { color: var(--action); border-color: var(--action); }
.invoice-status.ok { color: var(--accent); border-color: var(--accent); }
.invoice-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}
.invoice-meta .label {
  display: inline-block;
  min-width: 6.5rem;
  color: var(--muted);
  font-size: 0.86rem;
}
.invoice-total {
  text-align: right;
  font-size: 1.15rem;
  font-weight: 700;
  margin: 10px 0 18px;
}
.pre { white-space: pre-wrap; }
td.warn { color: var(--action); font-weight: 650; }
td.ok { color: var(--accent); font-weight: 650; }

@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}

@media (max-width: 800px) {
  .nav-toggle { display: inline-block; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    transform: translateX(-105%);
    transition: transform 0.18s ease;
    z-index: 20;
    box-shadow: 4px 0 24px rgba(0,0,0,0.2);
  }
  #nav-toggle:checked ~ .sidebar { transform: translateX(0); }
  .content { padding: 64px 16px 32px; }
}

@media print {
  .skip, .nav-toggle, .sidebar, .no-print, .invoice-toolbar { display: none !important; }
  .app { display: block; }
  .content { padding: 0; max-width: none; }
  body { background: #fff; }
}
