:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --line: #d8e0e8;
  --line-soft: #eaf0f5;
  --text: #102033;
  --muted: #607081;
  --muted-2: #8b9aab;
  --green: #118f5a;
  --green-strong: #0e6f46;
  --green-soft: #dff3ea;
  --red: #c03a32;
  --yellow: #b67b00;
  --blue: #1f6feb;
  --shadow: 0 10px 26px rgba(16, 32, 51, 0.06);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1114;
  --surface: #15191e;
  --surface-2: #1b2026;
  --line: #2b323a;
  --line-soft: #22282f;
  --text: #f1f4f6;
  --muted: #8e99a4;
  --muted-2: #66717c;
  --green: #22c89a;
  --green-strong: #1d7a63;
  --green-soft: rgba(34, 200, 154, 0.12);
  --red: #f0646a;
  --yellow: #e5b84c;
  --blue: #5ba8ed;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.42);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  font-size: 13px;
  letter-spacing: 0;
}
button, input { font: inherit; letter-spacing: 0; color: var(--text); }
button { cursor: pointer; }
.hidden { display: none !important; }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at top left, rgba(31, 111, 235, 0.12) 0%, rgba(31, 111, 235, 0) 34%),
    radial-gradient(circle at bottom right, rgba(17, 143, 90, 0.12) 0%, rgba(17, 143, 90, 0) 30%),
    linear-gradient(180deg, #f3f6f9 0%, #eaf0f5 100%);
}
.login-panel {
  width: min(420px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.login-badge {
  display: inline-flex;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green-strong);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}
.login-title { margin: 14px 0 6px; font-size: 28px; line-height: 1.2; }
.login-subtitle { margin: 0 0 16px; color: var(--muted); line-height: 1.6; }
.login-grid { display: grid; gap: 14px; margin-top: 14px; }
.login-grid label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.login-grid input {
  width: 100%;
  height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}
.login-grid input:focus { outline: 2px solid rgba(31, 111, 235, 0.16); }
.status-line { min-height: 18px; color: var(--red); font-size: 12px; }

.btn {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
}
.btn.primary { border-color: var(--green-strong); background: var(--green); color: #ffffff; font-weight: 700; }
.btn.secondary { background: var(--surface); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.danger { border-color: #c03a32; background: #fde8e6; color: #a03b3b; }
.btn.small { min-height: 26px; padding: 0 8px; font-size: 11px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.app-shell { min-height: 100vh; }
.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--green);
  color: #ffffff;
  font-size: 12px;
  font-weight: 800;
}
.brand strong { display: block; font-size: 14px; }
.brand small { display: block; color: var(--muted); font-size: 10px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.user-pill { color: var(--muted); font-size: 12px; }
.backend-error { padding: 8px 20px; text-align: center; background: #c03a32; color: #fff; }

.workspace { width: min(1500px, 100%); margin: 0 auto; padding: 22px; }
.view-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.view-heading h1 { margin: 4px 0 4px; font-size: 24px; line-height: 1.2; }
.view-heading p { margin: 0; color: var(--muted); }
.eyebrow { margin: 0; color: var(--green-strong); font-size: 10px; font-weight: 750; text-transform: uppercase; }
.portfolio-status { display: flex; align-items: center; gap: 8px; }
.portfolio-sync { color: var(--muted); }
.portfolio-sync.ok { color: var(--green-strong); }
.portfolio-sync.warn { color: var(--yellow); }
.portfolio-sync.muted { color: var(--muted-2); }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.summary-grid article { min-width: 0; padding: 14px 16px; border-right: 1px solid var(--line-soft); }
.summary-grid article:last-child { border-right: 0; }
.summary-grid span, .summary-grid em { display: block; color: var(--muted); font-size: 10px; font-style: normal; }
.summary-grid strong { display: block; overflow-wrap: anywhere; margin: 6px 0 4px; font-size: 20px; line-height: 1.2; }
.positive { color: var(--green-strong) !important; }
.negative { color: var(--red) !important; }

.portfolio-content { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 14px; margin-top: 14px; }
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line-soft);
}
.panel-title h2 { margin: 2px 0 0; font-size: 14px; }
.panel-title > span { color: var(--muted); font-size: 10px; }
.allocation-body { min-height: 210px; padding: 14px 16px; }
.allocation-row {
  display: grid;
  grid-template-columns: 8px 1fr auto;
  align-items: center;
  gap: 9px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line-soft);
}
.allocation-row:last-child { border-bottom: 0; }
.allocation-row span, .allocation-row small { display: block; min-width: 0; }
.allocation-row small { color: var(--muted); font-size: 9px; }
.dot { width: 7px; height: 7px; border-radius: 50%; }
.dot-0 { background: #118f5a; } .dot-1 { background: #b67b00; }
.dot-2 { background: #1f6feb; } .dot-3 { background: #e46a2a; }
.dot-4 { background: #8250df; } .dot-5 { background: #c9467d; }

.balance-list { min-height: 210px; max-height: 320px; overflow: auto; }
.asset-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line-soft);
}
.asset-row strong, .asset-row small { display: block; }
.asset-row small { color: var(--muted); font-size: 9px; }
.asset-row > span { text-align: right; }

.activity-panel { margin-top: 14px; }
.activity-title { align-items: center; }
.activity-toolbar { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line-soft); }
.tabs { display: flex; gap: 3px; }
.tab {
  min-height: 30px;
  padding: 0 9px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  white-space: nowrap;
}
.tab.active { background: var(--surface-2); color: var(--text); }
.activity-query {
  min-width: 130px;
  height: 34px;
  margin-left: auto;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}
.activity-table-wrap { min-height: 220px; max-height: 340px; overflow: auto; }

.tables-panel { margin-top: 14px; }
.panel-tabs { display: flex; align-items: center; gap: 3px; min-height: 42px; padding: 5px 8px; border-bottom: 1px solid var(--line); }
.table-wrap { max-height: 440px; overflow: auto; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 9px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 9px;
  font-weight: 600;
  text-align: left;
  text-transform: uppercase;
}
td { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); font-size: 11px; }
td small { display: block; color: var(--muted); font-size: 9px; }
tbody tr:hover { background: rgba(232, 240, 245, 0.65); }
.tag, .status-tag { display: inline-block; padding: 2px 5px; border-radius: 4px; background: var(--surface-2); font-size: 9px; }
.tag.long, .status-tag { color: var(--green-strong); }
.tag.short { color: var(--red); }
.reference { color: var(--muted); font-family: ui-monospace, monospace; font-size: 9px; }
.empty-state { min-height: 160px; display: grid; place-items: center; padding: 20px; color: var(--muted); text-align: center; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(16, 32, 51, 0.45);
}
.settings-dialog {
  width: min(560px, 100%);
  max-height: 85vh;
  overflow: auto;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.settings-dialog header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.settings-dialog h2 { margin: 0; font-size: 18px; }
.setting-section { padding: 14px 0; border-bottom: 1px solid var(--line-soft); }
.setting-section:last-child { border-bottom: 0; }
.setting-section h3 { margin: 0 0 10px; font-size: 13px; }
.setting-form { display: grid; gap: 10px; }
.setting-form label { display: grid; gap: 5px; color: var(--muted); font-size: 11px; }
.setting-form input {
  width: 100%;
  height: 36px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }
.user-list { display: grid; gap: 6px; }
.user-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px; border: 1px solid var(--line-soft); border-radius: 6px; }
.user-row strong, .user-row small { display: block; }
.user-row small { color: var(--muted); font-size: 9px; }

:root[data-theme="dark"] .login-screen {
  background:
    radial-gradient(circle at 50% 0%, #14232b, #0b0e12 52%);
}
:root[data-theme="dark"] .topbar { background: rgba(15, 17, 20, 0.92); }
:root[data-theme="dark"] .login-badge,
:root[data-theme="dark"] .btn.danger { color: var(--green); }
:root[data-theme="dark"] .btn.primary { color: #07120f; }
:root[data-theme="dark"] .brand-mark { color: #07120f; }
:root[data-theme="dark"] .eyebrow { color: var(--green); }
:root[data-theme="dark"] .positive { color: var(--green) !important; }
:root[data-theme="dark"] .portfolio-sync.ok { color: var(--green); }
:root[data-theme="dark"] tbody tr:hover { background: rgba(27, 32, 38, 0.7); }
:root[data-theme="dark"] .modal-backdrop { background: rgba(4, 7, 10, 0.76); }

@media (max-width: 1050px) {
  .summary-grid { grid-template-columns: repeat(3, 1fr); }
  .summary-grid article:nth-child(3) { border-right: 0; }
  .summary-grid article:nth-child(n+4) { border-top: 1px solid var(--line-soft); }
  .portfolio-content { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  .topbar { height: 52px; padding: 0 12px; }
  .brand small { display: none; }
  .workspace { padding: 14px 10px 24px; }
  .view-heading { align-items: flex-start; flex-direction: column; }
  .view-heading h1 { font-size: 20px; }
  .portfolio-status { width: 100%; justify-content: space-between; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .summary-grid article, .summary-grid article:nth-child(3) { border-right: 1px solid var(--line-soft); border-top: 1px solid var(--line-soft); }
  .summary-grid article:nth-child(-n+2) { border-top: 0; }
  .summary-grid article:nth-child(even) { border-right: 0; }
  .summary-grid article:last-child { grid-column: 1 / -1; }
  .activity-toolbar { align-items: stretch; flex-direction: column; }
  .activity-query { margin: 0; }
  .tabs { overflow-x: auto; }
}
