:root {
  color-scheme: light;
  --ink: #0b0b0b;
  --secondary: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --surface: #fcfcfb;
  --page: #f9f9f7;
  --card-bg: #ffffff;
  --input-bg: #ffffff;
  --primary: #2a78d6;
  --cat-orange: #eb6834;
  --cat-aqua: #1baf7a;
  --cat-violet: #4a3aa7;
  --good: #0ca30c;
  --critical: #d03b3b;
  --border: rgba(11, 11, 11, 0.10);
  --shadow: rgba(11, 11, 11, 0.06);
  --div-blue: #2a78d6;
  --div-gray: #f0efec;
  --div-red: #d03b3b;
  --error-bg: rgba(208, 59, 59, 0.12);
  --success-bg: rgba(12, 163, 12, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --ink: #ffffff;
    --secondary: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --surface: #1a1a19;
    --page: #0d0d0d;
    --card-bg: #201f1d;
    --input-bg: #201f1d;
    --primary: #3987e5;
    --cat-orange: #d95926;
    --cat-aqua: #199e70;
    --cat-violet: #9085e9;
    --good: #0ca30c;
    --critical: #e66767;
    --border: rgba(255, 255, 255, 0.10);
    --shadow: rgba(0, 0, 0, 0.35);
    --div-blue: #3987e5;
    --div-gray: #383835;
    --div-red: #e66767;
    --error-bg: rgba(230, 103, 103, 0.16);
    --success-bg: rgba(12, 163, 12, 0.18);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #ffffff;
  --secondary: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --surface: #1a1a19;
  --page: #0d0d0d;
  --card-bg: #201f1d;
  --input-bg: #201f1d;
  --primary: #3987e5;
  --cat-orange: #d95926;
  --cat-aqua: #199e70;
  --cat-violet: #9085e9;
  --good: #0ca30c;
  --critical: #e66767;
  --border: rgba(255, 255, 255, 0.10);
  --shadow: rgba(0, 0, 0, 0.35);
  --div-blue: #3987e5;
  --div-gray: #383835;
  --div-red: #e66767;
  --error-bg: rgba(230, 103, 103, 0.16);
  --success-bg: rgba(12, 163, 12, 0.18);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--ink);
  transition: background-color 0.2s ease, color 0.2s ease;
}

.app { display: flex; align-items: flex-start; min-height: 100vh; }

.sidebar {
  width: 300px;
  flex-shrink: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 15px 18px 24px;
  font-size: calc(1rem - 1pt);
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.brand { font-size: 1.25rem; margin: 0 0 0.2rem; }
.subtitle { color: var(--secondary); font-size: 0.85em; margin: 0 0 0.8rem; }

.top-controls {
  position: fixed;
  top: 15px;
  right: 20px;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.lang-toggle { display: flex; gap: 0.3rem; }
.lang-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--card-bg);
  padding: 0.35rem;
  border-radius: 8px;
  cursor: pointer;
  line-height: 1;
  box-shadow: 0 2px 8px var(--shadow);
  opacity: 0.5;
  transition: transform 0.15s ease, opacity 0.15s ease, border-color 0.15s ease;
}
.lang-btn img { display: block; width: 24px; height: 18px; object-fit: cover; border-radius: 3px; }
.lang-btn:hover { transform: translateY(-1px); opacity: 0.85; }
.lang-btn.active { opacity: 1; border-color: var(--primary); }
.lang-btn:active { transform: translateY(0); }

.theme-toggle {
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--ink);
  padding: 0.5rem 0.8rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1em;
  line-height: 1;
  box-shadow: 0 2px 8px var(--shadow);
  transition: transform 0.15s ease, background-color 0.2s ease, border-color 0.2s ease;
}
.theme-toggle:hover { transform: translateY(-1px); background: var(--page); }
.theme-toggle:active { transform: translateY(0); }

.side-section { margin: 0.6rem 0; }
.side-section h2 { font-size: 0.95em; margin: 0 0 0.4rem; }

hr { border: none; border-top: 1px solid var(--grid); margin: 0.5rem 0; }

.ticker-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.ticker-empty { color: var(--muted); font-size: 0.85em; }
.ticker-item { display: flex; justify-content: space-between; align-items: center; gap: 0.4rem; }
.ticker-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.remove-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9em;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.remove-btn:hover { background: var(--grid); color: var(--critical); }

input[type="text"], select {
  width: 100%;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--axis);
  border-radius: 8px;
  font-size: inherit;
  font-family: inherit;
  background: var(--input-bg);
  color: var(--ink);
  margin-bottom: 0.3rem;
  transition: border-color 0.15s ease, background-color 0.2s ease, box-shadow 0.15s ease;
}
input[type="text"]:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent);
}

label { display: block; font-weight: 600; font-size: 0.9em; margin: 0.4rem 0 0.2rem; }

.search-results {
  border: 1px solid var(--axis);
  border-radius: 8px;
  background: var(--card-bg);
  max-height: 220px;
  overflow-y: auto;
  margin-top: 0.3rem;
  box-shadow: 0 4px 14px var(--shadow);
}
.search-result-item { padding: 0.4rem 0.6rem; cursor: pointer; font-size: 0.9em; border-bottom: 1px solid var(--grid); }
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--page); }
.search-result-item small { display: block; color: var(--muted); }

.btn-primary {
  width: 100%;
  padding: 0.65rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: 1em;
  font-family: inherit;
  box-shadow: 0 2px 8px var(--shadow);
  transition: filter 0.15s ease, transform 0.1s ease;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.6; cursor: default; transform: none; }

.status-msg { margin-top: 0.6rem; font-size: 0.85em; padding: 0.5rem; border-radius: 8px; }
.status-msg.error { background: var(--error-bg); color: var(--critical); }
.status-msg.success { background: var(--success-bg); color: var(--good); }

.sidebar-footer {
  margin: auto 0 0;
  padding-top: 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.78em;
}

.content { flex: 1; min-width: 0; padding: 2rem 2.5rem; }
.empty-state { color: var(--secondary); font-size: 1.05em; }

.top-gainers { margin-bottom: 2rem; }
.section-title { font-size: 1em; margin: 0 0 0.7rem; }

.gainers-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 0.7rem; }
.gainers-status { color: var(--secondary); font-size: 0.9em; grid-column: 1 / -1; }

.gainer-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  box-shadow: 0 1px 3px var(--shadow);
  transition: transform 0.15s ease;
}
.gainer-card:hover { transform: translateY(-2px); }

.gainer-info { min-width: 0; }
.gainer-symbol { display: block; font-weight: 700; font-size: 0.9em; }
.gainer-name {
  display: block;
  font-size: 0.75em;
  color: var(--secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gainer-change { color: var(--good); font-weight: 600; font-size: 0.85em; white-space: nowrap; }

.gainer-add-btn {
  border: none;
  background: var(--primary);
  color: #fff;
  width: 1.6rem;
  height: 1.6rem;
  flex-shrink: 0;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95em;
  line-height: 1;
  transition: filter 0.15s ease;
}
.gainer-add-btn:hover { filter: brightness(1.1); }

.tabs { display: flex; gap: 0.2rem; margin-bottom: 1.2rem; border-bottom: 1px solid var(--grid); }
.tab-btn {
  border: none;
  background: transparent;
  padding: 0.6rem 1rem;
  font-size: 0.95em;
  cursor: pointer;
  color: var(--secondary);
  border-bottom: 2px solid transparent;
  border-radius: 8px 8px 0 0;
  font-weight: 500;
  font-family: inherit;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.tab-btn:hover { background: var(--surface); color: var(--ink); }
.tab-btn.active { color: var(--ink); border-bottom-color: var(--primary); font-weight: 600; }

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fade-in 0.2s ease; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.metric-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  box-shadow: 0 1px 3px var(--shadow);
  transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}
.metric-card:hover { transform: translateY(-2px); }
.metric-card .label { font-weight: 600; font-size: 0.85em; color: var(--secondary); margin-bottom: 0.3rem; }
.metric-card .value { font-size: 1.4rem; font-weight: 600; }
.metric-card .delta { font-size: 0.85em; font-weight: 600; margin-top: 0.2rem; }
.metric-card .delta.up { color: var(--good); }
.metric-card .delta.down { color: var(--critical); }
.metric-card .range { font-size: 0.78em; color: var(--muted); margin-top: 0.4rem; }

table { border-collapse: collapse; width: 100%; font-size: 0.9em; }
th, td { padding: 0.5rem 0.7rem; text-align: right; border-bottom: 1px solid var(--grid); }
th:first-child, td:first-child { text-align: left; }
th { color: var(--secondary); font-weight: 600; }
.table-wrap {
  overflow-x: auto;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.3rem 1rem;
  box-shadow: 0 1px 3px var(--shadow);
}

.corr-layout { display: flex; gap: 2rem; flex-wrap: wrap; align-items: flex-start; }
.heatmap { display: inline-grid; gap: 2px; }
.heatmap-cell {
  width: 52px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72em;
  border-radius: 4px;
}
.heatmap-label {
  font-size: 0.7em;
  color: var(--secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  text-align: center;
}
.corr-empty { color: var(--secondary); }

.charts-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.2rem; }
@media (max-width: 900px) { .charts-grid { grid-template-columns: 1fr; } }
.chart-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem 1rem;
  box-shadow: 0 1px 3px var(--shadow);
  transition: background-color 0.2s ease, border-color 0.2s ease;
}
.chart-card h3 { margin: 0 0 0.5rem; font-size: 0.95em; }
.price-canvas-wrap { position: relative; height: 220px; }
.rsi-canvas-wrap { position: relative; height: 90px; margin-top: 0.4rem; }
.price-canvas-wrap canvas, .rsi-canvas-wrap canvas { width: 100% !important; height: 100% !important; }
