/* ==========================================================================
   Base
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background: var(--page);
  color: var(--text-1);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

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

a:hover {
  text-decoration: underline;
}

button {
  font: inherit;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--series-1);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: var(--surface);
  color: var(--text-1);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}

.skip-link:focus {
  left: var(--space-4);
  top: var(--space-4);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   App frame
   ========================================================================== */

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

.shell {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(9, 14, 28, 0.5);
  z-index: 40;
  backdrop-filter: blur(2px);
}

/* Sidebar ---------------------------------------------------------------- */

.sidebar {
  background: var(--brand-900);
  color: rgba(255, 255, 255, 0.86);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-3) var(--space-4);
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 50;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-2) var(--space-4);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.logo {
  display: inline-flex;
  flex: none;
}

.sidebar__brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}

.sidebar__brand-text strong {
  color: #fff;
  font-size: 15px;
  letter-spacing: 0.01em;
}

.sidebar__brand-text small {
  color: rgba(255, 255, 255, 0.55);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.sidebar__close {
  display: none;
  margin-left: auto;
  color: rgba(255, 255, 255, 0.7);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  flex: 1;
}

.nav__group-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: rgba(255, 255, 255, 0.42);
  padding: var(--space-4) var(--space-3) var(--space-2);
}

.nav__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 9px var(--space-3);
  border-radius: var(--radius-md);
  color: rgba(255, 255, 255, 0.78);
  font-weight: 500;
  font-size: 13.5px;
  transition: background 120ms ease, color 120ms ease;
}

.nav__item:hover {
  background: rgba(255, 255, 255, 0.07);
  color: #fff;
  text-decoration: none;
}

.nav__item[aria-current='page'] {
  background: rgba(255, 255, 255, 0.13);
  color: #fff;
}

.nav__item svg {
  flex: none;
  opacity: 0.85;
}

.nav__count {
  margin-left: auto;
  font-size: 11.5px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border-radius: var(--radius-pill);
  padding: 1px 7px;
  font-variant-numeric: tabular-nums;
}

.nav__item[data-alert='true'] .nav__count {
  background: var(--critical);
}

.sidebar__footer {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: var(--space-4);
}

.budget-meter__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.65);
  margin-bottom: var(--space-2);
}

.budget-meter__head strong {
  color: #fff;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.meter {
  height: 6px;
  border-radius: var(--radius-pill);
  background: rgba(134, 182, 239, 0.28);
  overflow: hidden;
}

.meter__fill {
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--ramp-3);
  transition: width 600ms ease;
}

.budget-meter__note {
  margin-top: var(--space-2);
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.45);
  line-height: 1.4;
}

/* Topbar ----------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-height: var(--topbar-height);
  padding: var(--space-3) var(--space-5);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.topbar__menu {
  display: none;
}

.topbar__titles {
  min-width: 0;
  flex: 0 1 auto;
}

.topbar__titles h1 {
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar__subtitle {
  color: var(--text-3);
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar__actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.search {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 var(--space-3);
  height: 36px;
  color: var(--text-3);
  width: 260px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.search[hidden] {
  display: none;
}

.search:focus-within {
  border-color: var(--series-1);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--series-1) 18%, transparent);
}

.search input {
  border: 0;
  background: transparent;
  color: var(--text-1);
  font: inherit;
  width: 100%;
  outline: none;
}

.search input::placeholder {
  color: var(--text-3);
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-2);
}

.topbar .icon-button {
  border-color: var(--border);
  background: var(--surface-2);
}

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

#theme-toggle .icon-moon {
  display: none;
}

:root[data-theme='dark'] #theme-toggle .icon-moon {
  display: block;
}

:root[data-theme='dark'] #theme-toggle .icon-sun {
  display: none;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding-left: var(--space-3);
  border-left: 1px solid var(--border);
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-500), var(--series-3));
  color: #fff;
  font-size: 12.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.02em;
  flex: none;
}

.user-chip__text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.user-chip__text strong {
  font-size: 13px;
  font-weight: 600;
}

.user-chip__text small {
  color: var(--text-3);
  font-size: 11.5px;
}

/* Main ------------------------------------------------------------------- */

.main {
  padding: var(--space-5);
  flex: 1;
  min-width: 0;
  outline: none;
}

.app-footer {
  padding: var(--space-4) var(--space-5) var(--space-6);
  color: var(--text-3);
  font-size: 12px;
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
}

/* ==========================================================================
   Building blocks
   ========================================================================== */

.grid {
  display: grid;
  gap: var(--space-4);
}

.grid--kpis {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

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

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

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
  min-width: 0;
}

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

.card__head {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.card--flush .card__head {
  padding: var(--space-5) var(--space-5) 0;
}

.card__title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.005em;
}

.card__subtitle {
  color: var(--text-3);
  font-size: 12.5px;
  margin-top: 2px;
}

.card__tools {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* KPI tiles -------------------------------------------------------------- */

.kpi {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.kpi__label {
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 500;
}

.kpi__value {
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.kpi__row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.kpi__caption {
  color: var(--text-3);
  font-size: 12px;
}

.kpi__spark {
  height: 40px;
  margin-top: auto;
}

.delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 2px 7px;
  border-radius: var(--radius-pill);
}

.delta--good {
  background: var(--good-bg);
  color: var(--good-text);
}

.delta--bad {
  background: var(--critical-bg);
  color: var(--critical-text);
}

.delta--flat {
  background: var(--neutral-bg);
  color: var(--neutral-text);
}

.delta__period {
  color: var(--text-3);
  font-size: 12px;
  font-weight: 400;
}

/* Chips ------------------------------------------------------------------ */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--neutral-bg);
  color: var(--neutral-text);
}

.chip__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

.chip--good {
  background: var(--good-bg);
  color: var(--good-text);
}

.chip--warning {
  background: var(--warning-bg);
  color: var(--warning-text);
}

.chip--serious {
  background: var(--serious-bg);
  color: var(--serious-text);
}

.chip--critical {
  background: var(--critical-bg);
  color: var(--critical-text);
}

.chip--info {
  background: var(--info-bg);
  color: var(--info-text);
}

/* Buttons ---------------------------------------------------------------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 34px;
  padding: 0 var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-1);
  font-size: 13px;
  font-weight: 500;
  transition: background 120ms ease, border-color 120ms ease;
}

.button:hover {
  background: var(--surface-3);
  text-decoration: none;
}

.button--primary {
  background: var(--brand-600);
  border-color: var(--brand-600);
  color: #fff;
}

.button--primary:hover {
  background: var(--brand-700);
  border-color: var(--brand-700);
}

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

.button--sm {
  height: 28px;
  padding: 0 var(--space-3);
  font-size: 12.5px;
}

/* Segmented control ------------------------------------------------------ */

.segmented {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 2px;
  gap: 2px;
}

.segmented button {
  border: 0;
  background: transparent;
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 7px;
}

.segmented button[aria-pressed='true'] {
  background: var(--surface);
  color: var(--text-1);
  box-shadow: var(--shadow-sm);
}

/* Filter bar ------------------------------------------------------------- */

.filters {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.filters__label {
  font-size: 12px;
  color: var(--text-3);
  font-weight: 500;
  margin-right: var(--space-1);
}

.filter-pill {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  border-radius: var(--radius-pill);
  padding: 4px 11px;
  font-size: 12.5px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.filter-pill:hover {
  border-color: var(--border-strong);
  color: var(--text-1);
}

.filter-pill[aria-pressed='true'] {
  background: var(--brand-600);
  border-color: var(--brand-600);
  color: #fff;
}

.filter-pill__count {
  font-variant-numeric: tabular-nums;
  opacity: 0.72;
  font-size: 11.5px;
}

.select {
  height: 30px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-1);
  font: inherit;
  font-size: 12.5px;
  padding: 0 var(--space-2);
  max-width: 200px;
}

.filters__spacer {
  margin-left: auto;
}

.filters__result-count {
  font-size: 12.5px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

/* Tables ----------------------------------------------------------------- */

.table-wrap {
  overflow-x: auto;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.data th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  font-weight: 600;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 1;
}

table.data td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
  vertical-align: middle;
}

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

table.data tbody tr:hover {
  background: var(--surface-2);
}

table.data .cell-strong {
  color: var(--text-1);
  font-weight: 600;
}

table.data .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text-1);
}

table.data th.num {
  text-align: right;
}

.cell-primary {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.cell-primary strong {
  color: var(--text-1);
  font-weight: 600;
}

.cell-primary small {
  color: var(--text-3);
  font-size: 11.5px;
}

.mono {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

/* Pagination ------------------------------------------------------------- */

.pagination {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 12.5px;
  color: var(--text-2);
  flex-wrap: wrap;
}

.pagination__spacer {
  margin-left: auto;
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

/* Lists ------------------------------------------------------------------ */

.list {
  display: flex;
  flex-direction: column;
}

.list__item {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
  align-items: flex-start;
}

.list__item:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.list__item:first-child {
  padding-top: 0;
}

.list__body {
  min-width: 0;
  flex: 1;
}

.list__title {
  font-weight: 600;
  color: var(--text-1);
  font-size: 13px;
}

.list__meta {
  color: var(--text-3);
  font-size: 12px;
  margin-top: 2px;
}

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

.list__amount {
  font-weight: 600;
  color: var(--text-1);
}

.timeline-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 6px;
  flex: none;
  background: var(--series-1);
  box-shadow: 0 0 0 2px var(--surface);
}

.timeline-dot[data-kind='invoice'] {
  background: var(--serious);
}
.timeline-dot[data-kind='contract'] {
  background: var(--series-4);
}
.timeline-dot[data-kind='supplier'] {
  background: var(--critical);
}
.timeline-dot[data-kind='savings'] {
  background: var(--series-3);
}

/* Empty & error states --------------------------------------------------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-3);
  padding: var(--space-7) var(--space-5);
  color: var(--text-2);
}

.empty__icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-3);
  color: var(--text-3);
}

.empty__title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-1);
}

.empty__body {
  font-size: 13px;
  max-width: 42ch;
  color: var(--text-3);
}

/* Skeletons -------------------------------------------------------------- */

.skeleton {
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 37%, var(--surface-3) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: var(--radius-sm);
  height: 12px;
}

.skeleton--tile {
  height: 132px;
  border-radius: var(--radius-lg);
}

.skeleton--chart {
  height: 280px;
  border-radius: var(--radius-lg);
}

@keyframes shimmer {
  0% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0 50%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton {
    animation: none;
  }
  * {
    transition-duration: 1ms !important;
  }
}

/* ==========================================================================
   Charts
   ========================================================================== */

.chart {
  width: 100%;
  position: relative;
}

.chart svg {
  display: block;
  width: 100%;
  overflow: visible;
}

.chart__grid-line {
  stroke: var(--grid);
  stroke-width: 1;
}

.chart__axis-line {
  stroke: var(--axis);
  stroke-width: 1;
}

.chart__tick {
  fill: var(--text-3);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.chart__label {
  fill: var(--text-2);
  font-size: 11.5px;
}

.chart__value-label {
  fill: var(--text-1);
  font-size: 11.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.chart__hover-band {
  fill: transparent;
}

.chart__hover-band:hover {
  fill: color-mix(in srgb, var(--text-1) 4%, transparent);
}

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

.legend {
  display: flex;
  gap: var(--space-4);
  flex-wrap: wrap;
  align-items: center;
  font-size: 12.5px;
  color: var(--text-2);
}

.legend__item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend__key {
  width: 14px;
  height: 3px;
  border-radius: 2px;
  background: var(--series-1);
  flex: none;
}

.legend__key--square {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.chart-tooltip {
  position: fixed;
  z-index: 80;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-3);
  font-size: 12.5px;
  min-width: 150px;
  color: var(--text-1);
}

.chart-tooltip__title {
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 12.5px;
}

.chart-tooltip__row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: 3px;
}

.chart-tooltip__key {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  flex: none;
}

.chart-tooltip__name {
  color: var(--text-2);
}

.chart-tooltip__value {
  margin-left: auto;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.chart-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.chart-table th,
.chart-table td {
  padding: 6px var(--space-3);
  border-bottom: 1px solid var(--border);
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text-2);
}

.chart-table th:first-child,
.chart-table td:first-child {
  text-align: left;
  color: var(--text-1);
}

.chart-table thead th {
  color: var(--text-3);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Bar list (compact horizontal bars in HTML, not SVG) -------------------- */

.bar-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.bar-list__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px var(--space-3);
  align-items: center;
}

.bar-list__name {
  font-size: 12.5px;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-list__value {
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-1);
}

.bar-list__track {
  grid-column: 1 / -1;
  height: 8px;
  background: var(--surface-3);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.bar-list__fill {
  height: 100%;
  border-radius: 0 4px 4px 0;
  background: var(--ramp-3);
}

/* Detail panel ----------------------------------------------------------- */

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-4);
}

.detail-item__label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  font-weight: 600;
}

.detail-item__value {
  font-size: 14px;
  color: var(--text-1);
  margin-top: 2px;
  font-weight: 500;
}

.callout {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  background: var(--info-bg);
  color: var(--info-text);
  font-size: 13px;
  align-items: flex-start;
}

.callout--warning {
  background: var(--warning-bg);
  color: var(--warning-text);
}

.callout strong {
  display: block;
  margin-bottom: 2px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
}

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

.toggle-row__text strong {
  display: block;
  font-size: 13.5px;
  color: var(--text-1);
}

.toggle-row__text small {
  color: var(--text-3);
  font-size: 12px;
}

.switch {
  width: 40px;
  height: 22px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: var(--surface-3);
  position: relative;
  flex: none;
  transition: background 140ms ease, border-color 140ms ease;
}

.switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: transform 140ms ease;
}

.switch[aria-checked='true'] {
  background: var(--brand-600);
  border-color: var(--brand-600);
}

.switch[aria-checked='true']::after {
  transform: translateX(18px);
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 1180px) {
  .grid--kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

@media (max-width: 1023px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(84vw, var(--sidebar-width));
    transform: translateX(-100%);
    transition: transform 200ms ease;
    box-shadow: var(--shadow-lg);
  }

  .app[data-menu='open'] .sidebar {
    transform: translateX(0);
  }

  .sidebar__close,
  .topbar__menu {
    display: inline-flex;
  }

  .search {
    width: 190px;
  }

  .user-chip__text {
    display: none;
  }

  .user-chip {
    border-left: 0;
    padding-left: 0;
  }
}

@media (max-width: 767px) {
  .main {
    padding: var(--space-4);
  }

  .topbar {
    padding: var(--space-3) var(--space-4);
    gap: var(--space-3);
  }

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

  .card {
    padding: var(--space-4);
  }

  .card--flush .card__head {
    padding: var(--space-4) var(--space-4) 0;
  }

  .filters {
    padding: var(--space-3) var(--space-4);
  }

  .topbar__subtitle {
    display: none;
  }

  .search {
    width: 150px;
  }
}

@media (max-width: 639px) {
  .grid--kpis {
    grid-template-columns: minmax(0, 1fr);
  }

  /* Search stays available on phones; the identity chip is what gives way. */
  .user-chip {
    display: none;
  }

  .search {
    width: auto;
    min-width: 0;
    flex: 1 1 120px;
  }

  .topbar__titles h1 {
    font-size: 17px;
  }

  .topbar__actions {
    flex: 1 1 auto;
    min-width: 0;
    justify-content: flex-end;
  }

  /* Tables collapse into stacked record cards. */
  table.data,
  table.data tbody,
  table.data tr,
  table.data td {
    display: block;
    width: 100%;
  }

  table.data thead {
    display: none;
  }

  table.data tbody tr {
    border-bottom: 1px solid var(--border);
    padding: var(--space-3) var(--space-4);
  }

  table.data tbody tr:last-child {
    border-bottom: 0;
  }

  table.data td {
    border: 0;
    padding: 3px 0;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-4);
    text-align: right;
  }

  table.data td::before {
    content: attr(data-label);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-3);
    font-weight: 600;
    flex: none;
    text-align: left;
  }

  table.data td.num {
    text-align: right;
  }

  table.data td .cell-primary {
    align-items: flex-end;
    text-align: right;
  }

  .pagination {
    padding: var(--space-3) var(--space-4);
  }
}
