/* SpecML — визуальный стиль.
   Палитра холодная и сдержанная; единственный яркий элемент — шкала спектра. */

:root {
  --paper: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --ink: #172036;
  --muted: #5c667a;
  --line: #dce0e7;
  --accent: #2b4acb;
  --accent-ink: #ffffff;
  --accent-soft: #e7ebfb;
  --plate: #ffffff;
  --ok: #1d8f60;
  --warn: #b97708;
  --bad: #c63a43;
  --focus: #2b4acb;
  --shadow: 0 1px 2px rgba(23, 32, 54, .06), 0 8px 24px -12px rgba(23, 32, 54, .18);

  --sans: "Public Sans", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --serif: var(--sans);  /* заголовки — тоже Public Sans */
  --mono: var(--sans);   /* SMILES — тоже Public Sans */

  --spectrum: linear-gradient(90deg,
    #8d93a3 0%, #8d93a3 5.5%,
    #5b2a86 5.6%, #3a3fd0 14%, #1e7fe0 22%, #19b3c4 27%, #3cbf5a 31%,
    #c9d22e 39%, #f2b12b 44%, #ee6a2c 49%, #d6283b 60%, #7a1a2a 72%,
    #6b6170 76%, #8d93a3 100%);

  --r-lg: 14px;
  --r-md: 10px;
  --r-sm: 6px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0f1422; --surface: #161d2e; --surface-2: #1d2539; --ink: #e7eaf1; --muted: #98a1b3;
    --line: #2a3247; --accent: #8ea2ff; --accent-ink: #0f1422; --accent-soft: #232d4d; --plate: #f7f8fb;
    --ok: #43c08a; --warn: #e2a73b; --bad: #f0707a; --focus: #8ea2ff;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px -14px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0f1422; --surface: #161d2e; --surface-2: #1d2539; --ink: #e7eaf1; --muted: #98a1b3;
  --line: #2a3247; --accent: #8ea2ff; --accent-ink: #0f1422; --accent-soft: #232d4d; --plate: #f7f8fb;
  --ok: #43c08a; --warn: #e2a73b; --bad: #f0707a; --focus: #8ea2ff;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px -14px rgba(0,0,0,.6);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 16px/1.55 var(--sans); font-feature-settings: "tnum" 1;
}
img, svg { max-width: 100%; }
a { color: var(--accent); text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
button, input, select, textarea { font-family: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

h1, h2, h3 { font-family: var(--sans); font-weight: 600; letter-spacing: -.02em; line-height: 1.15; margin: 0; }
h1 { font-size: clamp(1.9rem, 4vw, 3rem); }
h2 { font-size: 1.6rem; }
h3 { font-size: 1.2rem; }
p { margin: 0 0 1em; }
code, .mono { font-family: var(--mono); font-size: .95em; }

.wrap { width: min(1200px, 100% - 2rem); margin-inline: auto; }
.wrap-narrow { width: min(780px, 100% - 2rem); margin-inline: auto; }

/* ---------- навигация ---------- */
.topbar { border-bottom: 1px solid var(--line); background: var(--surface); }
.topbar .wrap { display: flex; align-items: center; gap: 1.5rem; min-height: 64px; }
.brand { display: flex; align-items: center; gap: .6rem; text-decoration: none; color: var(--ink); }
.brand img { height: 34px; width: auto; }
.brand-word { font-family: var(--sans); font-size: 1.35rem; font-weight: 700; }
.nav { display: flex; gap: .25rem; margin-left: auto; }
.nav a { color: var(--muted); text-decoration: none; padding: .45rem .8rem; border-radius: var(--r-sm); font-weight: 500; }
.nav a:hover { color: var(--ink); background: var(--surface-2); }
.nav a[aria-current="page"] { color: var(--ink); background: var(--surface-2); }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: transparent; color: var(--ink); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }

/* ---------- шкала спектра ---------- */
.ruler { position: relative; margin-top: 2.2rem; }
.ruler-band { height: 12px; border-radius: 999px; background: var(--spectrum); }
.ruler-ticks { position: relative; height: 1.4rem; margin-top: .35rem; font-size: .78rem; color: var(--muted); }
.ruler-ticks span { position: absolute; transform: translateX(-50%); }
.ruler-ticks span::before { content: ""; position: absolute; left: 50%; top: -.45rem; width: 1px; height: .3rem; background: var(--muted); opacity: .6; }
.ruler-caption { display: flex; justify-content: space-between; font-size: .78rem; color: var(--muted); }

/* ---------- hero ---------- */
.hero { padding: 3.2rem 0 1rem; }
.hero h1 { max-width: 19ch; }
.hero .lede { max-width: 58ch; color: var(--muted); font-size: 1.12rem; margin-top: 1rem; }

/* ---------- рабочая область ---------- */
.workbench { scroll-margin-top: 1rem; display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 1.5rem; margin: 2rem auto 3rem; align-items: start; }
@media (max-width: 960px) { .workbench { grid-template-columns: 1fr; } }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); }
.panel-body { padding: 1.5rem; }
.input-panel { position: sticky; top: 1rem; }
@media (max-width: 960px) { .input-panel { position: static; } }

.tabs { display: flex; border-bottom: 1px solid var(--line); padding: 0 .75rem; }
.tabs button {
  appearance: none; border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted);
  padding: 1rem .75rem .85rem; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
[role="tabpanel"][hidden] { display: none; }

.field { margin-bottom: 1.15rem; }
.field label, .field-label { display: block; font-weight: 600; margin-bottom: .4rem; font-size: .95rem; }
.hint { color: var(--muted); font-size: .85rem; margin-top: .35rem; }
.input, .select, textarea.input {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-md); padding: .65rem .8rem;
}
textarea.input { font-family: var(--mono); font-size: .88rem; resize: vertical; min-height: 5.2rem; line-height: 1.45; word-break: break-all; }
.input:focus, .select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.row-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .5rem; }
.linklike { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  border-radius: var(--r-md); padding: .65rem 1.1rem; border: 1px solid transparent; line-height: 1.2;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-small { padding: .4rem .7rem; font-size: .88rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .6; cursor: progress; }

.switch, .field .switch { display: flex; margin: 0; align-items: center; gap: .65rem; cursor: pointer; font-weight: 600; font-size: .95rem; }
.switch input { margin: 0; appearance: none; width: 40px; height: 22px; border-radius: 999px; background: var(--line); position: relative; cursor: pointer; flex: none; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(18px); }

.dropzone {
  display: grid; place-items: center; text-align: center; gap: .3rem; padding: 1.6rem 1rem;
  border: 1.5px dashed var(--line); border-radius: var(--r-md); background: var(--surface-2); cursor: pointer;
}
.dropzone.is-over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone input { position: absolute; opacity: 0; pointer-events: none; }
.dropzone strong { font-weight: 600; }
.dropzone .file-name { font-family: var(--mono); font-size: .85rem; color: var(--ink); }

.notice { display: flex; gap: .75rem; padding: .85rem 1rem; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--surface-2); font-size: .93rem; }
.notice-error { border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); background: color-mix(in srgb, var(--bad) 8%, var(--surface)); }
.notice-ok { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); background: color-mix(in srgb, var(--ok) 8%, var(--surface)); }
.notice p { margin: 0; }

/* ---------- результаты ---------- */
.empty { padding: 2.5rem 1.75rem; color: var(--muted); }
.empty h2 { color: var(--ink); margin-bottom: .6rem; }
.empty ul { margin: 1rem 0 0; padding-left: 1.1rem; }
.empty li { margin: .25rem 0; }

.result-head { display: flex; gap: 1.25rem; align-items: stretch; flex-wrap: wrap; }
.plate { background: var(--plate); border-radius: var(--r-md); border: 1px solid var(--line); display: grid; place-items: center; padding: .5rem; }
.plate svg { display: block; width: 100%; height: auto; }
.plate-main { flex: 1 1 300px; min-height: 200px; }
.plate-side { flex: 0 1 190px; display: flex; flex-direction: column; gap: .5rem; }
.plate-side .plate { flex: 1; }
.caption { font-size: .82rem; color: var(--muted); }
.smiles-line { font-family: var(--mono); font-size: .8rem; color: var(--muted); word-break: break-all; margin-top: .75rem; }

.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin: 1.75rem 0 .75rem; }
.section-title h3 { font-size: 1.25rem; }
.section-title .caption { text-align: right; }

.spectrum-chart { width: 100%; height: auto; display: block; overflow: visible; }
.spectrum-chart .axis-text { fill: var(--muted); font: 12px var(--sans); }
.spectrum-chart .peak-label { fill: var(--ink); font: 600 13px var(--sans); }
.spectrum-chart .grid { stroke: var(--line); }
.stokes { display: flex; flex-wrap: wrap; gap: .4rem 1.25rem; font-size: .9rem; margin-top: .4rem; }
.stokes b { font-weight: 600; }

.ptable { width: 100%; border-collapse: collapse; font-size: .95rem; }
.ptable th { text-align: left; font-weight: 600; color: var(--muted); font-size: .8rem; padding: .5rem .6rem; border-bottom: 1px solid var(--line); }
.ptable td { padding: .7rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.ptable tr:last-child td { border-bottom: 0; }
.ptable .num { text-align: right; white-space: nowrap; }
.ptable .value { font-weight: 600; font-size: 1.05rem; }
.ptable .unit { color: var(--muted); font-size: .85rem; }
.ptable .dim td { color: var(--muted); }

.ad { display: inline-flex; align-items: center; gap: .4rem; font-size: .85rem; white-space: nowrap; }
.ad i { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); display: inline-block; }
.ad-reliable i { background: var(--ok); }
.ad-caution i { background: var(--warn); }
.ad-unreliable i { background: var(--bad); }
.pill { display: inline-block; font-size: .78rem; font-weight: 600; padding: .2rem .55rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }

.recs { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.recs li { padding: .7rem .9rem; border: 1px solid var(--line); border-radius: var(--r-md); }
.recs b { font-weight: 600; display: block; }
.recs span { color: var(--muted); font-size: .88rem; }

.result-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px solid var(--line); }

.similar-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 1rem; }
.sim-card { border: 1px solid var(--line); border-radius: var(--r-md); padding: .6rem; display: flex; flex-direction: column; gap: .5rem; background: var(--surface); }
.sim-card .plate { padding: .25rem; }
.sim-score { display: flex; align-items: center; gap: .5rem; font-weight: 600; font-size: .9rem; }
.sim-bar { flex: 1; height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.sim-bar i { display: block; height: 100%; background: var(--accent); }
.refs { display: flex; flex-wrap: wrap; gap: .3rem; font-size: .8rem; }
.refs a { padding: .15rem .45rem; border: 1px solid var(--line); border-radius: var(--r-sm); text-decoration: none; }
.refs a:hover { border-color: var(--accent); }

/* ---------- загрузка ---------- */
.progress { position: fixed; inset: 0 0 auto 0; height: 3px; z-index: 50; overflow: hidden; display: none; }
.progress.on { display: block; }
.progress::after { content: ""; position: absolute; inset: 0; background: var(--spectrum); transform-origin: left; animation: load 2.4s ease-in-out infinite; }
@keyframes load { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }

/* ---------- база данных ---------- */
.page-head { padding: 2.5rem 0 1.25rem; display: flex; flex-wrap: wrap; gap: 1rem 2rem; align-items: end; justify-content: space-between; }
.page-head p { color: var(--muted); max-width: 62ch; margin: .6rem 0 0; }
.db-tools { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .75rem 1rem; padding: 1rem 1.25rem; align-items: end; }
@media (max-width: 900px) { .db-tools { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .db-tools { grid-template-columns: 1fr; } }
.range label { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: .3rem; }
.range div { display: flex; gap: .35rem; }
.range input { width: 100%; min-width: 0; font: inherit; font-size: .9rem; padding: .45rem .5rem; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); color: var(--ink); }
.db-search label { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: .3rem; }
.db-actions { display: flex; gap: .5rem; }
.db-search input { padding: .55rem .75rem; max-width: 560px; }
.db-status { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .75rem 1.25rem; border-top: 1px solid var(--line); font-size: .88rem; color: var(--muted); flex-wrap: wrap; }

.table-scroll { overflow: auto; max-height: 72vh; border-top: 1px solid var(--line); }
.dbt { border-collapse: separate; border-spacing: 0; font-size: .88rem; min-width: 100%; }
.dbt th, .dbt td { padding: .55rem .75rem; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.dbt thead th { position: sticky; top: 0; background: var(--surface); z-index: 2; font-size: .78rem; color: var(--muted); font-weight: 600; vertical-align: bottom; white-space: normal; min-width: 7rem; max-width: 11rem; line-height: 1.3; }
.dbt thead th button { all: unset; cursor: pointer; display: inline-flex; gap: .25rem; align-items: baseline; }
.dbt thead th button:focus-visible { outline: 2px solid var(--focus); }
.dbt thead th[aria-sort] { color: var(--ink); }
.dbt .num { text-align: right; }
.dbt .sticky { position: sticky; left: 0; background: var(--surface); z-index: 1; border-right: 1px solid var(--line); }
.dbt thead .sticky { z-index: 3; min-width: 0; }
.dbt tbody tr:hover td { background: var(--surface-2); }
.dbt tbody tr:hover td.sticky { background: var(--surface-2); }
.thumb { all: unset; cursor: zoom-in; display: block; width: 150px; height: 100px; background: var(--plate); border-radius: var(--r-sm); }
.thumb img { width: 150px; height: 100px; display: block; }
.thumb:focus-visible { outline: 2px solid var(--focus); }
.dbt .wrap-cell { white-space: normal; min-width: 12rem; }
.dbt tbody.loading { opacity: .45; }
.no-copy { -webkit-user-select: none; user-select: none; }

.pager { display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
.pager button { min-width: 2.2rem; height: 2.2rem; font: inherit; font-size: .88rem; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: var(--r-sm); cursor: pointer; padding: 0 .55rem; }
.pager button[aria-current="page"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.pager button:disabled { opacity: .45; cursor: default; }
.pager select { font: inherit; font-size: .88rem; padding: .3rem; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); color: var(--ink); }

dialog.viewer { border: 0; border-radius: var(--r-lg); padding: 0; width: min(640px, 94vw); background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
dialog.viewer::backdrop { background: rgba(10, 14, 26, .55); }
.viewer-body { padding: 1.25rem; }
.viewer-body .plate img { width: 100%; height: auto; }
.viewer-head { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.25rem 0; }

/* ---------- about ---------- */
.prose h2 { margin: 2.6rem 0 .9rem; }
.prose p, .prose li { max-width: 68ch; }
.metrics { width: 100%; border-collapse: collapse; margin: 1rem 0 1.5rem; font-size: .95rem; }
.metrics th, .metrics td { padding: .6rem .7rem; border-bottom: 1px solid var(--line); text-align: center; }
.metrics th:not(:first-child), .metrics td:not(:first-child) { width: 16%; }
.metrics th:first-child, .metrics td:first-child { text-align: left; }
.metrics thead th { color: var(--muted); font-size: .8rem; font-weight: 600; }
.segmented { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .5rem; margin: .75rem 0 1rem; }
@media (max-width: 640px) { .segmented { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.segmented button { font: inherit; font-size: .9rem; line-height: 1.3; min-height: 3.4rem; padding: .5rem .75rem; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: var(--r-md); cursor: pointer; }
.segmented button:hover { border-color: var(--accent); }
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.chart-box { position: relative; height: 340px; }
.steps { counter-reset: s; list-style: none; padding: 0; margin: 1rem 0; display: grid; gap: 1rem; }
.steps li { counter-increment: s; position: relative; padding-left: 2.6rem; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: .05rem; width: 1.8rem; height: 1.8rem; border-radius: 50%; border: 1px solid var(--line); display: grid; place-items: center; font-weight: 600; font-size: .85rem; }
.timeline { list-style: none; padding: 0; margin: 1rem 0; border-left: 2px solid var(--line); }
.timeline li { padding: 0 0 1rem 1.25rem; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: .45rem; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.timeline time { display: block; color: var(--muted); font-size: .85rem; }
.team { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1.5rem; margin: 1rem 0; }
.person { text-align: center; }
.person img.avatar { width: 128px; height: 128px; object-fit: cover; border-radius: 50%; border: 1px solid var(--line); }
.person h3 { font-family: var(--sans); font-size: 1rem; font-weight: 600; margin: .6rem 0 .15rem; }
.person .role { color: var(--muted); font-size: .88rem; }
.person .links { display: flex; justify-content: center; gap: .6rem; margin-top: .5rem; }
.person .links img { width: 20px; height: 20px; }
.cite { border-left: 3px solid var(--accent); padding: .75rem 1rem; background: var(--surface); border-radius: 0 var(--r-md) var(--r-md) 0; }
.cite p { margin: 0 0 .5rem; }
.projects { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; margin: 1rem 0; }
.project-tile { text-decoration: none; display: flex; align-items: center; justify-content: center; height: 96px; padding: 12px 20px; overflow: hidden; background: #fff; border: 1px solid var(--line); border-radius: var(--r-md); }
.project-tile:hover { border-color: var(--accent); }
/* фиксированная высота в пикселях: процентная max-height в гриде не срабатывала, и высокий логотип вылезал */
.project-tile img { display: block; max-width: 100%; max-height: 70px; width: auto; height: auto; object-fit: contain; }
.project-name { font: 600 1.45rem/1 var(--sans); color: #172036; letter-spacing: -.01em; }
.mail-link { display: inline-flex; align-items: center; gap: .3rem; vertical-align: middle; }
/* логотипы рассчитаны на светлый фон — в тёмной теме кладём их на светлую подложку */
:root[data-theme="dark"] .brand img { background: #f7f8fb; border-radius: 6px; padding: 3px 8px; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brand img { background: #f7f8fb; border-radius: 6px; padding: 3px 8px; }
}

/* ---------- футер ---------- */
.footer { border-top: 1px solid var(--line); padding: 1.75rem 0 2.5rem; color: var(--muted); font-size: .88rem; }
.footer .wrap { display: flex; flex-wrap: wrap; gap: .75rem 2rem; justify-content: space-between; }
.footer a { color: var(--muted); }

@media (max-width: 640px) {
  .topbar .wrap { gap: .5rem; }
  .nav { gap: 0; }
  .nav a { padding: .4rem .45rem; font-size: .95rem; }
  .brand img { height: 28px; }
  .panel-body { padding: 1.1rem; }
  .thumb, .thumb img { width: 120px; height: 80px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
