/* Dark, yellow-and-black. Dark is the only theme. */
:root {
  --bg: #0a0a0a;
  --surface: #131313;
  --surface-raised: #1a1a1a;
  --surface-sunken: #0f0f0f;
  --fg: #f5f3e7;
  --fg-muted: #9a978a;
  --line: #262624;
  --accent: #ffd60a;
  --accent-hot: #ffe566;
  --accent-fg: #0a0a0a;
  --accent-soft: rgba(255, 214, 10, 0.12);
  --danger: #ff6b5b;
  --danger-soft: rgba(255, 107, 91, 0.12);
  --radius: 12px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Hazard stripe across the top. Slowly drifts; still under reduced motion. */
.hazard {
  height: 8px;
  background: repeating-linear-gradient(-45deg, var(--accent) 0 14px, var(--bg) 14px 28px);
  background-size: 40px 40px;
  animation: drift 2.4s linear infinite;
}
@keyframes drift {
  to { background-position: 40px 0; }
}

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 36px 24px 72px;
  display: grid;
  gap: 40px;
}

.page-header { display: grid; gap: 6px; }
.page-header-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* Login page: one narrow centered panel. */
.auth-body { display: grid; grid-template-rows: auto 1fr; min-height: 100dvh; }
.auth {
  width: 100%;
  max-width: 380px;
  margin: 0 auto;
  padding: 48px 24px;
  display: grid;
  gap: 16px;
  align-content: center;
}
.auth-form { grid-template-columns: 1fr; }

h1 {
  font-size: 30px;
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.02em;
  text-transform: uppercase;
}
.accent { color: var(--accent); }
h2 {
  font-size: 13px;
  font-weight: 700;
  margin: 0 0 14px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg-muted);
}
p { margin: 0; }
.muted { color: var(--fg-muted); }
.small { font-size: 13px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

.alert {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  padding: 10px 14px;
}
.alert[hidden] { display: none; }

/* Summary: one surface, four cells. Numbers count up on change. */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.stat {
  display: grid;
  gap: 6px;
  padding: 20px 22px;
  transition: background-color 200ms ease;
}
.stat:hover { background: var(--surface-raised); }
.stat + .stat { border-left: 1px solid var(--line); }
.stat-label {
  color: var(--fg-muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.stat-value {
  font-size: 26px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.stat:first-child .stat-value { color: var(--accent); }

.block { display: grid; gap: 12px; }
.two-col {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 36px;
  align-items: start;
}
.two-col > div { display: grid; gap: 12px; }

/* Tables and lists */
.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 12px 16px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background-color 180ms ease; }
tbody tr:hover { background: var(--accent-soft); }
th {
  color: var(--fg-muted);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  background: var(--surface-sunken);
}
th.num { text-align: right; }
td .sub { color: var(--fg-muted); font-size: 13px; margin-top: 2px; }

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  transition: background-color 180ms ease;
}
.list li:hover { background: var(--surface-raised); }
.list li:last-child { border-bottom: 0; }
.list .meta { color: var(--fg-muted); font-size: 13px; }
.list .actions-inline { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.list .empty { color: var(--fg-muted); display: block; }

/* Chart */
.chart {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.chart svg { width: 100%; height: auto; display: block; }
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  color: var(--fg-muted);
  font-size: 13px;
}
.legend i {
  display: inline-block;
  width: 14px;
  height: 3px;
  margin-right: 8px;
  vertical-align: middle;
  border-radius: 2px;
}
.legend i.dash {
  background: repeating-linear-gradient(90deg, var(--fg) 0 5px, transparent 5px 9px);
}

/* Forms */
.form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.field { display: grid; gap: 6px; font-size: 12px; color: var(--fg-muted); font-weight: 600; letter-spacing: 0.04em; }
.field > span { text-transform: uppercase; }
.field[hidden] { display: none; }
.full { grid-column: 1 / -1; }
.actions { display: flex; gap: 8px; }

input, select {
  font: inherit;
  font-size: 15px;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--fg);
  background: var(--surface-sunken);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  min-height: 42px;
  width: 100%;
  min-width: 0;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}
input:hover, select:hover { border-color: #3a3a37; }
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
select option { background: var(--surface-raised); color: var(--fg); }

fieldset.cuts {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
fieldset.cuts legend {
  color: var(--fg-muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0 6px;
}
fieldset.cuts .field { color: var(--fg-muted); }

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
  max-width: 500px;
}
.inline-form .form-error { flex-basis: 100%; }

/* Inline feedback */
.hint {
  color: var(--fg-muted);
  background: var(--accent-soft);
  border: 1px solid rgba(255, 214, 10, 0.35);
  border-radius: var(--radius);
  padding: 12px 16px;
}
.hint[hidden] { display: none; }

.form-error {
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  background: var(--danger-soft);
  border-radius: 8px;
  padding: 8px 12px;
  margin: 0;
}
.form-error[hidden] { display: none; }

/* Edit mode: accent border and a left bar, so it is obvious the form is editing a record. */
.form.editing {
  border-color: var(--accent);
  box-shadow: inset 4px 0 0 var(--accent);
}

/* Confirmation toast, bottom right, announced via aria-live on the element. */
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 700;
  font-size: 14px;
  padding: 11px 16px;
  border-radius: 10px;
  box-shadow: 0 12px 32px -8px rgba(0, 0, 0, 0.6);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 220ms ease, transform 300ms var(--ease-spring);
  z-index: 10;
}
.toast.show { opacity: 1; transform: none; }

/* Chart tooltip */
.chart-plot { position: relative; }
.chart-tip {
  position: absolute;
  top: 8px;
  transform: translateX(12px);
  min-width: 170px;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  display: grid;
  gap: 4px;
  pointer-events: none;
  box-shadow: 0 10px 24px -8px rgba(0, 0, 0, 0.6);
  z-index: 1;
}
.chart-tip.flip { transform: translateX(calc(-100% - 12px)); }
.chart-tip[hidden] { display: none; }
.chart-tip strong { font-variant-numeric: tabular-nums; }
.chart-tip span { display: flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }
.chart-tip i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.chart-tip .tip-total { border-top: 1px solid var(--line); padding-top: 4px; margin-top: 2px; font-weight: 700; }
.grow { flex: 1; }

/* Buttons. Primary is solid yellow with black text (high contrast). */
.btn {
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  min-height: 38px;
  padding: 7px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-raised);
  color: var(--fg);
  cursor: pointer;
  white-space: nowrap;
  transition: transform 160ms var(--ease-spring), background-color 160ms ease,
              border-color 160ms ease, box-shadow 200ms ease, color 160ms ease;
}
.btn:hover { border-color: #3d3d3a; background: #202020; }
.btn:active { transform: translateY(1px) scale(0.97); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}
.btn.primary:hover {
  background: var(--accent-hot);
  border-color: var(--accent-hot);
  box-shadow: 0 6px 24px -6px rgba(255, 214, 10, 0.55);
  transform: translateY(-1px);
}
.btn.danger { color: var(--danger); background: transparent; border-color: transparent; }
.btn.danger:hover { background: var(--danger-soft); border-color: transparent; box-shadow: none; }
.btn.small { min-height: 30px; padding: 4px 11px; font-size: 13px; }
.btn[hidden] { display: none; }

/* Layout rules for smaller screens */
@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat:nth-child(3) { border-left: 0; }
  .stat:nth-child(n + 3) { border-top: 1px solid var(--line); }
  .two-col { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  /* On phones the tooltip becomes a fixed readout across the top of the chart. */
  .chart-tip {
    left: 8px !important;
    right: 8px;
    top: 4px;
    min-width: 0;
    transform: none !important;
  }
  .page { padding: 24px 16px 56px; gap: 28px; }
  h1 { font-size: 24px; }
  .form { grid-template-columns: 1fr; }
  .inline-form { flex-direction: column; align-items: stretch; max-width: none; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat { padding: 16px; }
  .stat-value { font-size: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
