:root,
[data-theme="dark"] {
  color-scheme: dark;
  --bg-ground: #0E1517;
  --bg-surface: #151F22;
  --bg-elevated: #1D2A2E;
  --bg-chart: #111A1D;

  --text-primary: #F2F5F4;
  --text-muted: #9FB0B4;

  --border-subtle: #26353A;
  --border-control: #6B8187;

  --accent-bg: #E0A82E;
  --accent-hover: #C99422;
  --accent-fg: #0E1517;
  --accent-text: #E8B74B;
  --accent-tint: rgba(224, 168, 46, 0.14);

  --up-text: #2DD4A0;
  --up-tint: rgba(45, 212, 160, 0.12);
  --down-text: #FCA5A5;
  --down-tint: rgba(248, 113, 113, 0.14);

  --focus-ring: #E8B74B;
}

[data-theme="light"] {
  color-scheme: light;
  --bg-ground: #F5F4EF;
  --bg-surface: #FFFFFF;
  --bg-elevated: #EAE8DF;
  --bg-chart: #FFFFFF;

  --text-primary: #111A1C;
  --text-muted: #495A5E;

  --border-subtle: #D4D2C7;
  --border-control: #5E7074;

  --accent-bg: #8F630A;
  --accent-hover: #734E07;
  --accent-fg: #FFFFFF;
  --accent-text: #8F630A;
  --accent-tint: rgba(143, 99, 10, 0.1);

  --up-text: #0F766E;
  --up-tint: rgba(15, 118, 110, 0.1);
  --down-text: #B91C1C;
  --down-tint: rgba(185, 28, 28, 0.1);

  --focus-ring: #8F630A;
}

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

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg-ground);
  color: var(--text-primary);
  font-family: 'Sora', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: 'Roboto Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-variant-numeric: tabular-nums;
}

a[href],
button:not(:disabled),
select:not(:disabled),
label[for] {
  cursor: pointer;
}

button:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  z-index: 100;
  padding: 10px 14px;
  border-radius: 6px;
  background: var(--accent-bg);
  color: var(--accent-fg);
  font-weight: 700;
  text-decoration: none;
}

.skip-link:focus {
  left: 12px;
}

/* Header */
.top-tape {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
}

.top-tape-inner {
  max-width: 1560px;
  margin: 0 auto;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-title {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.conn-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
}

.conn-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
}

.conn-badge[data-mode="live"] {
  color: var(--up-text);
  border-color: var(--up-text);
  background: var(--up-tint);
}

.conn-badge[data-mode="live"] .conn-dot {
  background: var(--up-text);
}

.conn-badge[data-mode="poll"] {
  color: var(--accent-text);
  border-color: var(--accent-text);
}

.conn-badge[data-mode="poll"] .conn-dot {
  background: var(--accent-text);
}

.conn-badge[data-mode="offline"] {
  color: var(--down-text);
  border-color: var(--down-text);
  background: var(--down-tint);
}

.conn-badge[data-mode="offline"] .conn-dot {
  background: var(--down-text);
}

.tape-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tape-chip {
  padding: 5px 10px;
  border-radius: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  font-size: 0.78rem;
  color: var(--text-primary);
}

.tape-chip.is-gold {
  color: var(--accent-text);
  border-color: var(--border-control);
  font-weight: 700;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 6px;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent-bg);
  color: var(--accent-fg);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-control);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--text-primary);
}

.btn-ghost {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--border-subtle);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-elevated);
  border-color: var(--border-control);
}

.btn-sm {
  min-height: 36px;
  padding: 0 10px;
  font-size: 0.78rem;
}

/* Main Grid */
.desk-grid {
  max-width: 1560px;
  margin: 0 auto;
  padding: 14px 16px 20px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.chart-column {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.desk-bar {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.bar-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.mode-switch {
  display: inline-flex;
  padding: 3px;
  border-radius: 8px;
  background: var(--bg-ground);
  border: 1px solid var(--border-subtle);
  gap: 4px;
}

.mode-btn {
  min-height: 38px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
}

.mode-btn.is-active {
  background: var(--accent-bg);
  color: var(--accent-fg);
}

.select-broker {
  min-height: 44px;
  padding: 0 12px;
  border-radius: 6px;
  border: 1px solid var(--border-control);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 600;
}

.symbol-tag {
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--accent-tint);
  border: 1px solid var(--accent-text);
  color: var(--accent-text);
  font-size: 0.82rem;
  font-weight: 700;
}

.tf-btn,
.ind-btn {
  min-height: 40px;
  min-width: 44px;
  padding: 0 10px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
}

.tf-btn:hover,
.ind-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-control);
}

.tf-btn.is-active {
  background: var(--accent-bg);
  color: var(--accent-fg);
  border-color: var(--accent-bg);
}

.ind-btn.is-active {
  background: var(--accent-tint);
  color: var(--accent-text);
  border-color: var(--accent-text);
}

/* Chart Card */
.chart-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.cfd-stage {
  width: 100%;
  height: 580px;
  background: var(--bg-chart);
}

.lite-toolbar {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.lite-metrics {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.lite-metrics strong {
  color: var(--text-primary);
}

.ohlcv-bar {
  padding: 6px 14px;
  font-size: 0.78rem;
  color: var(--text-muted);
  background: var(--bg-chart);
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
  overflow-x: auto;
}

.lite-stage {
  position: relative;
  width: 100%;
  height: 500px;
  background: var(--bg-chart);
}

.chart-canvas {
  width: 100%;
  height: 100%;
}

.chart-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  padding: 20px;
  background: rgba(14, 21, 23, 0.88);
  color: #F2F5F4;
}

.chart-overlay h2 {
  margin: 0;
  font-size: 1.05rem;
}

.chart-overlay p {
  margin: 0;
  max-width: 40ch;
  font-size: 0.86rem;
  color: #CBD5E1;
}

/* Right Rail */
.desk-rail {
  min-width: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.rail-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
}

.rail-tab-btn {
  min-height: 46px;
  padding: 6px 8px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.rail-tab-btn:hover {
  color: var(--text-primary);
}

.rail-tab-btn.is-active {
  background: var(--bg-surface);
  color: var(--accent-text);
  border-bottom-color: var(--accent-text);
}

.tab-count {
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--bg-elevated);
  font-size: 0.72rem;
}

.rail-panel {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.watchlist-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.watch-row {
  width: 100%;
  min-height: 54px;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: inherit;
  font: inherit;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
}

.watch-row:hover {
  background: var(--bg-elevated);
  border-color: var(--border-control);
}

.watch-row.is-active {
  background: var(--accent-tint);
  border-color: var(--accent-text);
}

.watch-left,
.watch-right {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.watch-right {
  text-align: right;
}

.watch-name {
  font-weight: 700;
  font-size: 0.88rem;
}

.watch-sub {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.panel-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-label {
  font-size: 0.77rem;
  font-weight: 600;
  color: var(--text-muted);
}

.field-input {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border-control);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font: inherit;
  font-size: 0.88rem;
}

.form-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.form-actions .btn-primary {
  flex: 1 1 auto;
}

.form-error {
  margin: 0;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--down-tint);
  color: var(--down-text);
  font-size: 0.8rem;
  font-weight: 600;
}

.alert-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--border-subtle);
}

.alert-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
}

.alert-item.is-triggered {
  border-color: var(--accent-text);
  background: var(--accent-tint);
}

.alert-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.alert-title {
  font-size: 0.83rem;
  font-weight: 700;
}

.alert-status {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.empty-note {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.calc-result {
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.calc-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
}

.calc-row span:first-child {
  color: var(--text-muted);
}

.calc-row strong[data-dir="up"] {
  color: var(--up-text);
}

.calc-row strong[data-dir="down"] {
  color: var(--down-text);
}

.site-footer {
  max-width: 1560px;
  margin: 0 auto;
  padding: 10px 16px 24px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.site-footer p {
  margin: 0;
}

.app-toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(460px, calc(100vw - 24px));
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--accent-bg);
  color: var(--accent-fg);
  font-size: 0.84rem;
  font-weight: 700;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

@media (prefers-reduced-motion: no-preference) {
  .btn,
  .tf-btn,
  .ind-btn,
  .watch-row,
  .rail-tab-btn,
  .mode-btn {
    transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
  }
}

@media (min-width: 1100px) {
  .desk-grid {
    grid-template-columns: minmax(0, 2.4fr) minmax(330px, 0.92fr);
    gap: 16px;
    padding: 16px 20px 24px;
  }

  .cfd-stage {
    height: 620px;
  }
}

@media (max-width: 639px) {
  .top-tape-inner {
    padding: 8px 12px;
  }

  .desk-grid {
    padding: 10px 12px 18px;
  }

  .cfd-stage {
    height: 430px;
  }

  .lite-stage {
    height: 360px;
  }

  .field-row {
    grid-template-columns: minmax(0, 1fr);
  }
}
