/* Global light/dark theme layer for all templates */

:root[data-theme="dark"] {
  --bg: #0f1524;
  --bg2: #141d36;
  --panel: #17213a;
  --panel2: #141d36;
  --text: #e2e8f5;
  --muted: #aebad6;
  --line: #2a3555;
  --chip: #202c49;
  --surface: rgba(0, 0, 0, 0.16);
  --surface-2: rgba(255, 255, 255, 0.03);
  --surface-border: rgba(255, 255, 255, 0.08);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --chart-grid: rgba(159, 176, 255, 0.25);
  --chart-axis: rgba(230, 237, 243, 0.84);
  --chart-zero: rgba(185, 200, 255, 0.55);
  --chart-right-axis: rgba(159, 176, 255, 0.7);
  --chart-x-label: rgba(230, 237, 243, 0.75);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #eef3fa;
  --bg2: #f5f8fd;
  --panel: #ffffff;
  --panel2: #f5f8fd;
  --text: #13233d;
  --muted: #435c80;
  --line: #d9e2f1;
  --chip: #eaf0fb;
  --surface: rgba(255, 255, 255, 0.86);
  --surface-2: rgba(255, 255, 255, 0.82);
  --surface-border: rgba(16, 34, 63, 0.2);
  --shadow: 0 12px 30px rgba(20, 44, 82, 0.12);
  --chart-grid: rgba(62, 88, 128, 0.22);
  --chart-axis: rgba(24, 45, 75, 0.88);
  --chart-zero: rgba(67, 97, 143, 0.58);
  --chart-right-axis: rgba(44, 72, 114, 0.64);
  --chart-x-label: rgba(37, 61, 97, 0.8);
  color-scheme: light;
}

html[data-theme="dark"] body {
  background: radial-gradient(1200px 700px at 10% 10%, #1a2440 0%, var(--bg) 55%) fixed !important;
}

html[data-theme="light"] body {
  background: radial-gradient(1200px 700px at 10% 10%, #f7f9fd 0%, var(--bg) 58%) fixed !important;
}

html[data-theme="light"] .panel,
html[data-theme="light"] .card,
html[data-theme="light"] .kpi,
html[data-theme="light"] .chip,
html[data-theme="light"] .live-panel,
html[data-theme="light"] .table-card {
  background: var(--surface) !important;
  border-color: var(--surface-border) !important;
  box-shadow: var(--shadow) !important;
}

html[data-theme="light"] .panel-hd,
html[data-theme="light"] .hd,
html[data-theme="light"] .topbar {
  background: rgba(235, 242, 252, 0.72) !important;
  border-color: var(--surface-border) !important;
}

html[data-theme="light"] input,
html[data-theme="light"] select,
html[data-theme="light"] textarea,
html[data-theme="light"] button.btn.ghost,
html[data-theme="light"] .btn-soft {
  background: rgba(255, 255, 255, 0.86) !important;
  border-color: var(--surface-border) !important;
  color: var(--text) !important;
}

html[data-theme="light"] table th,
html[data-theme="light"] table td {
  border-bottom-color: rgba(16, 34, 63, 0.12) !important;
}

html[data-theme="light"] .muted,
html[data-theme="light"] .sub,
html[data-theme="light"] .small {
  color: var(--muted) !important;
}

html[data-theme="light"] .title,
html[data-theme="light"] .kpi .val,
html[data-theme="light"] h1,
html[data-theme="light"] h2,
html[data-theme="light"] h3,
html[data-theme="light"] h4 {
  color: var(--text) !important;
}

html[data-theme="light"] .kpi {
  background: rgba(255, 255, 255, 0.9) !important;
  border-color: rgba(16, 34, 63, 0.16) !important;
}

html[data-theme="light"] .kpi .lbl,
html[data-theme="light"] .kpi .val small,
html[data-theme="light"] .kpi .kpi-ts {
  color: rgba(55, 81, 120, 0.86) !important;
}

html[data-theme="light"] .chartwrap {
  background: rgba(246, 250, 255, 0.92) !important;
  border-color: rgba(28, 54, 89, 0.2) !important;
}

html[data-theme="light"] .market-summary-section {
  background: rgba(246, 251, 255, 0.88) !important;
  border-color: rgba(35, 60, 98, 0.2) !important;
}

html[data-theme="light"] .legend,
html[data-theme="light"] .sw {
  color: rgba(36, 60, 95, 0.92) !important;
}

html[data-theme="light"] .sw {
  background: rgba(238, 245, 255, 0.88) !important;
  border-color: rgba(38, 64, 102, 0.22) !important;
}

html[data-theme="light"] .price-table-wrap,
html[data-theme="light"] .plan-wrap,
html[data-theme="light"] .logbox {
  background: rgba(248, 252, 255, 0.92) !important;
  border-color: rgba(35, 60, 98, 0.22) !important;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8) !important;
}

html[data-theme="light"] .price-table thead th,
html[data-theme="light"] .plan-table th,
html[data-theme="light"] .plan-hd {
  background: rgba(234, 242, 252, 0.95) !important;
  color: rgba(29, 52, 85, 0.95) !important;
  border-bottom-color: rgba(35, 60, 98, 0.18) !important;
}

html[data-theme="light"] .price-table tbody td,
html[data-theme="light"] .plan-table td {
  color: rgba(20, 41, 72, 0.96) !important;
  border-bottom-color: rgba(35, 60, 98, 0.11) !important;
}

html[data-theme="light"] .price-table tbody tr:nth-child(odd) td,
html[data-theme="light"] .plan-table tr:nth-child(odd) td {
  background: rgba(236, 244, 253, 0.62) !important;
}

html[data-theme="light"] .price-table tbody tr:hover td {
  background: rgba(81, 129, 196, 0.16) !important;
}

html[data-theme="light"] .price-tooltip {
  background: rgba(246, 251, 255, 0.98) !important;
  color: rgba(18, 42, 76, 0.96) !important;
  border-color: rgba(35, 60, 98, 0.25) !important;
  box-shadow: 0 12px 28px rgba(26, 49, 84, 0.17) !important;
}

html[data-theme="light"] .price-tooltip .tt-hd {
  color: rgba(18, 42, 76, 0.96) !important;
}

html[data-theme="light"] .pill {
  background: rgba(238, 245, 255, 0.85) !important;
  border-color: rgba(34, 62, 101, 0.22) !important;
}

html[data-theme="light"] .logbox {
  color: rgba(21, 45, 80, 0.95) !important;
}

html[data-theme="light"] .price-table-wrap::-webkit-scrollbar-thumb,
html[data-theme="light"] .plan-scroll::-webkit-scrollbar-thumb {
  background: rgba(66, 95, 140, 0.32) !important;
}

html[data-theme="light"] .price-table-wrap::-webkit-scrollbar-track,
html[data-theme="light"] .plan-scroll::-webkit-scrollbar-track {
  background: rgba(220, 231, 247, 0.7) !important;
}

html[data-theme="light"] footer {
  color: rgba(57, 82, 120, 0.85) !important;
}

html[data-theme="light"] .err {
  color: #a33652 !important;
}

.theme-toggle-btn {
  position: fixed;
  right: 12px;
  top: 12px;
  z-index: 99999;
  width: auto;
  max-width: max-content;
  flex: 0 0 auto;
  min-width: 110px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--surface-border);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  user-select: none;
}

.theme-toggle-btn:hover {
  transform: translateY(-1px);
}

.theme-toggle-btn:active {
  transform: translateY(0);
}

@media (max-width: 900px) {
  .theme-toggle-btn {
    right: 10px;
    top: 10px;
    min-width: 100px;
    height: 32px;
    font-size: 11px;
  }
}
