:root {
  --bg: #f4f7f8;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --border: #dfe6e9;
  --text: #17202a;
  --muted: #74808d;
  --primary: #0f9f93;
  --primary-dark: #087c73;
  --green: #16a56f;
  --blue: #3478e5;
  --violet: #8b5cf6;
  --orange: #e69227;
  --red: #e5485d;
  --shadow: 0 1px 2px rgba(19, 34, 46, 0.05), 0 8px 24px rgba(35, 56, 68, 0.05);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { background: var(--bg); font-size: 14px; letter-spacing: 0; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
.hidden { display: none !important; }
.mobile-only { display: none !important; }

.auth-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 34px;
  padding: 32px 18px;
  background:
    linear-gradient(135deg, rgba(15, 159, 147, 0.08), transparent 48%),
    var(--bg);
}
.auth-brand { display: flex; align-items: center; gap: 13px; }
.auth-brand strong { display: block; font-size: 25px; }
.auth-brand span { display: block; margin-top: 4px; color: var(--muted); }
.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: white;
  font-size: 23px;
  font-weight: 800;
  background: linear-gradient(145deg, #10a99c, #2867c9);
  box-shadow: 0 8px 22px rgba(15, 159, 147, 0.22);
}
.brand-mark.small { width: 36px; height: 36px; font-size: 17px; }
.auth-panel {
  width: min(420px, 100%);
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--border); margin-bottom: 24px; }
.auth-tab { border: 0; background: transparent; padding: 11px; color: var(--muted); font-weight: 650; border-bottom: 2px solid transparent; }
.auth-tab.active { color: var(--primary-dark); border-color: var(--primary); }
.auth-form { display: grid; gap: 18px; }
label { display: grid; gap: 7px; color: #4e5a66; font-weight: 600; }
input, select, textarea {
  width: 100%;
  min-height: 40px;
  padding: 9px 11px;
  border: 1px solid #cfd8dc;
  border-radius: 6px;
  outline: none;
  color: var(--text);
  background: white;
}
textarea { min-height: 82px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15, 159, 147, 0.12); }
.form-error { min-height: 20px; margin: 10px 0 0; color: var(--red); font-size: 13px; }

.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  width: 232px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface);
}
.sidebar-brand { height: 72px; display: flex; align-items: center; gap: 11px; padding: 0 20px; font-size: 18px; border-bottom: 1px solid var(--border); }
.primary-nav { flex: 1; overflow-y: auto; padding: 16px 10px; }
.nav-section { margin: 18px 12px 7px; color: #9aa4ad; font-size: 11px; font-weight: 750; text-transform: uppercase; }
.nav-button {
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  color: #596572;
  background: transparent;
  text-align: left;
  font-weight: 620;
}
.nav-button svg { width: 18px; height: 18px; flex: 0 0 auto; }
.nav-button:hover { background: #f4f8f8; color: var(--text); }
.nav-button.active { color: var(--primary-dark); background: #eaf8f6; }
.nav-button.active svg { color: var(--primary); }
.sidebar-footer { padding: 12px 10px 18px; border-top: 1px solid var(--border); }
.danger-link:hover { color: var(--red); background: #fff1f3; }
.sidebar-scrim { display: none; }

.workspace { min-height: 100vh; margin-left: 232px; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
}
.topbar-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar h1 { margin: 0; font-size: 19px; line-height: 1.25; }
.topbar p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.icon-button {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: #65717d;
  background: white;
}
.icon-button:hover { color: var(--primary-dark); border-color: #b9d9d5; background: #f0faf8; }
.icon-button svg { width: 18px; height: 18px; }
.balance-pill { height: 38px; display: flex; align-items: center; gap: 8px; padding: 0 13px; border-radius: 6px; color: var(--primary-dark); background: #eaf8f6; font-weight: 750; }
.balance-pill svg { width: 17px; height: 17px; }
.profile-button { height: 46px; display: flex; align-items: center; gap: 9px; padding: 4px 8px; border: 0; background: transparent; color: var(--text); border-radius: 6px; }
.profile-button:hover { background: #f4f7f8; }
.profile-button > svg { width: 16px; color: var(--muted); }
.avatar { width: 34px; height: 34px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; color: white; background: #1a9d91; font-weight: 750; }
.profile-copy { display: grid; text-align: left; max-width: 150px; }
.profile-copy strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-copy small { color: var(--muted); margin-top: 2px; }

.content { width: 100%; max-width: 1680px; margin: 0 auto; padding: 28px; outline: none; }
.content.loading { opacity: 0.62; pointer-events: none; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.page-head h2 { margin: 0; font-size: 17px; }
.page-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; }
.button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 670;
}
.button svg { width: 17px; height: 17px; }
.button.primary { color: white; background: var(--primary); border-color: var(--primary); }
.button.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.button.secondary { color: #52606c; background: white; border-color: var(--border); }
.button.secondary:hover { color: var(--text); border-color: #bcc8ce; background: #f8fafb; }
.button.danger { color: var(--red); background: #fff; border-color: #f1c8cf; }
.button.danger:hover { background: #fff1f3; }
.button.small { min-height: 31px; padding: 5px 9px; font-size: 12px; }
.button.wide { width: 100%; }
.button:disabled { cursor: not-allowed; opacity: 0.55; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.metric-card { min-height: 112px; display: flex; align-items: center; gap: 15px; padding: 20px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.metric-icon { width: 42px; height: 42px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 8px; }
.metric-icon svg { width: 22px; height: 22px; }
.metric-icon.green { color: var(--green); background: #e6f8ef; }
.metric-icon.blue { color: var(--blue); background: #e9f1ff; }
.metric-icon.violet { color: var(--violet); background: #f2ebff; }
.metric-icon.orange { color: var(--orange); background: #fff4df; }
.metric-icon.red { color: var(--red); background: #ffecef; }
.metric-copy { min-width: 0; }
.metric-label { color: var(--muted); font-weight: 620; }
.metric-value { margin-top: 3px; font-size: 23px; line-height: 1.15; font-weight: 780; overflow-wrap: anywhere; }
.metric-note { margin-top: 5px; color: #89939d; font-size: 12px; }

.section {
  margin-bottom: 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.section-header { min-height: 56px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 18px; border-bottom: 1px solid var(--border); }
.section-header h2, .section-header h3 { margin: 0; font-size: 15px; }
.section-header span { color: var(--muted); font-size: 12px; }
.section-body { padding: 18px; }
.split-grid { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.4fr); gap: 18px; }
.provider-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.provider-item { min-width: 0; padding: 14px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-soft); }
.provider-item header { display: flex; justify-content: space-between; gap: 8px; font-weight: 730; }
.provider-item header strong, .provider-item header span { overflow-wrap: anywhere; }
.provider-item header span { color: var(--violet); }
.provider-item dl { display: grid; grid-template-columns: 1fr auto; gap: 7px 12px; margin: 13px 0 0; }
.provider-item dt { color: var(--muted); }
.provider-item dd { margin: 0; font-variant-numeric: tabular-nums; }
.empty-state { min-height: 150px; display: grid; place-items: center; align-content: center; gap: 10px; color: var(--muted); text-align: center; }
.empty-state svg { width: 30px; height: 30px; color: #9eb0b7; }

.donut-wrap { min-height: 270px; display: grid; grid-template-columns: 190px minmax(0, 1fr); align-items: center; gap: 24px; }
.donut { width: 180px; aspect-ratio: 1; position: relative; border-radius: 50%; background: #e9edef; }
.donut::after { content: ""; position: absolute; inset: 29%; border-radius: 50%; background: white; }
.legend { display: grid; gap: 10px; min-width: 0; }
.legend-row { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; align-items: center; gap: 9px; }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; }
.legend-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend-value { color: var(--muted); font-variant-numeric: tabular-nums; }
.chart-wrap { width: 100%; height: 280px; }
.chart-wrap canvas { width: 100%; height: 100%; display: block; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 12px 14px; border-bottom: 1px solid #e8edef; text-align: left; vertical-align: middle; }
th { color: #6e7a86; background: #f8fafb; font-size: 12px; font-weight: 720; white-space: nowrap; }
td { font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fbfdfd; }
.cell-main { display: block; font-weight: 650; color: var(--text); }
.cell-sub { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.positive { color: var(--green); }
.negative { color: var(--red); }
.badge { display: inline-flex; align-items: center; min-height: 24px; padding: 3px 8px; border-radius: 999px; font-size: 12px; font-weight: 680; white-space: nowrap; }
.badge.success { color: #08724e; background: #e6f7ef; }
.badge.warning { color: #9a5d08; background: #fff3db; }
.badge.danger { color: #b52b40; background: #ffecef; }
.badge.neutral { color: #66727e; background: #edf1f3; }
.actions-inline { display: flex; align-items: center; gap: 7px; white-space: nowrap; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.inline-form { display: flex; align-items: end; flex-wrap: wrap; gap: 12px; }
.inline-form label { min-width: 180px; flex: 1; }
.quick-amounts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; }
.quick-amounts button { min-height: 42px; border: 1px solid var(--border); border-radius: 6px; color: var(--text); background: white; font-weight: 700; }
.quick-amounts button:hover, .quick-amounts button.active { color: var(--primary-dark); border-color: var(--primary); background: #eefaf8; }
.code-box { display: flex; align-items: center; gap: 10px; padding: 13px; border: 1px solid #cbd9dc; border-radius: 6px; background: #f5f9fa; }
.code-box code { flex: 1; min-width: 0; overflow-wrap: anywhere; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.margin-bar { width: 94px; height: 7px; overflow: hidden; border-radius: 999px; background: #e9edef; }
.margin-bar span { display: block; height: 100%; background: var(--green); }

.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: rgba(18, 29, 38, 0.48); cursor: default; }
.modal-panel { position: relative; width: min(560px, 100%); max-height: min(760px, calc(100vh - 40px)); overflow-y: auto; border-radius: 8px; background: white; box-shadow: 0 22px 70px rgba(8, 22, 31, 0.22); }
.modal-header { min-height: 58px; display: flex; align-items: center; justify-content: space-between; padding: 10px 16px 10px 20px; border-bottom: 1px solid var(--border); }
.modal-header h2 { margin: 0; font-size: 17px; }
.modal-body { display: grid; gap: 16px; padding: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; padding: 15px 20px 20px; }
.modal .form-error { padding: 0 20px; }
.toast-region { position: fixed; right: 20px; bottom: 20px; z-index: 150; display: grid; gap: 9px; pointer-events: none; }
.toast { width: min(360px, calc(100vw - 40px)); padding: 12px 14px; border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: 6px; color: var(--text); background: white; box-shadow: 0 12px 35px rgba(20, 37, 48, 0.15); animation: toast-in 160ms ease-out; }
.toast.error { border-left-color: var(--red); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

@media (max-width: 1260px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .provider-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split-grid { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .mobile-only { display: grid !important; }
  .sidebar { transform: translateX(-100%); transition: transform 180ms ease; box-shadow: 14px 0 42px rgba(20, 37, 48, 0.14); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-scrim { position: fixed; inset: 0; z-index: 25; display: block; background: rgba(17, 29, 37, 0.38); opacity: 0; pointer-events: none; transition: opacity 180ms ease; }
  .sidebar-scrim.open { opacity: 1; pointer-events: auto; }
  .workspace { margin-left: 0; }
  .topbar { padding: 0 16px; }
  .content { padding: 18px 14px 28px; }
  .profile-copy, .profile-button > svg { display: none; }
  .profile-button { padding: 4px; }
  .topbar p { display: none; }
  .donut-wrap { grid-template-columns: 150px minmax(0, 1fr); }
  .donut { width: 145px; }
}

@media (max-width: 560px) {
  .topbar { height: 64px; }
  .topbar h1 { font-size: 17px; }
  .balance-pill { padding: 0 10px; }
  .topbar-actions { gap: 6px; }
  .topbar-actions > .icon-button { display: none; }
  .metric-grid { grid-template-columns: 1fr; gap: 11px; }
  .metric-card { min-height: 96px; padding: 16px; }
  .metric-value { font-size: 21px; }
  .provider-grid { grid-template-columns: 1fr; }
  .donut-wrap { grid-template-columns: 1fr; justify-items: center; }
  .legend { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .quick-amounts { grid-template-columns: repeat(2, 1fr); }
  .page-head { align-items: flex-start; }
  .page-head h2 { padding-top: 8px; }
  .section-body { padding: 14px; }
  .section-header { padding: 12px 14px; }
  .modal { padding: 10px; }
  .modal-panel { max-height: calc(100vh - 20px); }
}
