/* ─── 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: #0d1117; color: #e6edf3; line-height: 1.5; }
a { color: #58a6ff; text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; font-family: inherit; }

/* ─── Layout ───────────────────────────────────────────────────────── */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: #161b22; border-right: 1px solid #30363d; display: flex; flex-direction: column; position: fixed; top: 0; left: 0; height: 100vh; z-index: 100; }
.main { margin-left: 220px; flex: 1; min-height: 100vh; }
.header { background: #161b22; border-bottom: 1px solid #30363d; padding: 14px 24px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 50; }
.content { padding: 24px; }

/* ─── Sidebar ──────────────────────────────────────────────────────── */
.sidebar-logo { padding: 20px 16px; border-bottom: 1px solid #30363d; }
.sidebar-logo .logo-title { font-size: 16px; font-weight: 700; color: #f0f6fc; }
.sidebar-logo .logo-sub { font-size: 11px; color: #8b949e; margin-top: 2px; }
.nav { flex: 1; padding: 12px 0; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 16px; color: #8b949e; font-size: 13px; font-weight: 500; cursor: pointer; border-left: 3px solid transparent; transition: all 0.15s; }
.nav-item:hover { color: #e6edf3; background: #21262d; }
.nav-item.active { color: #58a6ff; background: #161b22; border-left-color: #58a6ff; }
.nav-item .nav-icon { font-size: 16px; width: 20px; }
.sidebar-bottom { padding: 12px 16px; border-top: 1px solid #30363d; }
.bot-status-badge { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 6px; font-size: 12px; font-weight: 600; }
.bot-status-badge.paused  { background: #21262d; color: #8b949e; }
.bot-status-badge.auto    { background: #0d2214; color: #3fb950; }
.bot-status-badge.manual  { background: #251d0e; color: #e3b341; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.status-dot.paused  { background: #8b949e; }
.status-dot.active  { background: #3fb950; animation: pulse 2s infinite; }
.status-dot.manual  { background: #e3b341; }
@keyframes pulse { 0%,100%{opacity:1}50%{opacity:0.4} }

/* ─── Cards ────────────────────────────────────────────────────────── */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.card { background: #161b22; border: 1px solid #30363d; border-radius: 10px; padding: 20px; }
.card-title { font-size: 11px; color: #8b949e; text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 8px; }
.card-value { font-size: 26px; font-weight: 700; color: #f0f6fc; }
.card-sub { font-size: 12px; color: #8b949e; margin-top: 4px; }
.card-value.positive { color: #3fb950; }
.card-value.negative { color: #f85149; }

/* ─── Tables ───────────────────────────────────────────────────────── */
.table-wrap { background: #161b22; border: 1px solid #30363d; border-radius: 10px; overflow: hidden; }
.table-header { padding: 16px 20px; border-bottom: 1px solid #30363d; display: flex; align-items: center; justify-content: space-between; }
.table-header h3 { font-size: 14px; font-weight: 600; color: #f0f6fc; }
table { width: 100%; border-collapse: collapse; }
th { padding: 10px 16px; text-align: left; font-size: 11px; color: #8b949e; text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid #30363d; font-weight: 600; }
td { padding: 12px 16px; font-size: 13px; border-bottom: 1px solid #21262d; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #1c2128; }

/* ─── Badges ───────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; }
.badge-buy     { background: #0d2214; color: #3fb950; }
.badge-sell    { background: #2c0f0f; color: #f85149; }
.badge-hold    { background: #251d0e; color: #e3b341; }
.badge-avoid   { background: #2c0f0f; color: #f85149; }
.badge-open    { background: #0c2d6b; color: #58a6ff; }
.badge-closed  { background: #161b22; color: #8b949e; border: 1px solid #30363d; }
.badge-stopped { background: #2c0f0f; color: #f85149; }
.badge-tp      { background: #0d2214; color: #3fb950; }
.badge-sl      { background: #2c0f0f; color: #f85149; }
.badge-manual  { background: #251d0e; color: #e3b341; }

/* ─── Buttons ──────────────────────────────────────────────────────── */
.btn { padding: 7px 14px; border-radius: 6px; font-size: 13px; font-weight: 600; border: 1px solid transparent; transition: all 0.15s; }
.btn-primary  { background: #238636; color: #fff; border-color: #2ea043; }
.btn-primary:hover  { background: #2ea043; }
.btn-danger   { background: #da3633; color: #fff; border-color: #f85149; }
.btn-danger:hover   { background: #f85149; }
.btn-outline  { background: transparent; color: #8b949e; border-color: #30363d; }
.btn-outline:hover  { color: #f0f6fc; border-color: #8b949e; }
.btn-confirm  { background: #0d2214; color: #3fb950; border: 1px solid #238636; }
.btn-confirm:hover  { background: #238636; color: #fff; }
.btn-reject   { background: #2c0f0f; color: #f85149; border: 1px solid #da3633; }
.btn-reject:hover   { background: #da3633; color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ─── Mode switcher ────────────────────────────────────────────────── */
.mode-switcher { display: flex; gap: 6px; }
.mode-btn { padding: 6px 14px; border-radius: 6px; font-size: 12px; font-weight: 600; border: 1px solid #30363d; background: transparent; color: #8b949e; transition: all 0.15s; }
.mode-btn.active-auto   { background: #0d2214; color: #3fb950; border-color: #238636; }
.mode-btn.active-manual { background: #251d0e; color: #e3b341; border-color: #9e6a03; }
.mode-btn.active-paused { background: #21262d; color: #8b949e; border-color: #6e7681; }
.mode-btn:hover { color: #e6edf3; border-color: #8b949e; }
.network-badge { padding: 4px 10px; border-radius: 6px; font-size: 11px; font-weight: 700; }
.network-badge.testnet { background: #251d0e; color: #e3b341; }
.network-badge.real    { background: #0d2214; color: #3fb950; }

/* ─── Signals ──────────────────────────────────────────────────────── */
.signal-card { background: #161b22; border: 1px solid #30363d; border-radius: 10px; padding: 16px; margin-bottom: 12px; }
.signal-card.pending { border-color: #9e6a03; }
.signal-header { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.signal-symbol { font-size: 16px; font-weight: 700; color: #f0f6fc; }
.signal-confidence { font-size: 12px; color: #8b949e; margin-left: auto; }
.signal-reasoning { font-size: 13px; color: #8b949e; margin-bottom: 10px; line-height: 1.5; }
.signal-actions { display: flex; gap: 8px; margin-top: 12px; }
.confidence-bar { height: 4px; background: #21262d; border-radius: 2px; margin: 6px 0; overflow: hidden; }
.confidence-fill { height: 100%; border-radius: 2px; transition: width 0.3s; }

/* ─── Forms ────────────────────────────────────────────────────────── */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 11px; color: #8b949e; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 5px; }
.form-group input, .form-group select { width: 100%; padding: 8px 12px; background: #0d1117; border: 1px solid #30363d; border-radius: 6px; color: #e6edf3; font-size: 13px; }
.form-group input:focus, .form-group select:focus { outline: none; border-color: #58a6ff; }
.form-section { background: #161b22; border: 1px solid #30363d; border-radius: 10px; padding: 20px; margin-bottom: 20px; }
.form-section h3 { font-size: 14px; font-weight: 600; color: #f0f6fc; margin-bottom: 16px; padding-bottom: 10px; border-bottom: 1px solid #30363d; }

/* ─── Toggle ───────────────────────────────────────────────────────── */
.toggle { position: relative; display: inline-block; width: 40px; height: 22px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: #21262d; border-radius: 22px; cursor: pointer; transition: 0.2s; }
.toggle-slider::before { content: ''; position: absolute; width: 16px; height: 16px; background: #8b949e; border-radius: 50%; top: 3px; left: 3px; transition: 0.2s; }
.toggle input:checked + .toggle-slider { background: #238636; }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); background: #fff; }

/* ─── Logs ─────────────────────────────────────────────────────────── */
.log-container { background: #0d1117; border: 1px solid #30363d; border-radius: 10px; height: 500px; overflow-y: auto; font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; padding: 12px; }
.log-line { padding: 2px 0; line-height: 1.6; }
.log-time { color: #484f58; }
.log-service { color: #58a6ff; }
.log-msg.info  { color: #8b949e; }
.log-msg.warn  { color: #e3b341; }
.log-msg.error { color: #f85149; }
.log-msg.debug { color: #6e7681; }

/* ─── Ticker bar ───────────────────────────────────────────────────── */
.ticker-bar { display: flex; gap: 20px; flex-wrap: wrap; }
.ticker-item { display: flex; align-items: center; gap: 6px; }
.ticker-symbol { font-size: 12px; color: #8b949e; font-weight: 600; }
.ticker-price { font-size: 13px; font-weight: 700; color: #f0f6fc; }
.ticker-change { font-size: 11px; }
.ticker-change.pos { color: #3fb950; }
.ticker-change.neg { color: #f85149; }

/* ─── P&L colors ───────────────────────────────────────────────────── */
.pnl-pos { color: #3fb950; font-weight: 600; }
.pnl-neg { color: #f85149; font-weight: 600; }

/* ─── Page title ───────────────────────────────────────────────────── */
.page-title { font-size: 20px; font-weight: 700; color: #f0f6fc; margin-bottom: 20px; }
.page-subtitle { font-size: 13px; color: #8b949e; margin-top: -14px; margin-bottom: 20px; }

/* ─── Empty state ──────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px; color: #8b949e; }
.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ─── Alert ────────────────────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: 6px; font-size: 13px; margin-bottom: 16px; }
.alert-info    { background: #0c2d6b; color: #58a6ff; border: 1px solid #1f6feb; }
.alert-success { background: #0d2214; color: #3fb950; border: 1px solid #238636; }
.alert-warning { background: #251d0e; color: #e3b341; border: 1px solid #9e6a03; }
.alert-danger  { background: #2c0f0f; color: #f85149; border: 1px solid #da3633; }

/* ─── Strategy tooltip (кастомный popup) ───────────────────────────── */
.strategy-badge { position: relative; }
.strategy-tooltip {
  position: fixed;
  z-index: 1000;
  max-width: 380px;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 10px;
  padding: 14px 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  font-size: 13px;
  line-height: 1.55;
  color: #c9d1d9;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.strategy-tooltip.visible { opacity: 1; }
.strategy-tooltip .st-title { font-size: 14px; font-weight: 700; color: #f0f6fc; margin-bottom: 8px; }
.strategy-tooltip .st-body { color: #c9d1d9; margin-bottom: 10px; }
.strategy-tooltip .st-when { color: #8b949e; font-size: 12px; padding-top: 8px; border-top: 1px dashed #30363d; }
.strategy-tooltip .st-when b { color: #d29922; }

/* ─── Mobile burger button (скрыта на десктопе) ────────────────────── */
.burger-btn {
  display: none;
  background: #161b22;
  border: 1px solid #30363d;
  color: #e6edf3;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 90;
}
.sidebar-overlay.open { display: block; }

/* ═══════════════════════════════════════════════════════════════════
   ── Responsive: планшет (≤ 1024px) ─────────────────────────────────
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
  .card-value { font-size: 22px; }
  .content { padding: 18px; }
  th, td { padding: 10px 12px; font-size: 12.5px; }
}

/* ═══════════════════════════════════════════════════════════════════
   ── Responsive: мобилка (≤ 768px) ──────────────────────────────────
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ── Sidebar slide-in ── */
  .sidebar {
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
  }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .burger-btn { display: block; }

  /* Sidebar nav item — больше для тапа */
  .nav-item { padding: 14px 16px; font-size: 14px; }
  .nav-item .nav-icon { font-size: 18px; }

  /* ── Header (sticky, адаптивный) ── */
  .header {
    padding: 10px 12px;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
  }
  .header > div:last-child { gap: 6px !important; }
  #headerUser { font-size: 11px; max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .network-badge { font-size: 10px; padding: 3px 7px; }

  /* Ticker — горизонтальный скролл, переезжает на отдельную строку */
  .ticker-bar {
    order: 99;
    width: 100%;
    overflow-x: auto;
    white-space: nowrap;
    padding-bottom: 4px;
    scrollbar-width: thin;
    gap: 14px;
  }
  .ticker-bar::-webkit-scrollbar { height: 3px; }
  .ticker-bar::-webkit-scrollbar-thumb { background: #30363d; border-radius: 2px; }
  .ticker-item { flex-shrink: 0; }

  /* ── Content layout ── */
  .content { padding: 12px; }
  .page-title { font-size: 18px; margin-bottom: 12px; }

  /* Cards — одна колонка */
  .cards { grid-template-columns: 1fr; gap: 10px; margin-bottom: 16px; }
  .card { padding: 14px; }
  .card-value { font-size: 20px; }
  .card-title { font-size: 10px; }

  /* ── ТАБЛИЦЫ → КАРТОЧКИ (главный мобильный приём) ── */
  /* Прячем заголовки, превращаем строки в карточки, td в строки label:value */
  .table-wrap { border-radius: 8px; overflow: visible; }
  .table-wrap table { width: 100%; border-collapse: separate; border-spacing: 0; }
  .table-wrap thead { display: none; }
  .table-wrap tbody { display: block; }
  .table-wrap tbody tr {
    display: block;
    background: #0d1117;
    border: 1px solid #21262d;
    border-radius: 8px;
    padding: 12px;
    margin: 8px 12px;
  }
  .table-wrap tbody tr:hover td { background: transparent; }
  .table-wrap tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px dashed #21262d;
    font-size: 13px;
    white-space: normal;
  }
  .table-wrap tbody td:last-child { border-bottom: none; padding-top: 8px; }
  /* Псевдо-label из data-label атрибута: HTML должен задать <td data-label="..."> */
  .table-wrap tbody td[data-label]::before {
    content: attr(data-label);
    color: #6e7681;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    font-weight: 600;
    margin-right: 12px;
    flex-shrink: 0;
  }
  /* Footer (Итого) тоже в карточку */
  .table-wrap tfoot { display: block; }
  .table-wrap tfoot tr {
    display: block;
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 12px;
    margin: 8px 12px;
    font-weight: 600;
  }
  .table-wrap tfoot td { display: flex; justify-content: space-between; padding: 4px 0; border: none; }
  .table-wrap tfoot td[colspan] { display: none; }

  /* Заголовок таблицы */
  .table-header { padding: 12px 16px; flex-direction: column; align-items: flex-start; gap: 6px; }
  .table-header h3 { font-size: 13px; }

  /* ── Формы ── */
  .form-row { grid-template-columns: 1fr; gap: 8px; }
  .form-group input, .form-group select, .form-group textarea {
    font-size: 16px; /* iOS no-zoom */
    padding: 10px 12px;
  }
  .form-section { padding: 14px; }
  .form-section h3 { font-size: 13px; }

  /* ── Кнопки ── */
  .btn { padding: 10px 14px; font-size: 14px; }
  .btn-sm { padding: 7px 10px; font-size: 12px; }

  /* Mode switcher на полной ширине */
  .mode-switcher { display: flex; width: 100%; gap: 4px; }
  .mode-btn { flex: 1; padding: 10px 8px; font-size: 11.5px; }

  /* Inline grid 1fr 1fr — раскладываем в колонку */
  [style*="grid-template-columns:1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
  /* Inline grids 3+ колонок — тоже в колонку */
  [style*="grid-template-columns:1fr 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* ── Signal cards ── */
  .signal-header { flex-wrap: wrap; gap: 6px; }
  .signal-symbol { font-size: 14px; }
  .signal-confidence { font-size: 11px; margin-left: 0; width: 100%; }

  /* ── Logs ── */
  .log-container { height: 400px; font-size: 11px; padding: 8px; }

  /* ── Charts canvas ── */
  canvas { max-width: 100%; height: auto !important; }

  /* ── Modals/overlays — не широкие на маленьком ── */
  #disclaimerOverlay > div {
    padding: 20px !important;
    max-height: 90vh;
    overflow-y: auto;
  }

  /* ── Action buttons в строках/карточках ── */
  td button { width: 100%; margin-top: 4px; }
}

/* ═══════════════════════════════════════════════════════════════════
   ── Очень маленькие экраны (≤ 480px) ──────────────────────────────
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  html { font-size: 13px; }
  .sidebar { width: 260px; }
  .content { padding: 10px; }
  .card { padding: 12px; }
  .card-value { font-size: 18px; }
  .page-title { font-size: 16px; }

  .table-wrap tbody tr { margin: 6px 8px; padding: 10px; }
  .table-wrap tfoot tr { margin: 6px 8px; padding: 10px; }
  .table-wrap tbody td { font-size: 12px; }
  .table-wrap tbody td[data-label]::before { font-size: 10px; }

  /* Mode switcher в столбик на крошечных экранах */
  .mode-switcher { flex-direction: column; }
  .mode-btn { width: 100%; }

  /* Header — компактнее */
  .header { padding: 8px 10px; }
  .header > div:last-child .btn { padding: 6px 10px; font-size: 11px; }
}
