/* ------------------------- Design tokens ------------------------- */
:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --surface-3: #f1f3f6;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --text: #101828;
  --text-2: #475467;
  --muted: #667085;
  --accent: #2a78d6;
  --accent-hover: #1c5cab;
  --accent-soft: #eaf2fc;
  --accent-text: #1c5cab;
  --success: #067647;
  --success-soft: #ecfdf3;
  --warning: #b54708;
  --warning-soft: #fffaeb;
  --danger: #c4320a;
  --danger-soft: #fef3f2;
  --info: #175cd3;
  --info-soft: #eff8ff;

  --sidebar-bg: #101828;
  --sidebar-text: #cbd2dc;
  --sidebar-muted: #8592a6;
  --sidebar-hover: rgba(255, 255, 255, 0.06);
  --sidebar-active: rgba(255, 255, 255, 0.1);

  /* chart roles (validated: dataviz palette slot 1 on this surface) */
  --series-1: #2a78d6;
  --grid: #eaecf0;
  --axis: #d0d5dd;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --sidebar-w: 248px;
}

/* Dark theme: follows the OS unless the user picked a theme (data-theme on <html>). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #0c0e12;
    --surface: #161a21;
    --surface-2: #1b2029;
    --surface-3: #222833;
    --border: #2a303c;
    --border-strong: #3a4250;
    --text: #f2f4f7;
    --text-2: #c2c8d2;
    --muted: #8b95a5;
    --accent: #3987e5;
    --accent-hover: #5598e7;
    --accent-soft: rgba(57, 135, 229, 0.14);
    --accent-text: #86b6ef;
    --success: #47cd89;
    --success-soft: rgba(71, 205, 137, 0.12);
    --warning: #fdb022;
    --warning-soft: rgba(253, 176, 34, 0.12);
    --danger: #f97066;
    --danger-soft: rgba(249, 112, 102, 0.12);
    --info: #84caff;
    --info-soft: rgba(132, 202, 255, 0.12);
    --sidebar-bg: #0a0c10;
    --series-1: #3987e5;
    --grid: #252b35;
    --axis: #3a4250;
    --shadow-sm: none;
    --shadow: none;
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0c0e12;
  --surface: #161a21;
  --surface-2: #1b2029;
  --surface-3: #222833;
  --border: #2a303c;
  --border-strong: #3a4250;
  --text: #f2f4f7;
  --text-2: #c2c8d2;
  --muted: #8b95a5;
  --accent: #3987e5;
  --accent-hover: #5598e7;
  --accent-soft: rgba(57, 135, 229, 0.14);
  --accent-text: #86b6ef;
  --success: #47cd89;
  --success-soft: rgba(71, 205, 137, 0.12);
  --warning: #fdb022;
  --warning-soft: rgba(253, 176, 34, 0.12);
  --danger: #f97066;
  --danger-soft: rgba(249, 112, 102, 0.12);
  --info: #84caff;
  --info-soft: rgba(132, 202, 255, 0.12);
  --sidebar-bg: #0a0c10;
  --series-1: #3987e5;
  --grid: #252b35;
  --axis: #3a4250;
  --shadow-sm: none;
  --shadow: none;
}

/* ------------------------- Base ------------------------- */
* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font: 14px/1.5 var(--font);
  background: var(--bg);
  color: var(--text);
}

a {
  color: var(--accent-text);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1,
h2,
h3 {
  margin: 0;
  color: var(--text);
  line-height: 1.25;
}

h1 {
  font-size: 1.45rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 1rem;
  font-weight: 600;
}

h3 {
  font-size: 0.9rem;
  font-weight: 600;
  margin: 1.1rem 0 0.6rem;
}

p {
  margin: 0 0 0.75rem;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.82rem;
}

.nowrap {
  white-space: nowrap;
}

.pre-line {
  white-space: pre-line;
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ------------------------- App shell ------------------------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 1rem 0.75rem;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.25rem 0.5rem 1.1rem;
  color: #fff;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, #3987e5, #1c5cab);
  color: #fff;
}

.brand-mark .mark {
  width: 22px;
  height: 22px;
  fill: #fff;
}

.signin-brand .brand-mark .mark {
  width: 26px;
  height: 26px;
}

.brand small {
  display: block;
  color: var(--sidebar-muted);
  font-weight: 500;
  font-size: 0.72rem;
}

.nav-group {
  margin-bottom: 0.9rem;
}

.nav-label {
  padding: 0 0.6rem 0.35rem;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sidebar-muted);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-weight: 500;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: #fff;
  text-decoration: none;
}

.nav-item.active {
  background: var(--sidebar-active);
  color: #fff;
  box-shadow: inset 2px 0 0 #3987e5;
}

.nav-item .icon {
  width: 17px;
  height: 17px;
  opacity: 0.85;
}

.nav-badge {
  margin-left: auto;
  min-width: 1.4rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 600;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.nav-badge.alert {
  background: #d92d20;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.user-card {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.5rem 0.6rem;
}

.avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #344054;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 650;
  flex: none;
}

.user-card .who {
  min-width: 0;
}

.user-card strong {
  display: block;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
}

.user-card .who span {
  display: block;
  color: var(--sidebar-muted);
  font-size: 0.75rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar .signout {
  width: 100%;
  box-shadow: none;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  justify-content: flex-start;
  background: transparent;
  color: var(--sidebar-text);
  border: 0;
  padding: 0.45rem 0.6rem;
  font-weight: 500;
}

.sidebar .signout:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.main {
  min-width: 0;
}

.mobile-bar {
  display: none;
}

.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 1.75rem 2rem 3rem;
}

/* ------------------------- Page headers ------------------------- */
.page-header,
.section-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.page-header .actions,
.section-header .actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.eyebrow {
  margin: 0 0 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.subtitle {
  margin: 0.3rem 0 0;
  color: var(--text-2);
}

.back {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-bottom: 0.75rem;
  color: var(--muted);
  font-weight: 500;
}

.back:hover {
  color: var(--text);
  text-decoration: none;
}

.lead {
  color: var(--text-2);
  max-width: 75ch;
  margin: -0.6rem 0 1.25rem;
}

/* ------------------------- Cards ------------------------- */
.card,
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.1rem 1.25rem;
  margin-bottom: 1rem;
}

.card > h2,
.panel > h2,
.card-header h2 {
  margin-bottom: 0.9rem;
}

.card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.9rem;
}

.card-header h2 {
  margin: 0;
}

.card-header a {
  font-size: 0.85rem;
  font-weight: 500;
}

.card.flush {
  padding: 0;
  overflow: hidden;
}

.card.flush > .card-header {
  padding: 1rem 1.25rem 0;
}

.panel.danger {
  border-color: var(--danger);
}

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.grid-halves {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  align-items: start;
}

/* ------------------------- KPI tiles ------------------------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.stat-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1rem 1.15rem;
  color: inherit;
}

a.stat-card:hover {
  text-decoration: none;
  border-color: var(--border-strong);
}

.stat-label {
  color: var(--text-2);
  font-size: 0.85rem;
  font-weight: 500;
}

.stat-value {
  display: block;
  margin: 0.35rem 0 0.2rem;
  font-size: 1.75rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--text);
}

.stat-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.delta {
  font-weight: 600;
}

.delta.up {
  color: var(--success);
}

.delta.down {
  color: var(--danger);
}

/* ------------------------- Charts ------------------------- */
.chart {
  width: 100%;
  height: auto;
  display: block;
}

.chart .gridline {
  stroke: var(--grid);
  stroke-width: 1;
}

.chart .baseline {
  stroke: var(--axis);
  stroke-width: 1;
}

.chart .tick {
  fill: var(--muted);
  font-size: 11px;
  font-family: var(--font);
  font-variant-numeric: tabular-nums;
}

.chart .bar {
  fill: var(--series-1);
  transition: opacity 0.12s;
}

.chart .col:hover .bar {
  fill: var(--accent-hover);
}

.chart:hover .col:not(:hover) .bar {
  opacity: 0.55;
}

.chart .hit {
  fill: transparent;
}

.chart .label {
  fill: var(--text-2);
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font);
}

.chart-note {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 0.4rem;
}

details.table-view {
  margin-top: 0.6rem;
}

details.table-view summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.8rem;
}

details.table-view .table-wrap {
  margin-top: 0.5rem;
  max-height: 260px;
  overflow: auto;
}

.meter {
  display: block;
  width: 100%;
  min-width: 60px;
  height: 6px;
}

.meter .track {
  fill: var(--accent-soft);
}

.meter .fill {
  fill: var(--series-1);
}

th.meter-col {
  width: 28%;
}

/* ------------------------- Tables ------------------------- */
.table-wrap {
  /* Positioned, so absolutely positioned content (e.g. .sr-only labels) scrolls inside the box
     instead of widening the whole page. */
  position: relative;
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

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

.card.flush .table-wrap {
  border: 0;
  border-radius: 0;
  border-top: 1px solid var(--border);
  margin-top: 0.9rem;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 0.65rem 0.9rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover td {
  background: var(--surface-2);
}

tfoot th,
tfoot td {
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.85rem;
  text-transform: none;
  letter-spacing: 0;
  border-top: 1px solid var(--border);
  border-bottom: 0;
}

td.empty {
  text-align: center;
  color: var(--muted);
  padding: 2rem 1rem;
}

tr.clickable td:first-child a {
  font-weight: 600;
  color: var(--text);
}

td .sub,
.sub {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

/* ------------------------- Status pills ------------------------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  background: var(--surface-3);
  color: var(--text-2);
}

.pill::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.pill.success {
  background: var(--success-soft);
  color: var(--success);
}

.pill.warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.pill.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.pill.info {
  background: var(--info-soft);
  color: var(--info);
}

.pill.plain::before {
  display: none;
}

/* ------------------------- Tabs & filters ------------------------- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.tabs {
  display: inline-flex;
  gap: 0.25rem;
  padding: 0.25rem;
  background: var(--surface-3);
  border-radius: var(--radius-sm);
  flex-wrap: wrap;
}

.tabs a {
  padding: 0.3rem 0.75rem;
  border-radius: 6px;
  color: var(--text-2);
  font-weight: 500;
  font-size: 0.85rem;
}

.tabs a:hover {
  color: var(--text);
  text-decoration: none;
}

.tabs a.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.tabs a .count {
  margin-left: 0.3rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.search {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.search input,
.search select {
  width: auto;
  min-width: 200px;
}

/* Pagination: summary on the left, a page bar styled like .tabs on the right. */
.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  padding: 0.9rem 0.25rem 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.pager-summary {
  margin: 0;
}

.pager-summary strong {
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

.pager-pages,
.pager-numbers {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.pager-pages {
  padding: 0.25rem;
  background: var(--surface-3);
  border-radius: var(--radius-sm);
}

.pager-step,
.pager-page {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  height: 2rem;
  padding: 0 0.6rem;
  border-radius: 6px;
  color: var(--text-2);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  white-space: nowrap;
}

a.pager-step:hover,
a.pager-page:hover {
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}

.pager-page[aria-current='page'] {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow);
}

.pager-step[aria-disabled='true'] {
  color: var(--muted);
  opacity: 0.5;
  cursor: default;
}

.pager-gap {
  min-width: 1.25rem;
  color: var(--muted);
  text-align: center;
}

/* Phones: "Page 3 of 12" replaces the page numbers. */
.pager-compact {
  display: none;
  padding: 0 0.5rem;
  color: var(--text-2);
  white-space: nowrap;
}

@media (max-width: 600px) {
  .pager {
    justify-content: center;
    text-align: center;
  }

  .pager-numbers {
    display: none;
  }

  .search input,
  .search select {
    flex: 1 1 100%;
    min-width: 0;
  }

  .pager-compact {
    display: inline;
  }
}

/* ------------------------- Forms ------------------------- */
form {
  margin: 0;
}

label {
  display: grid;
  gap: 0.35rem;
  font-weight: 500;
  font-size: 0.85rem;
  color: var(--text-2);
}

input,
select,
textarea {
  width: 100%;
  height: 38px;
  padding: 0 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  box-shadow: var(--shadow-sm);
}

textarea {
  height: auto;
  padding: 0.6rem 0.7rem;
}

/* Own chevron instead of the native arrow, which browsers place flush against the border. */
select {
  appearance: none;
  padding-right: 2.1rem;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 1.05rem) 52%,
    calc(100% - 0.75rem) 52%;
  background-size: 0.3rem 0.3rem;
  background-repeat: no-repeat;
  text-overflow: ellipsis;
}

input:disabled {
  background: var(--surface-3);
  color: var(--muted);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.compact-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.85rem;
  align-items: end;
}

.stacked-fields {
  display: grid;
  gap: 0.85rem;
}

.inline-form {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.inline-form input {
  width: 96px;
  flex: none;
}

td input.qty {
  width: 84px;
  text-align: right;
}

td input.price {
  width: 104px;
  text-align: right;
}

.inline-form label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.inline-form label input {
  width: auto;
}

.narrow {
  max-width: 460px;
  margin-top: 0.75rem;
}

.form-hint {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 0.6rem;
}

/* ------------------------- Buttons ------------------------- */
button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  height: 38px;
  padding: 0 0.95rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition:
    background 0.12s,
    border-color 0.12s,
    color 0.12s;
}

button:hover,
.button:hover {
  text-decoration: none;
}

button:focus-visible,
.button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button[type='submit'],
.button.primary {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

button[type='submit']:hover,
.button.primary:hover {
  background: var(--accent-hover);
}

button.secondary,
.button.secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

button.secondary:hover,
.button.secondary:hover {
  background: var(--surface-2);
}

button.danger,
.button.danger {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--border-strong);
}

button.danger:hover,
.button.danger:hover {
  background: var(--danger-soft);
  border-color: var(--danger);
}

button.success,
.button.success {
  background: var(--success-soft);
  color: var(--success);
  border-color: transparent;
}

.button.ghost {
  background: transparent;
  color: var(--text-2);
}

.button.ghost:hover {
  background: var(--surface-3);
  color: var(--text);
}

.button.sm,
button.sm {
  height: 32px;
  padding: 0 0.7rem;
  font-size: 0.8rem;
}

.table-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  align-items: center;
}

.table-actions form {
  display: inline-flex;
}

.actions-stack {
  display: grid;
  gap: 0.5rem;
}

.actions-stack button,
.actions-stack .button {
  width: 100%;
}

/* ------------------------- Flash messages ------------------------- */
.flash {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin: 0 0 1rem;
  font-weight: 500;
  border: 1px solid;
}

.flash .icon {
  margin-top: 1px;
}

.flash.success {
  background: var(--success-soft);
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 30%, transparent);
}

.flash.error {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 30%, transparent);
}

.flash.info {
  background: var(--info-soft);
  color: var(--info);
  border-color: color-mix(in srgb, var(--info) 30%, transparent);
}

/* ------------------------- Lists ------------------------- */
.list {
  display: grid;
}

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.list-row:last-child {
  border-bottom: 0;
}

.list-row .grow {
  flex: 1;
  min-width: 0;
}

.list-row.muted {
  color: var(--muted);
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 0.4rem;
  padding: 2rem 1rem;
  color: var(--muted);
  text-align: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}

.error-state .icon {
  width: 28px;
  height: 28px;
  stroke-width: 2.1;
}

.facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.9rem 1.25rem;
  margin: 0;
}

.facts.single {
  grid-template-columns: minmax(0, 1fr);
}

.facts dt {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.facts dd {
  margin: 0.2rem 0 0;
  color: var(--text);
}

.total-line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-top: 0.9rem;
  margin-top: 0.9rem;
  border-top: 1px solid var(--border);
}

.total-line strong {
  font-size: 1.35rem;
  font-variant-numeric: tabular-nums;
}

.quick-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ------------------------- Responsive ------------------------- */
@media (max-width: 1100px) {
  .grid-2,
  .grid-halves {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 900px) {
  .app {
    /* minmax(0, …) lets the column shrink below its content, so wide tables scroll inside their box. */
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  #nav-toggle:checked ~ .sidebar {
    transform: none;
    box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.4);
  }

  .mobile-bar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1rem;
    background: var(--sidebar-bg);
    color: #fff;
    font-weight: 600;
  }

  .mobile-bar label {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    color: #fff;
  }

  .container {
    padding: 1.25rem 1rem 2.5rem;
  }

  .search input,
  .search select {
    min-width: 0;
  }
}

.list + form,
.list + .stacked-fields {
  margin-top: 0.9rem;
}

/* ------------------------- Theme switch ------------------------- */
.theme-switch {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 9px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  width: fit-content;
}

.theme-switch form {
  display: contents;
}

.theme-switch button[type='submit'] {
  height: 28px;
  padding: 0 0.55rem;
  gap: 0.35rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  box-shadow: none;
}

.theme-switch button[type='submit']:hover {
  color: var(--text);
  background: transparent;
}

.theme-switch button[type='submit'][aria-pressed='true'] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.theme-switch .icon {
  width: 14px;
  height: 14px;
}

.sidebar .theme-switch {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.08);
  margin: 0 0 0.6rem;
  width: auto;
}

/* Icon above the label, so each label gets the full button width (Greek labels are longer). */
.sidebar .theme-switch button[type='submit'] {
  flex: 1 1 0;
  flex-direction: column;
  min-width: 0;
  height: auto;
  padding: 0.35rem 0.2rem;
  gap: 0.2rem;
  line-height: 1.1;
  color: var(--sidebar-muted);
}

.sidebar .theme-switch button[type='submit']:hover {
  color: #fff;
}

.sidebar .theme-switch button[type='submit'][aria-pressed='true'] {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  box-shadow: none;
}

/* ------------------------- Sign-in (centred card) ------------------------- */
.signin {
  min-height: 100vh;
  display: grid;
  grid-template-rows: 1fr auto;
  background: var(--bg);
}

.signin-main {
  display: grid;
  place-items: center;
  padding: 2.5rem 1rem;
}

.signin-box {
  width: min(400px, 100%);
}

.signin-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  margin-bottom: 1.5rem;
  font-size: 1.6rem;
  font-weight: 650;
  color: var(--text);
  letter-spacing: -0.01em;
}

.signin-brand .brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
}

.signin-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 2rem;
}

.signin-card h1 {
  font-size: 1.3rem;
  margin-bottom: 0.3rem;
}

.signin-card .lead-text {
  color: var(--text-2);
  margin: 0 0 1.5rem;
}

.signin-card form {
  display: grid;
  gap: 1rem;
}

.signin-card button[type='submit'] {
  width: 100%;
  height: 40px;
  margin-top: 0.25rem;
}

.signin-help {
  margin: 1.25rem 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.signin-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1rem 1.5rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.preference-switches {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
