:root {
  color-scheme: light;
  --bg: #f5f5f0;
  --panel: #ffffff;
  --panel-soft: #f8f8f3;
  --border: #dddddd;
  --text: #1a1a1a;
  --muted: #666666;
  --accent: #1a1a1a;
  --accent-strong: #000000;
  --success: #16a34a;
  --danger: #ef4444;
  --warning: #f59e0b;
  --shadow: 0 12px 28px rgba(0, 0, 0, 0.08);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1115;
  --panel: #161a1f;
  --panel-soft: #13171b;
  --border: rgba(255, 255, 255, 0.08);
  --text: #f7f9fb;
  --muted: #c7ced8;
  --accent: #64748b;
  --accent-strong: #475569;
  --success: #48ffbf;
  --danger: #ff6b6b;
  --warning: #fbbf24;
  --shadow: 0 18px 34px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Noto Sans TC", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: radial-gradient(circle at 10% 10%, rgba(15, 23, 42, 0.06), transparent 40%), var(--bg);
  color: var(--text);
}

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

.page {
  width: min(1480px, 96vw);
  margin: 0 auto;
  padding: 1rem 0 2rem;
}

.top-bar {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 0.75rem 1rem;
}

.api-alert-host {
  margin-top: 0.75rem;
}

.api-alert {
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 0.55rem 0.7rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  box-shadow: var(--shadow);
  font-size: 0.88rem;
}

.api-alert-left {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.api-alert-warning {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.42);
  color: #b45309;
}

.api-alert-error {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.42);
  color: #b91c1c;
}

.api-alert-success {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.42);
  color: #047857;
}

.api-alert-close {
  border: 1px solid currentColor;
  background: transparent;
  color: inherit;
  border-radius: 8px;
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

:root[data-theme="dark"] .api-alert-warning {
  color: #fcd34d;
}

:root[data-theme="dark"] .api-alert-error {
  color: #fecaca;
}

:root[data-theme="dark"] .api-alert-success {
  color: #86efac;
}

.brand {
  font-weight: 800;
  display: inline-flex;
  gap: 0.45rem;
  align-items: center;
  color: var(--text);
}

.nav-center {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
  flex: 1;
}

.nav-icon {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.45rem 0.65rem;
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
  color: var(--muted);
  background: var(--panel-soft);
  font-weight: 600;
  font-size: 0.9rem;
}

.nav-icon.active {
  color: #f5f5f5;
  background: #0f0f0f;
  border-color: #0f0f0f;
}

:root[data-theme="dark"] .nav-icon.active {
  color: #0f0f0f;
  background: #f5f5f5;
  border-color: #f5f5f5;
}

.actions {
  display: inline-flex;
  gap: 0.4rem;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--panel-soft);
  color: var(--text);
  border-radius: 12px;
  padding: 0.45rem 0.65rem;
  cursor: pointer;
}

.hero {
  margin-top: 1rem;
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
  background: linear-gradient(135deg, rgba(13, 18, 33, 0.96), rgba(5, 9, 20, 0.92));
  color: #f8fafc;
  padding: 1.2rem;
}

.hero h1 {
  margin: 0;
  font-size: clamp(1.5rem, 2.6vw, 2rem);
}

.hero p {
  margin: 0.4rem 0 0;
  color: rgba(248, 250, 252, 0.92);
}

.hero-row {
  margin-top: 0.85rem;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.hero-chip {
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  padding: 0.28rem 0.7rem;
  font-size: 0.84rem;
  background: rgba(2, 6, 23, 0.2);
}

.dashboard-grid {
  margin-top: 1rem;
  display: grid;
  gap: 0.8rem;
  grid-template-columns: repeat(12, minmax(0, 1fr));
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 0.9rem;
}

.card h2,
.card h3 {
  margin: 0;
  font-size: 1rem;
}

.muted {
  color: var(--muted);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.65rem;
}

.kpi {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-soft);
  padding: 0.7rem;
}

.kpi .label {
  font-size: 0.78rem;
  color: var(--muted);
}

.kpi .value {
  margin-top: 0.25rem;
  font-size: 1.2rem;
  font-weight: 700;
}

.macro-card {
  transition: border-color 0.2s ease, background 0.2s ease;
}

.macro-state-fear {
  border-color: rgba(239, 68, 68, 0.5);
  background: linear-gradient(145deg, rgba(254, 226, 226, 0.9), rgba(255, 255, 255, 0.95));
}

.macro-state-greed {
  border-color: rgba(34, 197, 94, 0.5);
  background: linear-gradient(145deg, rgba(220, 252, 231, 0.9), rgba(255, 255, 255, 0.95));
}

.macro-state-neutral {
  border-color: rgba(148, 163, 184, 0.45);
  background: linear-gradient(145deg, rgba(241, 245, 249, 0.95), rgba(255, 255, 255, 0.95));
}

.macro-state-buy {
  border-color: rgba(16, 185, 129, 0.55);
  background: linear-gradient(145deg, rgba(209, 250, 229, 0.92), rgba(255, 255, 255, 0.95));
}

.macro-state-sell {
  border-color: rgba(239, 68, 68, 0.55);
  background: linear-gradient(145deg, rgba(254, 226, 226, 0.92), rgba(255, 255, 255, 0.95));
}

.macro-state-hold {
  border-color: rgba(245, 158, 11, 0.5);
  background: linear-gradient(145deg, rgba(254, 243, 199, 0.92), rgba(255, 255, 255, 0.95));
}

.macro-state-moon-new {
  border-color: rgba(99, 102, 241, 0.5);
  background: linear-gradient(145deg, rgba(224, 231, 255, 0.92), rgba(255, 255, 255, 0.95));
}

.macro-state-moon-full {
  border-color: rgba(245, 158, 11, 0.55);
  background: linear-gradient(145deg, rgba(255, 247, 208, 0.92), rgba(255, 255, 255, 0.95));
}

.macro-state-moon-mid {
  border-color: rgba(56, 189, 248, 0.5);
  background: linear-gradient(145deg, rgba(224, 242, 254, 0.92), rgba(255, 255, 255, 0.95));
}

:root[data-theme="dark"] .macro-state-fear {
  background: linear-gradient(145deg, rgba(127, 29, 29, 0.35), rgba(30, 41, 59, 0.9));
}

:root[data-theme="dark"] .macro-state-greed {
  background: linear-gradient(145deg, rgba(20, 83, 45, 0.35), rgba(30, 41, 59, 0.9));
}

:root[data-theme="dark"] .macro-state-neutral {
  background: linear-gradient(145deg, rgba(51, 65, 85, 0.45), rgba(30, 41, 59, 0.9));
}

:root[data-theme="dark"] .macro-state-buy {
  background: linear-gradient(145deg, rgba(6, 95, 70, 0.4), rgba(30, 41, 59, 0.9));
}

:root[data-theme="dark"] .macro-state-sell {
  background: linear-gradient(145deg, rgba(127, 29, 29, 0.4), rgba(30, 41, 59, 0.9));
}

:root[data-theme="dark"] .macro-state-hold {
  background: linear-gradient(145deg, rgba(120, 53, 15, 0.45), rgba(30, 41, 59, 0.9));
}

:root[data-theme="dark"] .macro-state-moon-new {
  background: linear-gradient(145deg, rgba(49, 46, 129, 0.4), rgba(30, 41, 59, 0.9));
}

:root[data-theme="dark"] .macro-state-moon-full {
  background: linear-gradient(145deg, rgba(120, 53, 15, 0.45), rgba(30, 41, 59, 0.9));
}

:root[data-theme="dark"] .macro-state-moon-mid {
  background: linear-gradient(145deg, rgba(12, 74, 110, 0.45), rgba(30, 41, 59, 0.9));
}

.positive {
  color: var(--success);
}

.negative {
  color: var(--danger);
}

.warning {
  color: var(--warning);
}

.controls-row {
  margin-top: 0.6rem;
  display: grid;
  gap: 0.55rem;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.input,
.select,
.button {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  font-size: 0.92rem;
  background: var(--panel-soft);
  color: var(--text);
}

.button {
  cursor: pointer;
  font-weight: 700;
  background: linear-gradient(120deg, var(--accent-strong), var(--accent));
  color: #f8fafc;
  border-color: transparent;
}

.toggle-list {
  margin-top: 0.55rem;
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.module-settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}

.module-settings-body {
  margin-top: 0.55rem;
}

.module-settings-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
}

.module-settings-toggle i {
  transition: transform 0.2s ease;
}

.module-settings-collapsed .module-settings-body {
  display: none;
}

.module-settings-collapsed .module-settings-toggle i {
  transform: rotate(-90deg);
}

.toggle-item {
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
  font-size: 0.86rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.22rem 0.65rem;
  background: var(--panel-soft);
}

.chart-box {
  width: 100%;
  height: 360px;
}

.chart-box.small {
  height: 280px;
}

.table-wrap {
  margin-top: 0.5rem;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  font-size: 0.88rem;
  padding: 0.58rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  text-align: left;
  background: var(--panel-soft);
  color: var(--muted);
}

td.num,
th.num {
  text-align: right;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.badge {
  display: inline-flex;
  gap: 0.25rem;
  align-items: center;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-soft);
  padding: 0.15rem 0.55rem;
  font-size: 0.76rem;
  color: var(--muted);
}

.footer-note {
  margin-top: 1rem;
  font-size: 0.82rem;
  color: var(--muted);
  border-top: 1px dashed var(--border);
  padding-top: 0.8rem;
}

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

.grid-12 {
  grid-column: span 12;
}

.grid-8 {
  grid-column: span 8;
}

.grid-7 {
  grid-column: span 7;
}

.grid-6 {
  grid-column: span 6;
}

.grid-5 {
  grid-column: span 5;
}

.grid-4 {
  grid-column: span 4;
}

.grid-3 {
  grid-column: span 3;
}

.faq-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-soft);
  padding: 0.7rem;
}

.list {
  margin: 0;
  padding-left: 1rem;
}

#leverage-history .chart-box.small {
  height: 310px;
}

#leverage-history .list {
  margin-top: 0.45rem;
  max-height: 180px;
  overflow: auto;
  padding-right: 0.35rem;
}

#leverage-history .list li + li {
  margin-top: 0.35rem;
}

#leverage-table .table-wrap {
  max-height: 740px;
}

#leverage-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.card-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}

.chart-action-btn {
  min-width: 92px;
  padding: 0.38rem 0.6rem;
  font-size: 0.82rem;
}

.card-fullscreen {
  position: fixed !important;
  inset: 1.2rem;
  z-index: 1200;
  margin: 0 !important;
  width: auto !important;
  max-width: none !important;
  max-height: none !important;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(2, 6, 23, 0.55);
}

.card-fullscreen .chart-box {
  height: calc(100vh - 230px) !important;
}

body.no-scroll {
  overflow: hidden;
}

@media (max-width: 1080px) {
  .grid-8,
  .grid-7,
  .grid-6,
  .grid-5,
  .grid-4,
  .grid-3 {
    grid-column: span 12;
  }

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

  .chart-box {
    height: 300px;
  }

  #leverage-table .table-wrap {
    max-height: none;
  }
}

@media (max-width: 760px) {
  .page {
    width: 95vw;
  }

  .top-bar {
    flex-wrap: wrap;
    border-radius: 14px;
  }

  .nav-center {
    order: 3;
    width: 100%;
    justify-content: flex-start;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 0.2rem;
  }

  .kpi-grid {
    grid-template-columns: 1fr;
  }

  th,
  td {
    font-size: 0.82rem;
  }
}
