/* ==========================================================================
   Keseimbangan · Terminal Pasar (Japanese Editorial Studio)
   ========================================================================== */

:root,
[data-theme="dark"] {
  color-scheme: dark;
  --bg-ground: #0e0f11;
  --bg-surface: #151619;
  --bg-elevated: #1d1f24;
  --bg-header: rgba(14, 15, 17, 0.94);

  --text-primary: #f2f2ee;
  --text-secondary: #b0b0a9;
  --text-muted: #888882;

  --border: #282a30;
  --border-strong: #3d4049;
  --border-subtle: #22242a;

  --accent: #7ba4f0;
  --accent-hover: #9bc0ff;
  --accent-subtle: #192338;
  --accent-subtle-text: #93b6f5;

  --cta-bg: #f2f2ee;
  --cta-bg-hover: #dcdcd5;
  --cta-text: #111214;

  --up-text: #34d399;
  --up-tint: rgba(52, 211, 153, 0.12);
  --down-text: #f87171;
  --down-tint: rgba(248, 113, 113, 0.14);

  --gold-tape-bg: rgba(224, 168, 46, 0.12);
  --gold-tape-text: #e8b74b;
  --focus-ring: #7ba4f0;

  /* Canvas chart tokens */
  --chart-bg: #111619;
  --chart-grid: #1c2429;
  --chart-text: #8c9aa0;
  --chart-axis-border: #2b343b;
  --chart-up: #2dd4a0;
  --chart-down: #f87171;
  --chart-up-volume: rgba(45, 212, 160, 0.25);
  --chart-down-volume: rgba(248, 113, 113, 0.25);
  --chart-crosshair: #e0a82e;
  --chart-label-bg: #2a3238;
  --chart-label-text: #f2f2ee;

  --ind-ema20: #e0a82e;
  --ind-ema50: #38bdf8;
  --ind-bb: rgba(148, 163, 184, 0.72);
  --alert-line: #e0a82e;
}

[data-theme="light"] {
  color-scheme: light;
  --bg-ground: #f6f6f3;
  --bg-surface: #ffffff;
  --bg-elevated: #eeede8;
  --bg-header: rgba(246, 246, 243, 0.94);

  --text-primary: #141414;
  --text-secondary: #4a4a46;
  --text-muted: #5c5c57;

  --border: #dcdcd6;
  --border-strong: #bfbfb7;
  --border-subtle: #e5e5df;

  --accent: #22438c;
  --accent-hover: #1a3470;
  --accent-subtle: #eaeff9;
  --accent-subtle-text: #1d3a7a;

  --cta-bg: #141414;
  --cta-bg-hover: #2c2c2a;
  --cta-text: #ffffff;

  --up-text: #059669;
  --up-tint: rgba(5, 150, 105, 0.08);
  --down-text: #dc2626;
  --down-tint: rgba(220, 38, 38, 0.08);

  --gold-tape-bg: rgba(143, 99, 10, 0.09);
  --gold-tape-text: #8f630a;
  --focus-ring: #22438c;

  /* Canvas chart tokens */
  --chart-bg: #ffffff;
  --chart-grid: #e8e6de;
  --chart-text: #546266;
  --chart-axis-border: #d0cec4;
  --chart-up: #0f766e;
  --chart-down: #b91c1c;
  --chart-up-volume: rgba(15, 118, 110, 0.22);
  --chart-down-volume: rgba(185, 28, 28, 0.22);
  --chart-crosshair: #8f630a;
  --chart-label-bg: #1e2428;
  --chart-label-text: #ffffff;

  --ind-ema20: #8f630a;
  --ind-ema50: #0284c7;
  --ind-bb: rgba(100, 116, 139, 0.65);
  --alert-line: #b45309;
}

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

html {
  font-size: 14px;
}

body {
  background: var(--bg-ground);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.mono {
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
}

.font-mincho {
  font-family: "Shippori Mincho", Georgia, serif;
}

.skip-link {
  position: absolute;
  top: -100px;
  left: 1rem;
  background: var(--cta-bg);
  color: var(--cta-text);
  padding: 0.5rem 1rem;
  z-index: 100;
  border-radius: 2px;
  font-weight: 600;
  text-decoration: none;
}
.skip-link:focus {
  top: 1rem;
}

/* Header */
.top-tape {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg-header);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 0.65rem 1.25rem;
}

.top-tape-inner {
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand-group,
.tape-right,
.bar-group {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.brand-title {
  font-family: "Shippori Mincho", Georgia, serif;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand-badge {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  border-radius: 2px;
  background: var(--accent-subtle);
  color: var(--accent-subtle-text);
  border: 1px solid var(--border);
}

.conn-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 2px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-muted);
}
.conn-dot {
  width: 6px;
  height: 6px;
  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(--gold-tape-text);
  border-color: var(--gold-tape-text);
  background: var(--gold-tape-bg);
}
.conn-badge[data-mode="poll"] .conn-dot {
  background: var(--gold-tape-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-chip {
  font-size: 0.75rem;
  padding: 0.3rem 0.65rem;
  border-radius: 2px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.tape-chip.is-gold {
  background: var(--gold-tape-bg);
  color: var(--gold-tape-text);
  border-color: var(--gold-tape-text);
  font-weight: 700;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.4rem 0.8rem;
  min-height: 32px;
  border-radius: 2px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-primary);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.btn:hover {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
}
.btn-primary {
  background: var(--cta-bg);
  color: var(--cta-text);
  border-color: var(--cta-bg);
}
.btn-primary:hover {
  background: var(--cta-bg-hover);
  border-color: var(--cta-bg-hover);
}
.btn-ghost {
  background: transparent;
}
.btn-sm {
  padding: 0.22rem 0.55rem;
  font-size: 0.72rem;
  min-height: 26px;
}

/* Workspace Layout */
.desk-grid {
  flex: 1;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  padding: 1rem 1.25rem;
  display: grid;
  grid-template-columns: 1fr 350px;
  gap: 1.25rem;
  align-items: start;
}

@media (max-width: 1080px) {
  .desk-grid {
    grid-template-columns: 1fr;
  }
}

.chart-column {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
}

.desk-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.55rem 0.75rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 3px;
}

.provider-tag {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.18rem 0.45rem;
  border-radius: 2px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.symbol-tag {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-subtle);
  border: 1px solid var(--border);
  padding: 0.2rem 0.55rem;
  border-radius: 2px;
}

.live-price {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-primary);
}

.tf-btn,
.ind-btn {
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.25rem 0.55rem;
  border-radius: 2px;
  cursor: pointer;
}
.tf-btn:hover,
.ind-btn:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
}
.tf-btn.is-active,
.ind-btn.is-active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

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

.chart-toolbar {
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.chart-info {
  padding: 0.35rem 0.75rem;
  font-size: 0.72rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}
#ohlc-bar[data-dir="up"] { color: var(--up-text); }
#ohlc-bar[data-dir="down"] { color: var(--down-text); }

.chart-stats {
  display: flex;
  gap: 0.85rem;
  color: var(--text-muted);
}
.chart-stats strong {
  color: var(--text-primary);
}

.chart-stage {
  position: relative;
  height: 540px;
  min-height: 360px;
}
.chart-mount {
  width: 100%;
  height: 100%;
}
.candle-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
  outline: none;
}
.candle-canvas:focus-visible {
  box-shadow: inset 0 0 0 2px var(--focus-ring);
}

.chart-overlay {
  position: absolute;
  inset: 0;
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  text-align: center;
  padding: 1.5rem;
}
.chart-overlay[hidden] {
  display: none;
}

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

.rail-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.rail-tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.65rem 0.5rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border-bottom: 2px solid transparent;
}
.rail-tab-btn.is-active {
  background: var(--bg-surface);
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 700;
}

.tab-count {
  font-size: 0.65rem;
  background: var(--accent-subtle);
  color: var(--accent-subtle-text);
  padding: 0.08rem 0.35rem;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.rail-panel {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}
.rail-panel[hidden] {
  display: none;
}

.panel-caption {
  font-size: 0.74rem;
  color: var(--text-secondary);
  padding-bottom: 0.45rem;
  border-bottom: 1px solid var(--border-subtle);
}

/* Watchlist grouped by provider */
.watchlist-body {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  max-height: 520px;
  overflow-y: auto;
  padding-right: 0.2rem;
}

.watch-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.watch-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.watch-group-name {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-primary);
}

.watch-group-state {
  font-size: 0.65rem;
  padding: 0.1rem 0.4rem;
  border-radius: 2px;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.watch-group-state.is-on {
  color: var(--up-text);
  border-color: var(--up-text);
  background: var(--up-tint);
}

.watch-group-desc {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-bottom: 0.15rem;
}

.watch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 0.75rem;
  background: var(--bg-ground);
  border: 1px solid var(--border-subtle);
  border-radius: 3px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.watch-row:hover:not(:disabled) {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
}
.watch-row.is-active {
  background: var(--accent-subtle);
  border-color: var(--accent);
}
.watch-row:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.watch-left,
.watch-right {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.watch-right {
  align-items: flex-end;
}

.watch-name {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-primary);
}
.watch-row.is-active .watch-name {
  color: var(--accent);
}
.watch-sub {
  font-size: 0.68rem;
  color: var(--text-muted);
}
.watch-price {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-primary);
}
.watch-change {
  font-size: 0.68rem;
}
.watch-change[data-dir="up"] { color: var(--up-text); }
.watch-change[data-dir="down"] { color: var(--down-text); }

/* Forms & Metrics */
.panel-form {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}
.field-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.field-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-secondary);
}
.field-input {
  width: 100%;
  background: var(--bg-ground);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 0.8rem;
  padding: 0.45rem 0.6rem;
  border-radius: 2px;
  outline: none;
}
.field-input:focus {
  border-color: var(--focus-ring);
}
.form-error {
  font-size: 0.74rem;
  color: var(--down-text);
}
.form-actions {
  display: flex;
  gap: 0.5rem;
}
.form-actions .btn {
  flex: 1;
}

.calc-results {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.55rem;
  background: var(--bg-ground);
  padding: 0.7rem;
  border-radius: 2px;
  border: 1px solid var(--border-subtle);
}
.metric-box {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.metric-label {
  font-size: 0.65rem;
  color: var(--text-muted);
}
.metric-val {
  font-size: 0.82rem;
  font-weight: 700;
}
.metric-val.is-accent {
  color: var(--accent);
}
.metric-val[data-dir="up"] { color: var(--up-text); }
.metric-val[data-dir="down"] { color: var(--down-text); }

.empty-note {
  font-size: 0.72rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-subtle);
  padding-top: 0.65rem;
}

.alert-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  max-height: 260px;
  overflow-y: auto;
}
.alert-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.65rem;
  background: var(--bg-ground);
  border: 1px solid var(--border-subtle);
  border-radius: 2px;
}
.alert-item.is-triggered {
  opacity: 0.65;
  border-color: var(--gold-tape-text);
}
.alert-info {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.alert-title {
  font-size: 0.76rem;
  font-weight: 700;
}
.alert-status {
  font-size: 0.66rem;
  color: var(--text-muted);
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  padding: 1rem 1.25rem;
  margin-top: auto;
  font-size: 0.74rem;
  color: var(--text-muted);
}
.footer-inner {
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.footer-title {
  font-weight: 600;
  color: var(--text-primary);
}
.footer-inner a {
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 600;
}
.footer-inner a:hover {
  color: var(--accent);
}

.app-toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  padding: 0.65rem 1rem;
  border-radius: 3px;
  font-size: 0.8rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  z-index: 99;
}
.app-toast[hidden] {
  display: none;
}
