:root {
  color-scheme: dark light;

  --brand: #F45944;
  /* CN market convention: red = up, green = down */
  --up: #ef4444;
  --down: #22c55e;
  /* Semantic colors (keep danger as red) */
  --good: #22c55e;
  --bad: #ef4444;
  --warn: #f59e0b;

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;

  /* Dark (default). Light will be provided by prefers-color-scheme. */
  --bg: #0b1220;
  --card: #111a2e;
  --text: #e6edf3;
  --muted: #9fb0c0;
  --line: rgba(255, 255, 255, 0.08);
  --card-header-bg: rgba(255, 255, 255, 0.02);
  --control-bg: rgba(255, 255, 255, 0.04);
  --control-bg-hover: rgba(255, 255, 255, 0.07);
  --scrollbar-thumb: rgba(255, 255, 255, 0.22);
  --scrollbar-thumb-hover: rgba(255, 255, 255, 0.32);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f7f8;
    --card: #ffffff;
    --text: #111827;
    --muted: #6b7280;
    --line: rgba(0, 0, 0, 0.08);
    --card-header-bg: rgba(0, 0, 0, 0.02);
    --control-bg: rgba(0, 0, 0, 0.03);
    --control-bg-hover: rgba(0, 0, 0, 0.05);
    --scrollbar-thumb: rgba(0, 0, 0, 0.18);
    --scrollbar-thumb-hover: rgba(0, 0, 0, 0.28);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1220;
  --card: #111a2e;
  --text: #e6edf3;
  --muted: #9fb0c0;
  --line: rgba(255, 255, 255, 0.08);
  --card-header-bg: rgba(255, 255, 255, 0.02);
  --control-bg: rgba(255, 255, 255, 0.04);
  --control-bg-hover: rgba(255, 255, 255, 0.07);
  --scrollbar-thumb: rgba(255, 255, 255, 0.22);
  --scrollbar-thumb-hover: rgba(255, 255, 255, 0.32);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f7f8;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: rgba(0, 0, 0, 0.08);
  --card-header-bg: rgba(0, 0, 0, 0.02);
  --control-bg: rgba(0, 0, 0, 0.03);
  --control-bg-hover: rgba(0, 0, 0, 0.05);
  --scrollbar-thumb: rgba(0, 0, 0, 0.18);
  --scrollbar-thumb-hover: rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
}

html {
  /* Keep layout width stable when some pages scroll. */
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  line-height: 1.45;
  /* Minimal background (no "scrolling wallpaper"). */
  background: var(--bg);
  color: var(--text);
  overflow-y: scroll;
}

a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  max-width: 1024px;
  margin: 0 auto;
  padding: 16px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  max-width: 1024px;
  margin: 0 auto;
  flex-wrap: wrap;
}

.top-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  flex-wrap: wrap;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
  letter-spacing: 0.2px;
}

.brand.auth-brand {
  width: 100%;
  justify-content: center;
}

.brand-title {
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0.1px;
  color: var(--text);
}

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

.brand-domain {
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.6px;
  color: var(--muted);
}

.brand.auth-brand .brand-text {
  align-items: center;
  text-align: center;
}

.brand-logo {
  width: 32px;
  height: 32px;
  display: block;
}
.brand-logo.lg {
  width: 44px;
  height: 44px;
}

.brand-badge {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  background: rgba(244, 89, 68, 0.14);
  border: 1px solid rgba(244, 89, 68, 0.3);
  color: var(--text);
  font-weight: 800;
}

.menu {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-left: 10px;
}

.menu a {
  padding: 2px 0;
  color: var(--muted);
  font-weight: 400;
  font-size: 13px;
  letter-spacing: 0.2px;
  text-decoration: none;
}
.menu a:hover {
  color: var(--text);
  text-decoration: none;
}
.menu a.active {
  color: var(--brand);
  text-decoration: none;
}

.tabs {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.tab {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 2px 0;
  cursor: pointer;
  font-weight: 400;
  letter-spacing: 0.2px;
  color: var(--muted);
}
.tab:hover { color: var(--text); }
.tab.active,
.tab[aria-selected="true"] {
  color: var(--brand);
}

.nav {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.nav a {
  padding: 8px 10px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  color: var(--muted);
}
.nav a.active, .nav a:hover {
  color: var(--text);
  border-color: var(--line);
  background: var(--control-bg);
  text-decoration: none;
}

.btn.icon-btn.mobile-menu-btn {
  display: none;
}

@media (max-width: 640px) {
  .topbar .menu { display: none; }
  .topbar .nav #btnLang,
  .topbar .nav #btnTheme,
  .topbar .nav .user-menu { display: none; }
  .topbar .nav .btn.icon-btn.mobile-menu-btn { display: grid; }
}

.user-menu {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.user-trigger {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 2px 0;
  margin-left: 6px;
  cursor: pointer;
  font-weight: 400;
  letter-spacing: 0.2px;
  color: var(--muted);
}
.user-trigger:hover { color: var(--text); }

.user-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  z-index: 30;
  min-width: 160px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--card);
  padding: 6px;
  display: none;
  flex-direction: column;
  gap: 4px;
}

.user-dropdown:not([hidden]) {
  display: flex;
}

.dropdown-item {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  padding: 8px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 13px;
  font-weight: 400;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-decoration: none;
}
.dropdown-item:hover {
  background: var(--control-bg-hover);
  text-decoration: none;
}
.dropdown-item.danger { color: var(--bad); }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--control-bg);
  color: var(--text);
  padding: 8px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: 400;
  font-size: 13px;
  line-height: 1.15;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
  transition: background 120ms ease, border-color 120ms ease;
}
.btn:hover { background: var(--control-bg-hover); }
.btn:active { background: var(--control-bg-hover); }
.btn:focus {
  outline: none;
}
.btn:focus-visible {
  outline: none;
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn:disabled:hover,
.btn:disabled:active {
  background: var(--control-bg);
}
.btn.primary {
  border-color: rgba(244, 89, 68, 0.55);
  background: rgba(244, 89, 68, 0.16);
  color: var(--text);
}
.btn.danger {
  border-color: rgba(239, 68, 68, 0.45);
  background: rgba(239, 68, 68, 0.14);
}
.btn.sm {
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 12px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 0;
  background: transparent;
}
.icon-btn:hover {
  color: var(--text);
  border: 0;
  background: transparent;
}
.icon-btn:active {
  border: 0;
  background: transparent;
}
.icon-btn svg { width: 18px; height: 18px; display: block; }

.lang-icon {
  font-size: 11px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0.35px;
}

.ico {
  width: 16px;
  height: 16px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
}
.ico svg {
  width: 16px;
  height: 16px;
  display: block;
}

.btn.sm .ico { width: 14px; height: 14px; }
.btn.sm .ico svg { width: 14px; height: 14px; }

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--card);
}

.card-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  background: var(--card-header-bg);
}
.card-title { font-weight: 700; }
.card-body { padding: 14px 16px; }

.grid {
  display: grid;
  gap: 12px;
}
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

@media (max-width: 760px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3 { grid-template-columns: 1fr; }
  .grid.cols-2 { grid-template-columns: 1fr; }
  .topbar-inner { padding: 10px 12px; }
}

.muted { color: var(--muted); }
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 22px 16px;
  text-align: center;
  color: var(--muted);
  min-height: 140px;
}
.loading-state::before {
  content: none;
}
.loading-state[aria-busy="true"]::before {
  content: "";
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 2px solid var(--line);
  border-top-color: var(--brand);
  opacity: 0.95;
  animation: jgfund-spin 0.9s linear infinite;
}

.loading-inline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  text-align: center;
}
.loading-inline::before {
  content: none;
}
.loading-inline[aria-busy="true"]::before {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 2px solid var(--line);
  border-top-color: var(--brand);
  opacity: 0.95;
  animation: jgfund-spin 0.9s linear infinite;
}

@keyframes jgfund-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .loading-state[aria-busy="true"]::before,
  .loading-inline[aria-busy="true"]::before {
    animation: none;
  }
}
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 22px 16px;
  text-align: center;
  color: var(--muted);
  min-height: 120px;
  height: 100%;
}
.empty-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--control-bg);
  display: grid;
  place-items: center;
  color: var(--muted);
}
.empty-icon .ico,
.empty-icon svg {
  width: 22px;
  height: 22px;
}
.empty-icon .ico svg {
  width: 22px;
  height: 22px;
}
.empty-title {
  color: var(--text);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.2px;
}
.empty-desc {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
  max-width: 460px;
}
.kpi {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 20px; font-weight: 800; letter-spacing: 0.2px; }
.kpi .hint { font-size: 12px; color: var(--muted); }

.pos { color: var(--up); }
.neg { color: var(--down); }
.warn { color: var(--warn); }

table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th { color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: 0.2px; }
td { font-size: 14px; }

tbody tr:hover td {
  background: var(--control-bg);
}
tbody tr[data-code] {
  cursor: pointer;
}

.table-wrap {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

/* Keep tables in table layout on mobile; allow horizontal scroll instead. */
.holdings-table {
  min-width: 820px;
  table-layout: fixed;
}
.holdings-table col.col-drag { width: 38px; }
.holdings-table col.col-fund { width: 240px; }
.holdings-table col.col-cost { width: 150px; }
.holdings-table col.col-value { width: 150px; }
.holdings-table col.col-today { width: 130px; }
.holdings-table col.col-pnl { width: 150px; }

.holdings-table th[data-sort-key] {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  position: relative;
  padding-right: 22px;
}
.holdings-table th[data-sort-key]::before,
.holdings-table th[data-sort-key]::after {
  content: "";
  position: absolute;
  right: 6px;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  opacity: 0.35;
  pointer-events: none;
}
.holdings-table th[data-sort-key]::before {
  top: 50%;
  transform: translateY(-7px);
  border-bottom: 5px solid var(--muted);
}
.holdings-table th[data-sort-key]::after {
  top: 50%;
  transform: translateY(1px);
  border-top: 5px solid var(--muted);
}
.holdings-table th[data-sort-key]:hover {
  color: var(--text);
}
.holdings-table th[data-sort-key]:hover::before,
.holdings-table th[data-sort-key]:hover::after {
  opacity: 0.55;
}
.holdings-table th[data-sort-key][data-sort-active="1"] {
  color: var(--text);
  background: rgba(244, 89, 68, 0.06);
}
.holdings-table th[data-sort-key][data-sort-active="1"][data-sort-dir="asc"]::before {
  border-bottom-color: var(--brand);
  opacity: 0.95;
}
.holdings-table th[data-sort-key][data-sort-active="1"][data-sort-dir="asc"]::after {
  opacity: 0.15;
}
.holdings-table th[data-sort-key][data-sort-active="1"][data-sort-dir="desc"]::after {
  border-top-color: var(--brand);
  opacity: 0.95;
}
.holdings-table th[data-sort-key][data-sort-active="1"][data-sort-dir="desc"]::before {
  opacity: 0.15;
}

#btnCustomSort.active {
  border-color: rgba(244, 89, 68, 0.6);
  background: rgba(244, 89, 68, 0.14);
}

.holdings-table .drag-col {
  text-align: center;
}

.holdings-table:not([data-sort-mode="custom"]) col.col-drag { width: 0; }
.holdings-table:not([data-sort-mode="custom"]) th.drag-col,
.holdings-table:not([data-sort-mode="custom"]) td.drag-col {
  padding: 0;
  width: 0;
  border-bottom-color: transparent;
}
.holdings-table:not([data-sort-mode="custom"]) .drag-handle { display: none; }

.drag-handle {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 6px;
  border-radius: var(--radius-md);
  display: inline-grid;
  place-items: center;
  cursor: grab;
}
.drag-handle:hover {
  background: var(--control-bg);
  border-color: var(--line);
  color: var(--text);
}
.drag-handle:active { cursor: grabbing; }

.holdings-table tr.dragging td {
  background: var(--control-bg);
  opacity: 0.72;
}

.market-table {
  min-width: 640px;
  table-layout: fixed;
}
.market-table col.col-name { width: 260px; }
.market-table col.col-price { width: 130px; }
.market-table col.col-chg { width: 140px; }
.market-table col.col-time { width: 110px; }
.market-table td:nth-child(n + 2) { text-align: right; }

.market-cards {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

@media (max-width: 900px) {
  .market-cards {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.market-quote-card {
  position: relative;
  overflow: hidden;
  /* Keep base background aligned with theme card color. */
  background-image: none;
  transition: border-color 120ms ease, background-image 120ms ease;
}

.market-quote-card.market-dir-up {
  border-color: rgba(239, 68, 68, 0.18);
  background-image: linear-gradient(0deg, rgba(239, 68, 68, 0.045), rgba(239, 68, 68, 0.045));
}
.market-quote-card.market-dir-down {
  border-color: rgba(34, 197, 94, 0.18);
  background-image: linear-gradient(0deg, rgba(34, 197, 94, 0.045), rgba(34, 197, 94, 0.045));
}
.market-quote-card:hover {
  border-color: rgba(244, 89, 68, 0.28);
  background-image: linear-gradient(0deg, var(--control-bg-hover), var(--control-bg-hover));
}
.market-quote-card.market-dir-up:hover {
  border-color: rgba(239, 68, 68, 0.34);
  background-image:
    linear-gradient(0deg, rgba(239, 68, 68, 0.07), rgba(239, 68, 68, 0.07)),
    linear-gradient(0deg, var(--control-bg-hover), var(--control-bg-hover));
}
.market-quote-card.market-dir-down:hover {
  border-color: rgba(34, 197, 94, 0.34);
  background-image:
    linear-gradient(0deg, rgba(34, 197, 94, 0.07), rgba(34, 197, 94, 0.07)),
    linear-gradient(0deg, var(--control-bg-hover), var(--control-bg-hover));
}

/* Market custom cards editor */
.row.market-cards-editor-row,
.row.market-cards-add-row {
  gap: 8px;
  flex-wrap: nowrap;
}
.row.market-cards-add-row { margin-top: 12px; }

.row.market-cards-editor-row > .input,
.row.market-cards-add-row > .input {
  min-width: 0;
}

.row.market-cards-editor-row > .input.market-card-code,
.row.market-cards-add-row > .input.market-card-code {
  flex: 0 0 180px;
  width: 180px;
}
.row.market-cards-editor-row > .input.market-card-name,
.row.market-cards-add-row > .input.market-card-name {
  flex: 1 1 0;
}

@media (max-width: 640px) {
  .row.market-cards-editor-row,
  .row.market-cards-add-row {
    flex-wrap: wrap;
  }
  .row.market-cards-editor-row > .input.market-card-code,
  .row.market-cards-add-row > .input.market-card-code {
    flex: 1 1 180px;
    width: auto;
  }
  .row.market-cards-editor-row > .input.market-card-name,
  .row.market-cards-add-row > .input.market-card-name {
    flex: 1 1 220px;
  }
}

.market-quote-body { padding: 10px 12px; }
.market-quote-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.market-quote-title {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.market-quote-name {
  font-weight: 700;
  font-size: 13px;
  line-height: 1.2;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1 1 auto;
}
.market-quote-code {
  margin-top: 0;
  font-size: 9px;
  color: var(--muted);
  display: inline-block;
  line-height: 1.4;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0.9;
  flex: 0 0 auto;
}
.market-quote-time {
  font-size: 9px;
  color: var(--muted);
  white-space: nowrap;
  display: inline-block;
  opacity: 0.9;
}
.market-quote-main {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-top: 5px;
}
.market-quote-price {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.2px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.market-quote-move {
  display: flex;
  flex-direction: row;
  align-items: baseline;
  justify-content: flex-end;
  gap: 8px;
  white-space: nowrap;
}
.market-quote-pct {
  font-size: 10px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-variant-numeric: tabular-nums;
}
.market-quote-pct .ico,
.market-quote-pct .ico svg {
  width: 10px;
  height: 10px;
}
.market-quote-chg {
  font-size: 10px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.market-quote-move.pos .market-quote-chg,
.market-quote-move.neg .market-quote-chg {
  color: currentColor;
  opacity: 0.85;
}

@media (max-width: 640px) {
  /* Mobile: keep table layout, but reduce column widths/blank space. */
  th, td { padding: 8px 6px; }

  .holdings-table {
    min-width: 616px;
    table-layout: fixed;
  }
  .holdings-table col.col-drag { width: 34px; }
  .holdings-table col.col-fund { width: 150px; }
  .holdings-table col.col-cost { width: 115px; }
  .holdings-table col.col-value { width: 115px; }
  .holdings-table col.col-today { width: 85px; }
  .holdings-table col.col-pnl { width: 115px; }

  .holdings-table td { font-size: 13px; }
  .holdings-table td:nth-child(n + 2) { text-align: right; }

  .market-table {
    min-width: 560px;
    table-layout: fixed;
  }
  .market-table col.col-name { width: 210px; }
  .market-table col.col-price { width: 110px; }
  .market-table col.col-chg { width: 120px; }
  .market-table col.col-time { width: 100px; }
  .market-table td { font-size: 13px; }

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

@media (max-width: 420px) {
  .market-cards {
    grid-template-columns: 1fr;
  }
}

.holdings-table .fund-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.holdings-table .fund-code {
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.input {
  width: 100%;
  padding: 9px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--control-bg);
  color: var(--text);
  transition: background 120ms ease, border-color 120ms ease;
}
.input:hover { background: var(--control-bg-hover); }
.input:focus {
  outline: none;
}

.input-with-action {
  position: relative;
  width: 100%;
}

.input-with-action .input {
  padding-right: 92px;
}

.input-with-action .input-action {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  height: calc(100% - 10px);
  padding: 0 10px;
}

/* Select (dropdown) — keep native chevron for reliability */
select.input {
  cursor: pointer;
  font-size: 13px;
  line-height: 1.15;
  padding: 8px 34px 8px 14px;
}
.row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.row > .input:not(.shrink) { flex: 1; }
.row > :not(.input):not(.shrink) { flex: 0 0 auto; }
.shrink { flex: 0 0 auto; }
.input.shrink { width: auto; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  min-width: 240px;
  max-width: calc(100% - 32px);
}

.chart {
  width: 100%;
  height: 240px;
  display: block;
}

.chart-host {
  position: relative;
}

.chart-tooltip {
  position: absolute;
  z-index: 2;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(244, 89, 68, 0.22);
  background: var(--card);
  color: var(--text);
  pointer-events: none;
  line-height: 1.2;
}

.chart-tooltip .date {
  font-size: 11px;
  color: var(--muted);
}

.chart-tooltip .value {
  margin-top: 4px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.2px;
}

.chart-tooltip .meta {
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
}

.today-chart-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 10px;
  display: flex;
  justify-content: center;
  overflow: hidden;
}
.today-loading {
  width: 100%;
}
.today-chart-img {
  width: 100%;
  max-width: 560px;
  height: auto;
  display: block;
}

.today-split {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.today-left,
.today-right {
  min-width: 0;
}
.today-left {
  flex: 1 1 560px;
}
.today-right {
  flex: 0 1 420px;
}
@media (max-width: 900px) {
  .today-split { flex-direction: column; }
  .today-right { flex: 1 1 auto; width: 100%; }
}

/* Fund detail: keep actions usable on small screens */
.fund-actions {
  flex-wrap: wrap;
  gap: 6px;
}
.fund-nav-controls {
  flex-wrap: wrap;
  gap: 6px;
}
@media (max-width: 640px) {
  .fund-actions { width: 100%; justify-content: flex-start; }
  .fund-nav-controls { width: 100%; }
  .fund-nav-controls .input.shrink { width: 100%; }
}

/* Watchlist rows */
.watch-item {
  padding: 12px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.watch-link {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-decoration: none;
}
.watch-link:hover { text-decoration: none; }
.watch-left { min-width: 0; }
.watch-name {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.watch-code { font-size: 12px; }
.watch-added {
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.watch-right { text-align: right; flex: 0 0 auto; }
.watch-nav { font-size: 14px; }
.watch-pct { font-size: 12px; }
.watch-since { font-size: 12px; margin-top: 2px; }
.watch-remove {
  color: var(--muted);
}
.watch-remove:hover {
  color: var(--bad);
}

/* Mobile drawer (native <dialog>) */
dialog.drawer {
  border: 0;
  border-left: 1px solid var(--line);
  border-radius: 0;
  padding: 0;
  background: var(--card);
  color: var(--text);
  width: min(360px, calc(100% - 56px));
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  position: fixed;
  top: 0;
  right: 0;
  display: none;
  flex-direction: column;
  transform: translateX(110%);
  transition: transform 180ms ease;
}

dialog.drawer[open] {
  display: flex;
  transform: translateX(0);
}

dialog.drawer::backdrop {
  background: rgba(0, 0, 0, 0.46);
}

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

.drawer-user {
  min-width: 0;
}
.drawer-user-name {
  font-weight: 800;
  letter-spacing: 0.2px;
  color: var(--text);
}
.drawer-user-email {
  font-size: 12px;
  margin-top: 2px;
}

.drawer-body {
  padding: 14px 12px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.drawer-item {
  width: 100%;
  appearance: none;
  border: 1px solid var(--line);
  background: var(--control-bg);
  color: var(--text);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-decoration: none;
  cursor: pointer;
}
.drawer-item:hover {
  border-color: rgba(244, 89, 68, 0.35);
  text-decoration: none;
}
.drawer-item.active {
  border-color: rgba(244, 89, 68, 0.6);
}
.drawer-item.danger {
  border-color: rgba(239, 68, 68, 0.45);
  background: rgba(239, 68, 68, 0.14);
}

.drawer-value {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.drawer-sep {
  height: 1px;
  background: var(--line);
  margin: 2px 2px;
}

/* Modal (native <dialog>) */
dialog.modal {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 0;
  background: var(--card);
  color: var(--text);
  width: min(560px, calc(100% - 32px));
  max-height: calc(100dvh - 32px);
  display: none;
}

dialog.modal[open] {
  display: flex;
  flex-direction: column;
}

dialog.modal::backdrop {
  background: rgba(0, 0, 0, 0.46);
}

.modal-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.modal-title {
  font-weight: 800;
  letter-spacing: 0.2px;
}
.modal-body {
  padding: 14px 16px;
  overflow: auto;
}
.modal-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Minimal scrollbar: no track background, only thumb. */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background-color: var(--scrollbar-thumb);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background-color: var(--scrollbar-thumb-hover); }
