:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5b6575;
  --border: #d9dee6;
  --primary: #1f5eff;
  --primary-dark: #1647c4;
  --success: #1c7c46;
  --warning: #9a5b00;
  --danger: #b42318;
  --info: #1d5fa8;
  --focus: #ffb703;
  --radius: 8px;
  --space: 1rem;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; line-height: 1.5; background: var(--bg); }
a { color: var(--primary-dark); }
a:hover { text-decoration: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
code.small { font-size: .75rem; word-break: break-all; }

.skip-link { position: absolute; left: -999px; top: 0; background: var(--surface); padding: .5rem 1rem; z-index: 10; }
.skip-link:focus { left: 1rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.topbar { display: flex; align-items: center; gap: 1rem; padding: .6rem 1.25rem; background: #101828; color: #fff; }
.topbar a { color: #fff; }
.brand { font-weight: 700; font-size: 1.15rem; text-decoration: none; letter-spacing: .02em; }
.brand-large { font-size: 2rem; margin: 0; }
.org-name { opacity: .85; border-left: 1px solid #475467; padding-left: 1rem; }
.topbar-actions { margin-left: auto; display: flex; gap: 1rem; align-items: center; }

.shell { display: grid; grid-template-columns: 230px 1fr; min-height: calc(100vh - 48px); }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 1rem 0; }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar a { display: block; padding: .5rem 1.25rem; color: var(--text); text-decoration: none; border-left: 3px solid transparent; }
.sidebar a:hover, .sidebar a.active { background: #eef3ff; border-left-color: var(--primary); }
.content { padding: 1.5rem 2rem; max-width: 1400px; }

.public { display: flex; justify-content: center; }
.public-main { width: min(560px, 100%); padding: 3rem 1rem; }
.tagline { color: var(--muted); margin-top: 0; }

.page-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.page-header p { margin: .25rem 0 0; flex-basis: 100%; }
.actions, .action-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem; }
.panel.narrow { max-width: 560px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 1.25rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; text-decoration: none; color: var(--text); display: flex; flex-direction: column; }
.card-value { font-size: 1.8rem; font-weight: 700; }
.card-label { color: var(--muted); }
.card-alert .card-value { color: var(--danger); }

label { display: block; font-weight: 600; margin: .5rem 0 .25rem; }
label.radio, label.checkbox { font-weight: 400; display: flex; gap: .5rem; align-items: flex-start; }
input, select, textarea { font: inherit; padding: .5rem .6rem; border: 1px solid #98a2b3; border-radius: 6px; width: 100%; background: #fff; color: var(--text); }
input[type="radio"], input[type="checkbox"] { width: auto; margin-top: .3rem; }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--danger); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem; margin: .5rem 0; }
legend { font-weight: 700; padding: 0 .25rem; }
.stack > * + * { margin-top: .25rem; }
.stack button { margin-top: .75rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: .25rem 1.25rem; }
.form-grid .full { grid-column: 1 / -1; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; margin-bottom: 1rem; }
.filters label { margin: 0; font-size: .85rem; }
.filters input, .filters select { width: auto; min-width: 160px; }
.line { display: flex; gap: .5rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: .5rem; }
.line label { margin: 0; font-size: .85rem; }
.line select { min-width: 260px; width: auto; }
.line input { width: 110px; }
.line input.wide { width: 18rem; }
.line > .field-error { flex-basis: 100%; }
.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .25rem; }
form.inline { display: inline-flex; gap: .25rem; align-items: center; }
form.inline select { width: auto; }

button, .button { font: inherit; display: inline-block; padding: .5rem .9rem; border-radius: 6px; border: 1px solid #98a2b3; background: #fff; color: var(--text); cursor: pointer; text-decoration: none; }
button.primary, .button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover, .button.primary:hover { background: var(--primary-dark); }
button.danger { color: var(--danger); border-color: var(--danger); }
.link-button { background: none; border: none; padding: 0; color: inherit; text-decoration: underline; cursor: pointer; }
.choice-list { list-style: none; padding: 0; display: grid; gap: .5rem; }
.choice { width: 100%; text-align: left; display: flex; flex-direction: column; padding: .9rem 1rem; }

.table { width: 100%; border-collapse: collapse; background: var(--surface); }
.table th, .table td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table thead th { font-size: .85rem; color: var(--muted); background: #f9fafb; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }
.calendar td { text-align: center; font-variant-numeric: tabular-nums; }
.cell-free { background: #e8f6ee; }
.cell-partial { background: #fff4e0; }
.cell-full { background: #fde7e5; font-weight: 700; }
.cell-none { background: #f2f4f7; color: var(--muted); }
.matrix td { text-align: center; }

.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .8rem; font-weight: 600; border: 1px solid transparent; vertical-align: middle; }
.badge-success { background: #e8f6ee; color: var(--success); }
.badge-warning { background: #fff4e0; color: var(--warning); }
.badge-danger { background: #fde7e5; color: var(--danger); }
.badge-info { background: #e8f0fb; color: var(--info); }
.badge-muted, .badge-neutral { background: #f2f4f7; color: var(--muted); }

.flash { display: flex; justify-content: space-between; align-items: center; padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.flash-success { background: #e8f6ee; color: #0f5132; border: 1px solid #b7e2c8; }
.flash-error { background: #fde7e5; color: #7a1a12; border: 1px solid #f5c2bd; }
.flash-close { border: none; background: none; font-size: 1.2rem; cursor: pointer; }
.form-errors, .shortages { background: #fde7e5; color: #7a1a12; border: 1px solid #f5c2bd; border-radius: var(--radius); padding: .75rem 1rem; margin-bottom: 1rem; }
.field-error { color: var(--danger); margin: .2rem 0 0; font-size: .9rem; }
.email-banner { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; justify-content: space-between; padding: .6rem 1.25rem; background: #fff4d6; color: #5c3d00; border-bottom: 1px solid #f0d58c; position: sticky; top: 0; z-index: 5; }
.email-banner p { margin: 0; }
.email-banner-locked { background: #fde7e5; color: #7a1a12; border-bottom-color: #f5c2bd; }
.notice { background: #e8f0fb; border: 1px solid #c3d6f1; border-radius: var(--radius); padding: .75rem 1rem; margin-bottom: 1rem; }
.notice-danger { background: #fde7e5; border-color: #f5c2bd; }
.token { display: inline-block; padding: .4rem; background: #fff; border: 1px dashed var(--border); word-break: break-all; }

.details { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0 0 1rem; }
.details dt { color: var(--muted); }
.details dd { margin: 0; }
.pre { white-space: pre-wrap; }
.muted { color: var(--muted); }
.empty { color: var(--muted); font-style: italic; }
.row-list { list-style: none; padding: 0; margin: 0 0 1rem; }
.row-list li { padding: .4rem 0; border-bottom: 1px solid var(--border); }
.inline-stats { list-style: none; padding: 0; display: flex; gap: 1rem; flex-wrap: wrap; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: .35rem 0; border-bottom: 1px dashed var(--border); }
.timeline time { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: .5rem; }
details { margin-top: .75rem; }
summary { cursor: pointer; font-weight: 600; color: var(--primary-dark); }
.pagination { display: flex; gap: 1rem; align-items: center; margin-top: 1rem; }
.links { margin-top: 1rem; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); }
  .sidebar ul { display: flex; flex-wrap: wrap; }
  .content { padding: 1rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
