/* Quant Lab — стили платформы.
   Без фреймворков: один файл, обычный CSS. Дизайн-решения (шкала радиусов,
   кольцо фокуса, варианты кнопок, поведение таблиц) взяты из shadcn/ui
   и переложены на наш стек. */

:root {
  /* поверхности и текст */
  --bg: #f4f6f9;
  --panel: #ffffff;
  --text: #16181c;
  --text-2: #3f4753;
  --muted: #6b7280;
  --line: #e4e7ec;
  --line-soft: #eef1f5;

  /* смысловые цвета: зелёный — рост, красный — падение. Не декоративные. */
  --accent: #0b5cad;
  --accent-hover: #094c90;
  --accent-soft: #eaf2fb;
  --accent-2: #0a7d4f;
  --accent-2-soft: #e7f4ee;
  --danger: #b3261e;
  --danger-soft: #fdecea;
  --warn: #9a6b00;
  --warn-soft: #fff7e6;

  /* форма */
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --ring: 0 0 0 3px rgba(11, 92, 173, 0.28);
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-sm: 0 1px 3px rgba(16, 24, 40, 0.07), 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08);
  --ease: 150ms cubic-bezier(0.4, 0, 0.2, 1);

  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", Consolas, "SF Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; transition: color var(--ease); }
a:hover { color: var(--accent-hover); text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
h1, h2, h3, h4 { line-height: 1.25; letter-spacing: -0.011em; }

/* Числа выравниваем по разрядам — иначе колонки цен «пляшут». */
.stat-value, .data-table td, .progress-bar + div,
.lesson-content table td { font-variant-numeric: tabular-nums; }

/* ============================================================ шапка */
.topbar {
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 0 24px;
  height: 52px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}
.brand {
  font-weight: 650;
  font-size: 16px;
  color: var(--text);
  letter-spacing: -0.015em;
}
.brand:hover { text-decoration: none; }
.topbar nav { display: flex; gap: 4px; align-items: center; }
.topbar nav a:not(.brand) {
  color: var(--text-2);
  font-size: 14px;
  font-weight: 500;
  padding: 6px 11px;
  border-radius: var(--radius-xs);
  transition: background var(--ease), color var(--ease);
}
.topbar nav a:not(.brand):hover {
  background: var(--accent-soft);
  color: var(--accent);
  text-decoration: none;
}
.topbar nav .muted { font-size: 13px; padding-left: 8px; }

.container { max-width: 960px; width: 100%; margin: 28px auto 48px; padding: 0 20px; flex: 1; }
.footer { text-align: center; padding: 20px; font-size: 13px; color: var(--muted); }

h1 { font-size: 27px; margin: 0 0 6px; }

/* ============================================================ карточки */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-xs);
}
.narrow { max-width: 420px; margin: 48px auto; }
.center { text-align: center; }

/* ============================================================ формы */
label {
  display: block;
  margin: 14px 0 5px;
  font-weight: 550;
  font-size: 13.5px;
  color: var(--text-2);
}
input, select, textarea {
  width: 100%;
  height: 38px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-xs);
  font-size: 14.5px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color var(--ease), box-shadow var(--ease);
}
select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}
input:hover, select:hover { border-color: #cbd2db; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}
input[type="date"] { padding-right: 8px; }

/* ============================================================ кнопки */
button, .button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  padding: 0 16px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 550;
  line-height: 1;
  white-space: nowrap;
  border-radius: var(--radius-xs);
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition: background var(--ease), border-color var(--ease),
              box-shadow var(--ease), color var(--ease);
}
button:hover, .button-link:hover {
  background: var(--accent-soft);
  border-color: #c3d7ec;
  color: var(--accent);
  text-decoration: none;
}
button:focus-visible, .button-link:focus-visible,
a:focus-visible { outline: none; box-shadow: var(--ring); }
button:active { transform: translateY(0.5px); }
button:disabled {
  opacity: 0.5;
  pointer-events: none;
}

button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }

button.danger { color: var(--danger); border-color: #e6bdb9; }
button.danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }

button.small { height: 30px; padding: 0 11px; font-size: 13px; }

button.linklike {
  border: none; background: none; box-shadow: none; height: auto;
  color: var(--accent); padding: 0; font-size: inherit; font-weight: inherit;
}
button.linklike:hover { background: none; text-decoration: underline; }

form.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.primary-link { font-weight: 600; }
.small-link { font-size: 13px; margin-right: 10px; }
.danger-link { color: var(--danger); font-size: 13px; }
.danger-link:hover { color: var(--danger); }

/* ============================================================ сообщения */
.alert, .ok-box, .admin-note {
  border-radius: var(--radius-sm);
  padding: 11px 15px;
  font-size: 14px;
  border: 1px solid;
}
.alert { background: var(--danger-soft); border-color: #f3c9c5; color: var(--danger); margin: 12px 0; }
.ok-box { background: var(--accent-2-soft); border-color: #bfe3d2; color: #07603d; }
.admin-note { background: var(--warn-soft); border-color: #f0dfae; color: #6b5b2a; margin-bottom: 18px; }
.admin-note code { background: #f6efdb; }

/* ============================================================ значки */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  font-weight: 550;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--line-soft);
  color: var(--muted);
  white-space: nowrap;
}
.badge.available { background: var(--accent-soft); color: var(--accent); }
.badge.passed { background: var(--accent-2-soft); color: var(--accent-2); }
.badge.pending, .badge.draft-badge { background: var(--warn-soft); color: var(--warn); }
.badge.expired, .badge.disabled { background: var(--danger-soft); color: var(--danger); }

/* ============================================================ иконки */
.icon { flex: none; vertical-align: -0.14em; }

/* ============================================================ список уроков */
.lesson-list { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.lesson-card {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 20px;
  color: var(--text);
  box-shadow: var(--shadow-xs);
  transition: border-color var(--ease), box-shadow var(--ease), transform var(--ease);
}
.lesson-num {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--line-soft);
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}
.lesson-card.open .lesson-num { background: var(--accent-soft); color: var(--accent); }
.lesson-num.done { background: var(--accent-2-soft); color: var(--accent-2); }
.lesson-body { min-width: 0; flex: 1; }
.lesson-card h2 { margin: 7px 0 0; font-size: 17px; font-weight: 600; }
.lesson-card p { margin: 5px 0 0; font-size: 13.5px; }
.lesson-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  color: var(--muted);
  font-size: 12.5px;
}
.lesson-meta span { display: inline-flex; align-items: center; gap: 5px; }
.lesson-card.open:hover {
  border-color: #bcd3ea;
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
  text-decoration: none;
}
.lesson-card.open:focus-visible { box-shadow: var(--ring); }
.lesson-card.locked, .lesson-card.draft { opacity: 0.6; box-shadow: none; }
.lesson-card.draft-open { border-style: dashed; }

/* ============================================================ урок */
.breadcrumbs { margin-bottom: 14px; font-size: 14px; }

.lesson-content {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 34px 44px;
  box-shadow: var(--shadow-xs);
  font-size: 15.5px;
  line-height: 1.68;
  color: var(--text-2);
}
.lesson-content > :first-child { margin-top: 0; }
.lesson-content > :last-child { margin-bottom: 0; }

.lesson-content h1, .lesson-content h2,
.lesson-content h3, .lesson-content h4 {
  color: var(--text);
  /* якорь не должен уезжать под закреплённую шапку */
  scroll-margin-top: 68px;
}
.lesson-content h1 {
  font-size: 26px;
  margin: 0 0 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.lesson-content h2 {
  font-size: 20px;
  margin: 2em 0 0.7em;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--line-soft);
}
.lesson-content h3 { font-size: 16.5px; margin: 1.7em 0 0.5em; }
.lesson-content h4 { font-size: 15px; margin: 1.4em 0 0.4em; color: var(--text-2); }
.lesson-content p { margin: 0 0 1.05em; }
.lesson-content strong { color: var(--text); font-weight: 650; }
.lesson-content ul, .lesson-content ol { margin: 0 0 1.05em; padding-left: 1.5em; }
.lesson-content li { margin: 0.3em 0; }
.lesson-content hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }

.lesson-content code {
  font-family: var(--mono);
  font-size: 0.875em;
  background: var(--line-soft);
  color: #0f3f6e;
  padding: 1.5px 5px;
  border-radius: 4px;
}
.lesson-content pre {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.55;
  margin: 0 0 1.2em;
}
.lesson-content pre code { background: none; padding: 0; color: inherit; font-size: 1em; }

.lesson-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 0 0 1.3em;
  font-size: 13.5px;
  display: block;
  overflow-x: auto;
}
.lesson-content th, .lesson-content td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line-soft);
}
.lesson-content th {
  background: #fafbfc;
  color: var(--muted);
  font-weight: 600;
  font-size: 12.5px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.lesson-content tbody tr:hover td { background: #fafbfc; }
.lesson-content tbody tr:last-child td { border-bottom: none; }

.lesson-content blockquote {
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  margin: 0 0 1.3em;
  padding: 12px 18px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-2);
}
.lesson-content blockquote > :last-child { margin-bottom: 0; }
.lesson-content img { max-width: 100%; border-radius: var(--radius-sm); }

.lesson-actions { margin-top: 20px; }

/* видео */
.video-wrap { position: relative; padding-top: 56.25%; margin-bottom: 18px; }
.video-wrap iframe {
  position: absolute; inset: 0; width: 100%; height: 100%;
  border: 0; border-radius: var(--radius);
}

/* ============================================================ таблицы данных */
.data-table {
  border-collapse: collapse;
  width: 100%;
  background: var(--panel);
  font-size: 13.5px;
}
.data-table th, .data-table td {
  padding: 9px 12px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--line-soft);
}
.data-table th {
  background: #fafbfc;
  color: var(--muted);
  font-weight: 600;
  font-size: 12.5px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.data-table tbody tr { transition: background var(--ease); }
.data-table tbody tr:hover td { background: #fafbfc; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.data-table .actions input[type="date"],
.data-table .actions select { width: auto; height: 30px; font-size: 13px; }

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.table-scroll .data-table { font-size: 13px; }
.data-table.compact { font-size: 12.5px; }
.data-table.compact td, .data-table.compact th { padding: 6px 10px; white-space: nowrap; }
.row-hl td { background: #fffaeb !important; font-weight: 600; color: var(--text); }
.data-table tbody tr.row-hl:hover td { background: #fff5d9 !important; }

/* ============================================================ форма в сетке */
.grid-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
  gap: 14px 16px;
  align-items: end;
}
.grid-form label { margin-top: 0; }
.grid-form > div { min-width: 0; }
/* поля со списками чисел длинные — им нужна вся ширина строки */
.grid-form .field-wide { grid-column: 1 / -1; }
.submit-cell button { width: 100%; }

/* загрузка данных прямо в панели опыта */
.fetch-box {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
}
.fetch-box > summary {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 14px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  color: var(--accent);
  list-style: none;
  user-select: none;
}
.fetch-box > summary::-webkit-details-marker { display: none; }
.fetch-box > summary:hover { background: var(--line-soft); border-radius: var(--radius-sm); }
.fetch-box[open] > summary {
  border-bottom: 1px solid var(--line);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
.fetch-box .fetch-form { padding: 14px; }
.fetch-box > p[data-role="note"] { padding: 0 14px; margin: 0 0 10px; }
.fetch-box > div { padding: 0 14px 14px; }
.fetch-box > div:empty { padding: 0; }
.fetch-status { margin: 0; }
.no-data { margin: 0; padding: 9px 0; }

/* блок «скачать файл» в результате опыта */
.file-block {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 13px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.file-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.file-name {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  word-break: break-all;
}

/* галочка: подпись рядом с квадратиком, а не над ним */
.field-check label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  cursor: pointer;
  margin: 0;
  padding-bottom: 9px;
}
.field-check input[type="checkbox"] {
  width: 17px;
  height: 17px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
  flex: none;
}
.field-hint { display: block; font-size: 11.5px; color: var(--muted); margin-top: 4px; line-height: 1.4; }

/* ============================================================ фоновая задача */
.job-card { margin-top: 16px; }
.progress-row { display: flex; align-items: center; gap: 14px; }
.grow { flex: 1; min-width: 0; }
.progress-bar {
  height: 6px;
  background: var(--line-soft);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 7px;
}
.progress-bar span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.3s ease;
}
.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid #dfe3e8;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

.htmx-indicator { display: none; margin: 12px 0; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { display: block; }

/* ============================================================ метрики */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  gap: 10px;
  margin: 16px 0;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 13px 15px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  box-shadow: var(--shadow-xs);
}
.stat-label {
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 500;
  line-height: 1.35;
}
.stat-value { font-size: 22px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.2; }
.stat-value.pos { color: var(--accent-2); }
.stat-value.neg { color: var(--danger); }
.stat-hint { font-size: 11px; color: var(--muted); line-height: 1.35; }

/* ============================================================ каталог опытов */
.page-lead {
  color: var(--muted);
  font-size: 15px;
  margin: 0 0 22px;
  max-width: 70ch;
}
.exp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
  gap: 14px;
}
.exp-card {
  display: flex;
  flex-direction: column;
  gap: 7px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px 16px;
  color: var(--text);
  box-shadow: var(--shadow-xs);
  transition: border-color var(--ease), box-shadow var(--ease), transform var(--ease);
}
.exp-card:hover {
  border-color: #bcd3ea;
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  text-decoration: none;
}
.exp-card:focus-visible { box-shadow: var(--ring); }
.exp-card-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-xs);
  background: var(--accent-soft);
  font-size: 16px;
}
.exp-card h2 { margin: 0; font-size: 16px; font-weight: 650; }
.exp-card p {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--muted);
  flex: 1;
}
.exp-card-foot { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }

/* ============================================================ панель опыта */
.experiment-panel {
  margin: 30px 0;
  padding: 20px 24px 24px;
  background:
    radial-gradient(120% 140% at 0% 0%, #eef5fd 0%, rgba(238, 245, 253, 0) 55%),
    var(--panel);
  border: 1px solid #d3e2f2;
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.exp-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent);
  background: #e2edfa;
  border-radius: 999px;
  padding: 4px 12px;
  margin-bottom: 11px;
}
.exp-head h2 { margin: 0 0 5px; font-size: 18.5px; font-weight: 650; }
.exp-desc { margin: 0 0 18px; color: var(--text-2); font-size: 14px; line-height: 1.55; max-width: 70ch; }
.experiment-panel input,
.experiment-panel select { background: #fff; }

.exp-result:not(:empty) {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid #dceafa;
}

.block { margin-top: 26px; }
.block:first-child { margin-top: 0; }
.block-title { font-size: 15.5px; font-weight: 650; margin: 0 0 3px; }
.block-note { margin: 0 0 12px; line-height: 1.5; max-width: 78ch; }

.verdict {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  padding: 13px 18px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-2);
  font-size: 14.5px;
  line-height: 1.6;
}
.verdict p { margin: 0 0 9px; }
.verdict p:last-child { margin-bottom: 0; }
.verdict b { color: var(--text); }

/* ============================================================ графики */
.chart { height: 440px; width: 100%; }
.block .chart { height: 340px; }
.block .chart-candles { height: 420px; }

/* ============================================================ адаптив */
@media (max-width: 720px) {
  .container { padding: 0 14px; margin-top: 18px; }
  .lesson-content { padding: 22px 18px; font-size: 15px; }
  .topbar {
    position: static;
    height: auto;
    flex-direction: column;
    gap: 6px;
    padding: 10px 16px;
    backdrop-filter: none;
    background: var(--panel);
  }
  .topbar nav { flex-wrap: wrap; justify-content: center; }
  .experiment-panel { padding: 16px 16px 20px; }
  .chart { height: 320px; }
  .block .chart { height: 280px; }
  .stat-cards { grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); }
  .stat-value { font-size: 20px; }
}
