/* Separate family name keeps interface fonts independent of chart fonts. */
@font-face {
  font-family: "Editor PT Root UI";
  src: url("../Fonts/pt-root-ui_regular.otf") format("opentype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Editor PT Root UI";
  src: url("../Fonts/pt-root-ui_medium.otf") format("opentype");
  font-weight: 500 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Editor PT Root UI";
  src: url("../Fonts/pt-root-ui_bold.otf") format("opentype");
  font-weight: 700 900;
  font-style: normal;
  font-display: swap;
}

    :root {
      --ui-font: "Editor PT Root UI", system-ui, -apple-system, sans-serif;
      --bg:        #ffffff;
      --canvas:    #f6f6f5;   /* фон рабочей области, как у Figma */
      --panel:     #fbfbfa;   /* фон панелей, как у Notion */
      --border:    #d5d8dc;
      --border-2:  #e1e3e6;
      --text:      #2b2b29;
      --muted:     #646970;
      --muted-2:   #9298a0;
      --accent:    #4c6ef5;
      --accent-weak:#eef1fe;
      --header-h:  52px;
      --footer-h:  30px;
      --side-w:    288px;
      --radius:    7px;
      --ctrl-h:    32px;
    }

    * { box-sizing: border-box; }
    html, body { margin:0; height:100%; }
    body {
      font-family: "Inter", system-ui, -apple-system, sans-serif;
      color: var(--text);
      background: var(--canvas);
      font-size: 13px;
      -webkit-font-smoothing: antialiased;
    }
    ::-webkit-scrollbar { width:10px; height:10px; }
    ::-webkit-scrollbar-thumb { background:#dcdcd8; border-radius:8px; border:2px solid transparent; background-clip:content-box; }
    ::-webkit-scrollbar-thumb:hover { background:#c7c7c2; background-clip:content-box; }

    .header, .side, .footer, .zoom-controls {
      font-family: var(--ui-font);
    }
    .header button, .side button { font-family: inherit; }
    .side { line-height: 1.45; }
    .side input::placeholder, .side textarea::placeholder { color: var(--muted); opacity: 1; }
    .side select:disabled { color: var(--muted); background-color: #f0f1f3; cursor: default; }
    .side button:focus-visible, .header button:focus-visible, .zoom-controls button:focus-visible {
      outline: 2px solid var(--accent); outline-offset: 3px;
    }
    .switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 3px; }

    /* ── Сетка приложения (из макета) ───────────────────────── */
    .app {
      height:100vh; width:100vw;
      display:grid;
      grid-template-rows: var(--header-h) 1fr var(--footer-h);
      grid-template-columns: var(--side-w) 1fr var(--side-w);
      grid-template-areas:
        "header header  header"
        "left   content right"
        "footer footer  footer";
    }

    /* ── Хедер ──────────────────────────────────────────────── */
    .header {
      grid-area:header;
      display:flex; align-items:center;          /* вертикально по центру */
      justify-content:flex-start;                /* по левому краю */
      gap:10px;
      padding:0 18px;
      background:var(--bg);
      border-bottom:1px solid var(--border);
    }
    .header .logo {
      width:24px; height:24px; flex:none; display:block;
      border-radius:6px;
    }
    .header h1 {
      font-size:14px; font-weight:600; letter-spacing:-0.01em; margin:0;
      line-height:1.2;
    }
    .header .sp { flex:1; }
    /* ── Переключатель языка интерфейса ── */
    .lang-switch {
      display:flex; align-items:center; gap:2px; flex:none;
      background:var(--panel); border:1px solid var(--border); border-radius:8px; padding:2px;
    }
    .lang-switch button {
      border:none; background:transparent; border-radius:6px; cursor:pointer;
      font-family:inherit; font-size:11px; font-weight:600; letter-spacing:0.02em;
      color:var(--muted); padding:4px 8px; line-height:1;
    }
    .lang-switch button:hover { color:var(--text); }
    .lang-switch button.on { background:var(--bg); color:var(--text); box-shadow:0 1px 2px rgba(16,24,40,.08); }

    /* ── Панели ─────────────────────────────────────────────── */
    .side {
      background:var(--panel);
      overflow-y:auto;
      padding:6px 0 24px;
    }
    .left  { grid-area:left;  border-right:1px solid var(--border); }
    .right {
      grid-area:right; border-left:1px solid var(--border);
      scroll-padding-top:calc(var(--right-panel-sticky-h, 88px) + 8px);
    }
    .right-panel-jump {
      position: sticky; top: 0; z-index: 4;
      background: var(--panel);
      border-bottom: 1px solid var(--border);
      box-shadow: 0 1px 0 var(--border-2);
    }
    .right-panel-jump select { width: 100%; }
    .side.right > .section:not(.right-panel-jump) {
      scroll-margin-top: var(--right-panel-sticky-h, 80px);
    }
    .heatmap-stop-row { display:flex; align-items:flex-start; gap:6px; margin:6px 0; }
    .heatmap-stop-row input[type=number] { width:80px; flex:none; }
    .heatmap-stop-row input[type=color] { width:40px; flex:none; padding:2px; height:var(--ctrl-h); }
    .heatmap-stop-row .btn.icon { flex:none; min-width:28px; padding:0; }
    #heatmapStopsActions { display:flex; flex-wrap:wrap; gap:6px; margin-top:8px; }

    .section { padding:12px 16px; border-bottom:1px solid var(--border-2); }
    .section:last-child { border-bottom:none; }
    .section > .title {
      font-size:11px; font-weight:600; letter-spacing:0.06em; text-transform:uppercase;
      color:var(--muted); margin:0 0 10px;
    }

    /* Иерархия подписей в боковых панелях */
    .side.left,
    .side.right {
      --panel-hier-section: #30343b;
      --panel-hier-sub: #444b54;
      --panel-hier-field: #5e6570;
    }
    .side.left .section > .title,
    .side.right .section > .title {
      font-weight:700;
      color:var(--panel-hier-section);
    }
    .side.left .panel-sub,
    .side.right .panel-sub {
      font-size:12px; font-weight:700; color:var(--panel-hier-sub);
      margin:12px 0 6px; letter-spacing:0.01em;
    }
    .side.left .panel-sub--gap,
    .side.right .panel-sub--gap { margin:12px 0 8px; }
    .side.left .panel-note,
    .side.right .panel-note {
      font-size:12px; font-weight:400; color:var(--panel-hier-field);
      line-height:1.45; margin:0 0 8px;
    }
    .side.left .text-char-hint {
      font-size:12px; font-weight:400; color:var(--panel-hier-field);
      line-height:1.45; margin:0 0 8px;
    }
    .side.left .file-name { color:var(--panel-hier-field); }
    .side.left .panel-field-label,
    .side.right .panel-field-label,
    .side.left .field > label,
    .side.right .field > label,
    .side.left .row > label,
    .side.right .row > label {
      font-weight:400;
      color:var(--panel-hier-field);
    }
    .side.left .field > label,
    .side.right .field > label {
      display:block; font-size:13px; margin:0 0 4px; letter-spacing:0.01em;
    }
    .side.left .row > label,
    .side.right .row > label { flex:1; font-size:12.5px; }
    .side.left .panel-field-label,
    .side.right .panel-field-label { flex:1; font-size:12px; }

    /* Сворачивание разделов и подразделов */
    .side.left .panel-section-head,
    .side.right .panel-section-head,
    .side.left .panel-group-head,
    .side.right .panel-group-head {
      display:flex; align-items:center; justify-content:space-between; gap:8px;
      width:100%; padding:0; border:none; background:transparent; cursor:pointer; text-align:left;
    }
    .side.left .panel-section-head,
    .side.right .panel-section-head {
      margin:0 0 10px;
      font-size:12px; font-weight:700; letter-spacing:0.06em; text-transform:uppercase;
      color:var(--panel-hier-section);
    }
    .side.left .section[data-collapsed] > .panel-section-head,
    .side.right .section[data-collapsed] > .panel-section-head { margin-bottom:0; }
    .side.left .section[data-collapsed] > .section-body,
    .side.right .section[data-collapsed] > .section-body { display:none; }
    .side.left .panel-group-head,
    .side.right .panel-group-head {
      margin:12px 0 6px;
      font-size:12px; font-weight:700; color:var(--panel-hier-sub); letter-spacing:0.01em;
    }
    .side.left .panel-group-head--gap,
    .side.right .panel-group-head--gap { margin:12px 0 8px; }
    .side.left .panel-group[data-collapsed] > .panel-group-head,
    .side.right .panel-group[data-collapsed] > .panel-group-head { margin-bottom:0; }
    .side.left .panel-group[data-collapsed] > .panel-group-body,
    .side.right .panel-group[data-collapsed] > .panel-group-body { display:none; }
    .side.left .panel-chevron,
    .side.right .panel-chevron {
      flex:none; width:7px; height:7px; opacity:0.75;
      border-right:1.5px solid currentColor; border-bottom:1.5px solid currentColor;
      transform:rotate(45deg); transition:transform 0.15s ease;
    }
    .side.left .section[data-collapsed] .panel-section-head .panel-chevron,
    .side.right .section[data-collapsed] .panel-section-head .panel-chevron,
    .side.left .panel-group[data-collapsed] .panel-group-head .panel-chevron,
    .side.right .panel-group[data-collapsed] .panel-group-head .panel-chevron {
      transform:rotate(-45deg);
    }

    /* строки контролов */
    .row { display:flex; align-items:center; gap:8px; margin:7px 0; }
    .row label { flex:1; color:var(--text); font-size:12.5px; }
    .field { margin:8px 0; }
    .field > label {
      display:block; font-size:11px; color:var(--muted); margin:0 0 4px; letter-spacing:0.01em;
    }

    input[type=text], input[type=number], textarea, select {
      font-family:inherit; font-size:13px; color:var(--text);
      background:var(--bg); border:1px solid var(--border);
      border-radius:6px; padding:0 8px; height:var(--ctrl-h);
      outline:none; width:100%;
    }
    textarea { height:auto; padding:6px 8px; resize:vertical; min-height:48px; line-height:1.4; }
    input[type=number] { width:74px; flex:none; text-align:right; font-variant-numeric:tabular-nums; }
    input[type=number].op { width:52px; }
    select { appearance:none; -webkit-appearance:none; cursor:pointer;
      background-image:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a8a85' stroke-width='2.5'><path d='M6 9l6 6 6-6'/></svg>");
      background-repeat:no-repeat; background-position:right 8px center; padding-right:26px;
    }
    input:focus, textarea:focus, select:focus { border-color:var(--accent); box-shadow:0 0 0 3px var(--accent-weak); }

    .text-char-hint {
      font-size:11px; color:var(--muted); line-height:1.5; margin:0 0 8px;
    }
    .text-char-hint li { margin:3px 0; }
    .text-char-hint code {
      font-size:10.5px; background:var(--canvas); padding:1px 5px; border-radius:4px;
      font-family:"JetBrains Mono", ui-monospace, monospace;
    }
    .text-char-btns { display:flex; flex-wrap:wrap; gap:6px; margin:0 0 10px; }
    .text-char-btns button {
      min-width:34px; height:28px; padding:0 8px; border:1px solid var(--border);
      border-radius:6px; background:var(--bg); cursor:pointer; font-size:15px; line-height:1;
      color:var(--text); font-family:inherit;
    }
    .text-char-btns button:hover { border-color:var(--accent); background:var(--accent-weak); }

    input[type=color] {
      width:30px; height:24px; flex:none; padding:0; border:1px solid var(--border);
      border-radius:6px; background:var(--bg); cursor:pointer;
    }
    input[type=color]::-webkit-color-swatch-wrapper { padding:2px; }
    input[type=color]::-webkit-color-swatch { border:none; border-radius:4px; }
    .color-field { margin:0; width:100%; }
    .color-field-head { margin:0 !important; }
    .color-field .color-hex {
      width:100%; margin-top:6px; display:block; box-sizing:border-box;
      font-family:"JetBrains Mono", ui-monospace, monospace;
      font-size:11px; letter-spacing:0.02em; text-transform:uppercase;
    }
    .color-ctrl-swatch { display:inline-flex; flex:none; align-items:center; }
    .color-field--compact { flex:1; min-width:0; }
    .color-field--compact .color-hex { margin-top:4px; }
    .heatmap-stop-row .color-field-head { display:flex; align-items:center; }

    /* чекбокс / переключатель */
    .switch { position:relative; width:34px; height:20px; flex:none; }
    .switch input { position:absolute; inset:0; margin:0; width:100%; height:100%; opacity:0; cursor:pointer; z-index:1; }
    .switch .track {
      position:absolute; inset:0; background:#d7d7d3; border-radius:20px; transition:.15s;
    }
    .switch .track::after {
      content:""; position:absolute; top:2px; left:2px; width:16px; height:16px;
      background:#fff; border-radius:50%; transition:.15s; box-shadow:0 1px 2px rgba(0,0,0,.2);
    }
    .switch input:checked + .track { background:var(--accent); }
    .switch input:checked + .track::after { transform:translateX(14px); }

    /* мини-тогглы жирность/наклон */
    .tgl {
      width:30px; height:24px; flex:none; padding:0; cursor:pointer;
      border:1px solid var(--border); border-radius:6px; background:var(--bg);
      color:var(--muted); font-size:13px; line-height:1;
    }
    .tgl:hover { border-color:var(--muted-2); }
    .tgl.on { background:var(--accent-weak); border-color:var(--accent); color:var(--accent); }

    /* кнопки */
    .btn {
      display:inline-flex; align-items:center; justify-content:center; gap:6px;
      height:var(--ctrl-h); padding:0 12px; border:1px solid var(--border); border-radius:6px;
      background:var(--bg); color:var(--text); font-size:13px; font-family:inherit; cursor:pointer;
      transition:.12s; width:100%;
    }
    .btn:hover { border-color:var(--muted-2); background:#fff; }
    .btn:active { transform:translateY(1px); }
    .btn.primary { background:var(--accent); border-color:var(--accent); color:#fff; }
    .btn.primary:hover { background:#3b5bdb; }
    .btn-grid { display:grid; grid-template-columns:1fr 1fr; gap:8px; }
    .btn-grid-3 { display:grid; grid-template-columns:1fr 1fr 1fr; gap:8px; }
    .tpl-actions { display:flex; gap:8px; }
    .tpl-actions .btn { flex:1; }
    .btn.icon { flex:none; width:var(--ctrl-h); padding:0; font-size:16px; line-height:1; }

    /* ── Контент / рабочая область ──────────────────────────── */
    .content {
      grid-area:content; background:#e8e8e6; position:relative;
      overflow:hidden; display:flex; align-items:center; justify-content:center; padding:36px;
    }
    .viewport {
      position:relative; transform-origin:center center;
    }
    /* Сетка документа — только поверх фрейма, от левого верхнего угла */
    .doc-grid {
      position:absolute; left:0; top:0; margin:0;
      pointer-events:none; z-index:2;
      background-position:0 0;
      background-repeat:repeat;
      box-sizing:border-box;
    }
    .stage {
      position:relative; z-index:1; display:inline-block; overflow:hidden;
      background:transparent; border-radius:0; padding:0; font-size:0; line-height:0;
    }
    .chart-frame {
      position:relative; z-index:1; display:flex; flex-direction:column; box-sizing:border-box;
      font-size:initial; line-height:normal; min-height:0;
    }
    .chart-chrome {
      flex:0 0 auto; width:100%; box-sizing:border-box; overflow:hidden; min-width:0;
    }
    .chart-chrome-plot {
      flex:1 1 0; min-height:0; height:0; min-width:40px; position:relative; overflow:hidden;
      line-height:0; font-size:0; width:100%;
    }
    .chart-chrome-plot #viz {
      position:absolute; left:0; top:0; width:100%; height:100%;
      overflow:hidden; line-height:0; font-size:0;
      display:flex; align-items:center; justify-content:center;
    }
    /* autosize:fit делает холст Vega равным слоту, поэтому показываем его в
       натуральном размере (шрифт = заданному). max-* — только защита от
       обрезки при субпиксельных расхождениях, пропорции сохраняются. */
    .chart-chrome-plot #viz canvas,
    .chart-chrome-plot #viz svg {
      display:block; max-width:100%; max-height:100%;
    }
    .chart-chrome__inner { width:100%; box-sizing:border-box; }
    .chart-legend-typo { white-space:normal; word-break:break-word; }
    .chart-legend-body { white-space:normal; }
    .chart-legend-line { display:block; }
    .chart-legend-item { white-space:nowrap; }
    .chart-legend-body .legend-marker-slot,
    .chart-legend-body .legend-gap { display:inline-block; vertical-align:baseline; }
    .chart-legend-body .legend-marker-slot { position:relative; height:0; }
    .chart-legend-body .legend-marker { position:absolute; }
    .chart-legend-hm-gradient {
      display:block; height:14px; border-radius:2px;
    }
    .content.space-pan,
    .content.canvas-pan { cursor:grab; }
    .content.space-pan.panning,
    .content.canvas-pan.panning { cursor:grabbing; }

    /* ── Управление масштабом холста ── */
    .zoom-controls {
      position:absolute; top:14px; right:14px; z-index:10;
      display:flex; align-items:center; gap:2px;
      background:var(--bg); border:1px solid var(--border); border-radius:8px;
      padding:3px; box-shadow:0 1px 2px rgba(16,24,40,.08);
    }
    .zoom-controls button {
      width:28px; height:28px; border:none; background:transparent; border-radius:6px;
      cursor:pointer; color:var(--text); font-size:16px; line-height:1;
      display:flex; align-items:center; justify-content:center; font-family:inherit;
    }
    .zoom-controls button:hover { background:var(--canvas); }
    .zoom-controls button:active { transform:translateY(1px); }
    .zoom-controls .zlabel {
      min-width:46px; text-align:center; font-size:12px; color:var(--text);
      font-variant-numeric:tabular-nums; cursor:pointer; user-select:none;
    }
    .zoom-controls .zsep { width:1px; height:18px; background:var(--border); margin:0 2px; }

    /* ── Футер ──────────────────────────────────────────────── */
    .footer {
      grid-area:footer; display:grid; grid-template-columns:1fr auto 1fr; align-items:center;
      padding:0 16px; background:var(--bg); border-top:1px solid var(--border);
      color:var(--muted); font-size:11.5px;
    }
    .footer-start { display:flex; align-items:center; gap:14px; min-width:0; }
    .footer-center { justify-self:center; text-align:center; white-space:nowrap; }
    .footer-end { justify-self:end; white-space:nowrap; }
    .footer .dot { width:6px; height:6px; border-radius:50%; background:#37b24d; flex:none; }
    .footer code { font-family:"JetBrains Mono",monospace; font-size:11px; color:var(--text); }
    .footer a { color:var(--muted); text-decoration:none; }
    .footer a:hover { color:var(--text); text-decoration:underline; }
    .footer .sep { color:var(--border); user-select:none; margin:0 6px; }

    .hidden { display:none !important; }
    .file-name { font-size:11px; color:var(--muted); margin-top:6px; word-break:break-all; }

    @media (max-width:1080px){ :root{ --side-w:248px; } }

/* The mobile introduction shares the editor's language switch. */
.mobile-intro { display: none; }
@media (max-width: 900px), (max-width: 1100px) and (pointer: coarse) {
  .app { display: block; width: 100%; height: auto; min-height: 100dvh; background: #fff; }
  .app > .side, .app > .content, .app > .footer { display: none; }
  .header { min-height: 72px; padding: 14px 20px; gap: 10px; }
  .header h1 { font-size: 13px; max-width: 160px; }
  .header .lang-switch button { min-height: 40px; min-width: 42px; padding: 8px; }
  .mobile-intro { display: block; max-width: 680px; margin: auto; padding: 38px 24px 32px; font-family: var(--ui-font); }
  .mobile-eyebrow { color: #b43917; font-size: 12px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; }
  .mobile-intro h2 { margin: 16px 0; font-size: clamp(34px, 7vw, 52px); line-height: 1.08; font-weight: 700; letter-spacing: -.035em; white-space: pre-line; }
  .mobile-description { margin: 0; font-size: 17px; line-height: 1.55; color: #575b60; }
  .mobile-notice { display: flex; gap: 14px; padding: 20px; margin: 28px 0; background: #fff3ee; border: 1px solid #f3d7cb; border-radius: 14px; }
  .mobile-notice svg { flex: none; color: #b43917; margin-top: 2px; }
  .mobile-intro h3 { margin: 0 0 8px; font-size: 18px; line-height: 1.3; font-weight: 700; }
  .mobile-notice p, .mobile-features p { margin: 0; font-size: 15px; line-height: 1.5; color: #575b60; }
  .mobile-preview { margin: 30px -12px; }
  .mobile-preview img { display: block; width: 100%; height: auto; border-radius: 12px; }
  .mobile-preview .mobile-preview-en { display: none; }
  html[lang="en"] .mobile-preview .mobile-preview-ru { display: none; }
  html[lang="en"] .mobile-preview .mobile-preview-en { display: block; }
  .mobile-preview figcaption { margin-top: 12px; text-align: center; color: #646970; font-size: 13px; }
  .mobile-features { display: grid; gap: 24px; padding: 0 0 28px; }
  .mobile-github { display: flex; align-items: center; justify-content: space-between; min-height: 52px; padding: 14px 18px; border: 1px solid var(--border); border-radius: 10px; color: var(--text); text-decoration: none; font-size: 16px; font-weight: 600; }
  .mobile-github:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
  .mobile-credit { margin: 20px 0 0; font-size: 12px; line-height: 1.5; color: #646970; }
}
@media (max-width: 360px) {
  .header { padding-inline: 12px; }
  .header h1 { max-width: 125px; }
  .mobile-intro { padding-inline: 20px; }
}
