/* ─────────────────────────────────────────────────────────────────────────────
   TradingBot Dashboard — Dark Theme
   ───────────────────────────────────────────────────────────────────────────── */

/* ── Design tokens ─────────────────────────────────────────────────────────── */
:root {
  --bg-base:      #0f1117;
  --bg-surface:   #161b22;
  --bg-card:      #1c2333;
  --bg-card-hover:#21283a;
  --border:       #30363d;
  --border-light: #21262d;

  --green:        #22c55e;
  --green-dim:    #166534;
  --green-bg:     rgba(34,197,94,.10);
  --red:          #ef4444;
  --red-dim:      #991b1b;
  --red-bg:       rgba(239,68,68,.10);
  --amber:        #f59e0b;
  --amber-bg:     rgba(245,158,11,.10);
  --blue:         #3b82f6;
  --blue-bg:      rgba(59,130,246,.10);

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

  --mono:         'Roboto Mono', 'Courier New', monospace;

  --sidebar-w:    220px;
  --header-h:     56px;
  --radius:       8px;
  --radius-sm:    5px;
  --transition:   .15s ease;
}

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

html { font-size: 14px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Scrollbar ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-surface); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ─────────────────────────────────────────────────────────────────────────────
   LOGIN PAGE
   ───────────────────────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse 80% 60% at 50% -10%, rgba(59,130,246,.12) 0%, transparent 60%),
    var(--bg-base);
}

.login-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px 36px;
  width: 360px;
  box-shadow: 0 24px 64px rgba(0,0,0,.5);
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 32px;
}

.login-logo svg { color: var(--green); }
.login-logo span { font-size: 1.2rem; font-weight: 700; letter-spacing: -.3px; }

.login-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.login-subtitle {
  font-size: .85rem;
  color: var(--text-muted);
  margin-bottom: 28px;
}

.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: .8rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.form-input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--mono);
  font-size: .9rem;
  padding: 10px 12px;
  transition: border-color var(--transition);
  outline: none;
}

.form-input:focus { border-color: var(--blue); }
.form-input.error { border-color: var(--red); }

.login-error {
  font-size: .8rem;
  color: var(--red);
  margin-bottom: 16px;
  padding: 8px 12px;
  background: var(--red-bg);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(239,68,68,.2);
}

/* ─────────────────────────────────────────────────────────────────────────────
   APP SHELL
   ───────────────────────────────────────────────────────────────────────────── */

/* Header */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px 0 0;
  z-index: 100;
  transition: background var(--transition), border-color var(--transition);
}

.header.kill-active {
  background: rgba(239,68,68,.08);
  border-bottom-color: rgba(239,68,68,.3);
}

.header-logo {
  width: var(--sidebar-w);
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: .95rem;
  flex-shrink: 0;
}

.header-logo svg { color: var(--green); }

.header-spacer { flex: 1; }

.header-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .8rem;
  color: var(--text-muted);
  margin-right: 20px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}

.status-dot.connected  { background: var(--green); animation: pulse-green 2s infinite; }
.status-dot.reconnecting { background: var(--amber); animation: pulse-amber 1s infinite; }
.status-dot.offline    { background: var(--red); }

@keyframes pulse-green {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34,197,94,.4); }
  50%       { box-shadow: 0 0 0 5px rgba(34,197,94,0); }
}
@keyframes pulse-amber {
  0%, 100% { opacity: 1; }
  50%       { opacity: .4; }
}

/* Kill switch button (header) */
.btn-kill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--red-dim);
  background: var(--red-bg);
  color: var(--red);
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  letter-spacing: .04em;
  text-transform: uppercase;
}

.btn-kill:hover {
  background: rgba(239,68,68,.18);
  border-color: var(--red);
}

.btn-kill.reset {
  border-color: var(--amber-bg);
  background: var(--amber-bg);
  color: var(--amber);
  border-color: rgba(245,158,11,.4);
}

.btn-kill.reset:hover {
  background: rgba(245,158,11,.2);
}

/* Kill switch banner */
.kill-banner {
  position: fixed;
  top: var(--header-h);
  left: var(--sidebar-w);
  right: 0;
  z-index: 90;
  background: rgba(239,68,68,.15);
  border-bottom: 1px solid rgba(239,68,68,.3);
  padding: 8px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: .85rem;
  color: var(--red);
  font-weight: 500;
}

/* Watchdog dead-task banner */
.dead-banner {
  position: fixed;
  top: var(--header-h);
  left: var(--sidebar-w);
  right: 0;
  z-index: 91;                          /* above kill-banner (90) */
  background: rgba(220,38,38,.22);
  border-bottom: 2px solid rgba(220,38,38,.5);
  padding: 8px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: .85rem;
  color: #fca5a5;
  font-weight: 600;
  letter-spacing: .01em;
}

/* Sidebar */
.sidebar {
  position: fixed;
  left: 0;
  top: var(--header-h);
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px 0;
  z-index: 80;
}

.sidebar-section {
  padding: 0 8px;
  margin-bottom: 4px;
}

.sidebar-label {
  font-size: .7rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 8px 12px 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: .875rem;
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-link:hover { color: var(--text-primary); background: var(--border-light); }
.nav-link.active { color: var(--text-primary); background: var(--blue-bg); }
.nav-link.active svg { color: var(--blue); }
.nav-link svg { width: 16px; height: 16px; flex-shrink: 0; }

/* Main layout */
.layout {
  margin-left: var(--sidebar-w);
  margin-top: var(--header-h);
  min-height: calc(100vh - var(--header-h));
}

.layout.with-banner { margin-top: calc(var(--header-h) + 37px); }

.page {
  padding: 24px;
  max-width: 1280px;
}

.page-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.page-subtitle {
  font-size: .85rem;
  color: var(--text-muted);
  margin-bottom: 24px;
}

/* ─────────────────────────────────────────────────────────────────────────────
   COMPONENTS
   ───────────────────────────────────────────────────────────────────────────── */

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid transparent;
  outline: none;
}

.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}
.btn-primary:hover:not(:disabled) { background: #2563eb; }

.btn-success {
  background: var(--green-bg);
  color: var(--green);
  border-color: rgba(34,197,94,.3);
}
.btn-success:hover:not(:disabled) { background: rgba(34,197,94,.18); }

.btn-danger {
  background: var(--red-bg);
  color: var(--red);
  border-color: rgba(239,68,68,.3);
}
.btn-danger:hover:not(:disabled) { background: rgba(239,68,68,.18); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) { color: var(--text-primary); background: var(--border-light); }

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card-sm { padding: 14px 16px; }

.card-title {
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 10px;
}

/* Status grid (4 tiles) */
.status-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

@media (max-width: 900px) { .status-grid { grid-template-columns: repeat(2,1fr); } }

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
}

.stat-label {
  font-size: .75rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 8px;
}

.stat-value {
  font-family: var(--mono);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text-primary);
}

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

.stat-sub {
  font-size: .75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.badge-green  { background: var(--green-bg);  color: var(--green); }
.badge-red    { background: var(--red-bg);    color: var(--red); }
.badge-amber  { background: var(--amber-bg);  color: var(--amber); }
.badge-blue   { background: var(--blue-bg);   color: var(--blue); }
.badge-muted  { background: var(--border-light); color: var(--text-muted); }

/* Charts */
.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.chart-title {
  font-size: .9rem;
  font-weight: 600;
  color: var(--text-primary);
}

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

.chart-day-btn {
  padding: 4px 10px;
  border-radius: 4px;
  font-size: .75rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}
.chart-day-btn:hover { background: var(--border-light); color: var(--text-primary); }
.chart-day-btn.active { background: var(--blue-bg); color: var(--blue); border-color: rgba(59,130,246,.3); }

/* Live event feed */
.event-feed {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

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

.event-feed-title {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.feed-list {
  max-height: 200px;
  overflow-y: auto;
  font-size: .8rem;
  font-family: var(--mono);
}

.feed-item {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 12px;
  padding: 7px 16px;
  border-bottom: 1px solid var(--border-light);
  animation: slide-in .2s ease;
}

.feed-item:last-child { border-bottom: none; }
.feed-time  { color: var(--text-dim); }
.feed-event { color: var(--text-primary); }
.feed-event.green  { color: var(--green); }
.feed-event.red    { color: var(--red); }
.feed-event.amber  { color: var(--amber); }

.feed-empty {
  padding: 20px 16px;
  color: var(--text-dim);
  font-size: .8rem;
  text-align: center;
}

@keyframes slide-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Tables */
.table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
}

.data-table th {
  padding: 10px 16px;
  text-align: left;
  font-size: .7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
}

.data-table td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-card-hover); }

.mono { font-family: var(--mono); }

.empty-state {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: .9rem;
}

.empty-state svg {
  display: block;
  margin: 0 auto 12px;
  color: var(--text-dim);
}

/* Filters */
.filters {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}

.filter-select {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: .85rem;
  padding: 7px 10px;
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition);
}

.filter-select:focus { border-color: var(--blue); }

/* Mode badge (runner control) */
.runner-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 24px;
}

.mode-label {
  font-size: .75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-right: auto;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  width: 420px;
  max-width: calc(100vw - 40px);
  box-shadow: 0 32px 80px rgba(0,0,0,.6);
}

.modal-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--red-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  color: var(--red);
}

.modal-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.modal-body {
  font-size: .875rem;
  color: var(--text-muted);
  margin-bottom: 24px;
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Backtest */
.backtest-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

@media (max-width: 640px) { .backtest-form { grid-template-columns: 1fr; } }

/* Settings */
.settings-section { margin-bottom: 32px; }

.settings-title {
  font-size: .9rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-light);
}

.settings-row:last-child { border-bottom: none; }

.settings-key { font-size: .85rem; color: var(--text-primary); }
.settings-val { font-family: var(--mono); font-size: .8rem; color: var(--text-muted); }

/* Loading spinner */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast notifications */
.toast-wrap {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 240px;
  pointer-events: auto;
  animation: toast-in .2s ease;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}

.toast-success { background: var(--bg-surface); border: 1px solid var(--green); color: var(--green); }
.toast-error   { background: var(--bg-surface); border: 1px solid var(--red);   color: var(--red); }
.toast-info    { background: var(--bg-surface); border: 1px solid var(--blue);  color: var(--blue); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Utility */
.flex          { display: flex; }
.gap-2         { gap: 8px; }
.gap-3         { gap: 12px; }
.items-center  { align-items: center; }
.justify-between { justify-content: space-between; }
.mt-2          { margin-top: 8px; }
.mt-4          { margin-top: 16px; }
.mb-4          { margin-bottom: 16px; }
.mb-6          { margin-bottom: 24px; }
.text-muted    { color: var(--text-muted); }
.text-sm       { font-size: .8rem; }
.text-xs       { font-size: .7rem; }
.font-mono     { font-family: var(--mono); }
.w-full        { width: 100%; }
[x-cloak]      { display: none !important; }

/* ── Strategy Status grid ──────────────────────────────────────────────────── */
.strategy-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.strategy-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.strategy-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 8px;
}

.strategy-symbol {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-primary);
}

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

.strategy-empty {
  min-height: 60px;
  align-items: center;
  justify-content: center;
}

.indicator-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: .85rem;
}

.indicator-label {
  color: var(--text-muted);
  font-size: .75rem;
}

.indicator-value {
  font-size: .9rem;
  color: var(--text-primary);
}

.indicator-headline .indicator-value {
  font-size: 1.05rem;
  font-weight: 600;
}

.indicator-value.positive { color: var(--green); }
.indicator-value.negative { color: var(--red); }
.indicator-value.warning  { color: var(--amber); }

.indicator-hint {
  display: block;
  margin-top: 2px;
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--amber);
  text-align: right;
}

.strategy-card-foot {
  border-top: 1px solid var(--border-light);
  padding-top: 6px;
  text-align: right;
}
