:root {
  --bg: #0f1115;
  --fg: #e8eaed;
  --hint: #8a93a0;
  --link: #6db4ff;
  --button: #6db4ff;
  --button-text: #ffffff;
  --secondary-bg: #1a1d23;
  --section-bg: #1a1d23;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg);
             font-family: -apple-system, BlinkMacSystemFont, "SF Pro", "Segoe UI", sans-serif;
             font-size: 15px; min-height: 100vh; }

header { position: sticky; top: 0; background: var(--bg); z-index: 10;
         border-bottom: 1px solid rgba(255,255,255,0.08); }
.header-bar { display: flex; align-items: stretch; gap: 4px; padding-right: 4px; }
.tabs { display: flex; flex: 1; min-width: 0; }
.btn-fullscreen {
  background: transparent; border: 0; color: var(--hint);
  font-size: 18px; padding: 0 12px; cursor: pointer;
  border-bottom: 2px solid transparent; flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}
.btn-fullscreen:hover { color: var(--fg); background: rgba(255,255,255,0.05); }
.btn-fullscreen:active { transform: scale(0.95); }
.tab { flex: 1; background: transparent; border: 0; padding: 14px 8px;
       color: var(--hint); font-size: 14px; cursor: pointer;
       border-bottom: 2px solid transparent; }
.tab.active { color: var(--fg); border-bottom-color: var(--button); }
main { padding: 12px; padding-bottom: 80px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Drill-down уровни внутри «Стратегия» (list ↔ detail) */
.strategy-level { display: none; }
.strategy-level.active { display: block; }
.strategy-detail-header {
  display: flex; align-items: center; gap: 12px; margin-bottom: 12px;
  padding: 12px 14px; background: var(--section-bg); border-radius: 10px;
}
.strategy-detail-header h2 { margin: 0; font-size: 16px; flex: 1;
                              white-space: nowrap; overflow: hidden;
                              text-overflow: ellipsis; }
.btn-back {
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1);
  color: var(--fg); padding: 8px 14px; border-radius: 8px; font-size: 13px;
  cursor: pointer; flex-shrink: 0; transition: background 0.15s;
}
.btn-back:hover { background: rgba(96, 165, 250, 0.15);
                  border-color: rgba(96, 165, 250, 0.3); }

/* Sub-tabs внутри top-level tabs (например: Стратегия → Список / Настройки / Аналитика) */
.subtabs { display: flex; gap: 6px; margin-bottom: 12px; padding: 6px;
           background: rgba(255,255,255,0.04); border-radius: 10px; flex-wrap: wrap; }
.subtab { flex: 1; min-width: 110px; background: transparent; border: 0;
          color: var(--hint); padding: 10px 12px; border-radius: 8px;
          font-size: 13px; cursor: pointer; transition: background 0.15s; }
.subtab.active { background: rgba(96, 165, 250, 0.15); color: var(--fg);
                 font-weight: 600; }
.subtab:hover:not(.active) { background: rgba(255,255,255,0.04); }
.subtab-panel { display: none; }
.subtab-panel.active { display: block; }

.card { background: var(--section-bg); border-radius: 12px; padding: 16px; margin-bottom: 12px; }
.card h2, .card h3 { margin: 0 0 12px 0; font-size: 16px; }

table.kv { width: 100%; border-collapse: collapse; }
table.kv td { padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,0.06); }
table.kv td:first-child { color: var(--hint); width: 50%; }
table.kv tr:last-child td { border: 0; }

.actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.btn { background: rgba(255,255,255,0.08); border: 0; color: var(--fg);
       padding: 10px 16px; border-radius: 8px; font-size: 14px; cursor: pointer; }
.btn.primary { background: var(--button); color: var(--button-text); }
.btn:active { opacity: .7; }

input, textarea, select {
  width: 100%; background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1);
  color: var(--fg); padding: 10px 12px; border-radius: 8px;
  font-family: inherit; font-size: 14px; margin-bottom: 8px; resize: vertical;
}
textarea { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; }
input:focus, textarea:focus { outline: 2px solid var(--button); outline-offset: -1px; }

.setting-row { display: flex; align-items: center; gap: 8px; padding: 10px 12px;
               border-bottom: 1px solid rgba(255,255,255,0.06); }
.setting-row:last-child { border: 0; }
.setting-row label {
  flex: 1 1 auto;     /* лейбл занимает максимум места слева */
  min-width: 0;       /* позволяет тексту переноситься внутри flex-параметра */
  color: var(--fg);
  font-size: 13px;
  line-height: 1.35;
}
.setting-row .hint { color: var(--hint); font-size: 12px; display: block; margin-top: 2px; }
/* Все «скалярные» инпуты в строке настройки — компактные 120px справа.
   Включает number, text (intlist), select. flex:0 0 auto чтобы не растягивались. */
.setting-row input[type=number],
.setting-row input[type=text],
.setting-row select {
  width: 120px;
  min-width: 120px;
  max-width: 120px;
  flex: 0 0 auto;
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
/* iOS-style toggle switch — replaces native checkbox visually */
.setting-row input[type=checkbox] {
  appearance: none;
  -webkit-appearance: none;
  width: 48px;
  height: 28px;
  background: rgba(255,255,255,0.18);
  border-radius: 14px;
  position: relative;
  cursor: pointer;
  transition: background 0.18s ease;
  margin: 0;
  flex: 0 0 auto;
}
.setting-row input[type=checkbox]::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 24px;
  height: 24px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.18s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.setting-row input[type=checkbox]:checked {
  background: #22c55e;
}
.setting-row input[type=checkbox]:checked::before {
  transform: translateX(20px);
}

.category { background: var(--section-bg); border-radius: 12px; margin-bottom: 12px; overflow: hidden; }
.category-title { padding: 12px 16px; font-weight: 600; background: rgba(255,255,255,0.04); }

ul.strategies { list-style: none; margin: 0; padding: 0; }
ul.strategies li { padding: 14px 16px; margin-bottom: 8px;
                   border: 1px solid rgba(255,255,255,0.08);
                   border-radius: 10px;
                   background: rgba(255,255,255,0.02);
                   display: flex; align-items: center; gap: 8px;
                   transition: background 0.15s, border-color 0.15s, transform 0.1s; }
ul.strategies li:last-child { margin-bottom: 0; }
ul.strategies li.strategy-card { cursor: pointer; user-select: none; }
ul.strategies li.strategy-card:hover {
  background: rgba(96, 165, 250, 0.08);
  border-color: rgba(96, 165, 250, 0.3);
}
ul.strategies li.strategy-card:active { transform: scale(0.99); }
ul.strategies li.strategy-active { background: rgba(96, 165, 250, 0.12);
                                    border-color: rgba(96, 165, 250, 0.4); }
ul.strategies li.strategy-hint { background: transparent; border: 0; padding: 4px 0;
                                  margin-bottom: 6px; cursor: default; }
ul.strategies li .badge { font-size: 11px; padding: 2px 8px; border-radius: 4px;
                          background: rgba(255,255,255,0.1); white-space: nowrap; }
ul.strategies li .badge.active { background: var(--button); color: var(--button-text); }
.strategy-row { display: flex; align-items: center; gap: 10px; flex: 1; width: 100%; }
.strategy-name { font-weight: 500; display: flex; align-items: center; gap: 8px;
                 flex: 1; font-size: 15px; }
.strategy-actions { display: flex; gap: 8px; align-items: center; flex-wrap: nowrap; }
.strategy-arrow { color: var(--hint); font-size: 18px; transition: transform 0.15s; }
ul.strategies li.strategy-card:hover .strategy-arrow {
  color: var(--button); transform: translateX(3px);
}
.btn-mini { background: transparent; border: 1px solid rgba(255,255,255,0.15);
            color: var(--hint); padding: 4px 8px; border-radius: 6px;
            font-size: 13px; cursor: pointer; line-height: 1; }
.btn-mini:hover { color: #ef4444; border-color: rgba(239, 68, 68, 0.4); }
.badge.source-user { background: rgba(255, 200, 80, 0.2); color: #ffc850; }
.badge.source-builtin { background: rgba(180, 180, 180, 0.15); color: #aaa; }

.status-line { color: var(--hint); margin-top: 8px; min-height: 18px; }
.status-line.ok { color: #22c55e; }
.status-line.err { color: #ef4444; }

.action-msg { color: var(--hint); font-size: 13px; min-height: 18px;
              padding: 4px 0; line-height: 1.4; }
.action-msg.ok   { color: #22c55e; }
.action-msg.err  { color: #ef4444; }
.action-msg.warn { color: #fdf647; }
.action-msg.info { color: var(--hint); }

/* ─── Hint text (общее использование) ─── */
.hint { color: var(--hint); font-size: 13px; margin: 0 0 12px 0; line-height: 1.4; }

/* Multi-select checkbox group (used for asset_categories) */
.multi-row {
  display: flex; flex-wrap: wrap; gap: 6px 12px; justify-content: flex-end;
}
.multi-opt {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 13px; color: var(--fg); cursor: pointer;
  padding: 3px 8px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 6px;
}
.multi-opt input { margin: 0; }
.multi-opt:has(input:checked) {
  background: rgba(109, 180, 255, 0.15);
  border-color: var(--button);
}

/* Утилитарные классы для подсветки ячеек (понадобятся в этапе 2 для аналитики) */
.cell-good { color: #22c55e; }
.cell-warn { color: #fdf647; }
.cell-bad  { color: #ef4444; }

/* ─── Profit-today виджет (этап 2) ─── */
.profit-today { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.profit-amt { font-size: 28px; font-weight: 600; color: var(--hint); }
.profit-amt.ok { color: #22c55e; }
.profit-amt.err { color: #ef4444; }
.profit-meta { display: flex; gap: 14px; font-size: 13px; color: var(--hint); }
.profit-meta b { color: var(--fg); }

/* ─── Аналитика (этап 2) ─── */
.analytics-toolbar { display: flex; flex-direction: column; gap: 10px; padding-bottom: 10px;
                     border-bottom: 1px solid rgba(255,255,255,0.06); }
.period-selector, .hour-filter, .dow-filter { display: flex; align-items: center; gap: 6px;
                                                flex-wrap: wrap; }
.period-btn { background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.08);
              color: var(--hint); padding: 5px 12px; border-radius: 6px; font-size: 13px;
              cursor: pointer; }
.period-btn.active { background: rgba(96, 165, 250, 0.18); color: var(--fg);
                      border-color: var(--button); }
.hour-filter input { width: 56px; padding: 4px 6px; }
.dow-opt { font-size: 12px; padding: 2px 6px; border: 1px solid rgba(255,255,255,0.1);
            border-radius: 5px; cursor: pointer; }
.dow-opt:has(input:checked) { background: rgba(96, 165, 250, 0.15); border-color: var(--button); }
.dow-opt input { margin: 0 4px 0 0; }

.analytics-table-wrap { overflow-x: auto; max-width: 100%;
                        border-radius: 6px; border: 1px solid rgba(255,255,255,0.05); }
.analytics-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.analytics-table th, .analytics-table td { padding: 6px 8px; text-align: right;
                                            border-bottom: 1px solid rgba(255,255,255,0.04); }
.analytics-table th { background: rgba(255,255,255,0.03); color: var(--hint);
                       font-weight: 500; font-size: 11px; text-transform: none;
                       position: sticky; top: 0; z-index: 1; }
.analytics-table th:first-child, .analytics-table td:first-child { text-align: left; }
.analytics-table th.sortable { cursor: pointer; user-select: none; }
.analytics-table th.sortable:hover { color: var(--fg); }
.analytics-table th.sorted-asc::after  { content: " ▲"; color: var(--button); }
.analytics-table th.sorted-desc::after { content: " ▼"; color: var(--button); }
.analytics-table tbody tr { cursor: pointer; }
.analytics-table tbody tr:hover { background: rgba(255,255,255,0.03); }
.analytics-table .sep { background: rgba(255,255,255,0.06); width: 4px; padding: 0; color: transparent; }

.wr-green  { color: #22c55e; font-weight: 600; }
.wr-yellow { color: #fdf647; }
.wr-orange { color: #fb923c; }
.wr-red    { color: #ef4444; }
.profit-pos { color: #22c55e; }
.profit-neg { color: #ef4444; }

/* ─── Mobile-friendly analytics table (этап 3) ─── */
@media (max-width: 760px) {
  .analytics-table { font-size: 11px; }
  .analytics-table th, .analytics-table td { padding: 4px 6px; }
  .analytics-table th:first-child,
  .analytics-table td:first-child {
    position: sticky; left: 0; z-index: 2;
    background: var(--section-bg);
    box-shadow: 1px 0 0 rgba(255,255,255,0.06);
  }
  .analytics-table thead th:first-child { z-index: 3; }
  .analytics-toolbar { font-size: 12px; }
  .period-btn { padding: 4px 8px; font-size: 12px; }
}

/* ─── Сворачиваемая группа настроек под toggle (этап 3) ─── */
.setting-children {
  margin: 0 0 0 8px;
  padding: 4px 0 4px 12px;
  border-left: 3px solid var(--button);
  background: rgba(96, 165, 250, 0.05);
  border-radius: 0 6px 6px 0;
}
.setting-children .setting-row {
  /* меньше отступы, чтобы дети визуально компактнее родителя */
  padding: 8px 10px;
}
.setting-children .setting-row:first-child { padding-top: 10px; }
.setting-children .setting-row:last-child  { padding-bottom: 10px; }

/* ─── ⓘ icon + popover для пояснений настроек ─── */
.info-btn {
  background: transparent;
  border: 1px solid rgba(96, 165, 250, 0.35);
  color: var(--button);
  /* flex: 0 0 auto — НЕ тянется в .setting-row (display:flex родителе)  */
  flex: 0 0 auto;
  width: 18px; min-width: 18px; max-width: 18px;
  height: 18px; min-height: 18px; max-height: 18px;
  font-size: 11px; font-weight: 600;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center; justify-content: center;
  vertical-align: middle;
  margin-left: 0;
  line-height: 1;
  box-sizing: border-box;
}
.info-btn:hover { background: rgba(96, 165, 250, 0.15); }
.info-btn:active { transform: scale(0.92); }

.info-popover {
  position: fixed;
  display: none;
  max-width: 280px;
  padding: 12px 14px;
  background: var(--section-bg);
  border: 1px solid rgba(96, 165, 250, 0.5);
  border-radius: 10px;
  font-size: 12px; line-height: 1.5;
  color: var(--fg);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  z-index: 10000;
}
.info-popover.show { display: block; }
.info-popover-body { padding-right: 16px; }
.info-popover-key {
  font-family: ui-monospace, SF Mono, Menlo, monospace;
  font-size: 10px;
  color: var(--hint);
  margin-bottom: 6px;
  word-break: break-all;
}
.info-popover-close {
  position: absolute;
  top: 4px; right: 6px;
  background: transparent;
  border: 0;
  color: var(--hint);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
}
.info-popover-close:hover { background: rgba(255,255,255,0.06); color: var(--fg); }

/* ─── Чарт-панель (этап 3+) ─── */
.clickable-row { cursor: pointer; user-select: none; }
.clickable-row:hover td { color: var(--button); }
.clickable-row td:first-child { font-weight: 500; }
.row-arrow {
  display: inline-block;
  margin-left: 6px;
  color: var(--button);
  font-size: 10px;
  transition: transform 0.15s;
}

.chart-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.chart-header select {
  flex: 1; min-width: 140px;
  width: auto;
  padding: 6px 10px;
  font-size: 13px;
}

.chart-filter-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.chart-filter-btn {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--hint);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}
.chart-filter-btn.active {
  background: rgba(96, 165, 250, 0.18);
  color: var(--fg);
  border-color: var(--button);
}

.chart-hud {
  padding: 10px 14px;
  background: rgba(17, 24, 39, 0.85);
  border: 1px solid rgba(96, 165, 250, 0.4);
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.7;
  margin-bottom: 10px;
  overflow-x: auto;
  white-space: nowrap;
}
.chart-hud div { white-space: normal; }
.chart-hud .err { color: #ef4444; }

#chart-container {
  width: 100%;
  height: 360px;
  border-radius: 8px;
  overflow: hidden;
}
