/* Layout: панель параметров слева, «лист» плана справа; на телефоне — в одну колонку.
   Палитра: бирюза изразцов мавзолея Яссауи, золото орнамента, светлая степная бумага. */
:root {
  --bg: #f3f4ef;
  --surface: #ffffff;
  --paper: #fffefa;
  --ink: #1c2630;
  --muted: #5d6a72;
  --line: #d6dbd3;
  --accent: #0b7480;
  --accent-ink: #ffffff;
  --accent-soft: #e2f1f1;
  --gold: #a87a22;
  --gold-soft: #f6ecd6;
  --focus: #e0a526;
  --font-display: "Prata", "PT Serif", Georgia, serif;
  --font-body: "Golos Text", "Segoe UI", Roboto, Arial, sans-serif;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11171b;
    --surface: #182027;
    --paper: #1c252c;
    --ink: #e5ebe8;
    --muted: #9aa8ae;
    --line: #2e3b44;
    --accent: #45b5bd;
    --accent-ink: #0d1418;
    --accent-soft: #173238;
    --gold: #d8aa4c;
    --gold-soft: #2f2716;
    --focus: #e8b443;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11171b;
  --surface: #182027;
  --paper: #1c252c;
  --ink: #e5ebe8;
  --muted: #9aa8ae;
  --line: #2e3b44;
  --accent: #45b5bd;
  --accent-ink: #0d1418;
  --accent-soft: #173238;
  --gold: #d8aa4c;
  --gold-soft: #2f2716;
  --focus: #e8b443;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
}
[hidden] { display: none !important; }

/* ---------- шапка ---------- */
.top {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: relative;
}
.top::after {
  /* золотая полоса-орнамент */
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -4px;
  height: 4px;
  background:
    repeating-linear-gradient(135deg, var(--gold) 0 6px, transparent 6px 12px),
    var(--gold-soft);
  opacity: .7;
}
.top-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding-block: 18px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.brand { display: flex; gap: 14px; align-items: center; }
.brand-mark {
  flex: none;
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background:
    radial-gradient(circle at 50% 50%, var(--accent) 0 5px, transparent 6px),
    repeating-conic-gradient(var(--accent) 0 6deg, transparent 6deg 30deg);
  -webkit-mask: radial-gradient(circle, #000 0 19px, transparent 20px);
          mask: radial-gradient(circle, #000 0 19px, transparent 20px);
}
h1 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.6rem;
  line-height: 1.2;
  margin: 0;
  text-wrap: balance;
}
.brand-sub { margin: 2px 0 0; color: var(--muted); font-size: .9rem; }

/* ---------- раскладка ---------- */
.layout {
  max-width: 1400px;
  margin: 0 auto;
  padding-block: 28px 48px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 28px;
  align-items: start;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- панель параметров ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  display: grid;
  gap: 18px;
  position: sticky;
  top: 16px;
}
@media (max-width: 900px) { .panel { position: static; } }
fieldset { border: 0; margin: 0; padding: 0; display: grid; gap: 10px; min-width: 0; }
legend, label {
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0;
  margin-bottom: 6px;
}
.field { display: grid; gap: 0; min-width: 0; }
input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  width: 100%;
  min-width: 0;
}
textarea { resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
.hint { margin: 6px 0 0; font-size: .82rem; color: var(--muted); }

.chips { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.chips button {
  font: inherit;
  font-weight: 600;
  padding: 8px 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.chips button[aria-checked="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.seg { position: relative; display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg input { position: absolute; left: 0; top: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.seg label {
  margin: 0;
  text-transform: none;
  letter-spacing: 0;
  font-size: .92rem;
  font-weight: 500;
  color: var(--ink);
  text-align: center;
  padding: 9px 6px;
  cursor: pointer;
  background: var(--paper);
}
.seg label + input + label { border-left: 1px solid var(--line); }
.seg input:checked + label { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.seg input:focus-visible + label { outline: 2px solid var(--focus); outline-offset: -2px; }
.group-opts { display: grid; grid-template-columns: minmax(0, 1fr) 90px; gap: 10px; }

.more { border-top: 1px dashed var(--line); padding-top: 12px; }
.more summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.more[open] { display: grid; gap: 14px; }

.actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.btn {
  font: inherit;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  padding: 10px 14px;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 6px 11px; font-size: .86rem; font-weight: 500; }
.btn[aria-pressed="true"] { background: var(--gold-soft); border-color: var(--gold); }

/* ---------- вывод ---------- */
.out { min-width: 0; display: grid; gap: 14px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tabs button {
  font: inherit;
  font-weight: 600;
  background: none;
  border: 0;
  border-bottom: 3px solid transparent;
  padding: 8px 14px;
  color: var(--muted);
  cursor: pointer;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--gold); }
.view { display: grid; gap: 12px; min-width: 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: center; }
.tools { display: flex; flex-wrap: wrap; gap: 6px; }
.summary { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: .86rem; min-width: 0; }
.pill {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.pill.gold { background: var(--gold-soft); color: var(--gold); }
.pill.warn { background: var(--gold-soft); color: var(--ink); font-weight: 500; }
.status { margin: 0; min-height: 1.2em; font-size: .86rem; color: var(--accent); }

.sheet-wrap { overflow-x: auto; }
.sheet {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 32px 36px;
  min-width: 760px;
  box-shadow: 0 1px 0 var(--line), 0 12px 28px -18px rgba(0, 0, 0, .25);
}
@media (max-width: 900px) { .sheet { padding: 20px; } }
.sheet[contenteditable="true"] { outline: 2px dashed var(--gold); outline-offset: 4px; }

.plan-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.5rem;
  text-align: center;
  margin: 0 0 18px;
}
.plan-sub { font-family: var(--font-display); font-weight: 400; font-size: 1.2rem; margin: 26px 0 10px; }
.sheet h4 { margin: 18px 0 6px; font-size: 1rem; color: var(--accent); }
.sheet table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.sheet th, .sheet td { border: 1px solid var(--line); padding: 8px 10px; vertical-align: top; text-align: left; }
.sheet th { background: var(--accent-soft); font-weight: 600; }
.plan-head th { width: 26%; }
.plan-flow thead th { text-align: center; }
.plan-flow td.st { width: 15%; background: var(--gold-soft); }
.plan-flow td:nth-child(2) { width: 33%; }
.plan-flow td:nth-child(3) { width: 20%; }
.plan-flow td:nth-child(4) { width: 18%; }
.sheet p { margin: 0 0 8px; }
.sheet ul, .sheet ol { margin: 4px 0 8px; padding-left: 20px; }
.sheet .time { font-variant-numeric: tabular-nums; color: var(--gold); font-weight: 600; }
.sheet .form { font-size: .82rem; color: var(--muted); }
.sheet .muted { color: var(--muted); }
.sheet .key { color: var(--accent); font-size: .85rem; }
.sheet .blank { display: inline-block; min-width: 90px; border-bottom: 1px solid var(--muted); }
.plan-mini { margin-bottom: 8px; }

.sheet .code { font-variant-numeric: tabular-nums; color: var(--accent); }

/* Копия плана для PDF: всегда светлая, без тени и рамки */
.pdf-export { position: absolute; left: -12000px; top: 0; width: 1060px; }
.sheet.pdf-sheet {
  --paper: #ffffff; --ink: #000000; --muted: #555555; --line: #9aa3a6;
  --accent: #0b5a63; --accent-soft: #e3eef0; --gold: #8a6417; --gold-soft: #f7f1e3;
  width: auto; min-width: 0;
  padding: 0 4px; border: 0; border-radius: 0; box-shadow: none;
  background: #ffffff; color: #000000;
  font-family: var(--font-body); font-size: 15px; line-height: 1.45;
}

/* КТП */
.ktp-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.ktp { width: 100%; border-collapse: collapse; font-size: .9rem; min-width: 640px; }
.ktp th, .ktp td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.ktp th { font-size: .76rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.ktp td.n { font-variant-numeric: tabular-nums; color: var(--muted); width: 40px; }
.ktp tr.sec td { background: var(--gold-soft); font-weight: 600; color: var(--ink); }
.ktp .go { white-space: nowrap; }
.ktp .code { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--accent); }
.ktp .code .unverified { color: var(--muted); border-bottom: 1px dotted var(--muted); }
.ktp .rq { margin-top: 2px; font-size: .84rem; color: var(--muted); }
.ktp tr.soch td { color: var(--muted); font-size: .86rem; }
.ktp .muted { color: var(--muted); }
.badge {
  display: inline-block; margin-left: 4px; padding: 1px 7px; border-radius: 999px;
  font-size: .74rem; font-weight: 600; background: var(--gold-soft); color: var(--gold); white-space: nowrap;
}
.ktp-note { margin: 0; }
.code-ok { color: var(--accent); font-weight: 600; }
.code-auto { color: var(--muted); font-weight: 600; border-bottom: 1px dotted var(--muted); }

@media (prefers-reduced-motion: no-preference) {
  .sheet { transition: opacity .2s ease; }
  .sheet.fresh { animation: rise .35s ease; }
  @keyframes rise { from { transform: translateY(6px); } to { transform: none; } }
}

/* ---------- печать ---------- */
@media print {
  .top, .panel, .tabs, .toolbar, .status, #viewKtp { display: none !important; }
  body { background: #fff; color: #000; }
  .layout { display: block; padding: 0; }
  .sheet { border: 0; box-shadow: none; padding: 0; min-width: 0; background: #fff; }
  .sheet th { background: #eee !important; }
  .plan-flow td.st { background: #f7f7f7 !important; }
  .sheet, .sheet * { color: #000 !important; }
}
