:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #edf2f7;
  --line: #d8e0ea;
  --line-strong: #b9c6d4;
  --text: #152231;
  --muted: #647386;
  --faint: #95a3b3;
  --green: #0f766e;
  --green-dark: #115e59;
  --blue: #2563eb;
  --red: #be123c;
  --amber: #b7791f;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
  --sidebar: 220px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--text);
  background: var(--bg);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

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

button {
  color: inherit;
}

svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

[hidden] {
  display: none !important;
}

.toast {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 30;
  max-width: 420px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-weight: 750;
}

.toast.is-error {
  border-color: #fecdd3;
  background: #fff1f2;
  color: #9f1239;
}

.auth-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 24px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid #b8d3f7;
  border-radius: 8px;
  background: #fff;
  color: var(--blue);
  font-weight: 950;
}

.brand strong,
.brand small {
  display: block;
  line-height: 1.15;
}

.brand small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.auth-form,
.finance-form {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
}

input,
select {
  height: 40px;
  padding: 0 11px;
}

textarea {
  min-height: 82px;
  padding: 10px 11px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.button {
  min-height: 39px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 850;
  white-space: nowrap;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.button-primary {
  background: var(--green);
  color: #fff;
}

.button-primary:hover {
  background: var(--green-dark);
}

.button-danger {
  background: var(--red);
  color: #fff;
}

.button-ghost {
  border-color: var(--line);
  background: var(--surface);
}

.button-ghost:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.app-shell {
  min-height: 100dvh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar);
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px 12px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.98);
}

.sidebar-brand {
  height: 42px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  position: relative;
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  height: 40px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #526171;
  cursor: pointer;
  font-weight: 850;
  text-align: left;
}

.nav-item:hover,
.nav-item.is-active {
  border-color: #bfdbfe;
  background: #eaf2ff;
  color: var(--blue);
}

.nav-item.is-active::before {
  content: '';
  position: absolute;
  left: -12px;
  width: 3px;
  height: 24px;
  border-radius: 999px;
  background: var(--blue);
}

.logout {
  margin-top: auto;
  justify-content: flex-start;
  border-color: transparent;
}

.workspace {
  min-width: 0;
  margin-left: var(--sidebar);
  padding: 24px;
}

.topbar,
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 20px;
}

.topbar h1,
.panel h2,
.finance-ledger h3 {
  margin: 0;
  line-height: 1.15;
}

.topbar h1 {
  font-size: 28px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.range-control {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.range-control button {
  min-width: 74px;
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 850;
}

.range-control button.is-active,
.range-control button:hover {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.08);
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.metric {
  min-height: 104px;
  display: grid;
  align-content: center;
  gap: 8px;
  padding: 16px;
}

.metric span,
.stat-card span,
.client-row small,
.ledger-row small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.metric strong {
  font-size: 29px;
  line-height: 1;
}

.metric.is-money strong {
  color: var(--green);
}

.panel {
  padding: 18px;
}

.panel + .panel,
.finance-ledger {
  margin-top: 16px;
}

.panel-head {
  margin-bottom: 15px;
}

.panel-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.analytics-panel {
  display: grid;
  gap: 14px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.stat-card {
  min-height: 84px;
  display: grid;
  align-content: center;
  gap: 7px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.stat-card strong {
  font-size: 26px;
  line-height: 1;
}

.chart {
  min-height: 210px;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(20px, 1fr);
  align-items: end;
  gap: 8px;
  padding: 12px 4px 0;
  border-top: 1px solid var(--line);
}

.chart-bar {
  min-width: 0;
  display: grid;
  gap: 6px;
  align-items: end;
  justify-items: center;
}

.chart-bar span {
  width: 100%;
  max-width: 28px;
  min-height: 6px;
  border-radius: 6px 6px 0 0;
  background: linear-gradient(180deg, #2563eb, #0f766e);
}

.chart-bar small {
  max-width: 44px;
  overflow: hidden;
  color: var(--faint);
  font-size: 10px;
  font-weight: 800;
  text-overflow: ellipsis;
}

.client-list,
.client-table {
  display: grid;
  gap: 8px;
}

.client-row {
  display: grid;
  grid-template-columns:
    minmax(220px, 1.5fr) repeat(4, minmax(95px, 0.65fr))
    auto auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.client-row.is-compact {
  grid-template-columns:
    minmax(220px, 1.5fr) repeat(4, minmax(95px, 0.65fr))
    auto;
}

.client-row strong,
.ledger-row strong {
  display: block;
}

.client-row span,
.ledger-row span,
.ledger-row p {
  display: block;
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.client-row b {
  display: block;
  margin-top: 2px;
  font-size: 15px;
}

.ai-switch {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
}

.ai-switch input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.ai-switch-track {
  flex: 0 0 auto;
  width: 42px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  padding: 2px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: #e2e8f0;
  transition:
    background 140ms ease,
    border-color 140ms ease;
}

.ai-switch-track span {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.2);
  transition: transform 140ms ease;
}

.ai-switch-label {
  display: inline-flex;
  align-items: center;
  min-width: 34px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.ai-switch.is-on .ai-switch-track {
  background: var(--green);
  border-color: var(--green);
}

.ai-switch.is-on .ai-switch-track span {
  transform: translateX(18px);
}

.ai-switch.is-on .ai-switch-label {
  color: var(--text);
}

.ai-switch.is-off {
  color: var(--red);
}

.ai-switch.is-off .ai-switch-track {
  border-color: #fecdd3;
  background: #ffe4e6;
}

.ai-switch.is-off .ai-switch-label {
  color: var(--red);
}

.ai-switch:hover .ai-switch-track {
  border-color: var(--text);
}

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

.ledger-column {
  min-width: 0;
}

.ledger-column-head {
  min-height: 48px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.finance-ledger h3 {
  margin-bottom: 10px;
  font-size: 15px;
}

.ledger-column-head h3 {
  margin-bottom: 4px;
}

.ledger-column-head p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.finance-form {
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.amount-currency-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 118px;
  gap: 10px;
  align-items: end;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ledger-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.ledger-row + .ledger-row {
  margin-top: 8px;
}

.ledger-row > div:last-child {
  display: grid;
  justify-items: end;
  gap: 4px;
}

.ledger-row button {
  width: 24px;
  height: 24px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.empty {
  padding: 18px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  font-weight: 750;
}

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

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

@media (max-width: 760px) {
  :root {
    --sidebar: 0px;
  }

  .sidebar {
    position: sticky;
    top: 0;
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .sidebar-brand {
    min-width: 134px;
  }

  .nav {
    display: flex;
    min-width: max-content;
  }

  .nav-item {
    grid-template-columns: 20px auto;
    width: auto;
  }

  .nav-item.is-active::before {
    display: none;
  }

  .logout {
    margin-left: auto;
    margin-top: 0;
  }

  .workspace {
    margin-left: 0;
    padding: 16px;
  }

  .topbar,
  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .metrics,
  .stats-grid,
  .ledger-grid,
  .amount-currency-grid {
    grid-template-columns: 1fr;
  }

  .ledger-column-head {
    align-items: stretch;
    flex-direction: column;
  }
}
