/* =====================================================
   CRYPTO TRADING TOOL — GLOBAL STYLES
   Design: Dark terminal-grade UI, amber/green accents
   ===================================================== */

:root {
  /* Core palette */
  --bg-base:      #080b0f;
  --bg-panel:     #0f1318;
  --bg-surface:   #161c24;
  --bg-elevated:  #1e2630;
  --border:       #2a3340;
  --border-hi:    #3d4f62;

  /* Accents */
  --accent:       #f0b90b;   /* Binance amber */
  --accent-dim:   #c49509;
  --bull:         #0ecb81;   /* green */
  --bull-dim:     rgba(14,203,129,0.15);
  --bear:         #f6465d;   /* red */
  --bear-dim:     rgba(246,70,93,0.15);
  --alert-blue:   #3b82f6;
  --alert-orange: #f97316;

  /* Text */
  --text-hi:      #e8ecf0;
  --text-mid:     #8a96a3;
  --text-lo:      #4a5568;

  /* Chart */
  --chart-grid:   rgba(255,255,255,0.04);
  --chart-cross:  rgba(255,255,255,0.25);

  /* Sizing */
  --panel-w:      420px;
  --header-h:     44px;
  --tab-h:        42px;
  --radius:       4px;
  --radius-lg:    8px;

  /* Type */
  --font-mono:    'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  --font-ui:      -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;

  /* Motion */
  --t-fast:       120ms ease;
  --t-mid:        220ms ease;
}

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

html, body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  font-family: var(--font-ui);
  font-size: 13px;
  background: var(--bg-base);
  color: var(--text-hi);
  -webkit-font-smoothing: antialiased;
}

/* ── Scrollbars ─────────────────────────────────────── */
::-webkit-scrollbar           { width: 5px; height: 5px; }
::-webkit-scrollbar-track     { background: transparent; }
::-webkit-scrollbar-thumb     { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hi); }

/* ── Layout ─────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: 1fr var(--panel-w);
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  background: var(--border);
  gap: 1px;
}

/* ── Chart panel ────────────────────────────────────── */
.chart-panel {
  background: var(--bg-base);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.chart-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chart-title {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-hi);
  letter-spacing: 0.02em;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chart-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chart-btn {
  height: 28px;
  padding: 0 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-mid);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--t-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  white-space: nowrap;
}
.chart-btn:hover { background: var(--bg-elevated); color: var(--text-hi); border-color: var(--border-hi); }
.chart-btn.active { background: var(--accent); color: #000; border-color: var(--accent); }

.chart-select {
  height: 28px;
  padding: 0 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-hi);
  font-size: 12px;
  cursor: pointer;
  outline: none;
}
.chart-select:hover { border-color: var(--border-hi); }

.tf-btns {
  display: flex;
  gap: 2px;
}
.tf-btn {
  height: 26px;
  padding: 0 7px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text-mid);
  font-size: 11px;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: all var(--t-fast);
}
.tf-btn:hover { color: var(--text-hi); background: var(--bg-surface); }
.tf-btn.active { color: var(--accent); border-color: var(--accent); background: rgba(240,185,11,0.08); }

/* ── Chart body ─────────────────────────────────────── */
.chart-body {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.chart-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-base);
  z-index: 10;
  flex-direction: column;
  gap: 12px;
  color: var(--text-mid);
}
.chart-overlay.hidden { display: none; }

.placeholder-icon { font-size: 32px; opacity: 0.4; }
.placeholder-text { font-size: 13px; color: var(--text-lo); }

/* Spinner */
.spinner {
  width: 28px; height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Price/volume canvases */
.price-canvas-wrap {
  position: absolute;
  top: 0; left: 0; right: 0;
  bottom: 80px;  /* leave room for volume */
}
.volume-canvas-wrap {
  position: absolute;
  left: 0; right: 0;
  bottom: 0;
  height: 80px;
  border-top: 1px solid var(--border);
}

canvas { display: block; width: 100%; height: 100%; }

/* Zoom buttons */
.zoom-btns {
  position: absolute;
  top: 8px;
  left: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 5;
}
.zoom-btn {
  width: 26px; height: 26px;
  background: rgba(15,19,24,0.85);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-mid);
  font-size: 14px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--t-fast);
  backdrop-filter: blur(4px);
}
.zoom-btn:hover { color: var(--text-hi); border-color: var(--border-hi); }

/* Latest button */
.latest-btn {
  position: absolute;
  bottom: 90px;
  right: 90px;
  z-index: 5;
  background: rgba(240,185,11,0.15);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  color: var(--accent);
  font-size: 11px;
  padding: 4px 8px;
  cursor: pointer;
  display: none;
  backdrop-filter: blur(4px);
  transition: all var(--t-fast);
}
.latest-btn:hover { background: rgba(240,185,11,0.25); }
.latest-btn.visible { display: block; }

/* Line status popup */
.line-status-popup {
  position: absolute;
  top: 50px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  z-index: 20;
  display: none;
  min-width: 240px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.6);
}
.line-status-popup.visible { display: block; }

/* ── Side panel ─────────────────────────────────────── */
.side-panel {
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Tabs */
.tabs-nav {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.tab-btn {
  flex: 1;
  height: var(--tab-h);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-mid);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--t-fast);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.tab-btn:hover { color: var(--text-hi); background: var(--bg-surface); }
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: rgba(240,185,11,0.04);
}

.tab-badge {
  background: var(--bear);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
  line-height: 16px;
  display: none;
}
.tab-badge.visible { display: inline-block; }

.tab-panel { display: none; flex: 1; overflow: hidden; flex-direction: column; }
.tab-panel.active { display: flex; }

/* ── Filters bar ────────────────────────────────────── */
.filters-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.filter-label { color: var(--text-lo); font-size: 11px; white-space: nowrap; }

.filter-input, .filter-select {
  height: 26px;
  padding: 0 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-hi);
  font-size: 12px;
  outline: none;
  transition: border-color var(--t-fast);
}
.filter-input:focus, .filter-select:focus { border-color: var(--border-hi); }
.filter-input[type="text"] { width: 80px; }
.filter-input[type="number"] { width: 60px; }

.clear-btn {
  width: 20px; height: 20px;
  background: none; border: none;
  color: var(--text-lo); cursor: pointer; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  transition: color var(--t-fast);
}
.clear-btn:hover { color: var(--text-hi); }

.refresh-btn {
  height: 26px;
  padding: 0 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-mid);
  cursor: pointer;
  font-size: 13px;
  transition: all var(--t-fast);
  margin-left: auto;
}
.refresh-btn:hover { border-color: var(--accent); color: var(--accent); }
.refresh-btn.spinning { animation: spin 0.8s linear infinite; }

/* ── Coins table ────────────────────────────────────── */
.table-wrap {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.coins-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-family: var(--font-mono);
}

.coins-table thead {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-surface);
}

.coins-table th {
  padding: 7px 8px;
  text-align: right;
  color: var(--text-lo);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.coins-table th:first-child { text-align: left; }
.coins-table th:hover { color: var(--text-mid); }
.coins-table th.sort-asc::after  { content: ' ▲'; font-size: 9px; }
.coins-table th.sort-desc::after { content: ' ▼'; font-size: 9px; }

.coins-table td {
  padding: 6px 8px;
  text-align: right;
  border-bottom: 1px solid rgba(42,51,64,0.5);
  white-space: nowrap;
  vertical-align: middle;
}
.coins-table td:first-child { text-align: left; }

.coin-row {
  cursor: pointer;
  transition: background var(--t-fast);
}
.coin-row:hover { background: var(--bg-surface); }
.coin-row.selected { background: rgba(240,185,11,0.08); }
.coin-row.selected .sym { color: var(--accent); }

.sym { font-weight: 600; color: var(--text-hi); font-size: 12px; }
.exch-tag {
  font-size: 9px;
  color: var(--text-lo);
  display: block;
  font-family: var(--font-ui);
  font-weight: 400;
}

.bull { color: var(--bull); }
.bear { color: var(--bear); }
.neu  { color: var(--text-mid); }

/* Flash animation */
@keyframes flash-bull { 0%,100% { background: transparent; } 50% { background: rgba(14,203,129,0.15); } }
@keyframes flash-bear { 0%,100% { background: transparent; } 50% { background: rgba(246,70,93,0.15); } }
.flash-bull { animation: flash-bull 0.4s ease; }
.flash-bear { animation: flash-bear 0.4s ease; }

/* ── Alerts tab ─────────────────────────────────────── */
.alerts-panel { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; }

.alert-item {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
}
.alert-item.active  { border-left: 3px solid var(--alert-blue); }
.alert-item.triggered { border-left: 3px solid var(--text-lo); opacity: 0.6; }

.alert-sym { font-family: var(--font-mono); font-weight: 600; font-size: 13px; }
.alert-price { font-family: var(--font-mono); font-size: 12px; color: var(--text-mid); }
.alert-dist { font-size: 11px; }
.alert-actions { display: flex; gap: 6px; margin-top: 4px; }

.alert-btn {
  height: 22px;
  padding: 0 8px;
  border-radius: var(--radius);
  font-size: 11px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-mid);
  transition: all var(--t-fast);
}
.alert-btn:hover { border-color: var(--border-hi); color: var(--text-hi); }
.alert-btn.danger:hover { border-color: var(--bear); color: var(--bear); }

.alerts-empty {
  text-align: center;
  color: var(--text-lo);
  padding: 40px 20px;
  font-size: 12px;
}

/* ── Trade tab ─────────────────────────────────────── */
.trade-panel { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 10px; }

.auth-form, .order-ticket {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-lo);
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.field-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.field-label { font-size: 11px; color: var(--text-mid); }
.field-input {
  height: 30px;
  padding: 0 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-hi);
  font-size: 12px;
  font-family: var(--font-mono);
  outline: none;
  transition: border-color var(--t-fast);
  width: 100%;
}
.field-input:focus { border-color: var(--accent); }
.field-input[type="password"] { letter-spacing: 0.15em; }

.btn-primary {
  height: 32px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #000;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--t-fast);
  letter-spacing: 0.04em;
}
.btn-primary:hover { background: #d4a009; }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-row { display: flex; gap: 6px; }
.btn-buy  { flex: 1; height: 32px; background: var(--bull); border: none; border-radius: var(--radius); color: #000; font-weight: 700; font-size: 12px; cursor: pointer; transition: all var(--t-fast); }
.btn-sell { flex: 1; height: 32px; background: var(--bear); border: none; border-radius: var(--radius); color: #fff; font-weight: 700; font-size: 12px; cursor: pointer; transition: all var(--t-fast); }
.btn-buy.active  { box-shadow: 0 0 0 2px rgba(14,203,129,0.4); }
.btn-sell.active { box-shadow: 0 0 0 2px rgba(246,70,93,0.4); }

.order-preview {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  padding: 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.preview-row { display: flex; justify-content: space-between; }
.preview-label { color: var(--text-lo); }
.preview-val   { color: var(--text-hi); }

.positions-list { display: flex; flex-direction: column; gap: 6px; }
.position-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.pos-header { display: flex; justify-content: space-between; align-items: center; }
.pos-sym  { font-size: 13px; font-weight: 600; }
.pos-side { font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 3px; }
.pos-side.long  { background: rgba(14,203,129,0.2); color: var(--bull); }
.pos-side.short { background: rgba(246,70,93,0.2); color: var(--bear); }
.pos-pnl { font-size: 13px; font-weight: 600; }
.pos-close-btn {
  margin-top: 4px;
  height: 22px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-mid);
  font-size: 10px;
  cursor: pointer;
  transition: all var(--t-fast);
}
.pos-close-btn:hover { border-color: var(--bear); color: var(--bear); }

/* ── Scanner tab ────────────────────────────────────── */
.scanner-panel { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.scanner-controls {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}
.scanner-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.scanner-progress { font-family: var(--font-mono); font-size: 11px; color: var(--text-mid); }
.btn-scan-start {
  height: 28px; padding: 0 12px;
  background: var(--bull); border: none; border-radius: var(--radius);
  color: #000; font-size: 12px; font-weight: 700; cursor: pointer;
  transition: all var(--t-fast);
}
.btn-scan-start:hover { filter: brightness(1.1); }
.btn-scan-stop {
  height: 28px; padding: 0 12px;
  background: var(--bear); border: none; border-radius: var(--radius);
  color: #fff; font-size: 12px; font-weight: 700; cursor: pointer;
}

.scanner-table-wrap { flex: 1; overflow-y: auto; }
.scanner-table { width: 100%; border-collapse: collapse; font-family: var(--font-mono); font-size: 12px; }
.scanner-table th {
  padding: 6px 8px; text-align: right;
  color: var(--text-lo); font-size: 10px;
  text-transform: uppercase; letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface); position: sticky; top: 0;
}
.scanner-table th:first-child { text-align: left; }
.scanner-table td { padding: 5px 8px; text-align: right; border-bottom: 1px solid rgba(42,51,64,0.4); }
.scanner-table td:first-child { text-align: left; }
.scanner-row-item { cursor: pointer; transition: background var(--t-fast); }
.scanner-row-item:hover { background: var(--bg-surface); }
.scanner-row-item.current { background: rgba(240,185,11,0.08); }

/* ── Toast notifications ────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}
.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius-lg);
  padding: 10px 16px;
  font-size: 12px;
  color: var(--text-hi);
  box-shadow: 0 8px 24px rgba(0,0,0,0.6);
  animation: toast-in 0.2s ease;
  white-space: nowrap;
}
.toast.success { border-color: var(--bull); }
.toast.error   { border-color: var(--bear); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ── Responsive ─────────────────────────────────────── */
@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 60dvh 40dvh;
  }
  .chart-header .tf-btns { display: none; }
}
