/* ═══════════════════════════════════════════════════════════════════════
   TorgRobot Dashboard — Premium Dark Theme
   Спецификация: docs/dashboard/SPEC.md раздел 4
   ═══════════════════════════════════════════════════════════════════════ */

:root {
  /* Фон */
  --bg-primary: #0a0e14;
  --bg-secondary: #11161e;
  --bg-tertiary: #161c26;
  --bg-hover: #1a2230;

  /* Границы */
  --border: #1e293b;
  --border-light: #283548;

  /* Текст */
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  /* Семантика */
  --green: #22c55e;
  --green-bg: rgba(34, 197, 94, 0.10);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.10);
  --accent: #f59e0b;
  --accent-bg: rgba(245, 158, 11, 0.10);
  --gold: #f59e0b;
  --gold-bg: rgba(245, 158, 11, 0.10);
  --purple: #8b5cf6;
  --purple-bg: rgba(139, 92, 246, 0.10);
  --surface: #141b24;
  --surface-hover: #192230;

  /* Градиенты */
  --gradient-card: linear-gradient(135deg, #11161e 0%, #161c26 100%);
  --gradient-accent: linear-gradient(135deg, #f59e0b, #d97706);

  /* Типографика */
  --font-sans: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;

  /* Размеры */
  --text-xs: 0.6875rem;
  --text-sm: 0.8125rem;
  --text-base: 0.9375rem;
  --text-lg: 1.125rem;
  --text-xl: 1.5rem;
  --text-2xl: 2rem;

  /* Скругления */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;

  /* Отступы */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
}

/* ═══════════════════════════════════════════════════════════════════════
   RESET & BASE
   ═══════════════════════════════════════════════════════════════════════ */

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: var(--text-primary);
  background: var(--bg-primary);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

/* ═══════════════════════════════════════════════════════════════════════
   LAYOUT
   ═══════════════════════════════════════════════════════════════════════ */

.dashboard {
  max-width: 1440px;
  margin: 0 auto;
  padding: var(--space-md);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-md);
}

@media (min-width: 768px) {
  .dashboard-grid {
    grid-template-columns: 1fr 1fr;
  }
  .dashboard { padding: var(--space-lg); }
}

@media (min-width: 1200px) {
  .dashboard { padding: var(--space-xl); }
}

/* Полноширинные секции (decisions, trades) */
.section-full {
  grid-column: 1 / -1;
}

/* ═══════════════════════════════════════════════════════════════════════
   HEADER
   ═══════════════════════════════════════════════════════════════════════ */

.header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-md);
  grid-column: 1 / -1;
}

.header-brand {
  font-weight: 700;
  font-size: var(--text-lg);
  color: var(--text-primary);
  margin-right: auto;
}

.header-brand span {
  color: var(--accent);
}

.header-stat {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.header-stat .value {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-primary);
}

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

/* Status indicator */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  display: inline-block;
  flex-shrink: 0;
}
.status-dot.running {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  animation: pulse 2s ease-in-out infinite;
}
.status-dot.stale { background: var(--gold); }
.status-dot.stopped { background: var(--red); }
.status-dot.waiting { background: var(--gold); }

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

/* Mode badge */
.mode-badge {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}
.mode-badge.demo {
  background: var(--accent-bg);
  color: var(--accent);
  border: 1px solid rgba(245, 158, 11, 0.3);
}
.mode-badge.live {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Clock */
.header-clock {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--text-muted);
}

/* ═══════════════════════════════════════════════════════════════════════
   SECTION
   ═══════════════════════════════════════════════════════════════════════ */

.section {
  background: var(--gradient-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  overflow: hidden;
}

.section-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.section-title .icon {
  font-size: var(--text-base);
  color: var(--accent);
}

/* ═══════════════════════════════════════════════════════════════════════
   KPI CARDS
   ═══════════════════════════════════════════════════════════════════════ */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-md);
}

@media (min-width: 768px) {
  .kpi-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.kpi-card {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: var(--space-md);
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s;
}

.kpi-card:hover {
  border-color: var(--border);
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--gradient-accent);
  opacity: 0.6;
}

.kpi-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-xs);
  font-weight: 600;
}

.kpi-value {
  font-family: var(--font-mono);
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

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

.kpi-sub {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin-top: var(--space-xs);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.kpi-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.kpi-row-label {
  color: var(--text-muted);
  min-width: 52px;
}

.kpi-sep {
  color: var(--border-light);
  margin: 0 2px;
}

.kpi-sub .positive { color: var(--green); font-weight: 600; }
.kpi-sub .negative { color: var(--red); font-weight: 600; }

/* ═══════════════════════════════════════════════════════════════════════
   DATA TABLE
   ═══════════════════════════════════════════════════════════════════════ */

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.data-table th {
  text-align: left;
  padding: var(--space-sm) var(--space-md);
  color: var(--text-muted);
  font-weight: 500;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  white-space: nowrap;
}

.data-table tbody tr {
  transition: background 0.15s;
}

.data-table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}

.data-table tbody tr:hover {
  background: var(--bg-hover);
}

/* Ячейки таблицы */
.data-table td {
  color: var(--text-primary);
}

.data-table td.text-muted {
  color: var(--text-muted) !important;
}

/* Таблица — без моноширинного по умолчанию */
.data-table td:not(.mono) {
  font-family: var(--font-sans);
}

/* Текст в таблице (не числа) */
.data-table td.text-cell {
  font-family: var(--font-sans);
}

/* ═══════════════════════════════════════════════════════════════════════
   BADGES
   ═══════════════════════════════════════════════════════════════════════ */

.badge {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  letter-spacing: 0.03em;
  font-family: var(--font-sans);
}

.badge-buy  { background: var(--green-bg); color: var(--green); }
.badge-sell { background: var(--red-bg);   color: var(--red); }
.badge-wait { background: var(--gold-bg);  color: var(--gold); }
.badge-close { background: var(--purple-bg); color: var(--purple); }
.badge-filled { background: var(--green-bg); color: var(--green); }
.badge-cancelled { background: var(--bg-hover); color: var(--text-muted); }
.badge-rejected { background: var(--red-bg); color: var(--red); }
.badge-yes { background: var(--green-bg); color: var(--green); }
.badge-no  { background: var(--bg-hover); color: var(--text-muted); }
.badge-win  { background: var(--green-bg); color: var(--green); }
.badge-loss { background: var(--red-bg); color: var(--red); }

/* ═══════════════════════════════════════════════════════════════════════
   CONFIDENCE BAR
   ═══════════════════════════════════════════════════════════════════════ */

.confidence-bar {
  width: 60px;
  height: 4px;
  background: var(--bg-hover);
  border-radius: var(--radius-full);
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
  margin-right: var(--space-xs);
}

.confidence-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.3s;
}

.confidence-fill.low    { background: var(--red); }
.confidence-fill.medium { background: var(--gold); }
.confidence-fill.high   { background: var(--green); }

/* ═══════════════════════════════════════════════════════════════════════
   SL/TP DISTANCE BAR
   ═══════════════════════════════════════════════════════════════════════ */

.distance-bar-wrap {
  width: 80px;
  height: 4px;
  background: var(--bg-hover);
  border-radius: var(--radius-full);
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
  margin-right: var(--space-xs);
}

.distance-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--text-muted);
}

.distance-bar-fill.warning { background: var(--gold); }
.distance-bar-fill.danger  { background: var(--red); }

/* ═══════════════════════════════════════════════════════════════════════
   MODULE HEALTH INDICATORS
   ═══════════════════════════════════════════════════════════════════════ */

.module-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-md);
}

@media (min-width: 768px) {
  .module-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.module-card {
  padding: var(--space-md);
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  transition: border-color 0.2s;
  position: relative;
}

.module-card:hover {
  border-color: var(--border);
}

.module-card::after {
  content: '';
  position: absolute;
  top: 0; left: var(--space-md); right: var(--space-md);
  height: 1px;
  background: var(--gradient-accent);
  opacity: 0;
  transition: opacity 0.3s;
}

.module-card:hover::after {
  opacity: 0.5;
}

.module-name {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-xs);
  font-weight: 600;
}

.module-status {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
}

.module-meta {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-sm);
  line-height: 1.5;
}

/* ═══════════════════════════════════════════════════════════════════════
   MODAL
   ═══════════════════════════════════════════════════════════════════════ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: var(--space-md);
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  max-width: 640px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: var(--text-lg);
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: var(--text-xl);
  cursor: pointer;
  padding: var(--space-xs);
  line-height: 1;
}
.modal-close:hover { color: var(--text-primary); }

.modal-body {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.7;
  white-space: pre-wrap;
}

.modal-meta {
  display: flex;
  gap: var(--space-lg);
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px solid var(--border);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* ═══════════════════════════════════════════════════════════════════════
   CHART CONTAINER
   ═══════════════════════════════════════════════════════════════════════ */

.chart-container {
  width: 100%;
  height: 320px;
  position: relative;
}

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

.chart-controls {
  display: flex;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.chart-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font-sans);
}

.chart-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

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

/* ═══════════════════════════════════════════════════════════════════════
   STATES: loading, empty, error, stale
   ═══════════════════════════════════════════════════════════════════════ */

/* Skeleton loading */
.skeleton {
  background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-hover) 50%, var(--bg-tertiary) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-line {
  height: 14px;
  margin-bottom: var(--space-sm);
  width: 100%;
}

.skeleton-line.short { width: 60%; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: var(--space-xl) var(--space-md);
  color: var(--text-muted);
}

.empty-state .icon {
  font-size: 2rem;
  margin-bottom: var(--space-sm);
  opacity: 0.5;
}

.empty-state .text {
  font-size: var(--text-sm);
}

/* Error banner */
.error-banner {
  background: var(--red-bg);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: var(--red);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  margin-bottom: var(--space-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
  grid-column: 1 / -1;
}

.error-banner button {
  background: none;
  border: 1px solid var(--red);
  color: var(--red);
  padding: 2px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--text-xs);
}

/* Stale data warning */
.stale-warning {
  color: var(--gold);
  font-size: var(--text-xs);
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

/* ═══════════════════════════════════════════════════════════════════════
   UTILITY
   ═══════════════════════════════════════════════════════════════════════ */

.text-mono  { font-family: var(--font-mono); }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-green { color: var(--green); }
.text-red   { color: var(--red); }
.text-gold  { color: var(--gold); }

.truncate {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Scrollable table wrapper для мобильных */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* HTMX transitions */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline; }
.htmx-request.htmx-indicator { display: inline; }

.fade-in {
  animation: fadeIn 0.3s ease;
}

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

/* Market & Session */
.market-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--space-sm); }
.market-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; transition: border-color 0.2s; }
.market-card:hover { border-color: var(--border-light); }
.market-label { font-size: var(--text-xs); color: var(--text-muted); margin-bottom: 4px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.market-value { font-size: var(--text-lg); font-weight: 600; color: var(--text-primary); }
.market-value.bullish { color: var(--green); }
.market-value.bearish { color: var(--red); }
.market-value.high { color: var(--green); }
.market-value.good { color: var(--accent); }
.market-value.medium { color: var(--text-primary); }
.market-value.low { color: var(--text-muted); }
.market-sub { font-size: var(--text-xs); color: var(--text-muted); margin-top: 4px; }
.market-sub.positive { color: var(--green); }
.market-sub.negative { color: var(--red); }
.market-sessions { grid-column: 1 / -1; }
.session-timeline { display: flex; gap: 2px; margin-top: 8px; font-size: 10px; text-align: center; }
.session-bar { padding: 6px 2px; border-radius: 4px; background: var(--surface); border: 1px solid var(--border); color: var(--text-muted); transition: all 0.2s; }
.session-bar.active { background: rgba(245, 158, 11, 0.15); border-color: var(--accent); color: var(--accent); font-weight: 700; }
.session-bar.cme.active { background: rgba(34, 197, 94, 0.12); border-color: var(--green); color: var(--green); font-weight: 700; }
