:root {
  color-scheme: dark;
  --bg-color: #040914;
  --panel-bg: rgba(14, 25, 45, 0.6);
  --panel-border: rgba(43, 67, 107, 0.4);
  --text-primary: #e8eef8;
  --text-muted: #8c9fb8;
  --accent: #00ffcc;
  --accent-hover: #00d9a6;
  --accent-glow: rgba(0, 255, 204, 0.15);
  --bullish: #00e676;
  --bearish: #ff1744;
  --warn: #ffd166;
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-color);
  background-image: 
    radial-gradient(circle at 15% 0%, rgba(20, 50, 100, 0.4) 0%, transparent 40%),
    radial-gradient(circle at 85% 100%, rgba(0, 255, 204, 0.05) 0%, transparent 40%);
  background-attachment: fixed;
  color: var(--text-primary);
  line-height: 1.5;
}

/* Base Typo */
h1, h2, h3, p { margin: 0 0 1rem 0; }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font-family: inherit; }

.muted { color: var(--text-muted); }
.eyebrow { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--accent); font-weight: 700; margin-bottom: 0.5rem; }

/* ═══════ HEADER ═══════ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background: rgba(4, 9, 20, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--panel-border);
}

.logo {
  font-size: 1.5rem;
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.03em;
}
.accent-gradient {
  background: linear-gradient(135deg, #00ffcc, #00b3ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-controls {
  display: flex;
  gap: 1.5rem;
  flex: 1;
  justify-content: center;
  align-items: center;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* ═══════ COMPONENTS ═══════ */
.glass-card, .panel {
  background: var(--panel-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--glass-shadow);
}

.secondary-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-border);
  color: var(--text-primary);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 600;
}
.secondary-btn:hover { background: rgba(255, 255, 255, 0.1); }

.primary-btn, button[type="submit"] {
  background: var(--accent);
  color: #000;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-md);
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.2s;
  box-shadow: 0 4px 15px var(--accent-glow);
}
.primary-btn:hover, button[type="submit"]:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 50%;
  transition: background 0.2s, color 0.2s;
  display: grid;
  place-items: center;
}
.icon-btn:hover { background: rgba(255,255,255,0.1); color: var(--text-primary); }

/* Inputs */
input, select, textarea {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--panel-border);
  color: var(--text-primary);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.2s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--text-muted); margin-bottom: 0.25rem; }

/* ═══════ HEADER CONTROLS ═══════ */
.market-selector, .timeframe-bar {
  display: flex;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 20px;
  padding: 4px;
  border: 1px solid var(--panel-border);
}
.market-btn, .tf-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.4rem 0.8rem;
  border-radius: 16px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.2s;
}
.market-btn.active, .tf-btn.active {
  background: rgba(255,255,255,0.1);
  color: var(--text-primary);
}

.search-wrapper { position: relative; }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.search-input {
  background: rgba(0, 0, 0, 0.4);
  border-radius: 20px;
  padding: 0.5rem 1rem 0.5rem 2.2rem;
  width: 220px;
}
.search-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: #0b1526;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  box-shadow: var(--glass-shadow);
  max-height: 300px;
  overflow-y: auto;
  z-index: 1000;
}
.search-item {
  padding: 0.75rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 0.85rem;
}
.search-item:hover { background: rgba(255,255,255,0.05); }

.live-price-box {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem 1rem;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 20px;
  border: 1px solid var(--panel-border);
}
.live-symbol { font-weight: 700; font-size: 0.9rem; }
.live-price { font-family: monospace; font-size: 1rem; }
.live-change { font-size: 0.8rem; font-weight: 600; }
.live-change.positive { color: var(--bullish); }
.live-change.negative { color: var(--bearish); }

/* ═══════ NAVIGATION ═══════ */
.mode-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  max-width: 1440px;
  margin: 0 auto;
}
.mode-tabs {
  display: flex;
  gap: 1rem;
}
.mode-tab {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.5rem 0;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}
.mode-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.provider-status { font-size: 0.8rem; color: var(--text-muted); }

/* ═══════ DASHBOARD LAYOUT ═══════ */
.dashboard {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 2rem 3rem;
}

.chart-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1.5rem;
  align-items: start;
}

.chart-section { display: flex; flex-direction: column; gap: 1rem; }
.chart-container {
  height: 600px;
  background: #050a12;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  position: relative;
  overflow: hidden;
}

.chart-empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: rgba(5, 10, 18, 0.8);
  z-index: 10;
  text-align: center;
}
.chart-empty-icon { font-size: 4rem; margin-bottom: 1rem; opacity: 0.5; }

.chart-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.capture-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(0, 255, 204, 0.15);
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}
.capture-btn:hover:not(:disabled) { background: var(--accent); color: #000; }
.chart-status { font-size: 0.85rem; color: var(--text-muted); }

/* Sidebar */
.sidebar { display: flex; flex-direction: column; gap: 1.5rem; }
.card-header { padding: 1.25rem 1.25rem 1rem; border-bottom: 1px solid rgba(255,255,255,0.05); }
.card-header h3 { margin: 0; font-size: 1rem; font-weight: 700; }

.indicator-toggles { padding: 1rem; display: flex; flex-direction: column; gap: 0.75rem; }
.toggle-row { display: flex; justify-content: space-between; align-items: center; cursor: pointer; margin: 0; }
.toggle-label { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; color: var(--text-primary); font-weight: 600; }
.color-dot { width: 10px; height: 10px; border-radius: 50%; }

/* Custom Toggle Switch */
.toggle-input { display: none; }
.toggle-slider {
  position: relative;
  width: 36px;
  height: 20px;
  background: rgba(255,255,255,0.1);
  border-radius: 20px;
  transition: 0.3s;
}
.toggle-slider::before {
  content: "";
  position: absolute;
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.3s;
}
.toggle-input:checked + .toggle-slider { background: var(--accent); }
.toggle-input:checked + .toggle-slider::before { transform: translateX(16px); background: #000; }

.pattern-list { padding: 1rem; display: flex; flex-direction: column; gap: 0.75rem; max-height: 250px; overflow-y: auto; }
.pattern-item { padding: 0.75rem; background: rgba(0,0,0,0.2); border-radius: var(--radius-sm); border-left: 3px solid transparent; }
.pattern-item.bullish { border-color: var(--bullish); }
.pattern-item.bearish { border-color: var(--bearish); }
.confidence-badge { padding: 2px 6px; border-radius: 4px; font-size: 0.7rem; font-weight: 700; }
.confidence-badge.bullish { background: rgba(0, 230, 118, 0.15); color: var(--bullish); }
.confidence-badge.bearish { background: rgba(255, 23, 68, 0.15); color: var(--bearish); }

.signal-content { padding: 1.5rem; display: flex; flex-direction: column; align-items: center; gap: 1rem; }
.signal-badge { padding: 0.5rem 1.5rem; border-radius: 20px; font-weight: 800; font-size: 1.2rem; letter-spacing: 0.05em; }
.signal-badge.buy { background: rgba(0, 230, 118, 0.2); color: var(--bullish); }
.signal-badge.sell { background: rgba(255, 23, 68, 0.2); color: var(--bearish); }
.signal-badge.hold { background: rgba(255, 209, 102, 0.2); color: var(--warn); }

.confidence-ring-wrap { position: relative; width: 120px; height: 120px; }
.confidence-ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: rgba(255,255,255,0.05); stroke-width: 8; }
.ring-fill { fill: none; stroke: var(--warn); stroke-width: 8; stroke-linecap: round; stroke-dasharray: 314; stroke-dashoffset: 314; transition: stroke-dashoffset 1s ease-out; }
.ring-label { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 1.5rem; font-weight: 800; }

.signal-reasons { width: 100%; font-size: 0.8rem; color: var(--text-muted); background: rgba(0,0,0,0.2); padding: 1rem; border-radius: var(--radius-sm); }
.signal-reasons p { margin-bottom: 0.5rem; }
.signal-reasons p:last-child { margin-bottom: 0; }

/* ═══════ UPLOAD & RESULTS (Legacy Adaptation) ═══════ */
.upload-panel { padding: 2rem; max-width: 800px; margin: 0 auto; }
.drop-zone {
  min-height: 200px;
  border: 2px dashed var(--panel-border);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.2);
  cursor: pointer;
  transition: all 0.2s;
  margin: 1rem 0 2rem;
  color: var(--text-muted);
}
.drop-zone:hover, .drop-zone.dragging { border-color: var(--accent); background: rgba(0,255,204,0.05); }
.drop-zone input { display: none; }
.drop-zone img { max-width: 100%; max-height: 300px; border-radius: 8px; }

.grid { display: grid; gap: 1rem; margin-bottom: 1rem; }
.grid.two { grid-template-columns: 1fr 1fr; }
.checkbox-row { display: flex; align-items: center; gap: 0.5rem; margin: 1.5rem 0; font-weight: 400; color: var(--text-primary); }
.checkbox-row input { width: auto; margin: 0; }

.message { color: var(--bearish); font-size: 0.9rem; margin-top: 0.5rem; }

.empty-state { text-align: center; padding: 4rem 0; color: var(--text-muted); }
.empty-icon { font-size: 3rem; margin-bottom: 1rem; color: var(--panel-border); }

.results-section { max-width: 900px; margin: 2rem auto; }
.result-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem; }
.result-heading h2 { font-size: 3rem; margin: 0; }
.score-ring { width: 100px; height: 100px; border: 6px solid var(--panel-border); border-radius: 50%; display: flex; flex-direction: column; justify-content: center; align-items: center; }
.score-ring strong { font-size: 2rem; line-height: 1; }
.score-ring span { font-size: 0.75rem; color: var(--text-muted); }

.summary { padding: 1.5rem; background: rgba(0,255,204,0.1); border-left: 4px solid var(--accent); border-radius: var(--radius-sm); margin-bottom: 2rem; }
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 2rem; }
.metrics div { background: var(--panel-bg); padding: 1rem; border-radius: var(--radius-md); border: 1px solid var(--panel-border); text-align: center; }
.metrics span { display: block; font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.metrics strong { display: block; font-size: 1.5rem; margin-top: 0.5rem; }

.score-bars { margin-bottom: 2rem; }
.score-row { display: grid; grid-template-columns: 120px 1fr 40px; align-items: center; gap: 1rem; margin-bottom: 0.5rem; font-size: 0.85rem; }
.bar { height: 8px; background: rgba(0,0,0,0.5); border-radius: 4px; position: relative; }
.bar::after { content: ''; position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: rgba(255,255,255,0.2); }
.bar-fill { position: absolute; top: 0; height: 100%; background: var(--accent); border-radius: 4px; transition: width 0.3s; }

.detail-grid, .columns { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-bottom: 2rem; }
.detail-grid article { background: var(--panel-bg); padding: 1.5rem; border-radius: var(--radius-md); border: 1px solid var(--panel-border); }
.detail-grid h3 { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 0.5rem; text-transform: uppercase; letter-spacing: 0.05em; }

ul { padding-left: 1.25rem; margin: 0; color: var(--text-primary); }
ul li { margin-bottom: 0.5rem; }

details { background: rgba(0,0,0,0.2); padding: 1rem; border-radius: var(--radius-md); border: 1px solid var(--panel-border); margin-bottom: 2rem; }
summary { font-weight: 700; cursor: pointer; outline: none; }
.provider-card { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid rgba(255,255,255,0.05); }

/* Chat */
.assistant-panel { background: rgba(14, 25, 45, 0.4); border: 1px solid var(--accent); border-radius: var(--radius-lg); padding: 1.5rem; margin-bottom: 2rem; }
.assistant-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.chat-messages { max-height: 300px; overflow-y: auto; background: rgba(0,0,0,0.3); border-radius: var(--radius-md); padding: 1rem; margin-bottom: 1rem; border: 1px solid var(--panel-border); }
.chat-message { max-width: 85%; padding: 0.75rem 1rem; border-radius: 12px; margin-bottom: 1rem; font-size: 0.9rem; }
.assistant-message { background: rgba(0, 255, 204, 0.1); border-bottom-left-radius: 0; }
.user-message { background: rgba(255,255,255,0.1); border-bottom-right-radius: 0; margin-left: auto; }
.quick-prompts { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.quick-prompts button { background: transparent; border: 1px solid var(--panel-border); color: var(--text-muted); padding: 0.4rem 0.8rem; border-radius: 20px; font-size: 0.75rem; cursor: pointer; }
.quick-prompts button:hover { border-color: var(--accent); color: var(--text-primary); }
.chat-form { display: flex; gap: 1rem; align-items: flex-end; }
.chat-form textarea { flex: 1; margin: 0; min-height: 44px; resize: vertical; }
.chat-form button { margin: 0; white-space: nowrap; }

.disclaimer { font-size: 0.75rem; color: var(--text-muted); text-align: center; border-top: 1px solid var(--panel-border); padding-top: 1.5rem; }
footer { text-align: center; padding: 2rem; color: var(--text-muted); font-size: 0.85rem; }

/* ═══════ MODAL ═══════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}
.modal-card {
  width: 100%;
  max-width: 500px;
  margin: 1rem;
}
.modal-header {
  padding: 1.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h2 { margin: 0; font-size: 1.25rem; }
.modal-body { padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.key-hint { font-size: 0.75rem; color: var(--text-muted); margin: -0.5rem 0 0.5rem; }
.server-keys-info { margin-top: 1rem; padding: 1rem; background: rgba(0,0,0,0.2); border-radius: var(--radius-sm); border: 1px solid rgba(255,255,255,0.05); }
.modal-footer { padding: 1.5rem; border-top: 1px solid rgba(255,255,255,0.05); display: flex; justify-content: flex-end; }

/* Utilities */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }

@media (max-width: 992px) {
  .chart-layout { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .app-header { flex-wrap: wrap; gap: 1rem; }
  .header-controls { order: 3; width: 100%; flex-wrap: wrap; }
  .search-input { width: 100%; }
  .grid.two, .detail-grid, .columns { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: 1fr; }
  .chat-form { flex-direction: column; }
  .chat-form button { width: 100%; }
}
