:root {
  --ink: #17201d;
  --ink-soft: #5f6b66;
  --paper: #f4f5f1;
  --surface: #ffffff;
  --line: #dfe3dd;
  --line-strong: #c9cfc8;
  --sidebar: #19231f;
  --sidebar-soft: #26332d;
  --green: #166447;
  --green-soft: #e2f0e8;
  --amber: #a55a16;
  --amber-soft: #f7eadb;
  --red: #a53a32;
  --red-soft: #f8e6e3;
  --blue: #236b83;
  --blue-soft: #e0eef2;
  --shadow: 0 18px 55px rgba(23, 32, 29, 0.16);
  font-family: "Microsoft YaHei UI", "PingFang SC", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
}

button,
input,
select,
textarea { font: inherit; letter-spacing: 0; }

button { cursor: pointer; }

.is-hidden { display: none !important; }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px),
    linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px),
    var(--sidebar);
  background-size: 40px 40px;
}

.login-panel {
  width: min(420px, 100%);
  padding: 42px;
  background: var(--surface);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-panel .brand-mark { margin-bottom: 28px; }
.login-panel h1 { margin: 4px 0 12px; font-size: 30px; letter-spacing: 0; }
.login-copy { margin: 0 0 30px; color: var(--ink-soft); line-height: 1.7; }
.login-footnote { margin: 20px 0 0; color: #87918c; font-size: 12px; text-align: center; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 16px 18px;
  display: flex;
  flex-direction: column;
  color: #f7faf8;
  background: var(--sidebar);
  border-right: 1px solid #314039;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 10px 28px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  flex: 0 0 40px;
  color: #fff;
  background: var(--green);
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 6px;
  font-weight: 800;
}

.brand strong,
.brand span { display: block; }
.brand strong { font-size: 15px; }
.brand span { margin-top: 3px; color: #93a29b; font: 10px/1.2 ui-monospace, monospace; text-transform: uppercase; }

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

.nav-item {
  min-height: 44px;
  display: grid;
  grid-template-columns: 34px 1fr;
  align-items: center;
  width: 100%;
  padding: 0 12px;
  color: #aab7b1;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
}

.nav-item:hover { color: #fff; background: var(--sidebar-soft); }
.nav-item.is-active { color: #fff; background: #2b3b34; border-color: #3a4a43; }
.nav-index { color: #6f8178; font: 10px/1 ui-monospace, monospace; }
.nav-item.is-active .nav-index { color: #87c5a9; }

.sidebar-footer {
  margin-top: auto;
  padding: 16px 10px 0;
  display: flex;
  align-items: center;
  gap: 10px;
  border-top: 1px solid #314039;
}

.sidebar-footer strong,
.sidebar-footer span { display: block; }
.sidebar-footer strong { font-size: 11px; font-weight: 600; }
.sidebar-footer span { margin-top: 3px; color: #819088; font-size: 10px; }
.status-dot { width: 8px; height: 8px; flex: 0 0 8px; border-radius: 50%; background: #5dc58f; box-shadow: 0 0 0 4px rgba(93,197,143,.12); }

.workspace { min-width: 0; }

.topbar {
  min-height: 92px;
  padding: 20px clamp(20px, 3vw, 42px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  background: rgba(244,245,241,.95);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.eyebrow {
  margin: 0;
  color: #78837e;
  font: 10px/1.2 ui-monospace, "SFMono-Regular", Consolas, monospace;
}

.topbar h2 { margin: 5px 0 0; font-size: 22px; letter-spacing: 0; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.date-chip {
  height: 36px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  color: var(--ink-soft);
  border-left: 1px solid var(--line-strong);
  font-size: 12px;
}

.button,
.icon-button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 5px;
  font-weight: 650;
  transition: background .16s ease, border-color .16s ease, transform .16s ease;
}

.button { padding: 0 15px; font-size: 13px; }
.button:hover, .icon-button:hover { transform: translateY(-1px); }
.button-primary { color: #fff; background: var(--green); border-color: var(--green); }
.button-primary:hover { background: #0f573d; }
.button-secondary { color: var(--ink); background: var(--surface); border-color: var(--line-strong); }
.button-secondary:hover { border-color: #99a49f; }
.button-danger { color: var(--red); background: var(--red-soft); border-color: #ecc7c3; }
.button-block { width: 100%; }
.icon-button { width: 38px; padding: 0; display: grid; place-items: center; color: var(--ink-soft); background: transparent; border-color: var(--line-strong); font-size: 18px; }

main { padding: 30px clamp(20px, 3vw, 42px) 48px; }
.page-stack { display: grid; gap: 24px; }

.section-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
}

.section-header h3 { margin: 4px 0 0; font-size: 16px; }
.section-header p { margin: 5px 0 0; color: var(--ink-soft); font-size: 12px; }
.section-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.section-header.compact { margin-top: 4px; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  background: var(--surface);
}

.metric {
  min-width: 0;
  min-height: 138px;
  padding: 22px;
  border-right: 1px solid var(--line);
}

.metric:last-child { border-right: 0; }
.metric-label { color: var(--ink-soft); font-size: 12px; }
.metric-value { margin-top: 16px; font: 700 clamp(23px, 2.2vw, 32px)/1.1 ui-monospace, "SFMono-Regular", Consolas, monospace; overflow-wrap: anywhere; }
.metric-foot { margin-top: 10px; color: #79847f; font-size: 11px; }
.metric.is-positive .metric-value { color: var(--green); }
.metric.is-warning .metric-value { color: var(--amber); }

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(280px, .75fr);
  gap: 22px;
}

.panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.panel-header {
  min-height: 62px;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-header h3 { margin: 0; font-size: 14px; }
.panel-header span, .panel-header p { margin: 4px 0 0; color: var(--ink-soft); font-size: 11px; }
.monitor-actions { display: flex; align-items: flex-end; gap: 8px; flex-wrap: wrap; }
.monitor-settings { display: flex; align-items: flex-end; gap: 8px; flex-wrap: wrap; }
.monitor-strategy { display: inline-flex; align-items: stretch; min-height: 38px; border: 1px solid var(--line-strong); border-radius: 5px; overflow: hidden; background: var(--surface); }
.monitor-strategy-option { min-width: 88px; padding: 0 10px; color: var(--ink-soft); background: transparent; border: 0; font-size: 11px; font-weight: 700; cursor: pointer; }
.monitor-strategy-option + .monitor-strategy-option { border-left: 1px solid var(--line); }
.monitor-strategy-option.is-active { color: var(--green-deep); background: var(--green-soft); }
.custom-hours-control { display: flex; align-items: flex-end; gap: 8px; }
.custom-hours-control[hidden] { display: none; }
.compact-number { min-width: 120px; display: grid; gap: 5px; }
.compact-number > span { color: var(--ink-soft); font-size: 10px; font-weight: 650; }
.compact-number input { width: 100%; height: 38px; padding: 0 10px; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 5px; font-size: 12px; font-weight: 650; }
.compact-select { min-width: 118px; display: grid; gap: 5px; }
.compact-select > span { color: var(--ink-soft); font-size: 10px; font-weight: 650; }
.compact-select select {
  width: 100%;
  height: 38px;
  padding: 0 30px 0 10px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  font-size: 12px;
  font-weight: 650;
}
.low-balance-alert {
  min-height: 54px;
  padding: 11px 18px;
  display: flex;
  align-items: center;
  gap: 11px;
  color: #7d2823;
  background: var(--red-soft);
  border-bottom: 1px solid #ecc7c3;
}
.low-balance-alert strong, .low-balance-alert span { display: block; }
.low-balance-alert strong { font-size: 12px; }
.low-balance-alert div > span { margin-top: 3px; font-size: 10px; line-height: 1.45; overflow-wrap: anywhere; }
.monitor-list { display: grid; }
.monitor-row {
  min-height: 76px;
  padding: 13px 18px;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(150px, .45fr) 38px;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}
.monitor-row:last-child { border-bottom: 0; }
.monitor-source { min-width: 0; display: flex; align-items: center; gap: 10px; }
.monitor-source strong, .monitor-source span { display: block; }
.monitor-source strong { font-size: 13px; }
.monitor-source span { margin-top: 4px; color: var(--ink-soft); font-size: 10px; overflow-wrap: anywhere; }
.monitor-status-dot { width: 9px; height: 9px; flex: 0 0 9px; border-radius: 50%; background: #9aa39f; box-shadow: 0 0 0 4px rgba(154,163,159,.12); }
.monitor-row.is-ok .monitor-status-dot { background: #2d9a68; box-shadow: 0 0 0 4px rgba(45,154,104,.12); }
.monitor-row.is-checking .monitor-status-dot { background: var(--blue); box-shadow: 0 0 0 4px rgba(35,107,131,.12); }
.monitor-row.is-pending .monitor-status-dot { background: var(--amber); box-shadow: 0 0 0 4px rgba(165,90,22,.12); }
.monitor-row.is-error .monitor-status-dot { background: var(--red); box-shadow: 0 0 0 4px rgba(165,58,50,.12); }
.monitor-row.is-low { background: #fffafa; }
.monitor-row.is-low .monitor-status-dot { background: var(--red); box-shadow: 0 0 0 4px rgba(165,58,50,.12); }
.monitor-source strong em { margin-left: 8px; padding: 2px 5px; color: var(--red); background: var(--red-soft); border-radius: 3px; font-size: 9px; font-style: normal; }
.monitor-cell { min-width: 0; }
.monitor-cell span, .monitor-cell strong { display: block; }
.monitor-cell span { color: var(--ink-soft); font-size: 10px; }
.monitor-cell strong { margin-top: 6px; font: 700 14px/1.2 ui-monospace, "SFMono-Regular", Consolas, monospace; overflow-wrap: anywhere; }
.monitor-cell strong.negative { color: var(--red); }
.monitor-cell strong.warning { color: var(--red); }
.monitor-refresh:disabled { cursor: wait; opacity: .48; transform: none; }
.monitor-foot { padding: 10px 18px; color: #77827d; background: #fafbf9; border-top: 1px solid var(--line); font-size: 10px; }

.balance-history-panel { overflow: hidden; }
.balance-history-toolbar {
  min-height: 72px;
  padding: 12px 18px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  background: #f7f9f6;
  border-bottom: 1px solid var(--line);
}
.balance-control-group { display: flex; align-items: flex-end; gap: 8px; }
.balance-control-group-right { justify-content: flex-end; }
.balance-history-heading {
  padding: 16px 18px 12px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.balance-history-heading h3 { margin: 0; font-size: 14px; }
.balance-history-heading p, .balance-history-heading > span { margin: 4px 0 0; color: var(--ink-soft); font-size: 10px; }
.balance-history-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.balance-history-summary > div { min-width: 0; padding: 11px 18px; border-right: 1px solid var(--line); }
.balance-history-summary > div:last-child { border-right: 0; }
.balance-history-summary span, .balance-history-summary strong { display: block; }
.balance-history-summary span { color: var(--ink-soft); font-size: 10px; }
.balance-history-summary strong { margin-top: 5px; font: 700 13px/1.3 ui-monospace, "SFMono-Regular", Consolas, monospace; overflow-wrap: anywhere; }
.balance-history-summary strong.positive { color: var(--green); }
.balance-history-summary strong.negative { color: var(--red); }
.balance-chart-scroll { width: 100%; overflow-x: auto; padding: 4px 12px 10px; }
.balance-curve { width: 100%; min-width: 680px; height: auto; display: block; }
.balance-grid-line { stroke: #e4e8e4; stroke-width: 1; }
.balance-axis-label { fill: #7a8580; font: 10px ui-monospace, "SFMono-Regular", Consolas, monospace; }
.balance-area { fill: rgba(20, 106, 75, .09); }
.balance-line { fill: none; stroke: var(--green); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.balance-point { fill: var(--surface); stroke: var(--green); stroke-width: 2.5; vector-effect: non-scaling-stroke; }
.balance-point.is-low { stroke: var(--red); fill: var(--red-soft); }
.balance-threshold-line { stroke: var(--red); stroke-width: 1.5; stroke-dasharray: 6 5; vector-effect: non-scaling-stroke; }
.balance-threshold-label { fill: var(--red); font: 700 10px system-ui, sans-serif; }
.balance-history-empty { min-height: 250px; display: grid; place-items: center; color: var(--ink-soft); font-size: 11px; }
.text-button { padding: 4px; color: var(--green); background: none; border: 0; font-size: 12px; font-weight: 700; }
.text-button.danger { color: var(--red); }
.text-button:disabled { cursor: wait; opacity: .5; }
.row-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; min-width: 150px; }
tr.is-inactive { opacity: .62; }

.account-list { display: grid; }
.account-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(120px, .7fr) 112px;
  align-items: center;
  gap: 18px;
  min-height: 70px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.account-row:last-child { border-bottom: 0; }
.account-name { display: flex; align-items: center; gap: 10px; min-width: 0; }
.account-name strong { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.account-name span { display: block; margin-top: 3px; color: var(--ink-soft); font-size: 10px; }
.account-icon { width: 30px; height: 30px; flex: 0 0 30px; display: grid; place-items: center; color: var(--green); background: var(--green-soft); border-radius: 5px; font: 700 11px/1 ui-monospace, monospace; }
.balance-bar { height: 5px; overflow: hidden; background: #edf0ec; border-radius: 2px; }
.balance-bar span { display: block; height: 100%; background: var(--green); }
.balance-bar span.negative { background: var(--red); }
.account-balance { text-align: right; font: 700 14px/1.2 ui-monospace, monospace; }
.account-balance.negative { color: var(--red); }
.account-balance small { display: block; margin-top: 4px; color: var(--green); font: 700 9px/1.2 system-ui, sans-serif; }
.account-balance-stack { display: grid; gap: 4px; min-width: 145px; }
.account-balance-stack strong { display: block; }
.account-balance-stack span { color: var(--ink-soft); font-size: 10px; line-height: 1.35; overflow-wrap: anywhere; }

.usage-panel-header { align-items: flex-start; }
.usage-panel-note { color: var(--ink-soft); font-size: 10px; }
.provider-usage-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; padding: 14px 18px 18px; }
.provider-usage-card { min-width: 0; padding: 14px; background: #fafbf9; border: 1px solid var(--line); border-radius: 6px; }
.provider-usage-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; min-width: 0; }
.provider-usage-title h4 { margin: 0; font-size: 14px; }
.provider-usage-title span:not(.badge) { display: block; margin-top: 4px; color: var(--ink-soft); font-size: 10px; overflow-wrap: anywhere; }
.usage-stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 14px; }
.usage-stat { min-width: 0; padding: 9px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 4px; }
.usage-stat span, .usage-stat small { display: block; color: var(--ink-soft); font-size: 10px; overflow-wrap: anywhere; }
.usage-stat strong { display: block; margin-top: 5px; color: var(--ink); font: 700 15px/1.2 ui-monospace, "SFMono-Regular", Consolas, monospace; overflow-wrap: anywhere; }
.usage-stat small { margin-top: 4px; line-height: 1.3; }
.usage-visuals { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.usage-subhead { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.usage-subhead strong { font-size: 11px; }
.usage-subhead span { color: var(--ink-soft); font-size: 10px; }
.usage-trend { height: 92px; display: grid; grid-template-columns: repeat(auto-fit, minmax(22px, 1fr)); align-items: end; gap: 6px; padding: 8px 2px 0; border-bottom: 1px solid var(--line); }
.usage-trend-day { min-width: 0; height: 100%; display: grid; grid-template-rows: 1fr 15px; gap: 5px; align-items: end; text-align: center; }
.usage-trend-bar { height: 100%; display: flex; align-items: end; justify-content: center; }
.usage-trend-bar span { display: block; width: min(16px, 65%); min-height: 2px; background: var(--blue); border-radius: 2px 2px 0 0; }
.usage-trend-day small { color: var(--ink-soft); font-size: 9px; }
.usage-models { display: grid; gap: 8px; }
.usage-model-row { min-width: 0; }
.usage-model-top { display: flex; justify-content: space-between; gap: 8px; min-width: 0; }
.usage-model-top strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; }
.usage-model-top span { flex: 0 0 auto; color: var(--ink-soft); font-size: 9px; }
.usage-model-bar { height: 4px; margin-top: 4px; overflow: hidden; background: #e7ebe7; border-radius: 2px; }
.usage-model-bar span { display: block; height: 100%; background: var(--green); border-radius: 2px; }
.usage-empty { min-height: 92px; display: grid; place-items: center; color: var(--ink-soft); font-size: 11px; }
.usage-error { margin: 12px 0 0; padding: 8px 10px; color: var(--red); background: var(--red-soft); border-radius: 4px; font-size: 10px; overflow-wrap: anywhere; }

.chart { height: 242px; padding: 22px 18px 16px; display: grid; grid-template-columns: repeat(7, 1fr); align-items: end; gap: 12px; }
.chart-day { height: 100%; display: grid; grid-template-rows: 1fr 22px; gap: 8px; align-items: end; }
.chart-bars { height: 100%; display: flex; align-items: end; justify-content: center; gap: 4px; border-bottom: 1px solid var(--line); }
.chart-bar { width: min(13px, 40%); min-height: 2px; border-radius: 2px 2px 0 0; }
.chart-bar.income { background: var(--green); }
.chart-bar.outflow { background: var(--amber); }
.chart-label { color: #818b86; text-align: center; font: 10px/1 ui-monospace, monospace; }
.chart-legend { display: flex; gap: 14px; color: var(--ink-soft); font-size: 10px; }
.legend-dot { width: 7px; height: 7px; display: inline-block; margin-right: 5px; border-radius: 1px; }
.legend-dot.income { background: var(--green); }
.legend-dot.outflow { background: var(--amber); }

.segmented-control {
  display: inline-flex;
  padding: 3px;
  background: #edf0ec;
  border: 1px solid var(--line);
  border-radius: 5px;
}
.segment-button {
  min-width: 56px;
  height: 30px;
  padding: 0 10px;
  color: var(--ink-soft);
  background: transparent;
  border: 0;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 700;
}
.segment-button.is-active { color: #fff; background: var(--green); }
.cashflow-summary {
  min-height: 78px;
  padding: 14px 18px;
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr)) auto;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}
.cashflow-summary > div > span:not(.legend-dot) { display: block; color: var(--ink-soft); font-size: 10px; }
.cashflow-summary strong { display: block; margin-top: 6px; font: 700 18px/1 ui-monospace, monospace; }
.cashflow-summary strong.positive { color: var(--green); }
.cashflow-summary strong.negative { color: var(--red); }
.cashflow-chart-wrap { overflow-x: auto; }
.cashflow-chart {
  min-width: 680px;
  height: 278px;
  padding: 22px 18px 16px;
  display: flex;
  align-items: stretch;
  gap: 8px;
}
.cashflow-period {
  min-width: 38px;
  flex: 1 0 38px;
  display: grid;
  grid-template-rows: minmax(0, 1fr) 24px;
  gap: 8px;
}
.cashflow-bars {
  min-height: 0;
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 4px;
  border-bottom: 1px solid var(--line);
}
.cashflow-bar { width: min(15px, 42%); min-height: 2px; border-radius: 2px 2px 0 0; }
.cashflow-bar.income { background: var(--green); }
.cashflow-bar.outflow { background: var(--amber); }
.cashflow-label { color: #74807a; text-align: center; font: 10px/1 ui-monospace, monospace; white-space: nowrap; }

.notice {
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  color: #694017;
  background: var(--amber-soft);
  border: 1px solid #ecd2b3;
  border-radius: 5px;
  font-size: 12px;
  line-height: 1.6;
}
.notice strong { display: block; color: var(--amber); }
.notice-mark { font-weight: 800; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { min-width: 100px; padding: 13px 16px; text-align: left; border-bottom: 1px solid var(--line); font-size: 12px; }
th { color: #74807a; background: #fafbf9; font-size: 10px; font-weight: 700; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbf9; }
tbody tr.is-voided { opacity: .62; background: #f4f4f2; }
tbody tr.is-voided .amount { text-decoration: line-through; }
.accounts-table tr.is-admin-account { background: #fbf8f3; }
.amount { font: 700 12px/1.2 ui-monospace, monospace; white-space: nowrap; }
.amount.positive { color: var(--green); }
.amount.negative { color: var(--red); }
.muted { color: var(--ink-soft); }

.badge { display: inline-flex; align-items: center; min-height: 23px; padding: 0 8px; border-radius: 3px; font-size: 10px; font-weight: 700; white-space: nowrap; }
.badge.green { color: var(--green); background: var(--green-soft); }
.badge.amber { color: var(--amber); background: var(--amber-soft); }
.badge.blue { color: var(--blue); background: var(--blue-soft); }
.badge.gray { color: #5f6b66; background: #e9ece8; }
.badge.red { color: var(--red); background: var(--red-soft); }

.member-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.member-card { padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.member-card-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.member-card h3 { margin: 0; font-size: 14px; }
.member-balance-label { display: block; margin-top: 24px; color: var(--ink-soft); font-size: 10px; }
.member-balance { margin: 8px 0 6px; font: 700 25px/1 ui-monospace, monospace; }
.member-balance.positive { color: var(--green); }
.member-balance.negative { color: var(--red); }
.settlement-caption { min-height: 18px; margin-bottom: 14px; color: var(--ink-soft); font-size: 10px; }
.member-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding-top: 14px; border-top: 1px solid var(--line); }
.member-meta.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.member-meta span { display: block; color: var(--ink-soft); font-size: 10px; }
.member-meta strong { display: block; margin-top: 5px; font: 650 12px/1.2 ui-monospace, monospace; }

.empty-state { padding: 44px 20px; color: var(--ink-soft); text-align: center; }
.empty-state.compact { padding: 18px 12px; }
.loading-state { min-height: 50vh; display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--ink-soft); font-size: 12px; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--line-strong); border-top-color: var(--green); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 20, .56);
}

.modal {
  width: min(620px, 100%);
  max-height: min(790px, calc(100vh - 40px));
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.modal-header { min-height: 78px; padding: 18px 22px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.modal-header h3 { margin: 5px 0 0; font-size: 18px; }
.entry-form { padding: 22px; display: grid; gap: 17px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field { display: grid; gap: 7px; }
.field > span { color: var(--ink-soft); font-size: 11px; font-weight: 650; }
.field input, .field select, .field textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  outline: none;
}
.field textarea { min-height: 82px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(22,100,71,.1); }
.field-help { margin: -4px 0 0; color: var(--ink-soft); font-size: 10px; }
.form-preview { min-height: 52px; padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; gap: 16px; color: var(--green); background: var(--green-soft); border-radius: 4px; font-size: 11px; }
.form-preview strong { font: 700 18px/1 ui-monospace, monospace; }
.form-error { min-height: 18px; margin: 0; color: var(--red); font-size: 11px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }
.note-list { max-height: 230px; overflow-y: auto; border: 1px solid var(--line); border-radius: 4px; }
.note-item { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.note-item:last-child { border-bottom: 0; }
.note-item p { margin: 0; font-size: 12px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.note-item span { display: block; margin-top: 6px; color: var(--ink-soft); font-size: 10px; }

.toast-region { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: grid; gap: 8px; }
.toast { max-width: 340px; padding: 12px 14px; color: #fff; background: var(--sidebar); border: 1px solid #35453e; border-radius: 5px; box-shadow: 0 12px 35px rgba(23,32,29,.22); font-size: 12px; animation: toast-in .18s ease-out; }
.toast.error { background: #6f2a26; border-color: #914039; }
@keyframes toast-in { from { opacity: 0; transform: translateY(7px); } }

@media (max-width: 1080px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .provider-usage-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .content-grid { grid-template-columns: 1fr; }
  .member-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 780px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 14px; }
  .brand { padding: 0 4px 14px; }
  .nav { display: flex; overflow-x: auto; padding-bottom: 4px; }
  .nav-item { flex: 0 0 auto; width: auto; grid-template-columns: 1fr; min-height: 38px; padding: 0 12px; }
  .nav-index, .sidebar-footer { display: none; }
  .topbar { position: static; min-height: auto; padding: 16px 18px; align-items: flex-start; }
  .topbar-actions { justify-content: flex-end; flex-wrap: wrap; }
  .date-chip { display: none; }
  .topbar .button-secondary { display: none; }
  .monitor-header .button-secondary { display: inline-flex; }
  .provider-usage-grid { grid-template-columns: 1fr; }
  .balance-history-toolbar { align-items: flex-start; flex-wrap: wrap; }
  .balance-control-group-right { margin-left: auto; }
  main { padding: 20px 16px 36px; }
  .monitor-row { grid-template-columns: minmax(0, 1fr) 38px; gap: 12px; }
  .monitor-source { grid-column: 1; }
  .monitor-cell { grid-column: 1; grid-row: 2; }
  .monitor-refresh { grid-column: 2; grid-row: 1; }
  .member-grid { grid-template-columns: 1fr; }
  .member-meta.three { grid-template-columns: repeat(3, minmax(90px, 1fr)); overflow-x: auto; }
  .cashflow-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cashflow-summary .chart-legend { grid-column: 1 / -1; justify-self: start; }
  .accounts-table-panel { border: 0; background: transparent; }
  .accounts-table-wrap { overflow: visible; }
  .accounts-table thead { display: none; }
  .accounts-table,
  .accounts-table tbody,
  .accounts-table tr,
  .accounts-table td { display: block; width: 100%; }
  .accounts-table tbody { display: grid; gap: 12px; }
  .accounts-table tr {
    padding: 13px 15px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 6px;
  }
  .accounts-table td {
    min-width: 0;
    padding: 7px 0;
    display: grid;
    grid-template-columns: 78px minmax(0, 1fr);
    align-items: start;
    gap: 10px;
    border: 0;
    overflow-wrap: anywhere;
  }
  .accounts-table td::before {
    content: attr(data-label);
    color: #74807a;
    font-size: 10px;
    font-weight: 700;
  }
  .accounts-table td:first-child { padding-top: 0; font-size: 14px; }
  .accounts-table td:last-child { padding-bottom: 0; }
  .accounts-table .row-actions { min-width: 0; }
  .ledger-table-wrap { overflow: visible; }
  .ledger-table,
  .ledger-table tbody,
  .ledger-table tr,
  .ledger-table td { display: block; width: 100%; }
  .ledger-table thead { display: none; }
  .ledger-table tbody { display: grid; gap: 12px; }
  .ledger-table tr {
    padding: 13px 15px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 6px;
  }
  .ledger-table td {
    min-width: 0;
    padding: 6px 0;
    display: grid;
    grid-template-columns: 78px minmax(0, 1fr);
    align-items: start;
    gap: 10px;
    border: 0;
    overflow-wrap: anywhere;
    white-space: normal;
  }
  .ledger-table td::before {
    content: attr(data-label);
    color: #74807a;
    font-size: 10px;
    font-weight: 700;
  }
  .ledger-table td:first-child { padding-top: 0; }
  .ledger-table td:last-child { padding-bottom: 0; }
  .ledger-table .row-actions { min-width: 0; }
}

@media (max-width: 560px) {
  .login-panel { padding: 28px 22px; }
  .topbar h2 { font-size: 19px; }
  .topbar-actions .button { min-width: 42px; padding: 0 10px; }
  .metric-grid { grid-template-columns: 1fr; }
  .metric { min-height: 118px; border-right: 0; border-bottom: 1px solid var(--line); }
  .metric:last-child { border-bottom: 0; }
  .metric-value { font-size: 25px; }
  .monitor-header { align-items: flex-start; }
  .monitor-header { flex-direction: column; }
  .monitor-actions { width: 100%; align-items: stretch; flex-direction: column; }
  .monitor-settings { width: 100%; align-items: stretch; flex-direction: column; }
  .monitor-settings .monitor-strategy, .monitor-settings .compact-select, .monitor-settings .custom-hours-control { width: 100%; flex: none; }
  .monitor-strategy-option { min-width: 0; flex: 1; }
  .monitor-settings .custom-hours-control { min-width: 0; }
  .monitor-settings .custom-hours-control .compact-number { flex: 1; min-width: 0; }
  .monitor-actions .monitor-refresh-all { width: 100%; flex: none; }
  .balance-history-toolbar, .balance-control-group, .balance-control-group-right { width: 100%; }
  .balance-control-group-right { margin-left: 0; }
  .balance-control-group .compact-select { flex: 1; min-width: 0; }
  .balance-history-heading { align-items: flex-start; }
  .balance-history-summary { grid-template-columns: 1fr 1fr; }
  .balance-history-summary > div:nth-child(2) { border-right: 0; }
  .balance-history-summary > div:nth-child(3) { grid-column: 1 / -1; border-top: 1px solid var(--line); }
  .provider-usage-grid { padding: 12px; }
  .usage-visuals { grid-template-columns: 1fr; }
  .monitor-row { grid-template-columns: minmax(0, 1fr) 38px; }
  .monitor-source { grid-column: 1; }
  .monitor-cell { grid-column: 1; grid-row: 2; }
  .monitor-refresh { grid-column: 2; grid-row: 1; }
  .account-row { grid-template-columns: minmax(140px, 1fr) 92px; gap: 12px; }
  .account-row .balance-bar { display: none; }
  .section-header { align-items: flex-start; flex-direction: column; }
  .cashflow-header { align-items: flex-start; flex-direction: column; }
  .cashflow-summary { grid-template-columns: 1fr 1fr; }
  .cashflow-summary > div:nth-child(3) { grid-column: 1 / -1; }
  .cashflow-summary strong { font-size: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .modal-backdrop { padding: 0; place-items: end center; }
  .modal { width: 100%; max-height: 92vh; border-radius: 8px 8px 0 0; }
  .chart { gap: 6px; }
}
