*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #242736;
  --border: #2e3147;
  --accent: #4f8ef7;
  --accent-hover: #6ba3ff;
  --text: #e8eaf0;
  --text-muted: #7b80a0;
  --green: #26c281;
  --red: #e05260;
  --radius: 8px;
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.5px;
  white-space: nowrap;
}

.search-wrap {
  position: relative;
  flex: 0 0 260px;
}

.search-wrap svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

#ticker-input {
  width: 100%;
  padding: 9px 12px 9px 38px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.5px;
  outline: none;
  text-transform: uppercase;
  transition: border-color 0.15s;
}

#ticker-input::placeholder { text-transform: none; font-weight: 400; color: var(--text-muted); }
#ticker-input:focus { border-color: var(--accent); }

/* Settings button */
.settings-btn {
  margin-left: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.settings-btn:hover { color: var(--text); border-color: var(--accent); }

/* Settings modal */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.settings-overlay.hidden { display: none; }

.settings-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 420px;
  margin: 16px;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.settings-header h2 {
  font-size: 15px;
  font-weight: 700;
}

.settings-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.15s;
}
.settings-close:hover { color: var(--text); }

.settings-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
}

.settings-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.settings-input {
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  font-weight: 400;
  outline: none;
  transition: border-color 0.15s;
  letter-spacing: normal;
  text-transform: none;
}
.settings-input:focus { border-color: var(--accent); }
.settings-input::placeholder { color: var(--text-muted); }

.settings-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.settings-input-wrap .settings-input {
  width: 100%;
  padding-right: 36px;
}
.eye-btn {
  position: absolute;
  right: 10px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 0;
  transition: color 0.15s;
}
.eye-btn:hover { color: var(--text); }

.settings-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

.settings-save-btn {
  padding: 8px 20px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.settings-save-btn:hover { background: var(--accent-hover); }

/* Connect button */
.connect-btn {
  margin-left: auto;
  padding: 7px 14px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.connect-btn:hover { background: var(--accent-hover); }
.connect-btn.connected { background: var(--green); cursor: default; }

/* ── Controls bar ── */
.controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.control-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.control-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-right: 4px;
  white-space: nowrap;
}

/* Quick range buttons */
.range-btn,
.interval-btn {
  padding: 5px 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s;
  white-space: nowrap;
}

.range-btn:hover,
.interval-btn:hover { color: var(--text); background: var(--surface-2); }
.range-btn.active,
.interval-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.interval-btn:disabled {
  color: rgba(123, 128, 160, 0.4);
  cursor: not-allowed;
}

.interval-btn:disabled:hover {
  background: transparent;
}

/* Divider */
.divider {
  width: 1px;
  height: 24px;
  background: var(--border);
  flex-shrink: 0;
}

/* Custom date range */
.date-range {
  display: flex;
  align-items: center;
  gap: 6px;
}

.date-input-wrap {
  position: relative;
}

input[type="date"] {
  padding: 5px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
  outline: none;
  cursor: pointer;
  transition: border-color 0.12s;
  color-scheme: dark;
}

input[type="date"]:focus { border-color: var(--accent); }

.date-sep {
  color: var(--text-muted);
  font-size: 12px;
}

/* ── Main ── */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px 24px;
  gap: 16px;
}

/* Ticker info strip */
.ticker-info {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.ticker-name {
  font-size: 22px;
  font-weight: 700;
}

.ticker-price {
  font-size: 22px;
  font-weight: 600;
}

.ticker-change {
  font-size: 14px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
}

.ticker-change.up   { background: rgba(38,194,129,0.15); color: var(--green); }
.ticker-change.down { background: rgba(224, 82, 96,0.15); color: var(--red); }

.ticker-subtext {
  font-size: 12px;
  color: var(--text-muted);
}

/* Provider toggle */
.provider-toggle {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.provider-btn,
.yaxis-btn {
  padding: 5px 10px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s;
  white-space: nowrap;
}

.provider-btn:hover,
.yaxis-btn:hover { color: var(--text); }
.provider-btn.active,
.yaxis-btn.active { background: var(--accent); color: #fff; }

/* ── Price chart ── */
.chart-wrap {
  position: relative;
}

.zoom-undo-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 5px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s;
  z-index: 10;
}
.zoom-undo-btn:hover { color: var(--text); border-color: var(--accent); }
.zoom-undo-btn.hidden { display: none; }

#price-chart {
  width: 100%;
  height: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

#notifications {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.notification {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid;
  font-size: 13px;
  font-weight: 500;
}

.notification.hidden { display: none; }

.notification.warning {
  background: rgba(20, 16, 8, 0.6);
  border-color: #a06020;
  color: #f0a040;
}

.notification.info {
  background: rgba(8, 12, 28, 0.6);
  border-color: #4060a0;
  color: #7aa0f0;
}

/* ── Price table ── */
.table-wrap {
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

#price-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

#price-table thead {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  z-index: 1;
}

#price-table th,
#price-table td {
  padding: 7px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

#price-table th {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
}

#price-table tbody tr:last-child td { border-bottom: none; }
#price-table tbody tr:hover { background: var(--surface-2); }

/* ── Debug sheet ── */
.debug-sheet {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.debug-sheet summary {
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.debug-sheet summary::before {
  content: '▶';
  font-size: 9px;
  transition: transform 0.15s;
}

.debug-sheet[open] summary::before {
  transform: rotate(90deg);
}

.debug-sheet summary:hover { color: var(--text); }

/* Chart / embed area */
.chart-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.chart-container iframe {
  width: 100%;
  height: 600px;
  border: none;
  display: block;
}
