/* styles.css — Dark Trading Terminal — Mobile-First */

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

:root {
  --bg-base:    #0d1117;
  --bg-surface: #161b22;
  --bg-card:    #1c2128;
  --bg-hover:   #21262d;
  --bg-input:   #0d1117;

  --border:     #30363d;
  --border-dim: #21262d;

  --text-primary:   #e6edf3;
  --text-secondary: #8b949e;
  --text-dim:       #484f58;

  --green:      #22c55e;
  --green-dim:  rgba(34,197,94,0.15);
  --red:        #ef4444;
  --red-dim:    rgba(239,68,68,0.15);
  --blue:       #38bdf8;
  --amber:      #f59e0b;
  --purple:     #a855f7;
  --cyan:       #06b6d4;

  --radius-sm: 4px;
  --radius:    8px;
  --radius-lg: 12px;

  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  --font-ui:   'Inter', 'Segoe UI', system-ui, sans-serif;

  --header-h: 52px;
}

html { font-size: 14px; scroll-behavior: smooth; }

body {
  font-family: var(--font-ui);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* ── Typography ────────────────────────────────────────────────────────────── */
h1, h2, h3 { letter-spacing: -0.02em; }
small { font-size: 0.78rem; color: var(--text-secondary); }
label { color: var(--text-secondary); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; }

/* ── Scrollbars ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Layout ────────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  padding-bottom: 24px;
}

/* ── Header ────────────────────────────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--bg-base);
  border-bottom: 1px solid var(--border-dim);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 10px;
  backdrop-filter: blur(8px);
}

.header-logo {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
  color: var(--green);
  letter-spacing: 0.04em;
}

.header-logo span { color: var(--text-secondary); font-weight: 400; }

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.net-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.net-online  { background: var(--green); box-shadow: 0 0 6px var(--green); animation: pulse 2s infinite; }
.net-offline { background: var(--red); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* ── Daily PnL Banner ──────────────────────────────────────────────────────── */
.daily-pnl-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-dim);
  font-family: var(--font-mono);
}

.pnl-positive { background: var(--green-dim); }
.pnl-negative { background: var(--red-dim); }

.pnl-left { display: flex; align-items: center; gap: 10px; }

.pnl-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
}

.pnl-amount {
  font-size: 1.05rem;
  font-weight: 700;
}
.pnl-positive .pnl-amount { color: var(--green); }
.pnl-negative .pnl-amount { color: var(--red); }

.pnl-right { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.pnl-stat  { font-size: 0.72rem; color: var(--text-secondary); }
.win-rate  { color: var(--amber); }

/* ── Pair Selector ─────────────────────────────────────────────────────────── */
.pair-selector-row {
  display: flex;
  overflow-x: auto;
  gap: 6px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-dim);
  scrollbar-width: none;
}
.pair-selector-row::-webkit-scrollbar { display: none; }

.pair-btn {
  flex-shrink: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.pair-btn:active { transform: scale(0.96); }
.pair-btn.active {
  background: var(--green-dim);
  border-color: var(--green);
  color: var(--green);
}

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-dim);
  border-radius: var(--radius-lg);
  margin: 10px 12px 0;
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-dim);
}

.card-title {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
}

.card-body { padding: 12px 14px; }

/* ── Price Card ─────────────────────────────────────────────────────────────── */
.price-card-body {
  padding: 14px;
}

.price-main {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 10px;
}

#price-current {
  font-family: var(--font-mono);
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-primary);
  transition: color 0.2s;
}

#price-change {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
}

.price-up   { color: var(--green) !important; }
.price-down { color: var(--red)   !important; }

.price-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.price-stat-item { display: flex; flex-direction: column; gap: 2px; }
.price-stat-item label { font-size: 0.68rem; }
.price-stat-item value {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-primary);
}

.blink { animation: blink-anim 0.4s; }
@keyframes blink-anim {
  0%   { color: var(--green); }
  100% { color: var(--text-primary); }
}

/* ── Signal Card ────────────────────────────────────────────────────────────── */
.signal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px 14px;
}

.signal-item { display: flex; flex-direction: column; gap: 3px; }
.signal-item label { font-size: 0.68rem; }
.signal-item value {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
}

.signal-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 14px;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.signal-buy     { color: var(--green); background: var(--green-dim); border: 1px solid var(--green); }
.signal-sell    { color: var(--red);   background: var(--red-dim);   border: 1px solid var(--red); }
.signal-neutral { color: var(--text-secondary); background: var(--bg-hover); border: 1px solid var(--border); }

.conf-bar-track {
  height: 5px;
  background: var(--bg-hover);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 4px;
}
#signal-conf-bar {
  height: 100%;
  border-radius: 3px;
  transition: width 0.6s ease;
}

/* ── Auto mode badge ────────────────────────────────────────────────────────── */
.badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}
.badge-auto-on  { background: rgba(34,197,94,0.2); color: var(--green); border: 1px solid var(--green); }
.badge-auto-off { background: var(--bg-hover); color: var(--text-dim); border: 1px solid var(--border); }

/* ── Chart Section ──────────────────────────────────────────────────────────── */
.chart-section {
  margin: 10px 12px 0;
  background: var(--bg-card);
  border: 1px solid var(--border-dim);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.chart-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-dim);
  overflow-x: auto;
  scrollbar-width: none;
}
.chart-toolbar::-webkit-scrollbar { display: none; }

#chart-pair-label {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-right: 4px;
  white-space: nowrap;
}

#tf-selector {
  display: flex;
  gap: 4px;
}

.tf-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: all 0.12s;
  white-space: nowrap;
}
.tf-btn.active { background: var(--bg-hover); border-color: var(--border); color: var(--text-primary); }
.tf-btn:active { transform: scale(0.93); }

.chart-ema-legend {
  display: flex;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
}
.ema-dot {
  font-size: 0.68rem;
  font-family: var(--font-mono);
  display: flex;
  align-items: center;
  gap: 3px;
}
.ema-dot::before {
  content: '';
  display: inline-block;
  width: 12px; height: 2px;
  border-radius: 1px;
}
.ema20::before  { background: #38bdf8; }
.ema50::before  { background: #f59e0b; }
.ema200::before { background: #a855f7; }

.chart-ctrl-btn {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  cursor: pointer;
  white-space: nowrap;
}
.chart-ctrl-btn:active { transform: scale(0.94); }

.chart-wrap {
  position: relative;
  height: 340px;
}

#chart-container {
  width: 100%;
  height: 100%;
}

#chart-loading {
  position: absolute;
  inset: 0;
  background: rgba(13,17,23,0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Panel (collapsible) ────────────────────────────────────────────────────── */
.panel {
  margin: 10px 12px 0;
  background: var(--bg-card);
  border: 1px solid var(--border-dim);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid var(--border-dim);
  transition: background 0.12s;
}
.panel-header:active { background: var(--bg-hover); }

.panel-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.panel-count {
  font-size: 0.7rem;
  color: var(--text-dim);
}

.chevron {
  color: var(--text-dim);
  font-size: 1.1rem;
  transition: transform 0.2s;
}
.panel-collapsed .chevron { transform: rotate(90deg); }

.panel-body { overflow: hidden; transition: max-height 0.25s ease; }
.panel-body.collapsed { max-height: 0 !important; }

/* ── Open Trades ────────────────────────────────────────────────────────────── */
.trade-card {
  border-bottom: 1px solid var(--border-dim);
  padding: 12px 14px;
}
.trade-card:last-child { border-bottom: none; }

.trade-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.trade-pair {
  display: flex;
  align-items: center;
  gap: 7px;
}

.pair-badge {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
}

.trade-side {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  text-transform: uppercase;
}
.trade-side.buy  { background: var(--green-dim); color: var(--green); border: 1px solid var(--green); }
.trade-side.sell { background: var(--red-dim);   color: var(--red);   border: 1px solid var(--red); }

.trade-live-profit {
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 700;
}

.live-indicator {
  font-size: 0.6rem;
  animation: pulse 1.5s infinite;
}

.profit-positive { color: var(--green); }
.profit-negative { color: var(--red); }

.live-pnl-pct {
  font-size: 0.75rem;
  font-weight: 500;
}

.trade-card-body {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.trade-stat { display: flex; flex-direction: column; gap: 2px; }
.trade-stat label  { font-size: 0.65rem; }
.trade-stat value  { font-family: var(--font-mono); font-size: 0.78rem; color: var(--text-primary); }

.trade-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.trade-notes {
  font-size: 0.68rem;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.btn-close-trade {
  background: var(--red-dim);
  border: 1px solid var(--red);
  color: var(--red);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 0.75rem;
  font-weight: 700;
  font-family: var(--font-mono);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.12s;
}
.btn-close-trade:active  { transform: scale(0.95); }
.btn-close-trade:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Trade History Table ────────────────────────────────────────────────────── */
.history-table-wrapper { overflow-x: auto; }

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.history-table th {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border-dim);
  background: var(--bg-surface);
  white-space: nowrap;
}

.history-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-dim);
  font-family: var(--font-mono);
  white-space: nowrap;
}
.history-table tr:last-child td { border-bottom: none; }
.row-win td { background: rgba(34,197,94,0.03); }
.row-loss td { background: rgba(239,68,68,0.03); }

.td-date  { color: var(--text-secondary); font-size: 0.7rem; }
.td-profit { color: var(--green); font-weight: 700; }
.td-loss   { color: var(--red);   font-weight: 700; }

.pair-badge-sm {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  padding: 2px 5px;
  border-radius: 3px;
  font-size: 0.72rem;
  font-weight: 700;
}

/* ── Settings Panel ─────────────────────────────────────────────────────────── */
.settings-body { padding: 14px; }

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.setting-field { display: flex; flex-direction: column; gap: 5px; }

.setting-field label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-secondary);
}

.setting-field input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 8px 10px;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}
.setting-field input:focus { border-color: var(--green); }

.auto-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-top: 1px solid var(--border-dim);
  margin-bottom: 14px;
}

.auto-label {
  font-size: 0.85rem;
  font-weight: 700;
  font-family: var(--font-mono);
}
.auto-on  { color: var(--green); }
.auto-off { color: var(--text-secondary); }

/* Toggle switch */
.toggle-wrap { position: relative; display: inline-block; width: 44px; height: 24px; }
.toggle-wrap input { display: none; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  background: var(--text-secondary);
  border-radius: 50%;
  top: 2px; left: 2px;
  transition: transform 0.2s, background 0.2s;
}
.toggle-wrap input:checked + .toggle-slider { background: rgba(34,197,94,0.3); border-color: var(--green); }
.toggle-wrap input:checked + .toggle-slider::before { transform: translateX(20px); background: var(--green); }

#save-settings-btn {
  width: 100%;
  padding: 11px;
  background: var(--green);
  color: #0d1117;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 700;
  font-family: var(--font-ui);
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}
#save-settings-btn:active   { transform: scale(0.98); }
#save-settings-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── Manual Buy Fab ─────────────────────────────────────────────────────────── */
.fab-row {
  position: sticky;
  bottom: 16px;
  display: flex;
  justify-content: center;
  padding: 0 12px;
  margin-top: 16px;
  z-index: 50;
}

#manual-buy-btn {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #fff;
  border: none;
  border-radius: var(--radius-lg);
  padding: 14px 32px;
  font-size: 1rem;
  font-weight: 800;
  font-family: var(--font-ui);
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(34,197,94,0.35);
  letter-spacing: 0.04em;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 8px;
}
#manual-buy-btn:active { transform: scale(0.97); box-shadow: 0 2px 10px rgba(34,197,94,0.2); }

/* ── Buy Modal ──────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.72);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(4px);
}
.modal-overlay.open { display: flex; }

.modal-sheet {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 20px 20px 32px;
  width: 100%;
  max-width: 520px;
  animation: slide-up 0.22s ease;
}
@keyframes slide-up {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.modal-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.modal-info-item { display: flex; flex-direction: column; gap: 3px; }
.modal-info-item label { font-size: 0.68rem; }
.modal-info-item value { font-family: var(--font-mono); font-size: 0.9rem; font-weight: 700; }

.modal-field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.modal-field label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-secondary); }
.modal-field input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 12px;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  outline: none;
}
.modal-field input:focus { border-color: var(--green); }

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 10px;
  margin-top: 16px;
}

#modal-cancel {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 12px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

#modal-confirm {
  background: var(--green);
  border: none;
  color: #0d1117;
  padding: 12px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 800;
  cursor: pointer;
}
#modal-confirm:active   { transform: scale(0.98); }
#modal-confirm:disabled { opacity: 0.6; }

/* ── Toast Notifications ────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: min(90vw, 360px);
}

.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 0.82rem;
  font-weight: 500;
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.25s ease;
  pointer-events: auto;
  width: 100%;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { border-color: var(--green); }
.toast-error   { border-color: var(--red); }
.toast-icon    { font-weight: 900; }
.toast-success .toast-icon { color: var(--green); }
.toast-error   .toast-icon { color: var(--red); }

/* ── Empty States ───────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 16px;
  gap: 6px;
  color: var(--text-dim);
}
.empty-icon { font-size: 1.6rem; margin-bottom: 4px; }
.empty-state p { font-size: 0.85rem; color: var(--text-secondary); }
.empty-state small { text-align: center; max-width: 220px; }

/* ── Responsive — tablet ────────────────────────────────────────────────────── */
@media (min-width: 520px) {
  #app { padding-left: 0; padding-right: 0; }
  .chart-wrap { height: 420px; }
}

@media (min-width: 768px) {
  html { font-size: 15px; }
  .chart-wrap { height: 480px; }
  #price-current { font-size: 2rem; }
}

/* ── Reduced motion ─────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
