:root {
  --bg: #0b0f14;
  --panel: #121820;
  --border: #1e2836;
  --text: #e8edf5;
  --muted: #8b98ab;
  --accent: #1687d9;
  --bull: #48c756;
  --bear: #ff3338;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --mobile-nav-h: 56px;
  --chart-h-mobile: clamp(280px, 46vh, 480px);
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

.mobile-only { display: none !important; }

/* ── Top bar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: 0.02em;
}

.subtitle {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.symbol-more-wrap {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.symbol-more-label {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
}

.symbol-more-select {
  background: #141b24;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.45rem;
  font-size: 0.78rem;
  max-width: 10.5rem;
}

.symbol-more-select:focus {
  outline: none;
  border-color: #3d8fd1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-shrink: 0;
}

.ai-model-wrap {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.ai-model-label {
  font-size: 0.75rem;
  color: var(--muted);
}

.ai-model-select {
  background: #141b24;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.5rem;
  font-size: 0.78rem;
  max-width: 11rem;
}

.ai-model-select:focus {
  outline: none;
  border-color: #3d8fd1;
}

.btn-label-short { display: none; }

/* ── Overview ── */
.overview-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: #0e131a;
}

.overview-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.overview-card.active {
  border-color: var(--accent);
  background: rgba(22, 135, 217, 0.08);
}

.overview-card h3 {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
}

.overview-card p {
  margin: 0.15rem 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.ov-signals {
  font-size: 0.75rem !important;
  margin-top: 0.25rem !important;
}

.status-main .live-tag,
.ov-price .live-tag {
  color: #48c756;
  font-weight: 600;
}

/* ── Toolbar (desktop: one row) ── */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  padding: 0.6rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: #0e131a;
}

.symbol-group,
.interval-group,
.chart-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.scroll-x {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  flex-wrap: nowrap;
}

.scroll-x::-webkit-scrollbar { display: none; }

.scroll-x > .chip { flex-shrink: 0; }

.toolbar-label {
  font-size: 0.75rem;
  color: var(--muted);
  margin-right: 0.15rem;
}

/* ── Chips & buttons ── */
.chip {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.85rem;
  min-height: 34px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.chip.active {
  border-color: var(--accent);
  background: rgba(22, 135, 217, 0.15);
  color: #7ec8ff;
}

.chart-tabs .chip { border-radius: 8px; }

.btn-primary {
  border: none;
  background: var(--accent);
  color: white;
  padding: 0.45rem 0.95rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  min-height: 36px;
  touch-action: manipulation;
  white-space: nowrap;
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* ── Status ── */
.status-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 1.25rem;
  padding: 0.55rem 1.25rem;
  font-size: 0.88rem;
  border-bottom: 1px solid var(--border);
  background: #0e131a;
}

.status-main {
  font-weight: 500;
  flex: 1 1 280px;
}

.status-sub {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.sig-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  border: 1px solid transparent;
}

.sig-buy {
  color: #00E676;
  background: rgba(0, 230, 118, 0.08);
  border-color: rgba(0, 230, 118, 0.25);
}

.sig-sell {
  color: #FF5252;
  background: rgba(255, 82, 82, 0.08);
  border-color: rgba(255, 82, 82, 0.25);
}

.status-meta {
  color: var(--muted);
  font-size: 0.75rem;
  margin-left: auto;
}

.live-badge {
  font-size: 0.78rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  white-space: nowrap;
}

.live-badge.on { color: #48c756; border-color: #48c756; }
.live-badge.off { color: var(--muted); }

/* ── Main layout (desktop) ── */
.layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 0;
  align-items: start;
}

.chart-panel {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chart-wrap {
  height: calc(100vh - 300px);
  min-height: 420px;
  max-height: 680px;
  position: relative;
}

.chart-wrap.hidden { display: none; }

#local-chart,
#tv-chart {
  width: 100%;
  height: 100%;
}

.chart-error {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 200px;
  padding: 1.5rem;
  color: #ffb84d;
  text-align: center;
  line-height: 1.6;
  font-size: 0.9rem;
}

.chart-hint {
  margin: 0;
  padding: 0.45rem 1.25rem 0.25rem;
  color: var(--muted);
  font-size: 0.76rem;
}

.chart-hint a { color: #7ec8ff; }

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1.25rem;
  padding: 0.25rem 1.25rem 0.85rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.leg-trend { color: var(--muted); }
.leg-bull { color: #1687D9; font-weight: 700; }
.leg-bear { color: #C82F34; font-weight: 700; }
.leg-buy { color: #00E676; font-weight: 600; }
.leg-sell { color: #FF5252; font-weight: 600; }
.leg-flip { color: #FFB74D; }
.leg-gamma { color: #AB47BC; }

.chart-crosshair-tooltip {
  position: absolute;
  z-index: 20;
  pointer-events: none;
  min-width: 148px;
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  border: 1px solid #2a3545;
  background: rgba(11, 15, 20, 0.94);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
  font-size: 0.76rem;
  line-height: 1.45;
  color: #c8d4e5;
}

.chart-crosshair-tooltip.hidden {
  display: none;
}

.chart-crosshair-tooltip .tip-time {
  margin-bottom: 0.35rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid #1e2836;
  color: #9fb0c8;
  font-weight: 600;
}

.chart-crosshair-tooltip .tip-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.chart-crosshair-tooltip .tip-row span:first-child {
  color: #7a8da8;
}

.chart-crosshair-tooltip .tip-row .up { color: #26a69a; }
.chart-crosshair-tooltip .tip-row .down { color: #ef5350; }
.chart-crosshair-tooltip .tip-close em {
  font-style: normal;
  font-size: 0.72rem;
  opacity: 0.9;
}

/* ── AI panel ── */
.ai-panel {
  padding: 1rem 1.15rem 2rem;
  background: var(--panel);
  position: sticky;
  top: 0;
  max-height: 100vh;
  overflow-y: auto;
}

.ai-panel-title {
  margin: 0 0 0.25rem;
  font-size: 1rem;
}

.ai-updated-hint {
  margin: 0 0 0.85rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.ai-verdict {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  margin-bottom: 1rem;
  padding: 0.75rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
}

.ai-verdict-badge {
  flex-shrink: 0;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.ai-verdict-badge.bull {
  color: #00e676;
  background: rgba(0, 230, 118, 0.12);
  border: 1px solid rgba(0, 230, 118, 0.25);
}

.ai-verdict-badge.bear {
  color: #ff5252;
  background: rgba(255, 82, 82, 0.12);
  border: 1px solid rgba(255, 82, 82, 0.25);
}

.ai-verdict-badge.flat {
  color: #ffb74d;
  background: rgba(255, 183, 77, 0.12);
  border: 1px solid rgba(255, 183, 77, 0.25);
}

.ai-verdict-text {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.5;
  color: #dce6f5;
}

.ai-section {
  margin-bottom: 1rem;
}

.ai-section-title {
  margin: 0 0 0.45rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0.02em;
}

.ai-panel-toggle { display: none; }

.level-box {
  display: grid;
  gap: 0.55rem;
  padding: 0;
  border: none;
}

.level-row {
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.88rem;
}

.level-row.support { border-left: 3px solid #66bb6a; }
.level-row.resistance { border-left: 3px solid #ffb74d; }

.level-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
}

.level-label {
  color: var(--muted);
  font-size: 0.8rem;
}

.level-value {
  font-weight: 600;
  font-size: 0.95rem;
  color: #e8f0fa;
}

.level-hint {
  margin: 0.35rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
}

.ai-outlook { line-height: 1.6; font-size: 0.92rem; margin: 0; }

.ai-reasons {
  list-style: none;
  margin: 0;
  padding: 0;
  color: #b8c8dc;
  font-size: 0.86rem;
  line-height: 1.5;
}

.ai-reasons li {
  display: flex;
  gap: 0.45rem;
  align-items: flex-start;
  padding: 0.4rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.ai-reasons li:last-child { border-bottom: none; }

.ai-reasons .reason-icon {
  flex-shrink: 0;
  font-size: 0.9rem;
  line-height: 1.4;
}

.ai-news-section {
  margin-top: 0.25rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding-top: 0.75rem;
}

.ai-section-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.35rem 0;
  margin: 0 0 0.35rem;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-align: left;
}

.ai-section-toggle .ai-section-title {
  margin: 0;
  flex-shrink: 0;
}

.ai-news-toggle-meta {
  flex: 1;
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-section-toggle .toggle-icon {
  color: var(--muted);
  font-size: 0.85rem;
  transition: transform 0.15s ease;
}

.ai-news-section:not(.collapsed) .ai-section-toggle .toggle-icon {
  transform: rotate(90deg);
}

.ai-news-body {
  padding-bottom: 0.25rem;
}

.ai-news-section.collapsed .ai-news-body {
  display: none;
}

.ai-news {
  list-style: none;
  margin: 0;
  padding: 0;
}

.ai-news li {
  padding: 0.55rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.ai-news li:last-child { border-bottom: none; }

.ai-news-title {
  display: block;
  color: #dce6f5;
  font-size: 0.86rem;
  line-height: 1.45;
  text-decoration: none;
}

a.ai-news-title:hover { color: #7ec8ff; }

.ai-news-meta {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.72rem;
  color: var(--muted);
}

.ai-news-empty {
  color: var(--muted);
  font-size: 0.85rem;
}

.ai-news-note {
  margin: 0.35rem 0 0;
  font-size: 0.72rem;
  color: var(--muted);
}

.ai-risk-section .ai-risk {
  margin: 0;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  background: rgba(255, 184, 77, 0.08);
  border: 1px solid rgba(255, 184, 77, 0.2);
  color: #ffcc80;
  font-size: 0.86rem;
  line-height: 1.5;
}

.disclaimer {
  margin-top: 1.25rem;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.45;
}

/* ── Mobile bottom nav ── */
.mobile-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  display: flex;
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  height: calc(var(--mobile-nav-h) + var(--safe-bottom));
}

.mobile-nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.68rem;
  cursor: pointer;
  padding: 0.35rem 0;
}

.mobile-nav-btn .nav-icon { font-size: 1.1rem; line-height: 1; }
.mobile-nav-btn.active { color: #7ec8ff; }

/* ── Tablet ── */
@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }

  .chart-panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .ai-panel {
    position: static;
    max-height: none;
  }

  .chart-wrap {
    height: 52vh;
    min-height: 320px;
    max-height: 560px;
  }
}

/* ── Phone ── */
@media (max-width: 768px) {
  .mobile-only { display: flex !important; }

  .btn-label-long { display: none; }
  .btn-label-short { display: inline; }

  body {
    padding-bottom: calc(var(--mobile-nav-h) + var(--safe-bottom));
  }

  .topbar {
    padding: 0.5rem 0.85rem;
    padding-top: max(0.5rem, env(safe-area-inset-top));
    position: sticky;
    top: 0;
    z-index: 100;
  }

  .brand h1 { font-size: 1.05rem; }
  .subtitle { font-size: 0.72rem; }

  .overview-bar {
    display: flex;
    flex-direction: row;
    gap: 0.5rem;
    padding: 0.55rem 0.85rem;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
  }

  .overview-bar::-webkit-scrollbar { display: none; }

  .overview-card {
    flex: 0 0 min(44vw, 168px);
    scroll-snap-align: start;
    padding: 0.55rem 0.65rem;
  }

  .overview-card p {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .symbol-group.desktop-toolbar-item { display: none !important; }

  .toolbar {
    padding: 0.45rem 0.85rem;
    gap: 0.45rem;
  }

  .chart-hint { display: none; }

  .status-bar { padding: 0.5rem 0.85rem; }
  .status-main { font-size: 0.85rem; flex: 1 1 100%; }
  .status-meta { width: 100%; margin-left: 0; }

  .chart-wrap {
    height: var(--chart-h-mobile);
    min-height: 260px;
    max-height: none;
  }

  .chart-legend {
    padding: 0.35rem 0.85rem 0.65rem;
    font-size: 0.72rem;
  }

  .ai-panel { padding: 0 0.85rem 1rem; }

  .ai-panel-title { display: none; }

  .ai-panel-toggle.mobile-only {
    display: flex !important;
    width: 100%;
    border: none;
    background: transparent;
    color: var(--text);
    padding: 0.75rem 0;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
  }

  .ai-panel.collapsed .ai-panel-body { display: none; }
  .ai-panel.collapsed .toggle-icon { transform: rotate(-90deg); }
  .toggle-icon { transition: transform 0.2s; color: var(--muted); }

  body.view-ai .chart-panel,
  body.view-ai .status-bar,
  body.view-ai .toolbar { display: none; }

  body.view-ai .ai-panel { display: block; }
  body.view-ai .ai-panel.collapsed .ai-panel-body { display: block; }
  body.view-ai .ai-panel-title { display: block; padding-top: 0.5rem; }

  body.view-overview .layout,
  body.view-overview .toolbar,
  body.view-overview .status-bar { display: none; }

  body.view-overview .overview-bar {
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.85rem;
    gap: 0.65rem;
    max-height: calc(100dvh - 56px - var(--mobile-nav-h) - var(--safe-bottom));
  }

  body.view-overview .overview-card {
    flex: none;
    width: 100%;
  }

  body.view-overview .overview-card p { white-space: normal; }
}

@media (max-width: 380px) {
  .overview-card { flex: 0 0 48vw; }
}
