:root {
  --bordo: #6e1a2a;
  --bordo-600: #7e2233;
  --bordo-700: #561320;
  --bordo-900: #3a0c16;
  --bordo-tint: #f5eaec;
  --bordo-tint-2: #efdbdf;
  --bg: #f4f1ef;
  --surface: #ffffff;
  --surface-2: #fbf9f8;
  --surface-3: #f6f3f1;
  --ink: #1c1819;
  --ink-2: #4a4341;
  --muted: #645b56;
  --faint: #6e645e;
  --ghost: #bcb3ae;
  --line: #e8e3e0;
  --line-2: #ded7d3;
  --line-strong: #cfc6c1;
  --danger: #b23a2e;
  --danger-tint: #f7e7e4;
  --success: #2f6e54;
  --success-tint: #e7f0eb;
  --warning: #a8741a;
  --warning-tint: #f6eedd;
  --info: #355c7d;
  --info-tint: #e7eef3;
  --radius-sm: 6px;
  --radius: 8px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(28, 24, 25, 0.05);
  --shadow: 0 1px 2px rgba(28, 24, 25, 0.05), 0 8px 24px -18px rgba(28, 24, 25, 0.22);
  --shadow-lg: 0 24px 70px rgba(17, 17, 17, 0.28);
  --sidebar-width: 256px;
  --topbar-height: 66px;
  /* tracking para rótulos en mayúscula */
  --track-caps: 0.05em;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
}

[hidden] {
  display: none !important;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-thumb {
  background: #d8d0cb;
  border: 3px solid transparent;
  border-radius: var(--radius-pill);
  background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
  background: #c2b8b2;
  background-clip: content-box;
}

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

h1,
h2,
h3,
h4 {
  color: var(--ink);
  font-weight: 700;
  letter-spacing: 0;
}

h1 {
  max-width: 720px;
  margin-bottom: 14px;
  font-size: 44px;
  line-height: 1.08;
  letter-spacing: -0.01em;
}

h2 {
  margin-bottom: 0;
  font-size: 25px;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

h3 {
  margin-bottom: 0;
  font-size: 16px;
  line-height: 1.3;
}

h4 {
  margin-bottom: 0;
  font-size: 14px;
  line-height: 1.3;
}

.num,
.amount,
.kpi-val {
  font-variant-numeric: tabular-nums;
}

.muted {
  margin-bottom: 0;
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
}

.lead {
  max-width: 580px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.55;
}

/* Auth */
.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(320px, 440px);
  background: var(--bg);
}

.brand-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 56px;
  background: linear-gradient(160deg, var(--bordo) 0%, var(--bordo-700) 56%, var(--bordo-900) 100%);
  color: #fff;
}

.brand-panel .eyebrow,
.brand-panel h1 {
  color: #fff;
}

.brand-panel .lead {
  color: rgba(255, 255, 255, 0.78);
}

.brand-mark,
.brand-logo {
  width: 38px;
  height: 38px;
  flex: none;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.88);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.brand-mark {
  width: 48px;
  height: 48px;
  margin-bottom: 26px;
  font-size: 14px;
}

.brand-mark img,
.brand-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.brand-mark.has-logo,
.brand-logo.has-logo {
  background: #fff;
  border-color: rgba(255, 255, 255, 0.4);
}

.branding-editor {
  display: grid;
  gap: 14px;
  padding: 16px;
  max-width: 520px;
}

.branding-logo-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.branding-logo-preview {
  width: 56px;
  height: 56px;
  flex: none;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  font-weight: 800;
  color: var(--muted);
}

.branding-logo-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.branding-logo-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}

.password-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.password-wrap input {
  width: 100%;
  padding-right: 42px;
}

.password-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  border-radius: 8px;
}

.password-toggle:hover {
  color: var(--text);
}

.password-toggle svg {
  width: 18px;
  height: 18px;
}

.password-toggle .icon-eye-off {
  display: none;
}

.password-toggle.revealed .icon-eye {
  display: none;
}

.password-toggle.revealed .icon-eye-off {
  display: block;
}

.auth-card {
  align-self: center;
  margin: 40px;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.card-head.loose {
  margin-bottom: 22px;
  padding: 0;
  border: 0;
}

.auth-card .eyebrow {
  color: var(--muted);
}

/* App layout */
.app-layout,
.app {
  min-height: 100vh;
  height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  overflow: hidden;
  transition: grid-template-columns 160ms ease;
}

.sidebar {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: linear-gradient(178deg, var(--bordo) 0%, var(--bordo-700) 54%, var(--bordo-900) 100%);
  color: #f3e4e6;
}

.brand {
  height: var(--topbar-height);
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

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

.brand-name b {
  color: #fff;
  font-size: 15px;
  font-weight: 700;
}

.brand-name span,
.who span {
  color: rgba(243, 228, 230, 0.7);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
}

.sidebar-toggle {
  width: 32px;
  height: 32px;
  flex: none;
  display: grid;
  place-items: center;
  margin-left: auto;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
}

.sidebar-toggle:hover {
  background: rgba(255, 255, 255, 0.16);
}

.nav {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
}

.nav-group-label {
  padding: 14px 12px 7px;
  color: rgba(243, 228, 230, 0.62);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
}

.nav-item {
  width: 100%;
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 11px;
  margin: 2px 0;
  padding: 9px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: rgba(243, 228, 230, 0.85);
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease;
}

.nav-item svg {
  width: 17px;
  height: 17px;
  flex: none;
  opacity: 0.86;
}

.nav-item::before {
  content: attr(data-short);
  width: 30px;
  height: 30px;
  display: none;
  place-items: center;
  flex: none;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.nav-item.active {
  background: rgba(255, 255, 255, 0.13);
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: inset 2px 0 0 #fff;
  color: #fff;
}

.nav-item.active svg {
  opacity: 1;
}

.nav-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.side-foot {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 13px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.side-user {
  display: flex;
  align-items: center;
  gap: 11px;
}

.logout-btn {
  flex: none;
  margin-left: auto;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.logout-btn svg {
  width: 17px;
  height: 17px;
}

.logout-btn:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.34);
}

.conn-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: rgba(243, 228, 230, 0.72);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
}

.conn-status.offline {
  color: #f0bdb6;
}

.avatar {
  width: 34px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}

.who {
  min-width: 0;
  line-height: 1.25;
}

.who b {
  display: block;
  overflow: hidden;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (min-width: 981px) {
  .app-layout.sidebar-collapsed {
    --sidebar-width: 88px;
  }

  .app-layout.sidebar-collapsed .brand {
    justify-content: center;
    gap: 6px;
    padding: 12px 8px;
  }

  .app-layout.sidebar-collapsed .brand-name,
  .app-layout.sidebar-collapsed .nav-group-label,
  .app-layout.sidebar-collapsed .who {
    display: none;
  }

  .app-layout.sidebar-collapsed .sidebar-toggle {
    margin-left: 0;
  }

  .app-layout.sidebar-collapsed .nav {
    padding: 14px 10px;
  }

  .app-layout.sidebar-collapsed .nav-item {
    justify-content: center;
    padding: 5px;
    color: transparent;
    font-size: 0;
  }

  .app-layout.sidebar-collapsed .nav-item svg,
  .app-layout.sidebar-collapsed .nav-label {
    display: none;
  }

  .app-layout.sidebar-collapsed .nav-item::before {
    display: grid;
  }

  .app-layout.sidebar-collapsed .nav-item.active {
    box-shadow: none;
  }

  .app-layout.sidebar-collapsed .side-foot {
    justify-content: center;
    padding: 14px 8px;
  }
}

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.filter-field span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
}

.dot,
.badge::before {
  width: 7px;
  height: 7px;
  flex: none;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(47, 110, 84, 0.32);
}

.conn-status.offline .dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(178, 58, 46, 0.36);
}

.scroll {
  flex: 1;
  overflow-y: auto;
}

.screen {
  display: none;
  max-width: 1480px;
  margin: 0 auto;
  padding: 26px 30px 60px;
}

.screen.active {
  display: block;
}

/* Page primitives */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.page-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}

.head-actions,
.actions,
.row-actions,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.btn {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 15px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease, box-shadow 140ms ease;
}

.btn svg {
  width: 16px;
  height: 16px;
  flex: none;
}

.btn:hover {
  border-color: var(--line-strong);
  background: var(--surface-3);
}

.btn.full {
  width: 100%;
}

.btn.compact,
.btn.sm {
  min-height: 36px;
  padding: 7px 13px;
}

.btn.primary {
  border-color: var(--bordo);
  background: var(--bordo);
  color: #fff;
}

.btn.primary:hover {
  background: var(--bordo-600);
}

.btn.secondary {
  background: var(--surface);
}

.btn.ghost {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  color: var(--ink-2);
}

.btn.ghost:hover {
  background: var(--surface-3);
}

.btn.danger {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}

.danger-zone {
  margin-top: 16px;
  border: 1px solid var(--danger);
}

.danger-zone .inline-form {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.danger-zone .inline-form .field {
  flex: 1 1 220px;
  margin: 0;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

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

.dash-section {
  margin: 4px 0 12px;
}

.dash-section-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.kpi,
.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.kpi {
  min-width: 0;
  min-height: 132px;
  position: relative;
  overflow: hidden;
  padding: 17px 18px;
}

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

.kpi-label {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.kpi-ic {
  width: 32px;
  height: 32px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--bordo-tint);
  color: var(--bordo);
}

.kpi-ic svg {
  width: 17px;
  height: 17px;
}

.kpi-ic.success-ic {
  background: var(--success-tint);
  color: var(--success);
}

.kpi-ic.danger-ic {
  background: var(--danger-tint);
  color: var(--danger);
}

.kpi-ic.warn-ic {
  background: var(--warning-tint);
  color: var(--warning);
}

.kpi-val,
.kpi strong {
  display: block;
  overflow-wrap: anywhere;
  margin: 12px 0 8px;
  color: var(--ink);
  font-size: 28px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.05;
}

.kpi-sub,
.kpi small {
  display: block;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.kpi.feature {
  border-color: var(--bordo-700);
  background: linear-gradient(160deg, var(--bordo) 0%, var(--bordo-700) 100%);
  color: #fff;
}

.kpi.feature .kpi-label,
.kpi.feature .kpi-sub,
.kpi.feature small {
  color: rgba(255, 255, 255, 0.78);
}

.kpi.feature .kpi-val,
.kpi.feature strong {
  color: #fff;
}

.kpi.feature .kpi-ic {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.grid {
  display: grid;
  gap: 18px;
}

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

.grid.lower {
  margin-top: 18px;
}

.card {
  min-width: 0;
  overflow: hidden;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.card-head p,
.card-head .sub,
.line-head p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.card-body {
  padding: 18px;
}

.chart {
  min-height: 280px;
  padding: 18px;
}

.compact-chart {
  min-height: 300px;
}

.bar-chart {
  min-height: 380px;
}

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

.axis-label,
.axis-lbl {
  fill: var(--faint);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 12px;
  font-weight: 700;
}

.value-label,
.bar-val {
  fill: var(--ink-2);
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.chart-axis-major {
  fill: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.chart-strong-label {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.chart-value-major {
  fill: var(--ink-2);
  font-size: 14px;
  font-weight: 800;
}

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

.donut-chart {
  min-height: 240px;
  display: grid;
  grid-template-columns: minmax(180px, 0.85fr) minmax(0, 1fr);
  align-items: center;
  gap: 16px;
}

.donut-chart svg {
  max-width: 100%;
}

.chart-legend,
.legend {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 12px 14px;
  align-content: center;
}

.chart-legend {
  display: grid;
  gap: 12px;
}

.legend-item,
.legend .lg {
  min-width: 0;
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr);
  align-items: start;
  gap: 9px;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
}

.legend-item span:last-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.legend-swatch,
.legend .sw {
  width: 12px;
  height: 12px;
  margin-top: 3px;
  border-radius: 3px;
}

.account-state-list {
  display: grid;
  gap: 0;
  padding: 8px 18px 16px;
}

.account-state-row {
  min-width: 0;
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

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

.account-state-row.total {
  margin-top: 4px;
  padding-top: 14px;
  border-top: 1px solid var(--line-strong);
  font-weight: 800;
}

.account-state-row b,
.account-state-row strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.account-state-row b {
  color: var(--ink);
  font-size: 15px;
}

.account-state-row small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.account-state-row strong {
  color: var(--ink-2);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.account-state-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--line-strong);
}

/* Lists and alerts */
.list {
  display: grid;
  gap: 0;
  padding: 8px 18px;
}

.list-item {
  display: grid;
  gap: 3px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

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

.list-item b {
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
}

.list-item span {
  color: var(--muted);
  font-size: 14px;
}

.alert-item {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.alert-item .ai-ic {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--info-tint);
  color: var(--info);
}

.alert-item .ai-ic svg {
  width: 16px;
  height: 16px;
}

.alert-item.critical .ai-ic,
.alert-item.error .ai-ic {
  background: var(--danger-tint);
  color: var(--danger);
}

.alert-item.warning .ai-ic {
  background: var(--warning-tint);
  color: var(--warning);
}

.alert-item .ai-body {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.alert-item .ai-body b,
.alert-item .ai-body span {
  display: block;
}

.alert-item .amount-line {
  color: var(--ink);
  font-weight: 800;
}

/* Filters */
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px;
  margin-bottom: 18px;
}

.filter-field {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink-2);
  box-shadow: var(--shadow-sm);
}

.filter-field select {
  min-width: 160px;
  height: 34px;
  border: 0;
  background: transparent;
  color: var(--ink);
  outline: 0;
}

.filter-field input {
  height: 34px;
  border: 0;
  background: transparent;
  color: var(--ink);
  outline: 0;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 14px;
  padding: 5px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: var(--surface-3);
}

.tab {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.tab.active {
  border-color: var(--line);
  background: var(--surface);
  color: var(--bordo);
  box-shadow: var(--shadow-sm);
}

.state-message {
  min-height: 20px;
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.state-message:empty {
  min-height: 0;
  margin-bottom: 0;
}

.state-message[data-tone="success"] {
  color: var(--success);
}

.state-message[data-tone="error"] {
  color: var(--danger);
}

/* Tables */
.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.data-table th,
.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

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

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

.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
}

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

.empty-cell {
  padding: 28px 16px !important;
  color: var(--muted);
  text-align: center !important;
}

.badge {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
  white-space: nowrap;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  box-shadow: none;
}

.badge.draft,
.badge.open {
  border-color: var(--line-2);
  background: var(--surface-3);
  color: var(--muted);
}

.badge.draft::before,
.badge.open::before {
  background: var(--warning);
}

.badge.confirmed,
.badge.conf {
  background: var(--info-tint);
  color: var(--info);
}

.badge.confirmed::before,
.badge.conf::before {
  background: var(--info);
}

.badge.closed {
  background: var(--bordo-tint);
  color: var(--bordo);
}

.badge.closed::before {
  background: var(--bordo);
}

.badge.pos {
  background: var(--success-tint);
  color: var(--success);
}

.badge.pos::before {
  background: var(--success);
}

.badge.neg {
  background: var(--danger-tint);
  color: var(--danger);
}

.badge.neg::before {
  background: var(--danger);
}

.badge.warn {
  background: var(--warning-tint);
  color: var(--warning);
}

.badge.warn::before {
  background: var(--warning);
}

.amount {
  color: var(--ink);
  font-weight: 800;
}

.amount.neg,
.amt-neg {
  color: var(--danger);
}

.amount.pos,
.amt-pos {
  color: var(--success);
}

.row-actions {
  flex-wrap: wrap;
}

.text-btn {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

.text-btn:hover {
  border-color: var(--line-strong);
  background: var(--surface-3);
}

.danger-link {
  color: var(--danger);
}

/* Dialogs and forms */
.modal {
  width: min(620px, calc(100vw - 32px));
  max-height: min(86vh, 900px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
}

.modal.wide {
  width: min(940px, calc(100vw - 32px));
}

.modal.drawer {
  width: min(900px, calc(100vw - 16px));
  height: 100vh;
  max-height: 100vh;
  margin: 0 0 0 auto;
  border-radius: var(--radius) 0 0 var(--radius);
}

.modal::backdrop {
  background: rgba(17, 17, 17, 0.52);
}

.modal form {
  max-height: inherit;
  display: flex;
  flex-direction: column;
  overflow: auto;
  margin: 0;
  padding: 22px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: -22px -22px 18px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.icon-btn {
  width: 34px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
}

.icon-btn:hover {
  border-color: var(--line-strong);
  background: var(--surface-3);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 16px;
}

.field {
  min-width: 0;
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 700;
}

.field > span,
.field label,
.field legend {
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 700;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 40px;
  padding: 9px 12px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink);
  outline: 0;
}

.field textarea {
  resize: vertical;
}

.money-preview {
  min-height: 18px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
}

.money-preview[data-tone="ok"] {
  color: var(--success);
}

.petty-hint {
  min-height: 16px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.petty-hint[data-tone="ok"] {
  color: #6e1a2a;
}

.inline-range {
  min-width: 170px;
}

.inline-range > span {
  font-size: 11px;
}

.inline-range select {
  padding: 7px 10px;
  border: 1px solid var(--line, #ded7d3);
  border-radius: 8px;
  font: inherit;
  background: #fff;
}

.reconcile-note {
  margin: -4px 0 4px;
  font-size: 13px;
}

.count-input {
  width: 140px;
  max-width: 100%;
  padding: 6px 8px;
  text-align: right;
  border: 1px solid var(--line, #ded7d3);
  border-radius: 8px;
  font: inherit;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.filter-field:focus-within {
  border-color: color-mix(in srgb, var(--bordo), var(--line-2) 35%);
  box-shadow: 0 0 0 3px var(--bordo-tint);
}

.notes-field {
  max-width: 820px;
}

.check-field {
  grid-template-columns: 18px minmax(0, 1fr);
  align-content: end;
  align-items: center;
  min-height: 62px;
}

.check-field input {
  width: 18px;
  height: 18px;
  min-height: 18px;
  padding: 0;
}

.check-group {
  margin: 0 0 14px;
  padding: 10px 12px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.check-group legend {
  padding: 0 4px;
  color: var(--muted);
}

.inline-check {
  min-height: 34px;
  margin-bottom: 6px;
  color: var(--ink);
}

.line-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 12px;
  padding-top: 4px;
}

.payment-lines {
  display: grid;
  gap: 10px;
}

.payment-line {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr)) auto;
  gap: 10px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.payment-line .field {
  margin-bottom: 0;
}

.payment-line-check-field[hidden] {
  display: none;
}

.payment-line-remove {
  grid-column: -2 / -1;
  justify-self: end;
  align-self: start;
  margin-top: 26px;
}

.expense-lines {
  display: grid;
  gap: 8px;
  margin-top: 6px;
}

.expense-line {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(140px, 200px);
  gap: 12px;
  align-items: center;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.expense-line-label {
  font-weight: 600;
}

.expense-line input {
  text-align: right;
}

.form-error {
  margin: 0 0 14px;
  color: var(--danger);
  font-size: 13px;
  font-weight: 800;
}

.modal-actions {
  margin-top: 6px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.confirm p {
  margin-bottom: 12px;
  color: var(--muted);
  font-weight: 600;
}

/* Toasts */
.toast-region {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  width: min(360px, calc(100vw - 36px));
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--success);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 10px 30px rgba(28, 24, 25, 0.15);
  font-size: 14px;
  font-weight: 700;
}

.toast[data-tone="error"] {
  border-left-color: var(--danger);
}

/* Utility classes used by reference-derived renderers */
.bar-track {
  height: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface-3);
}

.bar-fill {
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--bordo);
}

.utag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 600;
}

.utag .udot {
  width: 9px;
  height: 9px;
  flex: none;
  border-radius: 3px;
}

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

@media (max-width: 980px) {
  .app-layout,
  .app {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .sidebar {
    min-height: auto;
  }

  .brand {
    height: auto;
  }

  .sidebar-toggle {
    display: none;
  }

  .nav {
    display: flex;
    gap: 6px;
    padding: 10px 12px;
    overflow-x: auto;
  }

  .nav-group-label {
    display: none;
  }

  .nav-item {
    width: auto;
    min-width: max-content;
  }

  .side-foot {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  .side-user {
    flex: 1;
    min-width: 0;
  }

  .main {
    overflow: visible;
  }

  .scroll {
    overflow: visible;
  }
}

@media (max-width: 760px) {
  .auth-shell {
    grid-template-columns: 1fr;
  }

  .brand-panel {
    min-height: 34vh;
    padding: 34px;
  }

  h1 {
    font-size: 36px;
  }

  .auth-card {
    margin: 22px;
  }

  .page-head,
  .head-actions,
  .line-head,
  .modal-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .screen {
    padding: 18px 14px 40px;
  }

  .grid.two,
  .kpis,
  .kpis.three,
  .donut-chart,
  .form-grid,
  .payment-line {
    grid-template-columns: 1fr;
  }

  .filters {
    display: grid;
  }

  .filter-field {
    align-items: stretch;
    justify-content: stretch;
  }

  .filter-field select {
    min-width: 0;
  }

  .btn.compact,
  .btn.full {
    width: 100%;
  }

  .modal form {
    padding: 18px;
  }

  .modal-head {
    margin: -18px -18px 16px;
    padding: 16px 18px;
  }
}
