    :root {
      --bg: #f4f6f8;
      --surface: #ffffff;
      --ink: #1a2332;
      --muted: #5c6b7a;
      --line: #e1e6ec;
      --accent: #0b6e4f;
      --accent-soft: #e7f5ef;
      --warn: #b45309;
      --warn-soft: #fff7ed;
      --danger: #b42318;
      --danger-soft: #fef3f2;
      --ok: #067647;
      --ok-soft: #ecfdf3;
      --shadow: none;
      --radius: 8px;
      --mono: "Cascadia Mono", "Consolas", "Liberation Mono", monospace;
      --sans: "Segoe UI", "Helvetica Neue", sans-serif;
    }

    .constitution-font-legend {
      margin: 8px 0 0;
      font-size: 0.84rem;
      color: var(--muted);
      line-height: 1.4;
    }
    .constitution-rules-list {
      display: flex;
      flex-direction: column;
      gap: 0;
      margin-top: 6px;
      min-height: 360px;
      overflow: visible;
      padding: 8px 10px;
      border: 1px solid var(--line);
      border-radius: 8px;
      background: #fff;
      font-family: var(--sans);
      font-size: 0.82rem;
      line-height: 1.4;
      box-sizing: border-box;
      color: var(--ink);
    }
    .constitution-rule-group {
      margin: 10px 0 4px;
      padding: 0 4px;
      font-family: var(--sans);
      font-size: 0.72rem;
      font-weight: 700;
      letter-spacing: 0.04em;
      text-transform: uppercase;
      color: var(--muted);
      line-height: 1.3;
      cursor: pointer;
      user-select: none;
    }
    .constitution-rule-group:hover {
      color: var(--accent);
    }
    .constitution-rule-group:first-child {
      margin-top: 2px;
    }
    .constitution-rule-group-hint {
      font-weight: 500;
      text-transform: none;
      letter-spacing: 0;
      color: var(--muted);
      opacity: 0.9;
    }
    .constitution-rule-group-empty {
      margin: 0 4px 6px 2.8em;
      padding: 4px 0;
      font-size: 0.78rem;
      color: var(--muted);
      cursor: pointer;
      user-select: none;
    }
    .constitution-rule-group-empty:hover {
      color: var(--accent);
    }
    .constitution-rule {
      display: flex;
      gap: 8px;
      align-items: flex-start;
      padding: 3px 4px 5px;
      border: 0;
      background: transparent;
      border-radius: 0;
    }
    .constitution-rule-num {
      flex: 0 0 2.2em;
      width: 2.2em;
      text-align: right;
      line-height: 1.4;
      user-select: none;
      color: var(--muted);
      font-variant-numeric: tabular-nums;
      font-size: 0.82rem;
    }
    .constitution-rule-text {
      flex: 1;
      min-width: 0;
      outline: none;
      white-space: pre-wrap;
      word-break: break-word;
      font: inherit;
      font-family: var(--sans);
      font-size: 0.82rem;
      line-height: 1.4;
      color: var(--ink);
      padding: 0;
    }
    .constitution-rule-text:focus {
      background: var(--accent-soft);
      border-radius: 3px;
    }
    .constitution-rule-del {
      flex: 0 0 24px;
      width: 24px;
      height: 24px;
      margin: 0;
      padding: 0;
      border: 0;
      border-radius: 4px;
      background: transparent;
      color: var(--muted);
      font: inherit;
      font-size: 1.15rem;
      line-height: 1;
      cursor: pointer;
      opacity: 0.55;
    }
    .constitution-rule-del:hover {
      opacity: 1;
      color: var(--danger);
      background: var(--danger-soft);
    }
    .constitution-rules-footer {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      align-items: center;
      margin-top: 10px;
    }
    .constitution-rules-footer-right {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      align-items: center;
      margin-left: auto;
    }
    .constitution-rule-editor-backdrop {
      position: fixed;
      inset: 0;
      background: rgba(15, 23, 42, 0.35);
      z-index: 80;
      display: none;
      align-items: center;
      justify-content: center;
      padding: 16px;
    }
    .constitution-rule-editor-backdrop.open {
      display: flex;
    }
    .constitution-rule-editor {
      width: min(560px, 100%);
      background: #fff;
      border-radius: 12px;
      border: 1px solid var(--line);
      box-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
      padding: 16px 18px;
    }
    .constitution-rule-editor h4 {
      margin: 0 0 12px;
      font-size: 1rem;
    }
    .constitution-rule-editor label {
      display: block;
      margin: 0 0 4px;
      font-size: 0.82rem;
      color: var(--muted);
    }
    .constitution-rule-editor select,
    .constitution-rule-editor textarea {
      width: 100%;
      box-sizing: border-box;
      margin-bottom: 12px;
      font-family: var(--sans);
      font-size: 0.82rem;
      line-height: 1.4;
    }
    .constitution-rule-editor textarea {
      min-height: 120px;
      resize: vertical;
    }
    .constitution-rule-editor-actions {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      justify-content: flex-end;
    }
    #constitutionText {
      position: absolute;
      width: 1px;
      height: 1px;
      padding: 0;
      margin: -1px;
      overflow: hidden;
      clip: rect(0, 0, 0, 0);
      white-space: nowrap;
      border: 0;
    }

    * { box-sizing: border-box; }
    html, body { margin: 0; padding: 0; }
    body {
      font-family: var(--sans);
      color: var(--ink);
      background: var(--bg);
      min-height: 100vh;
    }

    .app {
      max-width: 1100px;
      margin: 0 auto;
      padding: 24px 20px 48px;
    }

    header.app-header {
      display: flex;
      align-items: center;
      justify-content: flex-end;
      gap: 8px 4px;
      margin-bottom: 16px;
      flex-wrap: wrap;
    }

    .copy-toast {
      position: fixed;
      top: 16px;
      left: 50%;
      transform: translateX(-50%) translateY(-120%);
      z-index: 100;
      background: #0b6e4f;
      color: #fff;
      font-weight: 700;
      font-size: 0.95rem;
      padding: 12px 20px;
      border-radius: 10px;
      box-shadow: 0 10px 30px rgba(11, 110, 79, 0.35);
      opacity: 0;
      pointer-events: none;
      transition: transform .22s ease, opacity .22s ease;
      max-width: min(90vw, 520px);
      text-align: center;
    }
    .copy-toast.show {
      transform: translateX(-50%) translateY(0);
      opacity: 1;
    }
    .copy-toast.error {
      background: #b42318;
      box-shadow: 0 10px 30px rgba(180, 35, 24, 0.35);
    }

    /* Индикатор работы OCR / нейросети — компактный, справа сверху */
    .work-badge {
      position: fixed;
      right: 12px;
      top: 12px;
      z-index: 130;
      display: none;
      align-items: flex-start;
      gap: 8px;
      max-width: min(78vw, 280px);
      padding: 6px 10px 6px 7px;
      border-radius: 10px;
      background: #143028;
      color: #f4faf7;
      box-shadow: 0 4px 14px rgba(20, 48, 40, 0.35);
      font-size: 0.72rem;
      line-height: 1.15;
      pointer-events: none;
      opacity: 1;
      transition: opacity 0.85s ease;
    }
    .work-badge.visible { display: flex; }
    .work-badge.is-fading {
      opacity: 0;
    }
    .work-badge.is-fading .work-badge-icon::after {
      animation: none;
      opacity: 0.35;
    }
    .work-badge.has-log {
      max-width: min(82vw, 300px);
    }
    .work-badge[data-kind="ocr"] {
      background: linear-gradient(135deg, #0f3d55 0%, #14506e 100%);
    }
    .work-badge[data-kind="llm"] {
      background: linear-gradient(135deg, #3b1d63 0%, #5b2d8e 100%);
    }
    .work-badge-icon {
      flex: 0 0 auto;
      width: 22px;
      height: 22px;
      margin-top: 1px;
      border-radius: 6px;
      display: grid;
      place-items: center;
      background: rgba(255, 255, 255, 0.14);
      font-size: 0.58rem;
      font-weight: 800;
      letter-spacing: 0.01em;
      position: relative;
    }
    .work-badge-icon::after {
      content: '';
      position: absolute;
      inset: -2px;
      border-radius: 7px;
      border: 1.5px solid transparent;
      border-top-color: #9ef0c8;
      border-right-color: rgba(158, 240, 200, 0.35);
      animation: work-spin 0.85s linear infinite;
    }
    .work-badge[data-kind="llm"] .work-badge-icon::after {
      border-top-color: #e2c6ff;
      border-right-color: rgba(226, 198, 255, 0.4);
    }
    @keyframes work-spin {
      to { transform: rotate(360deg); }
    }
    .work-badge-body { min-width: 0; flex: 1; }
    .work-badge-engine {
      display: block;
      font-size: 0.58rem;
      font-weight: 700;
      letter-spacing: 0.04em;
      text-transform: uppercase;
      opacity: 0.78;
      margin-bottom: 0;
    }
    .work-badge-label {
      display: block;
      font-weight: 600;
      font-size: 0.7rem;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      max-width: 240px;
    }
    .work-badge-log {
      display: none;
      margin-top: 4px;
      padding-top: 4px;
      border-top: 1px solid rgba(255, 255, 255, 0.14);
      max-width: 240px;
    }
    .work-badge.has-log .work-badge-log {
      display: block;
    }
    .work-badge-log-line {
      display: block;
      font-size: 0.66rem;
      font-weight: 500;
      line-height: 1.3;
      opacity: 0.55;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .work-badge-log-line:last-child {
      opacity: 0.95;
      font-weight: 600;
    }
    .work-badge-log-line + .work-badge-log-line {
      margin-top: 1px;
    }

    .mkb-delete-warn {
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      z-index: 120;
      display: none;
      align-items: center;
      justify-content: center;
      gap: 12px;
      flex-wrap: wrap;
      padding: 10px 14px;
      background: #7f1d1d;
      color: #fff;
      font-size: 0.92rem;
      font-weight: 600;
      line-height: 1.35;
      box-shadow: 0 6px 20px rgba(127, 29, 29, 0.35);
    }
    .mkb-delete-warn.show { display: flex; }
    .mkb-delete-warn .mkb-delete-count {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      min-width: 1.6em;
      padding: 0 6px;
      border-radius: 6px;
      background: rgba(255, 255, 255, 0.18);
      font-variant-numeric: tabular-nums;
      font-weight: 800;
    }
    .mkb-delete-warn button {
      margin: 0;
      padding: 5px 12px;
      border: 1px solid rgba(255, 255, 255, 0.55);
      border-radius: 8px;
      background: #fff;
      color: #7f1d1d;
      font: inherit;
      font-size: 0.85rem;
      font-weight: 700;
      cursor: pointer;
    }
    .mkb-delete-warn button:hover { background: #fee2e2; }

    .brand h1 {
      margin: 0;
      font-size: 1.45rem;
      font-weight: 700;
      letter-spacing: -0.02em;
    }
    .brand p {
      margin: 6px 0 0;
      color: var(--muted);
      font-size: 0.92rem;
      max-width: 52ch;
      line-height: 1.45;
    }

    .header-actions {
      display: flex;
      gap: 8px;
      flex-shrink: 0;
    }

    .tabs {
      display: flex;
      flex-wrap: wrap;
      gap: 2px;
      margin: 0;
      border-bottom: none;
      padding: 0;
    }
    .tab {
      border: none;
      background: transparent;
      color: var(--muted);
      padding: 8px 10px;
      font: inherit;
      font-weight: 600;
      cursor: pointer;
      border-radius: 8px;
    }
    .tab:hover { color: var(--ink); background: rgba(255,255,255,0.55); }
    .tab.active {
      color: var(--accent);
      background: var(--surface);
      box-shadow: inset 0 -2px 0 var(--accent);
    }

    .panel { display: none; }
    .panel.active { display: block; }

    .card {
      background: var(--surface);
      border: 1px solid var(--line);
      border-radius: var(--radius);
      box-shadow: var(--shadow);
      padding: 16px;
    }

    .toolbar {
      display: flex;
      flex-wrap: wrap;
      gap: 10px;
      align-items: center;
      margin: 14px 0;
    }
    .toolbar[hidden] { display: none; }

    button, .btn {
      font: inherit;
      font-weight: 600;
      border-radius: 8px;
      border: 1px solid transparent;
      padding: 9px 14px;
      cursor: pointer;
      background: var(--accent);
      color: #fff;
    }
    button:hover:not(:disabled) { filter: brightness(1.05); }
    button:disabled {
      opacity: 0.45;
      cursor: not-allowed;
    }
    button.secondary, .btn.secondary {
      background: var(--surface);
      color: var(--ink);
      border-color: var(--line);
    }
    button.ghost {
      background: transparent;
      color: var(--muted);
      border-color: transparent;
    }
    button.danger {
      background: var(--danger-soft);
      color: var(--danger);
      border-color: #fecdca;
    }
    button.small {
      padding: 6px 10px;
      font-size: 0.85rem;
    }

    .dropzone {
      border: 2px dashed #9db0c0;
      border-radius: var(--radius);
      background: #f8fafc;
      min-height: 160px;
      display: flex;
      align-items: center;
      justify-content: center;
      text-align: center;
      padding: 24px;
      transition: border-color .15s, background .15s;
      cursor: pointer;
      position: relative;
    }
    .dropzone:hover, .dropzone.dragover {
      border-color: var(--accent);
      background: var(--accent-soft);
    }
    .dropzone.has-image { padding: 12px; }
    .dropzone img {
      max-width: 100%;
      max-height: 300px;
      object-fit: contain;
      border-radius: 8px;
    }
    .dropzone .hint {
      color: var(--muted);
      line-height: 1.5;
    }
    .dropzone .hint strong { color: var(--ink); }
    .dropzone input[type="file"] {
      position: absolute;
      inset: 0;
      opacity: 0;
      cursor: pointer;
    }

    .recognize-split {
      display: grid;
      grid-template-columns: 2fr 4fr 4fr;
      gap: 10px;
      margin: 0 0 12px;
      align-items: stretch;
      min-height: 220px;
    }
    .recognize-pane {
      display: flex;
      flex-direction: column;
      min-width: 0;
      min-height: 0;
      overflow: hidden;
      border: 1px solid var(--line);
      border-radius: 12px;
      padding: 8px 10px;
      background: #f7f9fb;
      transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    }
    .recognize-pane.is-active {
      background: #fff;
      border-color: var(--accent);
      box-shadow: 0 0 0 1px #b7e4d4;
    }
    .recognize-pane-label {
      margin: 0 0 6px;
      font-size: 0.78rem;
      font-weight: 700;
      color: var(--muted);
      letter-spacing: 0.02em;
      text-transform: uppercase;
      flex-shrink: 0;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .recognize-pane.is-active .recognize-pane-label {
      color: var(--accent);
    }
    .recognize-pane-label.is-llm-label {
      display: flex;
      flex-wrap: wrap;
      align-items: baseline;
      gap: 6px 10px;
      white-space: normal;
      text-overflow: unset;
      overflow: visible;
    }
    .recognize-pane-label .llm-model-tag {
      font-size: 0.72rem;
      font-weight: 600;
      letter-spacing: 0;
      text-transform: none;
      color: var(--muted);
      font-family: var(--mono);
    }
    .recognize-pane.is-active .recognize-pane-label .llm-model-tag {
      color: #0b6b4a;
    }
    .recognize-pane-label .llm-model-tag.is-warn {
      color: var(--warn);
    }
    .autopilot-llm-row {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      gap: 10px 14px;
    }
    .autopilot-llm-row .status {
      flex: 1;
      min-width: 180px;
    }
    .autopilot-llm-mode-tog {
      flex-shrink: 0;
    }
    .autopilot-llm-mode-tog.is-disabled {
      opacity: 0.55;
      pointer-events: none;
    }
    .recognize-pane-body {
      display: flex;
      flex-direction: column;
      flex: 1;
      min-height: 0;
      min-width: 0;
    }
    .recognize-pane .dropzone {
      flex: 1;
      min-height: 140px;
    }
    .recognize-text-pane,
    .recognize-voice-pane {
      display: flex;
      flex-direction: column;
      flex: 1;
      margin: 0;
      min-height: 140px;
    }
    .recognize-text-pane textarea,
    .recognize-voice-pane textarea {
      width: 100%;
      flex: 1;
      min-height: 140px;
      margin: 0;
      padding: 10px 12px;
      border: 1px solid var(--line);
      border-radius: 10px;
      font: inherit;
      font-size: 0.86rem;
      line-height: 1.45;
      resize: none;
      background: #fafbfc;
      color: var(--ink);
      box-sizing: border-box;
    }
    .recognize-text-pane textarea {
      font-family: var(--mono);
    }
    .recognize-voice-pane textarea {
      font-family: var(--sans);
      overflow-y: auto;
    }
    .recognize-text-pane textarea:focus,
    .recognize-voice-pane textarea:focus {
      outline: none;
      border-color: var(--accent);
      background: #fff;
    }

    .progress-wrap {
      display: none;
      margin: 12px 0 4px;
    }
    .progress-wrap.visible { display: block; }
    .progress-head {
      display: flex;
      align-items: center;
      gap: 8px;
      margin-bottom: 6px;
    }
    .progress-engine {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      font-size: 0.78rem;
      font-weight: 700;
      letter-spacing: 0.03em;
      text-transform: uppercase;
      color: #0f3d55;
      background: #e8f3f8;
      border-radius: 999px;
      padding: 3px 10px 3px 8px;
    }
    .progress-wrap[data-kind="llm"] .progress-engine {
      color: #4c1d95;
      background: #f3e8ff;
    }
    .progress-engine .spin {
      width: 12px;
      height: 12px;
      border: 2px solid currentColor;
      border-right-color: transparent;
      border-radius: 50%;
      animation: work-spin 0.75s linear infinite;
    }
    .progress-bar {
      height: 8px;
      background: #e5ebf1;
      border-radius: 999px;
      overflow: hidden;
    }
    .progress-bar > i {
      display: block;
      height: 100%;
      width: 0%;
      background: linear-gradient(90deg, #0b6e4f, #2a9d7a);
      transition: width .2s ease;
    }
    .progress-wrap[data-kind="llm"] .progress-bar > i {
      background: linear-gradient(90deg, #6d28d9, #a78bfa);
    }
    .progress-bar.indeterminate > i {
      width: 35% !important;
      animation: progress-indeterminate 1.1s ease-in-out infinite;
    }
    @keyframes progress-indeterminate {
      0% { transform: translateX(-120%); }
      100% { transform: translateX(320%); }
    }
    .progress-label {
      margin-top: 6px;
      font-size: 0.85rem;
      color: var(--muted);
    }

    .status {
      margin: 10px 0 0;
      font-size: 0.9rem;
      color: var(--muted);
      min-height: 1.3em;
    }
    .status.error { color: var(--danger); }
    .status.ok { color: var(--ok); }
    .status.warn { color: var(--warn); }

    .fields {
      display: grid;
      gap: 0;
      margin-top: 14px;
      border: 1px solid var(--line);
      border-radius: 10px;
      background: #fff;
      padding: 0 14px;
    }

    .field-card {
      border: none;
      border-radius: 0;
      background: transparent;
      padding: 0;
      margin: 0;
    }
    .field-card.is-collapsed .field-body,
    .field-card.is-collapsed .field-actions,
    .field-card.is-collapsed .field-missing {
      display: none;
    }
    .field-card.is-collapsible .field-head {
      cursor: pointer;
      user-select: none;
    }
    .field-card.is-collapsible .field-title::after {
      content: '▾';
      margin-left: 6px;
      font-size: 0.75rem;
      color: var(--muted);
      font-weight: 600;
    }
    .field-card.is-collapsible.is-collapsed .field-title::after {
      content: '▸';
    }
    .field-head {
      display: flex;
      position: relative;
      align-items: center;
      justify-content: space-between;
      gap: 10px;
      margin: 0;
      padding: 0;
      flex-wrap: nowrap;
      min-height: 0;
      line-height: 1.4;
    }
    .field-title {
      display: flex;
      align-items: center;
      gap: 8px;
      font-weight: 700;
      flex: 0 0 auto;
      min-width: 0;
      z-index: 1;
    }
    .field-head .mkb-ctx-cycles:not([hidden]) {
      position: static;
      transform: none;
      margin: 0 0 0 8px;
      margin-right: auto;
      z-index: 1;
      max-width: none;
      justify-content: flex-start;
      flex: 1 1 auto;
      flex-wrap: wrap;
      min-width: 0;
      overflow-x: visible;
    }
    .field-decide {
      display: inline-flex;
      align-items: center;
      gap: 4px;
      flex: 0 0 auto;
      margin-left: auto;
      z-index: 1;
    }
    .field-decide[hidden] {
      display: none !important;
    }
    .field-decide-btn {
      width: 28px;
      height: 28px;
      padding: 0;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      border-radius: 8px;
      font-size: 1rem;
      font-weight: 700;
      line-height: 1;
      cursor: pointer;
      border: 1px solid var(--line);
      background: #fff;
      color: var(--ink);
    }
    .field-decide-btn:hover {
      border-color: #b7e4d4;
      background: var(--accent-soft);
    }
    .field-decide-btn--ok {
      color: var(--ok);
      border-color: #abefc6;
      background: var(--ok-soft);
    }
    .field-decide-btn--ok:hover {
      border-color: var(--ok);
      background: #d1fadf;
    }
    .field-decide-btn--no {
      color: var(--danger);
      border-color: #fecdca;
      background: var(--danger-soft);
    }
    .field-decide-btn--no:hover {
      border-color: var(--danger);
      background: #fee4e2;
    }
    .badge {
      width: 22px;
      height: 22px;
      border-radius: 50%;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      font-size: 0.75rem;
      cursor: pointer;
      border: 1px solid transparent;
      user-select: none;
    }
    .badge.ok { background: var(--ok-soft); color: var(--ok); border-color: #abefc6; }
    .badge.bad { background: var(--danger-soft); color: var(--danger); border-color: #fecdca; }
    .badge.na { background: #f2f4f7; color: var(--muted); }

    .field-text {
      font-family: inherit;
      font-size: 0.82rem;
      line-height: 1.4;
      white-space: normal;
      overflow-wrap: anywhere;
      word-break: break-word;
      max-height: none;
      overflow: visible;
      background: transparent;
      border: none;
      border-radius: 0;
      padding: 0;
      margin: 0;
      cursor: pointer;
      transition: background .15s;
    }
    .field-text:hover {
      background: var(--accent-soft);
    }
    .field-text:active {
      background: #d9f0e7;
    }
    .field-text .glance-sec-title {
      display: block;
      font-weight: 700;
      color: var(--ink);
      margin: 0.55em 0 0.15em;
      padding: 0;
      line-height: 1.4;
    }
    .field-text .glance-sec-block:first-child > .glance-sec-title,
    .field-text > .glance-sec-title:first-child {
      margin-top: 0;
    }
    .field-text .glance-sec-body {
      display: block;
      padding: 0.1em 0 0.15em 0.75em;
      margin: 0 0 0.55em;
      line-height: 1.45;
      white-space: pre-wrap;
      word-break: break-word;
    }
    .field-text .glance-sec-body:last-child,
    .field-text .glance-sec-block:last-child .glance-sec-body:last-child {
      margin-bottom: 0;
    }
    .field-text .glance-imaging-title {
      font-weight: 700;
      color: var(--ink);
    }
    .field-text .glance-sec-block + .glance-sec-block {
      margin-top: 0.35em;
      padding-top: 0.35em;
      border-top: 1px solid rgba(15, 23, 42, 0.06);
    }
    .field-text .glance-service {
      display: block;
      font-size: 0.78rem;
      font-family: var(--mono);
      font-weight: 500;
      color: var(--muted);
      margin: 0;
      padding: 0;
      line-height: 1.4;
    }
    .field-text.ocr-version,
    .field-text.src-version,
    .field-text.fix-version {
      white-space: pre-wrap;
    }
    .spell-err {
      text-decoration-line: underline;
      text-decoration-style: wavy;
      text-decoration-color: #b42318;
      text-underline-offset: 3px;
      background: rgba(180, 35, 24, 0.08);
      border-radius: 2px;
      cursor: help;
    }
    .spell-miss {
      text-decoration-line: underline;
      text-decoration-style: dotted;
      text-decoration-color: #5c6b7a;
      text-underline-offset: 3px;
      background: rgba(92, 107, 122, 0.08);
      border-radius: 2px;
      cursor: pointer;
    }
    .spell-punct {
      text-decoration-line: underline;
      text-decoration-style: wavy;
      text-decoration-color: #b45309;
      text-underline-offset: 3px;
      background: rgba(180, 83, 9, 0.1);
      border-radius: 2px;
      cursor: help;
    }
    .field-body {
      width: 100%;
      min-width: 0;
    }
    .field-compare {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 10px;
      margin: 0;
      width: 100%;
      min-width: 0;
    }
    .field-compare > div {
      min-width: 0;
      width: 100%;
    }
    .field-compare-empty {
      min-height: 0;
      pointer-events: none;
    }
    .field-text.ocr-version,
    .field-text.src-version,
    .field-text.fix-version {
      padding: 0 6px;
      border-radius: 4px;
      margin: 0;
    }
    .field-text.ocr-version { background: #fffafa; }
    .field-text.src-version { background: #f8fafc; }
    .field-text.fix-version { background: #f6fdf8; }
    .field-compare-label {
      font-size: 0.72rem;
      font-weight: 700;
      color: var(--muted);
      letter-spacing: 0.02em;
      text-transform: uppercase;
      margin: 0;
    }
    .field-compare-hint {
      font-size: 0.78rem;
      color: var(--muted);
      margin: 0;
      line-height: 1.4;
    }
    .field-text.fix-version del,
    .diff-mark del {
      background: #fee4e2;
      color: #912018;
      text-decoration: line-through;
      border-radius: 2px;
    }
    .field-text.fix-version ins,
    .diff-mark ins {
      background: #d1fadf;
      color: #085d3a;
      text-decoration: none;
      font-weight: 700;
      border-radius: 2px;
      padding: 0 1px;
    }
    .field-missing {
      margin-top: 8px;
      font-size: 0.84rem;
      color: var(--danger);
      display: none;
    }
    .field-missing.open { display: block; }
    .field-missing ul { margin: 6px 0 0; padding-left: 18px; }
    .field-actions {
      display: none;
    }
    .field-card.has-proposal {
      position: relative;
      border-color: #c4a35a;
      box-shadow: 0 0 0 1px rgba(196, 163, 90, 0.25);
      transition: border-color 0.25s ease, box-shadow 0.25s ease, opacity 0.25s ease;
    }
    .field-card.has-proposal .field-compare > div {
      transition: opacity 0.32s ease, transform 0.32s ease, filter 0.32s ease;
      transform-origin: center center;
    }
    .field-card.proposal-busy .field-decide-btn {
      pointer-events: none;
      opacity: 0.55;
    }
    /* Принять: левый лопается как пузырь, правый наезжает на его место; ширины колонок те же */
    .field-card.proposal-accept {
      border-color: var(--ok);
      box-shadow: 0 0 0 2px rgba(6, 118, 71, 0.22);
    }
    .field-card.proposal-accept .field-compare > div:first-child {
      opacity: 0;
      transform: scale(0.12);
      filter: blur(2px);
      pointer-events: none;
    }
    .field-card.proposal-accept .field-compare > div:last-child {
      transform: translateX(calc(-100% - 10px));
      box-shadow: 0 0 0 2px rgba(6, 118, 71, 0.35);
      border-radius: 8px;
      z-index: 1;
    }
    .field-card.proposal-accept .field-decide {
      opacity: 0;
      transform: translateY(-4px);
      transition: opacity 0.2s ease, transform 0.2s ease;
    }
    /* Отклонить: правый уезжает вправо и лопается, левый на месте */
    .field-card.proposal-reject {
      border-color: var(--line);
      box-shadow: none;
    }
    .field-card.proposal-reject .field-compare > div:last-child {
      opacity: 0;
      transform: translateX(18px) scale(0.12);
      filter: blur(2px);
      pointer-events: none;
    }
    .field-card.proposal-reject .field-compare > div:first-child {
      box-shadow: 0 0 0 2px rgba(92, 107, 122, 0.2);
      border-radius: 8px;
    }
    .field-card.proposal-reject .field-decide {
      opacity: 0;
      transform: translateY(-4px);
      transition: opacity 0.2s ease, transform 0.2s ease;
    }
    .field-card.proposal-flash-ok {
      animation: proposalFlashOk 0.45s ease;
    }
    .field-card.proposal-flash-no {
      animation: proposalFlashNo 0.45s ease;
    }
    @keyframes proposalFlashOk {
      0% { box-shadow: 0 0 0 0 rgba(6, 118, 71, 0.35); }
      40% { box-shadow: 0 0 0 6px rgba(6, 118, 71, 0.12); border-color: var(--ok); }
      100% { box-shadow: none; }
    }
    @keyframes proposalFlashNo {
      0% { box-shadow: 0 0 0 0 rgba(92, 107, 122, 0.25); }
      40% { box-shadow: 0 0 0 6px rgba(92, 107, 122, 0.1); }
      100% { box-shadow: none; }
    }
    @media (prefers-reduced-motion: reduce) {
      .field-card.has-proposal .field-compare > div,
      .field-card.proposal-accept,
      .field-card.proposal-reject,
      .field-card.proposal-flash-ok,
      .field-card.proposal-flash-no {
        transition: none !important;
        animation: none !important;
      }
    }
    .autopilot-proposal-bar {
      display: inline-flex;
      flex-wrap: wrap;
      align-items: center;
      gap: 6px;
      margin: 0;
      padding: 0;
      border: 0;
      border-radius: 0;
      background: transparent;
    }
    .autopilot-proposal-bar[hidden] { display: none !important; }
    .autopilot-proposal-bar .status {
      margin: 0;
      font-size: 0.78rem;
      color: var(--muted);
      white-space: nowrap;
    }
    .autopilot-proposal-bar button {
      font-size: 0.78rem;
      padding: 4px 9px;
    }
    .ib-header-top {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      justify-content: space-between;
      gap: 8px 12px;
      margin-bottom: 6px;
    }
    .ib-header-top .ib-header-kicker {
      margin-bottom: 0;
    }
    @media (max-width: 720px) {
      .field-compare { grid-template-columns: 1fr; }
    }

    .raw-box {
      margin-top: 14px;
    }
    .raw-box details summary {
      cursor: pointer;
      font-weight: 600;
      color: var(--muted);
    }
    .raw-box pre {
      margin: 8px 0 0;
      font-family: var(--mono);
      font-size: 0.82rem;
      white-space: pre-wrap;
      background: #fff;
      border: 1px solid var(--line);
      border-radius: 8px;
      padding: 10px;
      max-height: 260px;
      overflow: auto;
    }

    .seq-banner {
      display: none;
      margin: 12px 0;
      padding: 12px 14px;
      border-radius: 10px;
      background: #eef6ff;
      border: 1px solid #b6d4fe;
      color: #194185;
      font-size: 0.92rem;
      line-height: 1.45;
    }
    .seq-banner.active { display: block; }

    /* Modal */
    .modal-backdrop {
      position: fixed;
      inset: 0;
      background: rgba(16, 24, 40, 0.45);
      display: none;
      align-items: center;
      justify-content: center;
      z-index: 50;
      padding: 16px;
    }
    .modal-backdrop.open { display: flex; }
    .modal {
      width: min(820px, 100%);
      max-height: min(90vh, 900px);
      overflow: auto;
      background: var(--surface);
      border-radius: 14px;
      box-shadow: 0 20px 50px rgba(16,24,40,0.25);
      padding: 18px 18px 16px;
    }
    .modal h2 {
      margin: 0 0 12px;
      font-size: 1.2rem;
    }
    .modal h3 {
      margin: 18px 0 8px;
      font-size: 1rem;
    }
    .form-row {
      display: grid;
      gap: 8px;
      margin-bottom: 10px;
    }
    .form-grid {
      display: grid;
      grid-template-columns: 1fr 1.4fr auto;
      gap: 8px;
      align-items: end;
    }
    label {
      font-size: 0.82rem;
      font-weight: 600;
      color: var(--muted);
      display: block;
      margin-bottom: 4px;
    }
    input[type="text"], input[type="number"], textarea, select {
      width: 100%;
      font: inherit;
      padding: 8px 10px;
      border: 1px solid var(--line);
      border-radius: 8px;
      background: #fff;
      color: var(--ink);
    }
    textarea { min-height: 70px; resize: vertical; font-family: var(--mono); font-size: 0.85rem; }
    .section-item, .kw-block, .profile-row {
      border: 1px solid var(--line);
      border-radius: 10px;
      padding: 10px;
      margin-bottom: 8px;
      background: #fafbfc;
    }
    .check-row {
      display: flex;
      align-items: center;
      gap: 8px;
      margin: 8px 0;
      font-size: 0.92rem;
    }
    .check-row input { width: auto; }
    .modal-footer {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      margin-top: 16px;
      padding-top: 12px;
      border-top: 1px solid var(--line);
    }

    #historyStatus {
      margin: 0 0 8px;
    }
    .history-list { display: grid; gap: 6px; }
    .history-card {
      display: block;
      width: 100%;
      box-sizing: border-box;
      margin: 0;
      text-align: left;
      font: inherit;
      font-weight: 500;
      color: inherit;
      cursor: pointer;
      border: 1px solid var(--line);
      border-radius: var(--radius);
      padding: 7px 10px;
      background: #fff;
    }
    .history-card:hover {
      border-color: #b7d7c8;
      background: var(--accent-soft);
      filter: none;
      text-decoration: none;
    }
    .history-card.is-dragging {
      opacity: 0.55;
      cursor: grabbing;
    }
    .history-card.is-drop-target {
      border-color: var(--accent);
      background: var(--accent-soft);
      box-shadow: inset 0 0 0 1px var(--accent);
    }
    .history-card-top {
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      gap: 8px;
    }
    .history-card .history-patient-name {
      flex: 1 1 auto;
      min-width: 0;
      font-size: 0.9rem;
      font-weight: 700;
      min-height: 1.2em;
      line-height: 1.25;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .history-card .history-patient-name:focus {
      white-space: normal;
      overflow: visible;
      text-overflow: clip;
    }
    .history-card-visits {
      display: grid;
      gap: 1px;
      margin-top: 3px;
    }
    .history-card-visit {
      display: flex;
      flex-direction: row;
      align-items: flex-start;
      gap: 8px;
      width: 100%;
      min-width: 0;
      box-sizing: border-box;
      margin: 0;
      padding: 0;
      text-align: left;
      font: inherit;
      font-weight: 500;
      color: inherit;
      cursor: pointer;
      border: none;
      border-radius: 0;
      background: transparent;
    }
    .history-card-visit-when {
      flex: 0 0 auto;
      font-size: 0.78rem;
      font-weight: 600;
      color: var(--muted);
      white-space: nowrap;
    }
    .history-card-visit-dx {
      flex: 1 1 auto;
      min-width: 0;
      font-size: 0.84rem;
      font-weight: 500;
      line-height: 1.35;
      color: var(--ink);
      white-space: normal;
      overflow: visible;
      overflow-wrap: break-word;
    }
    .history-card-dx {
      margin: 6px 0 0;
      font-size: 0.9rem;
      font-weight: 500;
      line-height: 1.4;
      color: var(--ink);
    }
    .history-sheet {
      border: none;
      border-radius: 0;
      padding: 0;
      background: transparent;
    }
    .history-back {
      margin: 0 0 6px;
      padding: 0;
    }
    .history-doc {
      margin: 10px 0 0;
      padding: 8px 0 2px;
      border: none;
      border-top: 1px solid var(--line);
      border-radius: 0;
      background: transparent;
    }
    .history-doc-top {
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      gap: 12px;
    }
    .history-doc-head {
      margin: 0;
      font-weight: 700;
    }
    button.history-doc-delete {
      flex: 0 0 auto;
      margin: 0;
      padding: 0;
      width: 28px;
      height: 28px;
      min-width: 28px;
      font-size: 1.2rem;
      font-weight: 500;
      line-height: 1;
      border-radius: 6px;
    }
    .history-delete-modal {
      width: min(460px, 100%);
    }
    .history-delete-detail {
      margin: 0 0 14px;
      font-size: 0.92rem;
      font-weight: 500;
      line-height: 1.45;
      color: var(--ink);
    }
    .history-shots-btn {
      margin: 4px 0 0;
      padding: 3px 10px;
      font-size: 0.8rem;
    }
    .history-shots-btn[hidden] { display: none; }
    .history-doc-sub {
      margin: 1px 0 0;
      font-size: 0.82rem;
      color: var(--muted);
    }
    .history-field-name {
      margin: 8px 0 1px;
      font-size: 0.9rem;
      font-weight: 700;
      color: var(--ink);
    }
    .history-chat-meta {
      margin: 12px 0 6px;
      padding: 8px 12px 10px;
      border: 1px solid #d5e0ee;
      border-left: 3px solid #3b6ea5;
      border-radius: 8px;
      background: #f3f6fb;
    }
    .history-chat-meta > summary {
      cursor: pointer;
      font-size: 0.78rem;
      font-weight: 700;
      letter-spacing: 0.03em;
      text-transform: uppercase;
      color: #3b6ea5;
    }
    .history-chat-meta-mode {
      margin: 8px 0 0;
      font-size: 0.88rem;
      color: var(--ink);
    }
    .history-chat-meta-label {
      margin: 10px 0 2px;
      font-size: 0.78rem;
      font-weight: 700;
      letter-spacing: 0.02em;
      text-transform: uppercase;
      color: var(--muted);
    }
    .history-chat-meta-text {
      margin: 0;
      padding: 0;
      white-space: pre-wrap;
      font-family: inherit;
      font-size: 0.86rem;
      line-height: 1.4;
      color: var(--ink);
      background: transparent;
      border: none;
    }
    .history-field-text {
      margin: 0;
      padding: 2px 4px;
      min-height: 1.3em;
      white-space: pre-wrap;
      font-family: inherit;
      font-size: 0.9rem;
      line-height: 1.35;
      background: transparent;
      border: none;
      border-radius: 4px;
      cursor: text;
      outline: none;
    }
    .history-field-text:focus {
      background: #fff;
      box-shadow: inset 0 0 0 1px var(--accent);
    }
    .history-field-text strong {
      font-weight: 700;
    }
    .history-field-doc {
      white-space: normal;
      padding: 4px 0 8px;
    }
    .history-field-doc .glance-sec-block {
      display: block;
      margin: 0;
      padding: 0;
      border: none;
    }
    .history-field-doc .glance-sec-title {
      display: block;
      font-weight: 700;
      margin: 0;
      padding: 0;
      line-height: 1.45;
    }
    .history-field-doc .glance-sec-body {
      display: block;
      margin: 0;
      padding: 0 0 0 1.15em;
      line-height: 1.45;
      white-space: pre-wrap;
      word-break: break-word;
    }
    .history-field-doc u.glance-sub-title {
      text-decoration: underline;
      text-underline-offset: 2px;
      font-weight: 600;
    }
    .history-patient {
      border: 1px solid var(--line);
      border-radius: 12px;
      padding: 12px 14px;
      background: #fff;
    }
    .history-patient-head {
      display: flex;
      flex-wrap: wrap;
      align-items: baseline;
      justify-content: space-between;
      gap: 8px;
      margin-bottom: 8px;
    }
    .history-patient-name {
      margin: 0;
      min-height: 1.3em;
      font-size: 1.05rem;
      font-weight: 700;
      outline: none;
      cursor: text;
      border-radius: 4px;
    }
    .history-patient-name:focus {
      box-shadow: inset 0 -1px 0 var(--accent);
    }
    .history-patient-name:empty::before {
      content: attr(data-placeholder);
      color: var(--muted);
      font-weight: 500;
    }
    .history-merge-modal {
      width: min(460px, 100%);
    }
    .history-merge-warn {
      margin: 0 0 14px;
      padding: 10px 12px;
      border-radius: 8px;
      background: var(--warn-soft);
      color: var(--warn);
      font-size: 0.92rem;
      font-weight: 500;
      line-height: 1.45;
    }
    .history-merge-choices {
      display: grid;
      gap: 8px;
    }
    .history-merge-choice {
      display: flex;
      flex-direction: column;
      align-items: flex-start;
      gap: 2px;
      width: 100%;
      text-align: left;
      background: var(--surface);
      color: var(--ink);
      border: 1px solid var(--line);
    }
    .history-merge-choice:hover:not(:disabled) {
      filter: none;
      border-color: var(--accent);
      background: var(--accent-soft);
    }
    .history-merge-choice-name {
      font-weight: 700;
    }
    .history-merge-choice-hint {
      font-size: 0.82rem;
      font-weight: 500;
      color: var(--muted);
    }
    .history-patient-sub {
      margin: 0;
      font-size: 0.85rem;
      color: var(--muted);
    }
    .history-visit {
      border-top: 1px solid var(--line);
      padding: 10px 0 0;
      margin-top: 10px;
    }
    .history-visit:first-of-type {
      border-top: none;
      padding-top: 0;
      margin-top: 4px;
    }
    .history-visit .meta {
      font-size: 0.85rem;
      color: var(--muted);
      margin-bottom: 6px;
    }

    .voice-facts {
      display: flex;
      flex-wrap: wrap;
      gap: 6px;
      margin: 10px 0 4px;
    }
    .voice-chip {
      font-size: 0.8rem;
      font-weight: 600;
      background: var(--accent-soft);
      color: var(--accent);
      border: 1px solid #b7e4d4;
      border-radius: 999px;
      padding: 4px 10px;
    }
    .voice-tpl-bar {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      gap: 10px;
      margin: 12px 0 4px;
      padding: 10px 12px;
      border: 1px solid #c5e6d8;
      border-radius: 10px;
      background: #f3fbf7;
    }
    .voice-tpl-bar[hidden] { display: none !important; }
    .voice-tpl-bar .voice-tpl-hint {
      flex: 1;
      min-width: 200px;
      font-size: 0.9rem;
      color: var(--muted);
    }
    .help-list {
      margin: 0;
      padding-left: 18px;
      color: var(--muted);
      font-size: 0.9rem;
      line-height: 1.5;
    }
    .help-list a { color: var(--accent); }
    .help-map {
      margin: 12px 0 0;
      padding: 0;
      list-style: none;
      display: flex;
      flex-direction: column;
      align-items: stretch;
      gap: 0;
      max-width: 420px;
    }
    .help-map li {
      position: relative;
      margin: 0;
      padding: 10px 12px;
      border: 1px solid var(--border, #d0d5dd);
      border-radius: 8px;
      background: var(--surface, #f8fafc);
      color: var(--text, #1a1a1a);
      font-size: 0.9rem;
      line-height: 1.35;
    }
    .help-map li strong {
      display: block;
      font-size: 0.95rem;
      margin-bottom: 2px;
    }
    .help-map li + li { margin-top: 18px; }
    .help-map li + li::before {
      content: '↓';
      position: absolute;
      top: -16px;
      left: 50%;
      transform: translateX(-50%);
      color: var(--muted);
      font-size: 0.85rem;
      line-height: 1;
    }
    .help-map-note {
      margin: 10px 0 0;
      font-size: 0.85rem;
      color: var(--muted);
      max-width: 420px;
    }

    .mkb-layout {
      display: grid;
      grid-template-columns: minmax(240px, 1fr) minmax(280px, 1.3fr);
      gap: 12px;
    }
    .mkb-layout.mkb-layout--single {
      grid-template-columns: 1fr;
    }
    .mkb-editor-slot:not([hidden]) {
      border: 1px solid var(--line);
    }
    .mkb-tpl-row {
      border-bottom: 1px solid var(--line);
    }
    .mkb-tpl-row:last-child { border-bottom: none; }
    .mkb-tpl-row-head {
      display: flex;
      align-items: center;
      flex-wrap: nowrap;
      gap: 6px 8px;
      width: 100%;
      text-align: left;
      border: none;
      background: transparent;
      color: inherit;
      padding: 4px 10px;
      font-weight: 500;
      line-height: 1.25;
    }
    .mkb-tpl-row-main {
      flex: 1 1 auto;
      min-width: 0;
      text-align: left;
      border: none;
      background: transparent;
      color: inherit;
      padding: 0;
      font: inherit;
      font-weight: 500;
      cursor: pointer;
      line-height: 1.25;
      white-space: normal;
    }
    .mkb-tpl-row-main:hover { filter: none; }
    .mkb-tpl-row-head.has-live .mkb-tpl-row-main { flex: 0 0 auto; }
    .mkb-tpl-row-live {
      flex: 1 1 auto;
      min-width: 0;
      font-weight: 500;
      line-height: 1.35;
      cursor: pointer;
      white-space: normal;
    }
    .mkb-field > .field-text .mkb-inline-tog {
      font-size: inherit;
      line-height: inherit;
    }
    .mkb-verified {
      flex: 0 0 auto;
      margin-left: auto;
      align-self: center;
      width: 28px;
      height: 28px;
      padding: 0;
      border: none;
      border-radius: 6px;
      background: transparent;
      color: #b0b6c0;
      font-size: 18px;
      line-height: 1;
      cursor: pointer;
    }
    .mkb-verified:hover,
    .mkb-verified.is-on {
      color: #c4a035;
      background: rgba(196, 160, 53, 0.14);
    }
    .mkb-tpl-row-actions {
      display: flex;
      flex-wrap: wrap;
      gap: 6px;
      justify-content: flex-end;
      margin-left: 0;
    }
    .mkb-tpl-row-actions:empty,
    .mkb-tpl-row:not(.is-expanded) .mkb-tpl-row-actions { display: none; }
    .mkb-tpl-row-head:hover,
    .mkb-tpl-row.is-expanded .mkb-tpl-row-head {
      background: var(--accent-soft);
    }
    .mkb-tpl-row-head .code {
      font-family: var(--mono);
      font-weight: 700;
      color: var(--accent);
      margin-right: 8px;
    }
    .mkb-tpl-row-head .name { font-weight: 500; }
    .mkb-tpl-row-head .kind-tag {
      font-size: 0.72rem;
      font-weight: 600;
      color: var(--muted);
      margin-left: 6px;
      text-transform: uppercase;
      letter-spacing: 0.02em;
    }
    .mkb-tpl-row-body {
      padding: 0 10px 6px;
    }
    .mkb-tpl-row-body .mkb-detail-inner {
      padding-top: 0;
    }
    .mkb-diag-toggles {
      margin: 4px 0 8px;
      font-size: 0.95rem;
      font-weight: 600;
      line-height: 1.35;
    }
    .mkb-tpl-row-body .mkb-tpl {
      border: none;
      border-radius: 0;
      padding: 0;
      margin: 0;
      background: transparent;
    }
    .mkb-tpl-row-body .mkb-fields {
      margin: 0 0 4px;
      border: none;
      border-radius: 0;
      background: transparent;
      padding: 0;
    }
    .mkb-field > .field-text {
      white-space: pre-wrap;
    }
    .mkb-field-head .mkb-diagnosis-catalog {
      flex: 1 1 auto;
      min-width: 0;
      max-width: 78%;
      margin-bottom: 0;
      font-family: ui-monospace, "Cascadia Mono", "Consolas", monospace;
      font-size: 0.82em;
      line-height: 1.35;
      color: var(--muted, #64748b);
      text-align: right;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .mkb-field > .field-text.mkb-diagnosis-clinical {
      margin-top: 2px;
    }
    .mkb-autogen {
      background: #fff3c4;
      box-shadow: inset 0 -1px 0 #c4a035;
      border-radius: 2px;
      cursor: help;
    }
    .mkb-autogen-empty {
      display: none;
    }
    .field-text.voice-editing .mkb-autogen {
      cursor: default;
    }
    #panel-mkb {
      --mkb-sticky-search-stack: 58px;
      --mkb-sticky-urgency-stack: 41px;
    }
    .mkb-search {
      display: flex;
      gap: 8px;
      margin-bottom: 10px;
    }
    #panel-mkb > .card > .mkb-search {
      position: sticky;
      top: var(--app-sticky-below-header, 46px);
      z-index: 28;
      padding: 8px 0 10px;
      background: var(--surface);
      box-shadow: 0 8px 16px -10px rgba(15, 23, 42, 0.18);
      border-bottom: 1px solid var(--line);
    }
    .mkb-search input { flex: 1; }
    .mkb-list {
      border: 1px solid var(--line);
      border-radius: 10px;
      background: #fff;
    }
    .mkb-list-footer {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      margin: 0 0 10px;
      align-items: center;
    }
    .mkb-list-footer .mkb-draft-note {
      flex: 1 1 100%;
      margin: 0;
      font-size: 0.78rem;
      color: var(--muted);
    }
    .mkb-inline-editor .mkb-inline-hint {
      margin: 0 0 8px;
      font-size: 0.8rem;
      color: var(--muted);
      line-height: 1.35;
    }
    .mkb-inline-editor .mkb-inline-meta {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      margin: 0 0 4px;
      align-items: center;
    }
    .mkb-inline-editor .mkb-inline-meta input {
      flex: 1 1 120px;
      min-width: 100px;
      font: inherit;
      padding: 6px 8px;
      border: 1px solid var(--line);
      border-radius: 8px;
      background: #fff;
    }
    .mkb-inline-editor .mkb-field textarea {
      display: block;
      width: 100%;
      min-height: 52px;
      margin: 0;
      padding: 6px 8px;
      border: 1px solid transparent;
      border-radius: 6px;
      font: inherit;
      font-size: 0.9rem;
      line-height: 1.4;
      background: transparent;
      color: var(--ink);
      overflow: hidden;
      resize: none;
      field-sizing: content;
    }
    .mkb-inline-editor .mkb-field textarea:hover,
    .mkb-inline-editor .mkb-field textarea:focus {
      outline: none;
      border-color: var(--line);
      background: #fff;
    }
    .mkb-inline-editor .mkb-field textarea:focus {
      border-color: var(--accent);
    }
    .mkb-urgency-section {
      margin: 0;
    }
    .mkb-urgency-section + .mkb-urgency-section {
      margin-top: 14px;
      padding-top: 2px;
      border-top: 2px solid #c8d0dc;
    }
    .mkb-urgency-title {
      position: sticky;
      top: calc(var(--app-sticky-below-header, 46px) + var(--mkb-sticky-search-stack, 58px));
      z-index: 2;
      margin: 0;
      padding: 10px 10px 8px;
      font-size: 1.08rem;
      font-weight: 800;
      letter-spacing: 0.01em;
      color: var(--ink);
      background: #fff;
      border-bottom: 2px solid var(--accent);
    }
    .mkb-urgency-section[data-urgency="planned"] .mkb-urgency-title {
      border-bottom-color: #6b7c93;
      color: #344054;
    }
    .mkb-group-title {
      position: sticky;
      top: calc(
        var(--app-sticky-below-header, 46px) +
        var(--mkb-sticky-search-stack, 58px) +
        var(--mkb-sticky-urgency-stack, 41px)
      );
      z-index: 1;
      display: flex;
      align-items: center;
      gap: 7px;
      margin: 0;
      padding: 5px 10px;
      font-size: 0.78rem;
      font-weight: 700;
      letter-spacing: 0.03em;
      text-transform: uppercase;
      color: #344054;
      background: #eef2f6;
      border-bottom: 1px solid var(--line);
      border-top: 1px solid var(--line);
    }
    .mkb-group-icon {
      flex: 0 0 20px;
      width: 20px;
      height: 20px;
      margin-left: auto;
      color: var(--accent);
      line-height: 0;
    }
    .mkb-group-icon svg {
      display: block;
      width: 20px;
      height: 20px;
    }
    .mkb-group-label {
      min-width: 0;
    }
    .mkb-group:first-child .mkb-group-title { border-top: none; }
    .mkb-item {
      display: block;
      width: 100%;
      text-align: left;
      border: none;
      border-bottom: 1px solid var(--line);
      border-radius: 0;
      background: transparent;
      color: inherit;
      padding: 10px 12px;
      font-weight: 500;
      cursor: pointer;
    }
    .mkb-item:hover, .mkb-item.active { background: var(--accent-soft); }
    .mkb-item .code {
      font-family: var(--mono);
      font-weight: 700;
      color: var(--accent);
      margin-right: 8px;
    }
    .mkb-item .meta { display: block; font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
    .mkb-detail h3 { margin: 0 0 8px; font-size: 1.05rem; }
    .mkb-detail .code-pill {
      display: inline-block;
      font-family: var(--mono);
      font-size: 0.85rem;
      background: var(--accent-soft);
      color: var(--accent);
      border-radius: 6px;
      padding: 2px 8px;
      margin: 0 6px 8px 0;
    }
    .mkb-tpl {
      border: 1px solid var(--line);
      border-radius: 10px;
      padding: 10px 12px;
      margin-bottom: 8px;
      background: #fbfcfd;
    }
    .mkb-tpl h4 { margin: 0 0 6px; font-size: 0.95rem; }
    .mkb-variant-row {
      display: flex;
      flex-wrap: wrap;
      gap: 8px 14px;
      align-items: center;
      margin: 4px 0 8px;
    }
    .mkb-variant-row .patient-row-label { min-width: 72px; }
    .mkb-detail > h3 {
      line-height: 1.45;
      font-weight: 700;
      font-size: 1.02rem;
    }
    .mkb-inline-tog {
      display: inline;
      margin: 0;
      padding: 0 3px;
      border: none;
      border-bottom: 2px solid var(--accent);
      border-radius: 3px;
      background: var(--accent-soft);
      color: var(--accent);
      font: inherit;
      font-weight: 800;
      cursor: pointer;
      vertical-align: baseline;
    }
    .mkb-inline-tog:hover {
      background: #d8f3e9;
      color: #0b6b4a;
    }
    .voice-suggest {
      margin: 8px 0 12px;
      padding: 10px 12px;
      border: 1px solid #c5e6d8;
      border-radius: 10px;
      background: #f3fbf7;
      font-size: 0.92rem;
    }
    .voice-suggest .voice-alt-row {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      margin-top: 8px;
    }
    .voice-suggest button.voice-alt {
      border: 1px solid var(--line);
      background: #fff;
      color: var(--ink);
      border-radius: 8px;
      padding: 6px 10px;
      cursor: pointer;
      font: inherit;
      font-size: 0.88rem;
      font-weight: 600;
      text-align: left;
    }
    .voice-suggest button.voice-alt:hover,
    .voice-suggest button.voice-alt.active {
      border-color: var(--accent);
      background: var(--accent-soft);
      color: var(--accent);
    }
    .field-text.voice-editing {
      cursor: text;
      outline: 1px solid var(--accent);
      background: #fff;
      max-height: none;
      padding: 8px 10px;
      border-radius: 6px;
      white-space: pre-wrap;
      word-break: break-word;
      line-height: 1.5;
      font-weight: 400;
    }
    .field-text.voice-editing:hover {
      background: #fff;
    }
    .mkb-fields {
      border: 1px solid var(--line);
      border-radius: 8px;
      background: #fff;
      padding: 2px 12px 4px;
      margin: 8px 0;
    }
    .mkb-field { padding: 4px 0; }
    .mkb-field-head {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      margin-bottom: 1px;
      min-height: 22px;
    }
    .mkb-field-head .mkb-field-name { margin-bottom: 0; }
    .mkb-field-name {
      font-weight: 700;
      font-size: 0.85rem;
      margin-bottom: 1px;
    }
    .mkb-ctx-cycles {
      display: flex;
      flex-wrap: wrap;
      gap: 4px 5px;
      justify-content: flex-end;
      align-items: center;
    }
    .mkb-ctx-cycle-sep {
      color: var(--muted);
      font-size: 0.75rem;
      font-weight: 700;
      line-height: 1;
      user-select: none;
      opacity: 0.45;
      padding: 0 1px;
      flex: 0 0 auto;
    }
    .mkb-ctx-seg {
      display: inline-flex;
      align-items: stretch;
      border: 1px solid var(--line);
      border-radius: 6px;
      overflow: hidden;
      background: #fff;
      flex: 0 0 auto;
    }
    .mkb-ctx-seg.is-disabled {
      border-color: #e5e7eb;
      background: #f3f4f6;
      opacity: 0.72;
    }
    button.mkb-ctx-cycle,
    button.mkb-disp-cycle {
      flex: 0 0 auto;
      margin: 0;
      padding: 1px 5px;
      border: 0;
      border-right: 1px solid var(--line);
      border-radius: 0;
      background: transparent;
      color: var(--muted);
      font: inherit;
      font-size: 0.66rem;
      font-weight: 600;
      line-height: 1.35;
      cursor: pointer;
      box-sizing: border-box;
      text-align: center;
      white-space: nowrap;
    }
    .mkb-ctx-seg > button.mkb-ctx-cycle:last-child {
      border-right: 0;
    }
    button.mkb-ctx-cycle.is-active,
    button.mkb-disp-cycle.is-active {
      background: var(--accent-soft);
      color: var(--accent);
      font-weight: 700;
    }
    button.mkb-ctx-cycle:hover:not(.is-active),
    button.mkb-disp-cycle:hover:not(.is-active) {
      background: #f3f5f7;
      color: var(--ink);
    }
    button.mkb-ctx-cycle.is-active:hover,
    button.mkb-disp-cycle.is-active:hover {
      background: var(--accent-soft);
      color: var(--accent);
    }
    .mkb-ctx-seg.is-disabled button.mkb-ctx-cycle,
    .mkb-ctx-seg.is-disabled button.mkb-ctx-cycle.is-active,
    .mkb-ctx-seg.is-disabled button.mkb-ctx-cycle:hover,
    .mkb-ctx-seg.is-disabled button.mkb-ctx-cycle.is-active:hover {
      background: transparent;
      color: #9ca3af;
      font-weight: 600;
      cursor: default;
      border-right-color: #e5e7eb;
    }
    .mkb-field .field-text {
      max-height: none;
      overflow: visible;
      font-size: 0.8rem;
      white-space: pre-wrap;
    }
    .mkb-preview {
      font-family: var(--mono);
      font-size: 0.78rem;
      white-space: pre-wrap;
      max-height: 140px;
      overflow: auto;
      background: #fff;
      border: 1px solid var(--line);
      border-radius: 8px;
      padding: 8px;
      margin: 8px 0;
    }
    .mkb-empty { color: var(--muted); font-size: 0.9rem; padding: 12px; }

    .tx-section { margin-bottom: 10px; }
    .tx-section:last-child { margin-bottom: 0; }
    .tx-section h3 {
      margin: 0 0 4px;
      font-size: 0.88rem;
      font-weight: 700;
    }
    .tx-section.tx-fold > summary {
      list-style: none;
      cursor: pointer;
      margin: 0;
      font-size: 0.88rem;
      font-weight: 700;
      user-select: none;
    }
    .tx-section.tx-fold > summary::-webkit-details-marker { display: none; }
    .tx-section.tx-fold > summary::after {
      content: ' ▸';
      color: var(--muted);
      font-weight: 600;
    }
    .tx-section.tx-fold[open] > summary::after { content: ' ▾'; }
    .tx-section.tx-fold[open] > summary { margin-bottom: 4px; }
    .tx-blocks { display: grid; gap: 4px; }
    .tx-block {
      border: 1px solid var(--line);
      border-radius: 6px;
      background: #fff;
      padding: 6px 8px;
      cursor: pointer;
      transition: background .12s, border-color .12s;
    }
    .tx-block:hover {
      background: var(--accent-soft);
      border-color: #b7e4d4;
    }
    .tx-block:active { background: #d9f0e7; }
    .tx-block-label {
      font-size: 0.72rem;
      font-weight: 700;
      color: var(--muted);
      text-transform: uppercase;
      letter-spacing: 0.02em;
      margin-bottom: 2px;
    }
    .tx-block-body {
      margin: 0;
      font-family: var(--mono);
      font-size: 0.78rem;
      line-height: 1.3;
      white-space: pre-wrap;
    }
    .tx-note {
      margin: 6px 0 0;
      font-size: 0.8rem;
      color: var(--muted);
    }
    .tx-note a {
      color: var(--accent, #0d9488);
      text-decoration: underline;
      text-underline-offset: 2px;
    }
    .tx-subhead {
      margin: 12px 0 6px;
      font-size: 0.82rem;
      font-weight: 700;
      color: var(--muted);
      text-transform: uppercase;
      letter-spacing: 0.03em;
    }
    .tx-subhead:first-of-type { margin-top: 4px; }
    .tx-dose-bar {
      display: flex;
      align-items: center;
      justify-content: flex-end;
      gap: 8px;
      margin: 8px 0 0;
      padding: 4px 8px;
      background: #eef2f6;
      border: 1px solid var(--line);
      border-bottom: none;
      border-radius: 8px 8px 0 0;
    }
    .tx-dose-bar + .tx-dose-panel .tx-table,
    .tx-dose-bar + .tx-dose-panel + .tx-dose-panel .tx-table {
      border-top: none;
      border-top-left-radius: 0;
      border-top-right-radius: 0;
    }
    .tx-section-head .tx-dose-tog {
      margin-left: auto;
    }
    .tx-dose-tog {
      display: inline-grid;
      grid-template-columns: 1fr 1fr;
      border: 1px solid var(--line);
      border-radius: 8px;
      overflow: hidden;
      background: #fff;
      flex-shrink: 0;
    }
    .tx-dose-tog button {
      margin: 0;
      border: none;
      border-radius: 0;
      background: transparent;
      color: var(--muted);
      font: inherit;
      font-size: 0.78rem;
      font-weight: 600;
      padding: 6px 12px;
      line-height: 1.2;
      cursor: pointer;
      white-space: nowrap;
    }
    .tx-dose-tog button + button {
      border-left: 1px solid var(--line);
    }
    .tx-dose-tog button.is-active {
      background: var(--accent);
      color: #fff;
    }
    .tx-dose-tog button:hover:not(.is-active) {
      background: var(--accent-soft);
      color: var(--ink);
    }
    .tx-dose-panel[hidden] {
      display: none !important;
    }
    .tx-section-head {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      margin-bottom: 4px;
    }
    .tx-section-head h3 { margin: 0; }
    #txUserSection #btnTxAdd {
      display: inline-block;
      margin-top: 8px;
    }
    .tx-user-form {
      display: none;
      border: 1px solid var(--line);
      border-radius: 8px;
      background: #fafbfc;
      padding: 10px 12px;
      margin-bottom: 10px;
      gap: 8px;
    }
    .tx-user-form.show { display: grid; }
    .tx-user-form label {
      display: grid;
      gap: 4px;
      font-size: 0.82rem;
      color: var(--muted);
      font-weight: 600;
    }
    .tx-user-form input,
    .tx-user-form textarea {
      width: 100%;
      border: 1px solid var(--line);
      border-radius: 6px;
      padding: 8px 10px;
      font: inherit;
      background: #fff;
      color: var(--ink);
    }
    .tx-user-form textarea {
      min-height: 120px;
      font-family: var(--mono);
      font-size: 0.84rem;
      line-height: 1.45;
      resize: vertical;
    }
    .tx-user-form .toolbar { margin: 0; }
    .tx-block { position: relative; }
    .tx-block-actions {
      position: absolute;
      top: 4px;
      right: 4px;
      display: flex;
      gap: 4px;
    }
    .tx-block-actions .small {
      padding: 2px 8px;
      font-size: 0.72rem;
    }
    .tx-block.user-tx .tx-block-label { padding-right: 110px; }
    .tx-empty {
      margin: 0;
      font-size: 0.85rem;
      color: var(--muted);
    }
    .tx-table {
      width: 100%;
      border-collapse: collapse;
      font-size: 0.88rem;
      background: #fff;
      border: 1px solid var(--line);
      border-radius: 8px;
      overflow: hidden;
    }
    .tx-table th, .tx-table td {
      padding: 8px 12px;
      border-bottom: 1px solid #eef2f6;
      text-align: left;
      vertical-align: top;
    }
    .tx-table th {
      background: #eef2f6;
      font-size: 0.78rem;
      text-transform: uppercase;
      letter-spacing: 0.03em;
      color: #344054;
    }
    .tx-table tr:last-child td { border-bottom: none; }
    .tx-table tr[data-copy-line],
    .tx-table td[data-copy-line] { cursor: pointer; }
    .tx-table tr[data-copy-line]:hover td,
    .tx-table td[data-copy-line]:hover { background: var(--accent-soft); }

    @media (max-width: 720px) {
      .form-grid { grid-template-columns: 1fr; }
      header.app-header { flex-direction: column; }
      .mkb-layout { grid-template-columns: 1fr; }
      .recognize-split {
        grid-template-columns: 1fr;
        grid-template-rows: 2fr 4fr 4fr;
        min-height: 520px;
      }
    }

    /* ----- Автопилот ----- */
    .autopilot-layout {
      display: grid;
      gap: 14px;
    }
    .autopilot-status-row {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      gap: 12px;
    }
    .autopilot-dot {
      width: 12px;
      height: 12px;
      border-radius: 50%;
      background: #c45c5c;
      box-shadow: 0 0 0 3px rgba(196, 92, 92, 0.2);
      flex-shrink: 0;
    }
    .autopilot-dot.on {
      background: #1a9b6c;
      box-shadow: 0 0 0 3px rgba(26, 155, 108, 0.25);
      animation: autopilot-dot-blink 1.1s ease-in-out infinite;
    }
    @keyframes autopilot-dot-blink {
      0%, 100% { opacity: 1; }
      50% { opacity: 0.25; }
    }
    @media (prefers-reduced-motion: reduce) {
      .autopilot-dot.on { animation: none; }
    }
    .autopilot-shot-label {
      display: flex;
      align-items: center;
      gap: 8px;
      margin: 0 0 6px;
    }
    .autopilot-shot-label .autopilot-shot-title {
      flex: 0 1 auto;
    }
    .autopilot-mode-icon {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 28px;
      height: 28px;
      padding: 0;
      border: 1px solid var(--line);
      border-radius: 8px;
      background: #fff;
      color: var(--muted);
      cursor: default;
      flex-shrink: 0;
      line-height: 0;
    }
    button.autopilot-mode-icon {
      cursor: pointer;
      transition: background .12s, border-color .12s, color .12s;
    }
    button.autopilot-mode-icon:hover {
      background: var(--accent-soft);
      border-color: #b7e4d4;
      color: var(--ink);
    }
    button.autopilot-mode-icon.is-on {
      background: #e8f7f1;
      border-color: #1a9b6c;
      color: #0f7a54;
    }
    .autopilot-mode-icon svg {
      display: block;
    }
    .autopilot-shot-label .autopilot-dot,
    .autopilot-speech-mic-wrap .autopilot-dot {
      flex-shrink: 0;
    }
    .autopilot-speech-mic-wrap {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      flex-shrink: 0;
    }
    .autopilot-speech-mic-wrap .autopilot-dot {
      display: none;
    }
    .autopilot-speech-mic-wrap .autopilot-dot.on {
      display: inline-block;
    }
    .autopilot-shot-label .autopilot-dot {
      display: none;
    }
    .autopilot-shot-label .autopilot-dot.on {
      display: inline-block;
    }
    .autopilot-settings {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
      gap: 12px;
      margin-top: 8px;
    }
    .autopilot-settings label {
      display: block;
      font-size: 0.85rem;
      color: var(--muted);
      margin-bottom: 4px;
    }
    /* Шапка истории болезни (над разделами) */
    .autopilot-history-wrap {
      display: grid;
      gap: 0;
    }
    .autopilot-history-wrap .fields {
      margin-top: 0;
      border-top-left-radius: 0;
      border-top-right-radius: 0;
    }
    .ib-header {
      border: 1px solid var(--line);
      border-bottom: none;
      border-radius: 10px 10px 0 0;
      padding: 14px 16px 12px;
      background:
        linear-gradient(180deg, #f7fafc 0%, #fff 72%);
    }
    .ib-header.is-identified {
      background: linear-gradient(180deg, #eef8f3 0%, #fff 75%);
      border-color: #b7e0cc;
    }
    .ib-header.is-switched {
      background: linear-gradient(180deg, #fff6ea 0%, #fff 75%);
      border-color: #f6d5a8;
    }
    .ib-header.is-unknown {
      background: #fff;
    }
    .ib-header-kicker {
      font-size: 0.72rem;
      font-weight: 700;
      letter-spacing: 0.06em;
      text-transform: uppercase;
      color: var(--muted);
      margin-bottom: 6px;
    }
    .ib-header-main {
      display: flex;
      flex-wrap: nowrap;
      align-items: center;
      gap: 10px 14px;
      min-width: 0;
    }
    .ib-header-name {
      margin: 0;
      flex: 0 1 auto;
      min-width: 0;
      font-family: inherit;
      font-size: 1.2rem;
      font-weight: 700;
      line-height: 1.3;
      color: var(--ink);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      cursor: pointer;
      border-radius: 4px;
      outline: none;
    }
    .ib-header-name:hover {
      background: var(--accent-soft);
    }
    .ib-header-name.is-empty {
      font-family: var(--mono);
      font-size: 0.86rem;
      font-weight: 400;
      line-height: 1.5;
      color: var(--ink);
      white-space: pre-wrap;
      overflow: visible;
      text-overflow: unset;
    }
    .ib-header-name.voice-editing {
      background: #fff;
      box-shadow: inset 0 0 0 1px var(--accent);
      cursor: text;
      padding: 2px 4px;
      white-space: pre-wrap;
      overflow: visible;
      text-overflow: unset;
    }
    .ib-header-meta {
      display: flex;
      flex-wrap: nowrap;
      align-items: center;
      gap: 8px;
      margin-top: 0;
      margin-left: auto;
      flex: 0 0 auto;
      font-size: 0.86rem;
      color: var(--muted);
    }
    .ib-header-meta [hidden] {
      display: none !important;
    }
    .ib-header-meta-item strong {
      color: var(--ink);
      font-weight: 600;
    }
    .ib-header-status {
      flex: 0 0 auto;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      margin: 0;
      padding: 0;
      border: 0;
      background: transparent;
      color: var(--ok);
      font-size: 1.05rem;
      font-weight: 700;
      line-height: 1;
      letter-spacing: 0;
      border-radius: 0;
      white-space: nowrap;
      user-select: none;
    }
    .ib-header.is-identified .ib-header-status {
      color: var(--ok);
    }
    .ib-header.is-switched .ib-header-status {
      color: var(--warn);
    }
    .ib-header.is-unknown .ib-header-status {
      display: none;
    }
    .autopilot-patient-hint {
      margin-top: 8px;
      font-size: 0.78rem;
      color: var(--muted);
      line-height: 1.35;
    }
    .autopilot-tpl-bar {
      display: flex;
      flex-wrap: wrap;
      align-items: flex-start;
      gap: 10px 14px;
      margin-top: 12px;
      padding-top: 12px;
      border-top: 1px solid var(--border, #e5e7eb);
    }
    .autopilot-tpl-bar-actions {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      flex-shrink: 0;
    }
    .autopilot-tpl-similar {
      flex: 1;
      min-width: 220px;
      font-size: 0.8rem;
      line-height: 1.4;
      color: var(--muted);
    }
    .autopilot-tpl-similar strong {
      color: var(--text, #111);
      font-weight: 600;
    }
    .autopilot-tpl-similar .tpl-hit {
      color: var(--text, #111);
    }
    .autopilot-tpl-similar .tpl-warn {
      color: var(--warn, #b54708);
    }
    .autopilot-tpl-similar .tpl-ok {
      color: var(--ok, #067647);
    }
    .autopilot-log {
      max-height: 200px;
      overflow: auto;
      font-family: var(--mono);
      font-size: 0.8rem;
      color: var(--muted);
      white-space: pre-wrap;
      overflow-wrap: anywhere;
      word-break: break-word;
      margin: 0;
    }
    .autopilot-journal-row {
      display: grid;
      grid-template-columns: minmax(200px, 0.85fr) minmax(280px, 1.35fr);
      gap: 12px;
      align-items: stretch;
    }
    /* высота ряда = поле МКБ; журнал не раздувает соседа */
    .autopilot-journal-row > * {
      min-height: 0;
    }
    .autopilot-journal-cell {
      min-height: 0;
      max-height: 100%;
      overflow: hidden;
      display: flex;
      flex-direction: column;
      gap: 6px;
    }
    .autopilot-journal-cell > strong {
      flex: 0 0 auto;
    }
    .autopilot-journal-cell .autopilot-log {
      flex: 1 1 0;
      min-height: 0;
      max-height: none;
      height: auto;
      overflow-x: hidden;
      overflow-y: auto;
      white-space: pre-wrap;
      overflow-wrap: anywhere;
      word-break: break-word;
      overscroll-behavior: contain;
    }
    .autopilot-journal-row .autopilot-tpl-pane {
      min-height: 0;
      display: flex;
      flex-direction: column;
      width: 100%;
    }
    .autopilot-tpl-pane {
      min-height: 0;
      display: flex;
      flex-direction: column;
      width: 100%;
    }
    .autopilot-tpl-pane .recognize-pane-body {
      display: flex;
      flex-direction: column;
      gap: 6px;
      min-height: 0;
      flex: 1;
    }
    .autopilot-film-row {
      display: grid;
      grid-template-columns: minmax(180px, 240px) minmax(0, 1fr);
      gap: 12px;
      align-items: stretch;
    }
    .autopilot-film-row .autopilot-shot-pane {
      width: 100%;
      height: auto;
      max-height: none;
      min-height: 0;
      overflow: hidden;
      display: flex;
      flex-direction: column;
      box-sizing: border-box;
    }
    .autopilot-film {
      min-width: 0;
      min-height: 0;
      border: 1px solid var(--line);
      border-radius: 12px;
      background: linear-gradient(180deg, #f7f9fb 0%, #eef2f6 100%);
      display: flex;
      flex-direction: column;
      overflow: hidden;
      box-sizing: border-box;
    }
    .autopilot-film-head {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 8px 10px 4px;
      flex-shrink: 0;
    }
    .autopilot-film-head strong {
      font-size: 0.85rem;
    }
    .autopilot-film-hint {
      font-size: 0.72rem;
      color: var(--muted);
      flex: 1;
      min-width: 0;
    }
    .autopilot-film-clear {
      margin: 0;
      font-size: 0.72rem;
      padding: 3px 8px;
      line-height: 1.2;
      color: var(--muted);
    }
    .autopilot-film-clear:hover {
      color: var(--ink);
    }
    .autopilot-doc-lanes {
      display: flex;
      flex-wrap: wrap;
      gap: 6px;
      padding: 0 10px 4px;
      flex-shrink: 0;
    }
    .autopilot-doc-lane {
      margin: 0;
      border: 1px solid var(--line);
      background: #fff;
      color: var(--ink);
      border-radius: 999px;
      padding: 3px 10px;
      font-size: 0.72rem;
      line-height: 1.3;
      cursor: pointer;
    }
    .autopilot-doc-lane.is-empty {
      opacity: 0.45;
    }
    .autopilot-doc-lane.is-active {
      background: var(--accent);
      border-color: var(--accent);
      color: #fff;
      font-weight: 600;
    }
    .autopilot-film-card.is-dim {
      opacity: 0.38;
    }
    .autopilot-film-card.is-lane-diary {
      box-shadow: inset 0 0 0 2px rgba(180, 120, 20, 0.35);
    }
    .autopilot-film-card.is-lane-skip {
      box-shadow: inset 0 0 0 2px rgba(120, 120, 120, 0.28);
    }
    .autopilot-film-strip {
      display: flex;
      flex-direction: row;
      gap: 10px;
      overflow-x: auto;
      overflow-y: hidden;
      padding: 8px 10px 12px;
      flex: 1;
      align-items: center;
      scroll-behavior: smooth;
    }
    .autopilot-film-strip:empty::before {
      content: 'Новые кадры появятся здесь →';
      color: var(--muted);
      font-size: 0.78rem;
      padding-left: 4px;
    }
    .autopilot-film-card {
      flex: 0 0 auto;
      width: 132px;
      border: 1px solid var(--line);
      border-radius: 10px;
      background: #fff;
      overflow: hidden;
      display: flex;
      flex-direction: column;
      position: relative;
      box-shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
      cursor: pointer;
      padding: 0;
      text-align: left;
      font: inherit;
      color: inherit;
      transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
    }
    .autopilot-film-card:hover {
      border-color: var(--accent);
      box-shadow: 0 2px 8px rgba(11, 110, 79, 0.12);
      transform: translateY(-1px);
    }
    .autopilot-film-card.is-active {
      border-color: var(--accent);
      box-shadow: 0 0 0 2px rgba(11, 110, 79, 0.2);
    }
    .autopilot-film-card.is-ocr .autopilot-film-meta,
    .autopilot-film-card.is-pending .autopilot-film-meta {
      color: #0b6e4f;
    }
    .autopilot-film-card.is-error .autopilot-film-meta {
      color: #a33;
    }
    .autopilot-film-card img {
      display: block;
      width: 100%;
      height: 78px;
      object-fit: cover;
      background: #e8ecf0;
    }
    .autopilot-film-meta {
      font-size: 0.68rem;
      padding: 4px 6px 6px;
      color: var(--muted);
      line-height: 1.25;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .autopilot-film-remove {
      position: absolute;
      top: 4px;
      right: 4px;
      width: 22px;
      height: 22px;
      margin: 0;
      padding: 0;
      border: 0;
      border-radius: 999px;
      background: rgba(15, 23, 42, 0.55);
      color: #fff;
      font-size: 14px;
      line-height: 1;
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      opacity: 0;
      transition: opacity 0.12s ease, background 0.12s ease;
    }
    .autopilot-film-zoom {
      position: absolute;
      top: 4px;
      left: 4px;
      width: 22px;
      height: 22px;
      margin: 0;
      padding: 0;
      border: 0;
      border-radius: 999px;
      background: rgba(15, 23, 42, 0.55);
      color: #fff;
      font-size: 13px;
      line-height: 1;
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      opacity: 0;
      transition: opacity 0.12s ease, background 0.12s ease;
    }
    .autopilot-film-card:hover .autopilot-film-remove,
    .autopilot-film-card:focus-within .autopilot-film-remove,
    .autopilot-film-card:hover .autopilot-film-zoom,
    .autopilot-film-card:focus-within .autopilot-film-zoom {
      opacity: 1;
    }
    .autopilot-film-remove:hover {
      background: #b42318;
    }
    .autopilot-film-zoom:hover {
      background: var(--accent);
    }
    /* Оверлей увеличенного кадра киноленты */
    .film-lightbox {
      position: fixed;
      inset: 0;
      z-index: 140;
      display: none;
      align-items: center;
      justify-content: center;
      background: rgba(10, 14, 22, 0.82);
      backdrop-filter: blur(2px);
      padding: 24px;
      box-sizing: border-box;
    }
    .film-lightbox.is-open {
      display: flex;
    }
    .film-lightbox-stage {
      position: relative;
      max-width: min(98vw, 1600px);
      max-height: 94vh;
      width: min(98vw, 1600px);
      height: min(94vh, 900px);
      display: flex;
      align-items: center;
      justify-content: center;
      overflow: hidden;
      border-radius: 10px;
      user-select: none;
      cursor: default;
      touch-action: none;
    }
    .film-lightbox-stage.is-zoomed {
      cursor: grab;
    }
    .film-lightbox-stage.is-panning {
      cursor: grabbing;
    }
    .film-lightbox-img {
      display: block;
      max-width: 96vw;
      max-height: 90vh;
      width: auto;
      height: auto;
      object-fit: contain;
      transform-origin: center center;
      transition: transform 0.08s ease-out;
      box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
      background: #111;
      pointer-events: auto;
      -webkit-user-drag: none;
    }
    .film-lightbox-stage.is-panning .film-lightbox-img {
      transition: none;
    }
    .film-lightbox-close,
    .film-lightbox-nav {
      position: absolute;
      border: 0;
      margin: 0;
      padding: 0;
      cursor: pointer;
      color: #fff;
      background: rgba(15, 23, 42, 0.55);
      display: inline-flex;
      align-items: center;
      justify-content: center;
      transition: background 0.12s ease;
    }
    .film-lightbox-close:hover,
    .film-lightbox-nav:hover {
      background: rgba(15, 23, 42, 0.85);
    }
    .film-lightbox-close {
      top: 16px;
      right: 16px;
      width: 36px;
      height: 36px;
      border-radius: 999px;
      font-size: 22px;
      line-height: 1;
      z-index: 2;
    }
    .film-lightbox-nav {
      top: 50%;
      transform: translateY(-50%);
      width: 40px;
      height: 56px;
      border-radius: 10px;
      font-size: 28px;
      line-height: 1;
      z-index: 2;
    }
    .film-lightbox-nav.prev { left: 16px; }
    .film-lightbox-nav.next { right: 16px; }
    .film-lightbox-nav:disabled {
      opacity: 0.25;
      cursor: default;
    }
    .film-lightbox-meta {
      position: absolute;
      left: 50%;
      bottom: 16px;
      transform: translateX(-50%);
      z-index: 2;
      padding: 6px 12px;
      border-radius: 999px;
      background: rgba(15, 23, 42, 0.65);
      color: #f4f6f8;
      font-size: 0.78rem;
      font-weight: 600;
      white-space: nowrap;
      pointer-events: none;
    }
    .autopilot-glance.is-split {
      margin-top: 0;
      min-height: 280px;
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 12px;
      align-items: stretch;
    }
    .autopilot-glance-col {
      min-width: 0;
      min-height: 280px;
      border: 1px solid var(--line);
      border-radius: 12px;
      background: #fff;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      box-sizing: border-box;
      padding: 8px 10px 10px;
    }
    .autopilot-glance-col-body {
      flex: 1;
      min-height: 0;
      display: flex;
      flex-direction: column;
    }
    .autopilot-glance-col-body .glance-stage-panel.is-active {
      display: block;
      flex: 1;
      min-height: 180px;
      height: auto;
      width: 100%;
      box-sizing: border-box;
      resize: vertical;
    }
    .autopilot-glance-col-body div.glance-stage-panel.is-active {
      resize: none;
      outline: none;
    }
    .autopilot-glance-col-body div.glance-stage-panel.is-active:focus {
      border-color: #9db4e8;
      box-shadow: 0 0 0 2px rgba(67, 112, 214, 0.12);
    }
    .autopilot-glance-col-body div.glance-stage-panel[data-user-locked="1"] {
      border-color: #c4a574;
      background: #fffaf2;
    }
    .autopilot-glance-stage-lock {
      margin-left: auto;
      font-size: 0.72rem;
      color: #8a6a32;
      font-weight: 600;
      white-space: nowrap;
    }
    .autopilot-glance-stage-lock[hidden] {
      display: none !important;
    }
    .autopilot-glance-col .autopilot-glance-ocr,
    .autopilot-glance-col .autopilot-glance-llm-wrap {
      flex: 1;
      min-height: 160px;
    }
    @media (max-width: 860px) {
      .autopilot-glance.is-split {
        grid-template-columns: 1fr 1fr;
      }
    }
    .autopilot-glance-col-llm .autopilot-glance-llm-wrap {
      position: relative;
      display: flex;
      flex-direction: column;
      gap: 6px;
      min-height: 0;
      flex: 1;
    }
    .autopilot-glance-col-llm .autopilot-glance-ocr.is-llm {
      flex: 1;
      min-height: 120px;
    }
    .autopilot-glance-col .glance-stage-panel {
      display: none;
    }
    .autopilot-glance-col .glance-stage-panel.is-active {
      display: block;
    }
    .autopilot-glance-mode-row {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      gap: 8px 10px;
      padding: 0 0 8px;
      min-height: 28px;
    }
    /* единый размер переключателей: Кадр/Склейка · Авто/По требованию · Instant/Expert · Свой файл/Живой экран */
    .autopilot-glance-stage-tog,
    .autopilot-llm-run-tog,
    .autopilot-llm-mode-tog,
    .autopilot-shot-toggle {
      box-sizing: border-box;
      display: inline-grid !important;
      grid-auto-flow: column;
      grid-auto-columns: 1fr;
      height: 28px;
      min-height: 28px;
      max-height: 28px;
      align-items: stretch;
      border: none !important;
      border-radius: 8px;
      overflow: hidden;
      background: #fff;
      box-shadow: inset 0 0 0 1px var(--line);
    }
    .autopilot-shot-toggle {
      display: grid !important;
      grid-template-columns: 1fr 1fr;
      width: 100%;
    }
    .autopilot-glance-stage-tog button,
    .autopilot-llm-run-tog button,
    .autopilot-llm-mode-tog button,
    .autopilot-shot-toggle button,
    .autopilot-speech-head-actions > button {
      box-sizing: border-box;
      height: 28px !important;
      min-height: 28px !important;
      max-height: 28px !important;
      min-width: 0;
      padding: 0 10px !important;
      margin: 0;
      border: none !important;
      border-radius: 0 !important;
      font-family: inherit !important;
      font-size: 0.78rem !important;
      font-weight: 600 !important;
      line-height: 1 !important;
      letter-spacing: normal;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      white-space: nowrap;
      background: transparent;
      color: var(--muted);
      cursor: pointer;
    }
    .autopilot-glance-stage-tog button + button,
    .autopilot-llm-run-tog button + button,
    .autopilot-llm-mode-tog button + button,
    .autopilot-shot-toggle button + button {
      border-left: 1px solid var(--line) !important;
    }
    .autopilot-glance-stage-tog button.is-active,
    .autopilot-llm-run-tog button.is-active,
    .autopilot-llm-mode-tog button.is-active,
    .autopilot-shot-toggle button.is-active {
      background: var(--accent) !important;
      color: #fff !important;
      font-weight: 600 !important;
    }
    .autopilot-glance-stage-tog button:hover:not(.is-active),
    .autopilot-llm-run-tog button:hover:not(.is-active),
    .autopilot-llm-mode-tog button:hover:not(.is-active),
    .autopilot-shot-toggle button:hover:not(.is-active) {
      background: var(--accent-soft) !important;
      color: var(--ink) !important;
    }
    .autopilot-film-card.is-in-stitch {
      border-color: #2f6fed;
      box-shadow: 0 0 0 2px rgba(47, 111, 237, 0.22);
    }
    .autopilot-film-card.is-in-stitch::after {
      content: '';
      position: absolute;
      left: 0;
      right: 0;
      bottom: 0;
      height: 3px;
      background: #2f6fed;
    }
    .autopilot-speech-head-actions {
      display: inline-flex;
      align-items: center;
      gap: 8px;
      flex-shrink: 0;
    }
    .autopilot-shot-pane .recognize-pane-body {
      display: flex;
      flex-direction: column;
      flex: 1;
      min-height: 0;
      gap: 4px;
    }
    .autopilot-shot-pane .recognize-pane-label {
      margin-bottom: 2px;
      white-space: normal;
    }
    .autopilot-shot-pane .autopilot-glance-when {
      margin: 0;
      font-size: 0.72rem;
      line-height: 1.25;
      flex-shrink: 0;
    }
    .autopilot-shot-pane .autopilot-shot-toolbar {
      margin-top: auto;
      flex-shrink: 0;
    }
    .autopilot-speech-pane {
      min-height: 0;
      display: flex;
      flex-direction: column;
      gap: 6px;
      width: 100%;
    }
    .autopilot-speech-pane .autopilot-speech-head {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px 12px;
      flex-wrap: nowrap;
      min-height: 28px;
    }
    .autopilot-speech-pane .autopilot-speech-head-left {
      display: flex;
      align-items: center;
      gap: 10px 14px;
      flex-wrap: nowrap;
      min-width: 0;
      flex: 1;
    }
    .autopilot-speech-pane .autopilot-speech-title {
      font-size: 0.9rem;
      line-height: 1;
      white-space: nowrap;
    }
    .autopilot-speech-pane .autopilot-speech-debounce {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      margin: 0;
      font-size: 0.78rem;
      line-height: 1;
      color: var(--muted);
      white-space: nowrap;
    }
    .autopilot-speech-pane .autopilot-speech-debounce-title {
      cursor: help;
      border-bottom: 1px dotted currentColor;
      color: var(--muted);
      font-weight: 600;
    }
    .autopilot-speech-pane .autopilot-speech-debounce-step {
      width: 24px;
      height: 24px;
      margin: 0;
      padding: 0;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      border: 1px solid var(--line);
      border-radius: 6px;
      background: #fff;
      color: var(--ink);
      font: inherit;
      font-size: 1rem;
      font-weight: 700;
      line-height: 1;
      cursor: pointer;
      flex-shrink: 0;
    }
    .autopilot-speech-pane .autopilot-speech-debounce-step:hover {
      border-color: var(--accent);
      color: var(--accent);
      background: var(--accent-soft);
    }
    .autopilot-speech-pane .autopilot-speech-debounce input[type="range"] {
      width: 90px;
      height: 18px;
      margin: 0;
      vertical-align: middle;
    }
    .autopilot-speech-pane .autopilot-speech-debounce-val {
      min-width: 2.2em;
      font-variant-numeric: tabular-nums;
      color: var(--ink);
      font-weight: 600;
    }
    .autopilot-speech-pane #autopilotTranscriptClear {
      flex-shrink: 0;
    }
    .autopilot-speech-pane #autopilotTranscript {
      width: 100%;
      min-height: 88px;
      font: inherit;
      line-height: 1.45;
      box-sizing: border-box;
      resize: vertical;
    }
    /* подсветка активного режима захвата / шаблона */
    .autopilot-layout .recognize-pane.is-active {
      background: #f7f9fb;
      border-color: var(--line);
      box-shadow: none;
    }
    .autopilot-layout .recognize-pane.is-mode-active {
      background: #fff;
      border-color: var(--accent);
      box-shadow: 0 0 0 2px rgba(11, 110, 79, 0.18);
    }
    .autopilot-layout .autopilot-tpl-pane.is-mode-active {
      border-color: var(--accent);
      box-shadow: 0 0 0 2px rgba(11, 110, 79, 0.18);
      background: #fff;
    }
    .autopilot-film-row .autopilot-glance-shot {
      flex: 0 0 auto;
      width: 100%;
      height: auto;
      min-height: 0;
      max-height: none;
      aspect-ratio: var(--shot-aspect, 16 / 9);
      overflow: hidden;
    }
    .autopilot-film-row .autopilot-glance-shot .hint {
      font-size: 0.72rem;
      padding: 10px 12px;
    }
    .autopilot-speech-pane #autopilotTranscriptClear {
      flex-shrink: 0;
      align-self: center;
    }
    .autopilot-speech-pane #autopilotTranscript {
      flex: 1;
      width: 100%;
      min-height: 96px;
      margin: 0;
      font: inherit;
      line-height: 1.45;
      box-sizing: border-box;
      resize: vertical;
    }
    .autopilot-tpl-pane .autopilot-tpl-search {
      width: 100%;
      box-sizing: border-box;
      font: inherit;
      font-size: 0.82rem;
      padding: 7px 9px;
      border: 1px solid var(--line);
      border-radius: 8px;
    }
    .autopilot-tpl-pane .autopilot-tpl-status {
      margin: 0;
      font-size: 0.72rem;
      line-height: 1.3;
    }
    .autopilot-tpl-pane .autopilot-tpl-list {
      flex: 1;
      min-height: 200px;
      max-height: 360px;
      overflow-x: hidden;
      overflow-y: auto;
      border: 1px solid var(--line);
      border-radius: 10px;
      background: #fff;
    }
    .autopilot-tpl-pane .mkb-item {
      padding: 8px 10px;
      font-size: 0.8rem;
    }
    .autopilot-tpl-pane .mkb-group-title {
      font-size: 0.7rem;
      padding: 6px 10px;
    }
    .autopilot-tpl-pane .mkb-group-icon {
      display: none;
    }
    .autopilot-mode-badge {
      display: inline-block;
      font-size: 0.72rem;
      font-weight: 700;
      padding: 2px 8px;
      border-radius: 999px;
      background: var(--accent-soft);
      color: var(--accent);
      margin-left: 6px;
      vertical-align: middle;
    }
    .autopilot-mode-badge.is-screen {
      background: #eef2f6;
      color: #475467;
    }
    @media (max-width: 860px) {
      .autopilot-journal-row {
        grid-template-columns: 1fr;
      }
      .autopilot-journal-cell .autopilot-log {
        min-height: 100px;
        max-height: 160px;
        height: auto;
      }
      .autopilot-film-row {
        grid-template-columns: 1fr;
      }
      .autopilot-film-row .autopilot-shot-pane {
        max-width: 320px;
        height: auto;
        max-height: none;
        min-height: 0;
      }
      .autopilot-film {
        min-height: 160px;
      }
    }
    .autopilot-glance {
      display: grid;
      grid-template-columns: 1fr;
      gap: 10px;
      align-items: stretch;
      min-height: 220px;
    }
    .autopilot-glance .recognize-pane.autopilot-glance-unified {
      min-height: 220px;
    }
    .autopilot-glance-stage-bar {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      gap: 8px 12px;
      margin-bottom: 6px;
      min-height: 28px;
    }
    .autopilot-glance-stage-bar .autopilot-glance-ocr-btn {
      margin-left: auto;
      height: 28px;
      padding: 0 10px;
      font-size: 0.78rem;
      font-weight: 600;
      line-height: 1;
      white-space: nowrap;
    }
    .autopilot-glance-stage-bar .autopilot-glance-ocr-btn:disabled {
      opacity: 0.45;
      cursor: not-allowed;
    }
    .autopilot-glance-stage-bar .llm-model-tag {
      font-size: 0.72rem;
      font-weight: 600;
      color: var(--muted);
      font-family: var(--mono);
    }
    .autopilot-glance-stage-bar .llm-model-tag.is-warn {
      color: var(--warn);
    }
    .autopilot-glance .glance-stage-panel {
      display: none;
      flex: 1;
      min-height: 180px;
      width: 100%;
    }
    .autopilot-glance .glance-stage-panel.is-active {
      display: block;
    }
    .autopilot-glance .autopilot-glance-llm-wrap.glance-stage-panel.is-active {
      display: flex;
      flex-direction: column;
      position: relative;
      min-height: 180px;
    }
    .autopilot-glance textarea.glance-stage-panel.is-active {
      display: block;
    }
    .autopilot-glance-llm-wrap > .autopilot-glance-ocr.is-llm {
      flex: 1;
      min-height: 120px;
      height: auto;
      overflow: auto;
    }
    .autopilot-glance-llm-wrap.is-thinking > .autopilot-glance-ocr.is-llm {
      min-height: 80px;
    }
    /* Размышления DeepSeek (как на chat.deepseek.com) */
    .glance-think {
      display: none;
      flex-shrink: 0;
      margin: 0 0 8px;
      border: 1px solid #e3e7ee;
      border-radius: 10px;
      background: #f7f8fb;
      overflow: hidden;
    }
    .glance-think.is-visible {
      display: block;
    }
    .glance-think-toggle {
      width: 100%;
      display: flex;
      align-items: center;
      gap: 8px;
      margin: 0;
      padding: 8px 10px;
      border: 0;
      background: transparent;
      color: #5c6575;
      font: inherit;
      font-size: 0.78rem;
      font-weight: 600;
      line-height: 1.3;
      text-align: left;
      cursor: pointer;
    }
    .glance-think-toggle:hover {
      color: #3b4f7a;
      background: rgba(255, 255, 255, 0.55);
    }
    .glance-think.is-streaming .glance-think-toggle {
      color: #3b6fd9;
    }
    .glance-think-spin {
      width: 14px;
      height: 14px;
      flex-shrink: 0;
      box-sizing: border-box;
      border: 2px solid #c5d4f5;
      border-top-color: #3b6fd9;
      border-radius: 50%;
      animation: work-spin 0.8s linear infinite;
    }
    .glance-think:not(.is-streaming) .glance-think-spin {
      display: none;
    }
    .glance-think-label {
      flex: 1;
      min-width: 0;
    }
    .glance-think-chevron {
      flex-shrink: 0;
      width: 0.55em;
      height: 0.55em;
      border-right: 2px solid currentColor;
      border-bottom: 2px solid currentColor;
      transform: rotate(45deg);
      opacity: 0.7;
      transition: transform 0.15s ease;
      margin-right: 2px;
    }
    .glance-think.is-open .glance-think-chevron {
      transform: rotate(-135deg);
      margin-top: 4px;
    }
    .glance-think-body {
      display: none;
      max-height: min(280px, 42vh);
      overflow: auto;
      padding: 0 12px 10px;
      font-size: 0.78rem;
      line-height: 1.5;
      color: #6b7280;
      white-space: pre-wrap;
      word-break: break-word;
    }
    .glance-think.is-open .glance-think-body,
    .glance-think.is-streaming .glance-think-body {
      display: block;
    }
    .glance-think-body:empty::before {
      content: attr(data-placeholder);
      color: #9aa3b2;
      font-weight: 400;
    }
    .autopilot-glance-llm-wrap.is-thinking .autopilot-glance-llm-loading {
      display: none;
    }
    .autopilot-glance-llm-loading {
      display: none;
      position: absolute;
      inset: 0;
      z-index: 3;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 10px;
      border-radius: 10px;
      background: rgba(245, 248, 255, 0.88);
      color: var(--ink);
      pointer-events: none;
    }
    .autopilot-glance-llm-wrap.is-loading:not(.is-thinking) .autopilot-glance-llm-loading {
      display: flex;
    }
    .autopilot-glance-spin {
      width: 28px;
      height: 28px;
      box-sizing: border-box;
      border: 2.5px solid #c5d4f5;
      border-top-color: #3b6fd9;
      border-radius: 50%;
      animation: work-spin 0.8s linear infinite;
    }
    .autopilot-glance-llm-loading-label {
      font-size: 0.82rem;
      font-weight: 600;
      color: #3b4f7a;
    }
    @media (prefers-reduced-motion: reduce) {
      .autopilot-glance-spin { animation: none; border-top-color: #c5d4f5; }
    }
    .autopilot-glance-shot {
      position: relative;
      flex: 0 0 auto;
      width: 100%;
      aspect-ratio: var(--shot-aspect, 16 / 9);
      min-height: 0;
      border: 1px solid #d5dbe6;
      border-radius: 10px;
      background: linear-gradient(180deg, #f6f8fb 0%, #eef1f6 100%);
      overflow: hidden;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      box-sizing: border-box;
    }
    .autopilot-glance-shot:hover:not(.has-img) {
      border-color: #b8c4d6;
      background: linear-gradient(180deg, #f3f6fb 0%, #e8edf5 100%);
    }
    .autopilot-glance-shot:focus-visible {
      outline: 2px solid var(--accent);
      outline-offset: 2px;
    }
    .autopilot-glance-shot.has-img {
      background: #e8ecf2;
      border-style: solid;
      border-color: var(--line);
    }
    .autopilot-glance-shot img {
      display: block;
      width: 100%;
      height: 100%;
      object-fit: contain;
      object-position: center;
      background: transparent;
    }
    .autopilot-glance-shot img[hidden],
    .autopilot-glance-shot:not(.has-img) img {
      display: none !important;
    }
    .autopilot-glance-shot .hint {
      position: absolute;
      inset: 0;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      text-align: center;
      gap: 4px;
      padding: 12px 14px;
      font-size: 0.78rem;
      color: #6b7280;
      line-height: 1.4;
      pointer-events: none;
    }
    .autopilot-glance-shot.has-img .hint {
      display: none;
    }
    .autopilot-glance-zoom {
      position: absolute;
      top: 6px;
      left: 6px;
      z-index: 2;
      width: 28px;
      height: 28px;
      margin: 0;
      padding: 0;
      border: 0;
      border-radius: 999px;
      background: rgba(15, 23, 42, 0.55);
      color: #fff;
      cursor: pointer;
      display: none;
      align-items: center;
      justify-content: center;
      opacity: 0;
      transition: opacity 0.12s ease, background 0.12s ease;
    }
    .autopilot-glance-zoom svg {
      display: block;
      pointer-events: none;
    }
    .autopilot-glance-shot.has-img .autopilot-glance-zoom {
      display: inline-flex;
      opacity: 0.78;
    }
    .autopilot-glance-shot.has-img:hover .autopilot-glance-zoom,
    .autopilot-glance-shot.has-img:focus-within .autopilot-glance-zoom,
    .autopilot-glance-zoom:focus-visible {
      opacity: 1;
    }
    .autopilot-glance-zoom:hover,
    .autopilot-glance-zoom:focus-visible {
      background: var(--accent);
    }
    .autopilot-glance-when {
      margin: 6px 0 0;
      font-size: 0.72rem;
      color: var(--muted);
      line-height: 1.3;
    }
    .autopilot-glance-when strong {
      color: var(--ink);
      font-weight: 600;
    }
    .autopilot-shot-toolbar {
      display: flex;
      flex-direction: column;
      gap: 6px;
      margin-top: 8px;
    }
    .autopilot-glance-shot.is-drop {
      outline: 2px solid var(--accent);
      outline-offset: -2px;
      background: #e8f5f0;
    }
    .autopilot-shot-pane.is-file-mode .autopilot-glance-shot {
      border-style: solid;
    }
    .autopilot-series {
      margin-top: 8px;
      padding: 8px 10px;
      border: 1px solid var(--line);
      border-radius: 10px;
      background: #fafbfc;
      display: flex;
      flex-direction: column;
      gap: 6px;
      min-width: 0;
    }
    .autopilot-series-head {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      gap: 6px 10px;
      font-size: 0.78rem;
      line-height: 1.3;
    }
    .autopilot-series-head strong {
      font-size: 0.85rem;
      white-space: nowrap;
    }
    .autopilot-series-status {
      color: var(--muted);
      flex: 1;
      min-width: 120px;
    }
    .autopilot-series-status.is-warn {
      color: #9a5b00;
    }
    .autopilot-series-actions {
      display: inline-flex;
      flex-wrap: wrap;
      align-items: center;
      gap: 6px;
    }
    .autopilot-series-actions button {
      margin: 0;
      font-size: 0.75rem;
      padding: 4px 8px;
      line-height: 1.2;
    }
    .autopilot-series-strip {
      display: flex;
      gap: 8px;
      overflow-x: auto;
      padding: 2px 0 4px;
      min-height: 72px;
      align-items: stretch;
    }
    .autopilot-series-strip:empty::before {
      content: 'Пока пусто — при прокрутке осмотра в ЕМИАС кадры появятся здесь';
      color: var(--muted);
      font-size: 0.75rem;
      align-self: center;
    }
    .autopilot-series-thumb {
      flex: 0 0 auto;
      width: 108px;
      border: 1px solid var(--line);
      border-radius: 8px;
      background: #fff;
      padding: 0;
      cursor: pointer;
      text-align: left;
      overflow: hidden;
      display: flex;
      flex-direction: column;
      position: relative;
    }
    .autopilot-series-thumb:hover {
      border-color: var(--accent);
    }
    .autopilot-series-thumb.is-active {
      border-color: var(--accent);
      box-shadow: 0 0 0 1px var(--accent);
    }
    .autopilot-series-thumb img {
      display: block;
      width: 100%;
      height: 56px;
      object-fit: cover;
      background: #e8ecf0;
    }
    .autopilot-series-thumb-meta {
      font-size: 0.68rem;
      padding: 3px 5px;
      color: var(--muted);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .autopilot-series-thumb.is-pending .autopilot-series-thumb-meta,
    .autopilot-series-thumb.is-ocr .autopilot-series-thumb-meta {
      color: #0b6e4f;
    }
    .autopilot-series-thumb.is-error .autopilot-series-thumb-meta {
      color: #a33;
    }
    .autopilot-series-view-tog {
      display: flex;
      flex-wrap: wrap;
      gap: 4px;
    }
    .autopilot-series-view-tog button {
      margin: 0;
      font-size: 0.7rem;
      padding: 3px 7px;
      line-height: 1.2;
      background: #fff;
      border: 1px solid var(--line);
      border-radius: 999px;
      color: var(--muted);
      cursor: pointer;
    }
    .autopilot-series-view-tog button.is-active {
      background: #e8f5f0;
      border-color: var(--accent);
      color: var(--ink);
      font-weight: 600;
    }
    .autopilot-glance-ocr {
      flex: 1;
      min-height: 180px;
      width: 100%;
      box-sizing: border-box;
      resize: vertical;
      font: inherit;
      font-size: 0.82rem;
      line-height: 1.4;
      border: 1px solid var(--line);
      border-radius: 10px;
      padding: 8px 10px;
      background: #fff;
    }
    div.autopilot-glance-ocr {
      overflow: auto;
      white-space: pre-wrap;
      word-break: break-word;
      resize: vertical;
    }
    div.autopilot-glance-ocr.is-llm {
      white-space: normal;
    }
    /* во время стрима — plain text с переносами, без HTML-мигания */
    div.autopilot-glance-ocr.is-llm.is-streaming-text {
      white-space: pre-wrap;
      word-break: break-word;
    }
    /* блок раздела в окне нейросети */
    div.autopilot-glance-ocr.is-llm .glance-sec-block {
      display: block;
    }
    .field-text .glance-sec-block {
      display: contents;
    }
    @keyframes glance-sec-enter {
      from {
        opacity: 0;
        transform: translateY(8px);
      }
      to {
        opacity: 1;
        transform: none;
      }
    }
    div.autopilot-glance-ocr.is-llm .glance-sec-block {
      will-change: transform, opacity;
    }
    div.autopilot-glance-ocr.is-llm .glance-sec-block.glance-sec-enter {
      animation: glance-sec-enter 0.38s ease-out both;
    }
    div.autopilot-glance-ocr.is-llm .glance-sec-block.glance-sec-shift {
      transition: transform 0.38s ease-out;
    }
    @media (prefers-reduced-motion: reduce) {
      div.autopilot-glance-ocr.is-llm .glance-sec-block.glance-sec-enter {
        animation: none;
      }
      div.autopilot-glance-ocr.is-llm .glance-sec-block.glance-sec-shift {
        transition: none;
      }
    }
    div.autopilot-glance-ocr strong.glance-sec-title {
      display: block;
      font-weight: 700;
      color: var(--ink);
      margin: 0.85em 0 0;
      padding: 0;
      line-height: 1.4;
    }
    div.autopilot-glance-ocr.is-llm .glance-sec-block > strong.glance-sec-title {
      margin-top: 0.55em;
    }
    div.autopilot-glance-ocr.is-llm .glance-sec-block:first-child > strong.glance-sec-title {
      margin-top: 0;
    }
    div.autopilot-glance-ocr strong.glance-imaging-title,
    .field-text strong.glance-imaging-title {
      display: inline;
      font-weight: 700;
      color: var(--ink);
      margin: 0;
      padding: 0;
      line-height: inherit;
    }
    div.autopilot-glance-ocr strong.glance-sec-title:first-child,
    div.autopilot-glance-ocr .glance-service + strong.glance-sec-title {
      margin-top: 0;
    }
    div.autopilot-glance-ocr .glance-sec-body {
      display: block;
      padding: 0.15em 0 0.35em 0.85em;
      margin: 0;
      line-height: 1.45;
      white-space: pre-wrap;
      word-break: break-word;
    }
    div.autopilot-glance-ocr .glance-service {
      display: block;
      font-size: 0.78rem;
      font-family: var(--mono);
      font-weight: 500;
      color: var(--muted);
      letter-spacing: 0.01em;
      margin: 0;
      padding: 0;
      line-height: 1.4;
    }
    div.autopilot-glance-ocr .glance-service--inline,
    .field-text .glance-service--inline {
      display: inline;
      margin: 0 0 0 0.35em;
      padding: 0;
      font-size: 0.78rem;
      font-family: var(--mono);
      font-weight: 500;
      color: var(--muted);
      letter-spacing: 0.01em;
      white-space: nowrap;
    }
    div.autopilot-glance-ocr .glance-service + .glance-service {
      margin: 0;
    }
    .autopilot-mode-badge.is-template {
      background: #eef2f6;
      color: #667085;
      font-family: var(--mono);
      font-weight: 600;
      letter-spacing: 0.02em;
    }
    div.autopilot-glance-ocr u.glance-sub-title,
    .field-text u.glance-sub-title {
      text-decoration: underline;
      text-underline-offset: 2px;
      font-weight: 600;
      color: var(--ink);
    }
    div.autopilot-glance-ocr[data-placeholder]:empty::before {
      content: attr(data-placeholder);
      color: var(--muted);
      white-space: pre-wrap;
    }
    .autopilot-glance-ocr.is-llm {
      background: #f5f8ff;
      border-color: #c5d4f5;
    }
    video#autopilotVideo {
      position: fixed;
      width: 1px;
      height: 1px;
      opacity: 0;
      pointer-events: none;
      left: -10px;
      top: -10px;
    }
