:root {
  --paper: #f6f2e9;
  --surface: #fffdf8;
  --ink: #1d2521;
  --muted: #5f6a63;
  --line: #e2dbcc;
  --line-strong: #cfc6b3;
  --brand: #1f5c4a;
  --brand-strong: #174538;
  --brand-soft: #e8efe9;
  --accent: #b4643a;
  --danger: #8c2f2f;
  --danger-soft: #fbecec;
  --ok: #2f6b4f;
  --ok-soft: #e9f3ec;
  --warn: #8a5a12;
  --warn-soft: #fbf1dd;
  --info: #2b5c7a;
  --info-soft: #e9f1f6;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(29, 37, 33, 0.05), 0 10px 26px rgba(29, 37, 33, 0.05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.15; margin: 0 0 0.35em; }
h1 { font-size: clamp(1.6rem, 1.2rem + 1.2vw, 2.15rem); letter-spacing: -0.01em; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.6em; }
a { color: var(--brand-strong); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--brand); }
strong { font-weight: 650; }
:focus-visible { outline: 3px solid rgba(31, 92, 74, 0.45); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }

.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 100;
  background: var(--brand); color: #fff; padding: 10px 16px; border-radius: 0 0 10px 10px;
  text-decoration: none; transition: top 0.15s ease;
}
.skip-link:focus { top: 0; color: #fff; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-height: 64px; padding: 8px 24px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  display: grid; place-items: center; width: 38px; height: 38px; flex: 0 0 auto;
  border-radius: 50%; background: var(--brand); color: #fff;
  font-family: var(--serif); font-size: 1.25rem; font-weight: 700;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-name { font-family: var(--serif); font-size: 1.06rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 0.72rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.topbar-user { display: flex; align-items: center; gap: 12px; min-width: 0; }
.user-badge { display: inline-flex; align-items: center; gap: 8px; font-size: 0.86rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { padding: 2px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-strong); font-size: 0.72rem; font-weight: 600; }

.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: calc(100vh - 64px); }
.sidebar {
  position: sticky; top: 64px; align-self: start;
  height: calc(100vh - 64px); overflow-y: auto;
  padding: 18px 14px 24px; border-right: 1px solid var(--line); background: var(--surface);
  display: flex; flex-direction: column; justify-content: space-between; gap: 20px;
}
.nav-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.nav-list a {
  display: block; padding: 9px 12px; border-radius: 9px;
  color: var(--muted); font-size: 0.92rem; font-weight: 500; text-decoration: none;
}
.nav-list a:hover { background: #f4f0e6; color: var(--ink); }
.nav-list a.is-active { background: var(--brand-soft); color: var(--brand-strong); font-weight: 650; }
.logout-form { padding-top: 12px; border-top: 1px solid var(--line); }

.content { padding: 28px clamp(18px, 3vw, 40px) 60px; max-width: 1220px; width: 100%; }

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.page-head h1 { margin-bottom: 0.2em; }
.eyebrow { margin: 0 0 4px; font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); font-weight: 650; }
.section-title { margin-bottom: 14px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.card-head .section-title { margin-bottom: 14px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px 22px; margin-bottom: 18px;
}
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
.grid-2 > .card { margin-bottom: 0; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { margin-bottom: 0; padding: 16px 18px; }
.stat-label { margin: 0 0 2px; font-size: 0.72rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); font-weight: 650; }
.stat-value { margin: 0; font-family: var(--serif); font-size: 2.1rem; line-height: 1.1; }
.stat-money { margin: 2px 0 0; font-variant-numeric: tabular-nums; font-weight: 600; font-size: 0.92rem; }

.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.row-actions { display: flex; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-tight { display: flex; flex-direction: column; gap: 8px; }
.muted { color: var(--muted); }
.small { font-size: 0.84rem; }
.mono { font-family: var(--mono); font-size: 0.88em; letter-spacing: 0.02em; }
.wrap { word-break: break-word; overflow-wrap: anywhere; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { color: var(--muted); padding: 18px 4px; margin: 0; }
.hint { color: var(--muted); font-size: 0.8rem; margin: 6px 0 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: 999px; border: 1px solid transparent;
  font-family: inherit; font-size: 0.9rem; font-weight: 600; line-height: 1.3;
  text-decoration: none; cursor: pointer; transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-strong); color: #fff; }
.btn-secondary { background: transparent; border-color: var(--line-strong); color: var(--ink); }
.btn-secondary:hover { background: #f2ede1; color: var(--ink); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #732323; color: #fff; }
.btn-ghost { background: transparent; color: var(--muted); border-color: transparent; }
.btn-ghost:hover { background: #f2ede1; color: var(--ink); }
.btn-sm { padding: 6px 12px; font-size: 0.82rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.alerts { margin-bottom: 16px; }
.alert { padding: 11px 14px; border-radius: var(--radius-sm); border: 1px solid; font-size: 0.9rem; margin-bottom: 10px; }
.alert-success { background: var(--ok-soft); border-color: #c6ddcd; color: #22543d; }
.alert-error { background: var(--danger-soft); border-color: #edc9c9; color: var(--danger); }
.alert-info { background: var(--info-soft); border-color: #c7dbe7; color: var(--info); }
.alert-warning { background: var(--warn-soft); border-color: #e8d3a8; color: var(--warn); }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 16px; }
.field > label { font-size: 0.85rem; font-weight: 650; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: 10px;
  background: #fffefb; color: var(--ink); font-family: inherit; font-size: 0.95rem;
}
input[type="color"] { padding: 4px; height: 44px; }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--brand); }
textarea { resize: vertical; min-height: 76px; }
input:hover, select:hover, textarea:hover { border-color: #b9ae99; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(31, 92, 74, 0.14); outline: none; }
input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--danger); }
.field-error { margin: 0; color: var(--danger); font-size: 0.82rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px; }
.checkbox-row { display: flex; flex-direction: column; gap: 10px; margin: 4px 0 18px; }
.checkbox { display: flex; align-items: flex-start; gap: 10px; font-size: 0.9rem; }
.checkbox input { margin-top: 2px; flex: 0 0 auto; }
.input-code { font-family: var(--mono); letter-spacing: 0.12em; font-size: 1.05rem; text-transform: uppercase; }

.filter-form { padding: 16px 20px 18px; }
.filter-form .field { margin-bottom: 12px; }

.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table-wrap table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th {
  text-align: left; font-size: 0.72rem; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--muted); font-weight: 650; padding: 8px 10px; border-bottom: 1px solid var(--line-strong);
  white-space: nowrap;
}
td { padding: 11px 10px; border-bottom: 1px solid #efe8da; vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbf8f1; }
td pre { margin: 0; white-space: pre-wrap; font-family: var(--mono); font-size: 0.78rem; }

.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px;
  border-radius: 999px; font-size: 0.74rem; font-weight: 650; white-space: nowrap;
  background: #eee8da; color: var(--muted);
}
.badge-lg { font-size: 0.9rem; padding: 5px 14px; }
.badge-active { background: var(--ok-soft); color: var(--ok); }
.badge-redeemed { background: var(--info-soft); color: var(--info); }
.badge-expired, .badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-blocked { background: var(--danger-soft); color: var(--danger); }
.badge-void, .badge-unknown, .badge-neutral { background: #eee9dd; color: #5c5a52; }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px 22px; margin: 0; }
.facts > div { min-width: 0; }
.facts dt { font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); font-weight: 650; margin-bottom: 2px; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.facts-tight { gap: 10px 18px; }

.code-card { display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap; }
.code-block {
  margin: 0 0 4px; padding: 14px 18px; border-radius: 12px; background: #f3f0e7;
  border: 1px dashed var(--line-strong);
  font-family: var(--mono); font-size: clamp(1.15rem, 1rem + 0.8vw, 1.5rem);
  letter-spacing: 0.14em; font-weight: 700; overflow-wrap: anywhere;
}

details.card { padding: 0; }
details.card > summary {
  padding: 16px 22px; cursor: pointer; font-weight: 650; list-style-position: inside;
  border-radius: var(--radius);
}
details.card > summary:hover { background: #f9f5ec; }
.details-body { padding: 4px 22px 20px; }
details.card[open] > summary { border-bottom: 1px solid var(--line); margin-bottom: 16px; }

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.list li { display: flex; flex-direction: column; gap: 2px; padding-bottom: 10px; border-bottom: 1px solid #efe8da; }
.list li:last-child { border-bottom: 0; padding-bottom: 0; }
.list-main { font-size: 0.92rem; }

.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.timeline li { display: flex; gap: 12px; align-items: flex-start; }
.timeline-dot { width: 8px; height: 8px; margin-top: 7px; border-radius: 50%; background: var(--brand); flex: 0 0 auto; }
.timeline-title { margin: 0; font-size: 0.9rem; font-weight: 550; }
.timeline p { margin: 0; }

.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; }

.pdf-frame { width: 100%; height: min(78vh, 900px); border: 1px solid var(--line-strong); border-radius: 12px; background: #fff; margin-bottom: 14px; }
.print-actions { margin-top: 4px; }

.footer {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px;
  padding: 18px clamp(18px, 3vw, 40px); border-top: 1px solid var(--line);
  color: var(--muted); font-size: 0.78rem;
}

.logo-row { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; }
.logo-preview { max-width: 220px; max-height: 120px; border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 8px; }

.public-body { min-height: 100vh; display: flex; flex-direction: column; }
.public-main { flex: 1; display: grid; place-items: center; padding: 32px 18px; }
.public-footer {
  display: flex; justify-content: space-between; gap: 12px; padding: 16px 24px;
  color: var(--muted); font-size: 0.8rem; border-top: 1px solid var(--line);
}
.auth-card {
  width: min(440px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: 20px; padding: clamp(22px, 4vw, 34px); box-shadow: var(--shadow);
}
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.auth-brand h1 { margin: 0; font-size: 1.4rem; }
.auth-body { background: radial-gradient(circle at 15% 0%, #efe9db 0%, var(--paper) 55%); }
.error-code { font-family: var(--serif); font-size: 3rem; color: var(--line-strong); margin: 0 0 4px; }

.check-card { width: min(500px, 100%); }
.check-status {
  display: flex; align-items: center; gap: 14px; padding: 16px 18px;
  border-radius: 14px; border: 1px solid var(--line); margin: 16px 0;
}
.check-icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; font-size: 1.25rem; font-weight: 700; flex: 0 0 auto; }
.check-label { margin: 0; font-family: var(--serif); font-size: 1.3rem; }
.check-status p { margin: 0; }
.check-ok { background: var(--ok-soft); border-color: #c6ddcd; }
.check-ok .check-icon { background: var(--ok); color: #fff; }
.check-invalid { background: var(--danger-soft); border-color: #edc9c9; }
.check-invalid .check-icon { background: var(--danger); color: #fff; }
.check-unknown { background: #f1ece1; }
.check-unknown .check-icon { background: var(--muted); color: #fff; }

@media (max-width: 1024px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky; top: 64px; height: auto; z-index: 20;
    flex-direction: row; align-items: center; justify-content: flex-start;
    border-right: 0; border-bottom: 1px solid var(--line); padding: 8px 14px; overflow-x: auto;
  }
  .nav-list { flex-direction: row; gap: 4px; }
  .nav-list a { white-space: nowrap; }
  .logout-form { border-top: 0; padding-top: 0; margin-left: auto; }
  .content { padding-top: 20px; }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .topbar { padding: 8px 16px; }
  .topbar-user { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .page-head { align-items: flex-start; }
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  h1 { font-size: 1.55rem; }
  .sidebar { top: 64px; }
  .brand-name { max-width: 45vw; }
}

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

@media print {
  .topbar, .sidebar, .footer, .page-head .row, .print-actions, .alert, form.filter-form { display: none !important; }
  body { background: #fff; }
  .shell { grid-template-columns: 1fr; }
  .content { padding: 0; max-width: none; }
  .pdf-frame { height: 100vh; border: 0; }
}
