﻿  * { margin: 0; padding: 0; box-sizing: border-box; }

  body, button, input, textarea, select {
    font-family: var(--font-ui);
  }

  :root, [data-theme="dark"] {
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --scrollbar-track: transparent;
    --scrollbar-thumb: #333;
    --bg-page: #000;
    --bg-surface: #050505;
    --bg-elevated: #0a0a0a;
    --bg-sub: #0c0c0c;
    --bg-hover: #1a1a1a;
    --bg-active: #1c1c1c;
    --bg-bubble: #1a1a1a;
    --text-primary: #fff;
    --text-secondary: #ddd;
    --text-muted: #888;
    --text-faint: #666;
    --border: #141414;
    --border-strong: #282828;
    --border-soft: #252525;
    --link: #9ecbff;
    --private-accent: #4a8fc9;
    --table-header-bg: #141414;
    --table-border: #333;
    --accent-muted: #555;
    --input-bg: #111;
    --input-border: #252525;
    --input-text: #fff;
    --input-placeholder: #6d6d6d;
    --input-focus-border: #3a3a3a;
    --logo-fill: #ffffff;
    --on-accent: #000000;
    --voice-btn-bg: #111111;
    --voice-btn-fg: #ffffff;
    --bg-main: #000000;
    --bg-invert: #ffffff;
    --motion-fast: 0.22s;
    --motion-normal: 0.35s;
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  }
  [data-theme="light"] {
    --scrollbar-thumb: #c8c8ce;
    --bg-page: #f5f5f7;
    --bg-surface: #fff;
    --bg-elevated: #fafafa;
    --bg-sub: #f7f7f9;
    --bg-hover: #eee;
    --bg-active: #e8e8ed;
    --bg-bubble: #fff;
    --text-primary: #111;
    --text-secondary: #333;
    --text-muted: #666;
    --text-faint: #888;
    --border: #e5e5ea;
    --border-strong: #d1d1d6;
    --border-soft: #ebebf0;
    --link: #0066cc;
    --private-accent: #004080;
    --table-header-bg: #f0f0f5;
    --table-border: #d8d8de;
    --accent-muted: #999;
    --input-bg: #fff;
    --input-border: #d1d1d6;
    --input-text: #111;
    --input-placeholder: #888;
    --input-focus-border: #0066cc;
    --logo-fill: #111111;
    --on-accent: #ffffff;
    --voice-btn-bg: #ffffff;
    --voice-btn-fg: #111111;
    --bg-main: #f5f5f7;
    --bg-invert: #111111;
  }

  [data-theme="dark"] .voice-btn {
    border: 1px solid var(--border-strong);
  }
  [data-theme="light"] .voice-btn {
    border: 1px solid var(--input-border);
  }
  [data-theme="light"] .voice-btn:hover {
    background: #f0f0f2;
    color: var(--voice-btn-fg);
  }
  [data-theme="light"] .mic-btn {
    color: var(--text-secondary);
    border: 1px solid var(--border-strong);
    background: var(--bg-elevated);
  }
  [data-theme="light"] .mic-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-strong);
  }
  [data-theme="light"] .model-selector {
    background: var(--input-bg);
    color: var(--text-primary);
    border-color: var(--input-border);
  }
  [data-theme="light"] .model-selector:hover,
  [data-theme="light"] .model-selector.active {
    background: var(--bg-hover);
    border-color: var(--border-strong);
  }
  [data-theme="light"] .model-dropdown {
    background: var(--bg-surface);
    border-color: var(--border-strong);
    box-shadow: 0 10px 40px rgba(0,0,0,0.12);
  }
  [data-theme="light"] .model-option:hover,
  [data-theme="light"] .model-option.active { background: var(--bg-hover); }
  [data-theme="light"] .model-option-title { color: var(--text-primary); }
  [data-theme="light"] .model-option.active .model-option-icon svg { color: var(--text-primary); }
  [data-theme="light"] .sidebar-icon-label { color: var(--text-primary); }
  [data-theme="light"] .expand-btn:hover,
  [data-theme="light"] .topbar-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
  [data-theme="light"] .new-project-btn { color: var(--text-muted); }
  [data-theme="light"] .new-project-btn:hover { color: var(--text-primary); }

  * {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
  }
  ::-webkit-scrollbar { width: 6px; height: 6px; }
  ::-webkit-scrollbar-track { background: var(--scrollbar-track); }
  ::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 999px;
  }

  body {
    background: var(--bg-page);
    color: var(--text-primary);
    font-family: var(--font-ui);
    height: 100vh;
    display: flex;
    overflow: hidden;
    transition: background var(--motion-fast) var(--ease-out), color var(--motion-fast) var(--ease-out);
  }

  @keyframes msgEnter {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
  }
  @keyframes extrasFade {
    from { opacity: 0; }
    to { opacity: 1; }
  }
  @keyframes orbImpulse {
    0%, 100% { opacity: 0.45; transform: scale(0.88); }
    35% { opacity: 1; transform: scale(1.12); }
    70% { opacity: 0.55; transform: scale(0.92); }
  }
  @keyframes linkPulse {
    0%, 100% { stroke-opacity: 0.2; }
    35% { stroke-opacity: 0.85; }
  }
  @media (prefers-reduced-motion: reduce) {
    .msg-enter { animation: none; opacity: 1; transform: none; }
    .reply-extras { animation: none; }
    .protocol-avatar .orb, .protocol-avatar .orb-link { animation: none !important; }
  }
  .msg-enter {
    animation: msgEnter var(--motion-normal) var(--ease-out) both;
  }
  .reply-extras {
    animation: extrasFade var(--motion-normal) var(--ease-out) both;
  }
  .view-fade-in {
    animation: extrasFade 0.28s var(--ease-out) both;
  }

  :root { --panel-topbar-h: 44px; }

  /* ─── SIDEBAR ─── */
  .sidebar {
    width: 44px;
    background: var(--bg-surface);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 0;
    gap: 0;
    border-right: 1px solid var(--border);
    transition: width var(--motion-normal) var(--ease-out);
    overflow: hidden;
    position: relative;
    z-index: 10;
    flex-shrink: 0;
  }
  .sidebar.expanded { width: 220px; }

  .sidebar-topbar {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 2px;
    min-height: var(--panel-topbar-h);
    height: var(--panel-topbar-h);
    width: 100%;
    padding: 0 4px 0 6px;
    flex-shrink: 0;
    box-sizing: border-box;
  }

  .sidebar-logo {
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 32px;
    min-width: 32px;
    height: 32px;
    cursor: pointer;
    flex-shrink: 0;
  }
  .sidebar-logo svg { width: 28px; height: auto; display: block; }

  .sidebar .expand-btn-top { display: none; }
  .sidebar.expanded .expand-btn-top { display: flex; margin-left: auto; }
  .sidebar.expanded .expand-btn-bottom { display: none !important; }

  .sidebar-topbar + .sidebar-section { padding-top: 6px; }

  .sidebar-icon-row {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 7px 7px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-primary);
    gap: 10px;
    transition: background var(--motion-fast) var(--ease-out), color var(--motion-fast) var(--ease-out);
    white-space: nowrap;
    min-height: 34px;
  }
  .sidebar-icon-row:hover { background: var(--bg-hover); color: var(--text-primary); }
  .sidebar-icon-row.active { background: var(--bg-active); color: var(--text-primary); }
  .sidebar-icon-row svg { flex-shrink: 0; width: 18px; height: 18px; }

  .sidebar-icon-label {
    font-size: 13px;
    opacity: 0;
    transition: opacity 0.15s;
    font-weight: 400;
    color: var(--text-primary);
  }
  .sidebar.expanded .sidebar-icon-label { opacity: 1; }

  .sidebar-section {
    width: 100%;
    padding: 0 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .sidebar.expanded .sidebar-section {
    align-items: stretch;
  }

  .sidebar-section-header {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 7px 7px;
    min-height: 34px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-primary);
    gap: 10px;
    white-space: nowrap;
    box-sizing: border-box;
    transition: background var(--motion-fast) var(--ease-out), color var(--motion-fast) var(--ease-out);
  }
  .sidebar-section-header:hover { background: var(--bg-hover); color: var(--text-primary); }
  .sidebar-block-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
  }
  .sidebar-block-text {
    font-size: 13px;
    font-weight: 400;
    color: var(--text-primary);
    opacity: 0;
    transition: opacity 0.15s;
    flex-shrink: 0;
  }
  .sidebar.expanded .sidebar-block-text {
    opacity: 1;
  }
  .sidebar-section-header .section-chevron {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
    opacity: 0;
    transition: transform 0.2s ease, opacity 0.15s;
  }
  .sidebar.expanded .sidebar-section-header .section-chevron {
    opacity: 0.65;
  }
  .sidebar-section.collapsed .section-chevron { transform: rotate(-90deg); }
  [data-sidebar-nav].section-nav-collapsed .section-chevron { transform: rotate(-90deg); }
  .history-clear-btn {
    font-size: 10px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    border: none;
    background: transparent;
  }
  .history-clear-btn:hover { color: var(--text-primary); background: var(--bg-hover); }
  .history-empty {
    font-size: 12.5px;
    color: var(--text-muted);
    padding: 7px 8px;
    opacity: 0;
  }
  .sidebar.expanded .history-empty { opacity: 1; }
  .sidebar-history-row {
    display: flex;
    align-items: center;
    margin-bottom: 3px;
    opacity: 0;
    transition: opacity 0.15s;
    position: relative;
    border-radius: 6px;
  }
  .sidebar.expanded .sidebar-history-row { opacity: 1; }
  /* Единая поверхность подсветки строки (как в Grok) — не отдельно название и точки. */
  .sidebar-history-row:hover,
  .sidebar-history-row:has(.history-menu-btn.is-open) { background: var(--bg-hover); }
  .sidebar-history-item {
    flex: 1;
    min-width: 0;
    font-size: 14px;
    color: var(--text-secondary);
    padding: 7px 8px;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background: transparent;
    transition: color var(--motion-fast);
  }
  .sidebar-history-item.active { color: var(--text-primary); font-weight: 500; }
  .sidebar-history-row:has(.sidebar-history-item.active) { background: var(--bg-active); }
  /* Название плавно затухает у правого края, где появляются три точки (fade-эффект Grok). */
  .sidebar-history-row:hover .sidebar-history-item,
  .sidebar-history-row:has(.history-menu-btn.is-open) .sidebar-history-item {
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 44px), transparent 100%);
    mask-image: linear-gradient(to right, #000 calc(100% - 44px), transparent 100%);
  }
  .history-menu-btn {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 0;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s, color 0.15s;
  }
  /* Три точки — только у строки под курсором, при фокусе с клавиатуры или открытом меню. */
  .sidebar-history-row:hover .history-menu-btn,
  .history-menu-btn:focus-visible,
  .history-menu-btn.is-open { opacity: 1; }
  .history-menu-btn:hover { background: var(--bg-active); color: var(--text-primary); }
  .history-menu-portal {
    position: fixed;
    z-index: 10050;
    min-width: 130px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md, 12px);
    padding: 4px 0;
    box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  }
  .history-menu-portal button {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    text-align: left;
    padding: 8px 12px;
    font-size: 12.5px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
  }
  .history-menu-portal button svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    color: var(--text-muted);
  }
  .history-menu-portal button:hover { background: var(--bg-hover); }
  .history-menu-portal button:hover svg { color: var(--text-secondary); }
  .history-menu-portal button.danger { color: #e57373; }
  .history-menu-portal button.danger svg { color: #e57373; }
  .sidebar-section-highlight {
    background: var(--bg-active);
    border-radius: var(--radius-sm, 8px);
    transition: background 0.3s ease;
  }
  .sidebar-section-header-flash .sidebar-block-text {
    color: var(--text-primary);
    transition: color 0.35s ease;
  }
  .sidebar-block-label {
    font-size: 13px;
    font-weight: 400;
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    gap: 8px;
  }
  .sidebar-section.collapsed .sidebar-section-body { display: none; }
  .history-show-all-btn {
    font-size: 12.5px;
    color: var(--text-muted);
    padding: 7px 8px;
    margin-top: 2px;
    cursor: pointer;
    border: none;
    background: transparent;
    text-align: left;
    width: 100%;
    opacity: 1;
    transition: color 0.15s;
  }
  .history-show-all-btn:hover { color: var(--text-primary); }
  .history-show-all-header {
    margin-left: auto;
    font-size: 11px;
    color: var(--text-muted);
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 6px;
    opacity: 0;
    flex-shrink: 0;
  }
  .sidebar.expanded .history-show-all-header { opacity: 1; }
  .history-show-all-header:hover { color: var(--text-primary); background: var(--bg-hover); }
  .topbar-btn.is-private-active {
    color: var(--private-accent);
    border-color: color-mix(in srgb, var(--private-accent) 42%, transparent);
  }
  [data-theme="light"] .topbar-btn.is-private-active {
    border-color: color-mix(in srgb, var(--private-accent) 32%, transparent);
  }
  .topbar-private-badge {
    font-size: 12px;
    color: var(--private-accent);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 8px;
    background: color-mix(in srgb, var(--private-accent) 16%, transparent);
  }
  [data-theme="light"] .topbar-private-badge {
    background: color-mix(in srgb, var(--private-accent) 10%, transparent);
  }
  .input-bar.is-private-mode {
    border-color: color-mix(in srgb, var(--private-accent) 38%, transparent);
    background: color-mix(in srgb, var(--input-bg) 90%, var(--private-accent) 10%);
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--private-accent) 12%, transparent);
  }
  [data-theme="light"] .input-bar.is-private-mode {
    border-color: color-mix(in srgb, var(--private-accent) 28%, transparent);
    background: color-mix(in srgb, var(--input-bg) 92%, var(--private-accent) 8%);
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--private-accent) 8%, transparent);
  }
  .input-bar.is-private-mode:focus-within {
    border-color: color-mix(in srgb, var(--private-accent) 55%, transparent);
  }
  [data-theme="light"] .input-bar.is-private-mode:focus-within {
    border-color: color-mix(in srgb, var(--private-accent) 40%, transparent);
  }
  .history-browser-card {
    display: flex;
    flex-direction: column;
  }
  .history-browser-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px 10px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }
  .history-browser-toolbar-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    flex-shrink: 0;
    padding-left: 2px;
  }
  .history-browser-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 22px;
    line-height: 1;
    width: 32px;
    height: 32px;
    padding: 0;
    cursor: pointer;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color 0.15s, background 0.15s;
  }
  .history-browser-close:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
  }
  .history-browser-search {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 6px 4px;
    color: var(--input-text);
    font-size: 14px;
    outline: none;
    box-shadow: none;
  }
  .history-browser-search::placeholder { color: var(--input-placeholder); }
  .history-browser-search:focus { outline: none; border: none; box-shadow: none; }
  .history-browser-body {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }
  .history-browser-body.preview-collapsed .history-browser-preview { display: none; }
  .history-browser-body.preview-collapsed .history-browser-sidebar {
    width: 100%;
    max-width: none;
    min-width: 0;
    flex: 1 1 auto;
    flex-shrink: 1;
    border-right: none;
    padding: 10px 14px 14px;
  }
  .history-browser-body.preview-collapsed .history-browser-item-title {
    white-space: normal;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-height: 1.35;
    overflow: hidden;
  }
  .history-browser-body.preview-collapsed .history-browser-item-row {
    align-items: flex-start;
  }
  .history-browser-body.preview-collapsed .history-browser-item-main {
    padding-top: 6px;
    padding-bottom: 6px;
    align-items: flex-start;
  }
  .history-browser-body.preview-collapsed .history-browser-item-trailing {
    padding-top: 2px;
  }
  .history-browser-item-main {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 4px 7px 8px;
    cursor: pointer;
  }
  .history-browser-item-date {
    font-size: 10px;
    color: var(--text-muted);
    line-height: 1.2;
    white-space: nowrap;
    flex-shrink: 0;
    transition: opacity 0.12s ease, visibility 0.12s ease;
  }
  .history-browser-item-trailing {
    position: relative;
    flex-shrink: 0;
    width: 92px;
    height: 28px;
    padding-right: 2px;
  }
  .history-browser-item-trailing .history-browser-item-date {
    position: absolute;
    right: 2px;
    top: 50%;
    transform: translateY(-50%);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 1;
    visibility: visible;
    pointer-events: none;
  }
  .history-browser-item-trailing .history-browser-item-actions {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 1px;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    padding-right: 0;
    transition: opacity 0.12s ease, visibility 0.12s ease;
  }
  .history-browser-item-row:hover .history-browser-item-trailing .history-browser-item-date,
  .history-browser-item-row.editing .history-browser-item-trailing .history-browser-item-date {
    opacity: 0;
    visibility: hidden;
  }
  .history-browser-item-row:hover .history-browser-item-trailing .history-browser-item-actions,
  .history-browser-item-row.editing .history-browser-item-trailing .history-browser-item-actions {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }
  .history-browser-sidebar {
    width: 340px;
    min-width: 280px;
    max-width: 34%;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 10px 12px 14px;
    flex-shrink: 0;
  }
  .history-browser-new-btn {
    width: 100%;
    text-align: left;
    padding: 8px 10px;
    margin-bottom: 10px;
    border-radius: 8px;
    border: 1px dashed var(--border);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;
  }
  .history-browser-new-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
  .history-browser-group-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    padding: 8px 6px 4px;
  }
  .history-browser-item-row {
    display: flex;
    align-items: center;
    gap: 2px;
    border-radius: 8px;
    margin-bottom: 2px;
    min-height: 36px;
    transition: background 0.12s ease;
  }
  .history-browser-item-row:hover,
  .history-browser-item-row.active { background: var(--bg-hover); }
  .history-browser-item-row.active { background: var(--bg-active); }
  .history-browser-item-row.editing { background: var(--bg-active); }
  .history-browser-item-title {
    flex: 1;
    min-width: 0;
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .history-browser-item-row:hover .history-browser-item-title,
  .history-browser-item-row.active .history-browser-item-title { color: var(--text-primary); }
  .history-browser-item-edit-input {
    flex: 1;
    min-width: 0;
    margin: 4px 0 4px 6px;
    background: var(--input-bg);
    border: 1px solid var(--input-focus-border);
    border-radius: 7px;
    padding: 6px 8px;
    font-size: 13px;
    color: var(--input-text);
    outline: none;
  }
  .history-browser-item-actions {
    display: none;
    align-items: center;
    gap: 1px;
    flex-shrink: 0;
  }
  .history-browser-item-row.editing .history-browser-item-actions {
    display: flex;
    padding-right: 4px;
  }
  .hb-action-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    border-radius: 7px;
    color: var(--text-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.12s, color 0.12s;
  }
  .hb-action-btn svg { width: 14px; height: 14px; stroke: currentColor; fill: none; }
  .hb-action-btn:hover { background: var(--bg-elevated); color: var(--text-primary); }
  .hb-action-btn.danger:hover { color: #e57373; }
  .hb-action-btn.confirm:hover { color: #81c784; }
  .history-browser-preview {
    flex: 1 1 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 14px 20px 18px;
    font-size: 13px;
    line-height: 1.55;
    color: var(--text-secondary);
    min-width: 0;
  }
  .history-browser-preview .hb-preview-empty {
    color: var(--text-muted);
    padding: 24px 12px;
    font-size: 13px;
  }
  .history-browser-preview .hb-preview-messages {
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
  }
  .history-browser-preview .hb-msg-user {
    display: flex;
    justify-content: flex-end;
  }
  .history-browser-preview .hb-msg-user-bubble {
    background: var(--bg-bubble);
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    padding: 9px 13px;
    font-size: 13px;
    line-height: 1.5;
    max-width: 82%;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text-primary);
  }
  .history-browser-preview .hb-msg-assistant { margin-bottom: 4px; }
  .history-browser-preview .hb-msg-role {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 6px;
  }
  .history-browser-preview .hb-msg-text {
    color: var(--text-primary);
    font-size: 13px;
    line-height: 1.55;
  }
  .history-browser-preview .hb-msg-text .md-rendered { font-size: 13px; }
  .history-browser-preview .hb-msg-text table { font-size: 12px; }
  .history-browser-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 16px 12px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
  }
  .history-browser-preview-toggle {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    border-radius: 8px;
    color: var(--text-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.12s, color 0.12s;
  }
  .history-browser-preview-toggle svg { width: 18px; height: 18px; stroke: currentColor; fill: none; }
  .history-browser-preview-toggle:hover { background: var(--bg-hover); color: var(--text-primary); }
  .history-browser-footer-right {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
  }
  .hb-footer-btn {
    height: auto;
    padding: 4px 2px;
    font-size: 12px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: color 0.12s;
  }
  .hb-footer-btn:hover { color: var(--text-primary); background: transparent; }
  .hb-footer-btn.primary { color: var(--text-primary); font-weight: 500; }
  .hb-footer-btn.danger { color: #e57373; }
  .hb-footer-btn.danger:hover { color: #ef9a9a; }
  .hb-kbd {
    font-size: 10px;
    line-height: 1.2;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 2px 6px;
    font-family: inherit;
    white-space: nowrap;
  }
  .projects-empty {
    font-size: 12.5px;
    color: var(--text-muted);
    padding: 7px 8px;
    opacity: 0;
  }
  .sidebar.expanded .projects-empty { opacity: 1; }

  .new-project-btn {
    font-size: 13px;
    color: var(--text-secondary);
    padding: 7px 8px;
    margin-bottom: 6px;
    gap: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    border-radius: 6px;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s;
    white-space: nowrap;
  }
  .sidebar.expanded .new-project-btn { opacity: 1; }

  .sidebar-project-item {
    flex: 1;
    min-width: 0;
    padding: 7px 8px;
    border-radius: 6px;
    font-size: 14px;
    color: var(--text-primary);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background: transparent;
    transition: color var(--motion-fast);
  }
  .sidebar-project-row {
    display: flex;
    align-items: center;
    margin-bottom: 3px;
    opacity: 0;
    transition: opacity 0.15s;
    position: relative;
    border-radius: 6px;
  }
  .sidebar.expanded .sidebar-project-row { opacity: 1; }
  /* Единая поверхность подсветки + точки только при наведении (как в истории). */
  .sidebar-project-row:hover,
  .sidebar-project-row:has(.project-menu-btn.is-open) { background: var(--bg-hover); }
  .sidebar-project-item.active { color: var(--text-primary); font-weight: 500; }
  .sidebar-project-row:has(.sidebar-project-item.active) { background: var(--bg-active); }
  .sidebar-project-item.all-chats { color: var(--text-muted); font-size: 11.5px; }
  .sidebar-project-item.all-chats.active { color: var(--text-primary); }
  /* Название затухает у правого края, не перекрывая три точки. */
  .sidebar-project-row:has(.project-menu-btn):hover .sidebar-project-item,
  .sidebar-project-row:has(.project-menu-btn.is-open) .sidebar-project-item {
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 44px), transparent 100%);
    mask-image: linear-gradient(to right, #000 calc(100% - 44px), transparent 100%);
  }
  .project-menu-btn {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 0;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s, color 0.15s;
  }
  .sidebar-project-row:hover .project-menu-btn,
  .project-menu-btn:focus-visible,
  .project-menu-btn.is-open { opacity: 1; }
  .project-menu-btn:hover { background: var(--bg-active); color: var(--text-primary); }

  .projects-panel {
    width: 0;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: width var(--motion-normal) var(--ease-out);
    z-index: 9;
  }
  .projects-panel.open { width: 280px; }
  .projects-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: var(--panel-topbar-h);
    height: var(--panel-topbar-h);
    padding: 0 10px;
    flex-shrink: 0;
    gap: 8px;
    box-sizing: border-box;
  }
  .projects-panel-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
  }
  .projects-panel-close {
    flex-shrink: 0;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background var(--motion-fast), color var(--motion-fast);
  }
  .projects-panel-close svg { width: 16px; height: 16px; }
  .projects-panel-close:hover { background: var(--bg-hover); color: var(--text-primary); }
  .projects-panel-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    min-height: 0;
  }
  .projects-panel-chats-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 4px 6px;
    margin-top: 2px;
  }
  .projects-panel-chats-header .sidebar-block-label {
    flex: 1;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    text-transform: none;
    letter-spacing: normal;
  }
  .projects-panel-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px;
    margin-bottom: 12px;
  }
  .projects-panel-card-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
  }
  .projects-panel-card-title svg {
    width: 13px;
    height: 13px;
    flex-shrink: 0;
    opacity: 0.85;
  }
  .project-prompt-preview {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 11px 12px;
    min-height: 44px;
    cursor: pointer;
    transition: border-color var(--motion-fast), background var(--motion-fast);
    background: var(--bg-sub);
  }
  .project-prompt-preview:hover {
    border-color: var(--border-strong);
    background: var(--bg-hover);
  }
  .project-prompt-preview-text {
    font-size: 12px;
    line-height: 1.45;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
    white-space: pre-wrap;
  }
  .project-prompt-preview.is-empty .project-prompt-preview-text {
    color: var(--text-muted);
    font-style: italic;
  }
  .projects-panel-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 6px;
  }
  .project-workspace-title { display: none; }
  .projects-panel .sidebar-history-row,
  .projects-panel .history-empty { opacity: 1; }
  .projects-panel .sidebar-history-item {
    font-size: 14px;
    color: var(--text-secondary);
  }
  .projects-panel .history-empty {
    font-size: 12.5px;
    color: var(--text-muted);
    opacity: 1;
  }

  .project-workspace {
    display: none;
    margin-top: 0;
    padding: 8px;
    border-radius: 8px;
    background: var(--bg-sub);
    border: 1px solid var(--border);
    opacity: 1;
  }
  .projects-panel .project-workspace.visible {
    display: block;
    background: transparent;
    border: none;
    padding: 0;
  }
  .projects-panel-empty {
    font-size: 12px;
    color: var(--text-muted);
    padding: 16px 8px;
    text-align: center;
    line-height: 1.45;
  }
  .project-workspace-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
  }
  .project-workspace-label {
    display: block;
    font-size: 10px;
    color: var(--text-muted);
    margin: 8px 0 4px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }
  .project-prompt-input {
    width: 100%;
    min-height: 72px;
    max-height: 140px;
    resize: vertical;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-main);
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 12px;
    line-height: 1.45;
    padding: 8px;
    box-sizing: border-box;
  }
  .project-files-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px; }
  .project-file-row {
    display: flex; align-items: center; gap: 6px;
    font-size: 12px; color: var(--text-secondary);
    padding: 5px 6px; border-radius: 6px; background: transparent;
  }
  .project-file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .project-file-remove {
    border: none; background: transparent; color: var(--text-muted);
    cursor: pointer; font-size: 14px; line-height: 1; padding: 0 2px;
  }
  .project-file-remove:hover { color: var(--text-primary); }
  .project-workspace-actions { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
  .project-action-btn {
    width: 100%; border: 1px solid var(--border); background: transparent;
    color: var(--text-secondary); border-radius: 9px; padding: 9px 12px;
    font-size: 12.5px; cursor: pointer; text-align: left;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
  }
  .project-action-btn:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--border-strong); }
  .project-action-btn.primary {
    background: var(--text-primary); color: var(--bg-surface); border: 1px solid var(--text-primary);
    text-align: center; font-weight: 600;
    transition: opacity 0.15s, transform 0.12s;
  }
  .project-action-btn.primary:hover { background: var(--text-primary); opacity: 0.9; transform: translateY(-1px); }

  .auth-menu {
    display: none;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md, 12px);
    padding: 8px;
    min-width: 168px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.35);
    z-index: 10050;
  }
  .auth-menu button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 10px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
  }
  .auth-menu button:hover { background: var(--bg-hover); }
  .auth-menu-btn { display: flex !important; align-items: center; gap: 9px; }
  .auth-menu-btn svg { width: 15px; height: 15px; flex-shrink: 0; color: var(--text-muted); }
  .auth-menu-btn:hover svg { color: var(--text-primary); }
  .auth-menu-email {
    font-size: 11px;
    color: var(--text-muted);
    padding: 4px 10px 8px;
    word-break: break-all;
  }
  .normative-cite { color: var(--link); cursor: pointer; text-decoration: underline; }
  .citation-link {
    color: var(--link) !important;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
  }
  .citation-link:hover { opacity: 0.85; }
  .sources-list .citation-link { display: block; }

  .practice-match-banner details { margin-top: 8px; }
  .practice-match-banner summary {
    cursor: pointer;
    font-weight: 500;
    font-size: 13px;
    color: var(--text-primary);
    list-style: none;
  }
  .practice-match-banner summary::-webkit-details-marker { display: none; }

  .pii-workspace {
    display: none; position: fixed; inset: 0; z-index: 10000;
    flex-direction: column; background: var(--bg-page);
    font-family: var(--font-ui);
  }
  .pii-workspace.open { display: flex; }
  body.pii-workspace-open { overflow: hidden; }

  .pii-bar {
    display: flex; align-items: center; gap: 20px;
    padding: 16px 24px; flex-shrink: 0;
    border-bottom: 1px solid var(--border);
  }
  .pii-back {
    justify-self: start; display: inline-flex; align-items: center; gap: 6px;
    background: transparent; border: none; padding: 6px 12px; border-radius: 10px;
    cursor: pointer; font-size: 13px; color: var(--text-muted); font-family: inherit;
    transition: background 0.15s, color 0.15s;
  }
  .pii-back:hover { color: var(--text-primary); background: var(--bg-hover); }
  .pii-back svg { width: 14px; height: 14px; opacity: 0.75; }
  .pii-bar-headline {
    display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; min-width: 0;
  }
  .pii-bar-title {
    margin: 0; font-size: 20px; font-weight: 600; color: var(--text-primary);
    letter-spacing: -0.02em; white-space: nowrap;
  }
  .pii-bar-count {
    font-size: 18px; font-weight: 500; color: var(--text-muted);
    letter-spacing: -0.01em; white-space: nowrap;
  }
  .pii-bar-count:empty { display: none; }

  .pii-foot {
    flex-shrink: 0; border-top: 1px solid var(--border);
    padding: 14px 24px 18px; background: var(--bg-surface);
  }
  .pii-foot-hint {
    margin: 0 0 14px; font-size: 14px; line-height: 1.55;
    color: var(--text-muted); text-align: center;
  }
  .pii-foot-actions {
    display: flex; align-items: center; justify-content: center;
    gap: 8px; flex-wrap: wrap;
  }
  .pii-foot-btn {
    display: inline-flex; align-items: center; gap: 8px;
    font-size: 13px; font-weight: 500; color: var(--text-secondary);
    padding: 9px 16px; border-radius: 11px; cursor: pointer;
    background: var(--bg-elevated); border: 1px solid var(--border-strong); font-family: inherit;
    transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s, transform 0.12s;
    user-select: none; white-space: nowrap;
  }
  .pii-foot-btn:hover { background: var(--bg-hover); border-color: var(--accent-muted); color: var(--text-primary); transform: translateY(-1px); }
  .pii-foot-btn svg { width: 16px; height: 16px; flex-shrink: 0; stroke: currentColor; fill: none; }
  .pii-foot-btn input { display: none; }
  .pii-foot-btn.active { background: var(--bg-active); border-color: var(--accent-muted); color: var(--text-primary); }
  .pii-foot-btn.solid {
    background: var(--text-primary); color: var(--bg-surface); border-color: transparent;
    font-weight: 600; padding: 9px 20px; border-radius: 11px;
  }
  .pii-foot-btn.solid:hover { opacity: 0.9; background: var(--text-primary); border-color: transparent; }
  .pii-foot-btn:disabled { opacity: 0.28; cursor: not-allowed; pointer-events: none; }
  .pii-foot-status {
    margin: 10px 0 0; font-size: 12px; color: var(--text-faint);
    text-align: center; min-height: 16px;
  }

  .pii-body { display: flex; flex: 1; min-height: 0; overflow: hidden; }
  .pii-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
  .pii-doc-scroll {
    flex: 1; overflow-y: auto; padding: 32px 24px 48px;
  }
  .pii-doc-column {
    position: relative;
    max-width: 680px; margin: 0 auto;
    font-size: 15px; line-height: 1.7; color: var(--text-primary);
  }
  .pii-doc-column.pii-doc-column-wide { max-width: none; width: 100%; }
  .pii-doc-rich-wrap {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px 10px 32px;
    overflow-x: auto;
  }
  .pii-doc-rich-wrap.pii-rich-preview .pii-rich-mark {
    background: transparent !important;
    box-shadow: none !important;
    cursor: default;
    text-decoration: none;
  }
  .pii-doc-rich-style {
    position: absolute; width: 0; height: 0; overflow: hidden;
    clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
  }
  .pii-doc-rich-body {
    margin: 0 auto;
    font-family: var(--font-ui);
    font-size: 15px;
    line-height: 1.65;
    color: var(--text-primary);
  }
  .pii-doc-rich-body .docx-pii-wrapper {
    margin: 0 auto;
    padding: 0;
    background: transparent;
    font-family: var(--font-ui) !important;
  }
  .pii-doc-rich-body .docx-pii-wrapper > section.docx-pii {
    margin: 0 auto 18px;
    background: var(--bg-surface) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
    padding: 36px 44px !important;
    max-width: 820px;
  }
  .pii-doc-rich-body .docx-pii-wrapper > section.docx-pii:last-child {
    margin-bottom: 0;
  }
  .pii-doc-rich-body .docx-pii,
  .pii-doc-rich-body .docx-pii * {
    font-family: var(--font-ui) !important;
  }
  .pii-doc-rich-body .docx-pii p,
  .pii-doc-rich-body .docx-pii span,
  .pii-doc-rich-body .docx-pii li {
    color: inherit;
  }
  .pii-doc-rich-body .docx-pii h1,
  .pii-doc-rich-body .docx-pii h2,
  .pii-doc-rich-body .docx-pii h3,
  .pii-doc-rich-body .docx-pii h4 {
    color: var(--text-primary);
    font-weight: 600;
    letter-spacing: -0.02em;
    margin: 1.1em 0 0.5em;
  }
  .pii-doc-rich-body .docx-pii table {
    border-collapse: collapse;
    width: 100%;
    margin: 12px 0;
    font-size: 14px;
  }
  .pii-doc-rich-body .docx-pii td,
  .pii-doc-rich-body .docx-pii th {
    border: 1px solid var(--border);
    padding: 8px 10px;
    vertical-align: top;
  }
  .pii-doc-rich-body .docx-int-link,
  .pii-doc-rich-body .docx-pii a {
    color: var(--link);
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
  }
  .pii-doc-rich-body .docx-int-link:hover,
  .pii-doc-rich-body .docx-pii a:hover {
    opacity: 0.85;
  }
  .pii-doc-rich-body .docx-pii sup,
  .pii-doc-rich-body .docx-pii .docx-footnote-ref {
    font-size: 0.75em;
    vertical-align: super;
    line-height: 0;
  }
  .pii-doc-rich-body .docx-pii [id],
  .pii-doc-rich-body .docx-pii a[name] {
    scroll-margin-top: 80px;
  }
  .pii-doc-rich-wrap {
    scroll-behavior: smooth;
  }
  .pii-doc-rich-body .docx-math-el,
  .pii-doc-rich-body math {
    font-size: 1.05em;
    color: var(--text-primary);
  }
  .pii-doc-rich-body .docx-pii img {
    max-width: 100%;
    height: auto;
  }
  [data-theme="light"] .pii-doc-rich-wrap {
    background: var(--bg-surface);
    border-color: var(--border);
  }
  [data-theme="light"] .pii-doc-rich-body .docx-pii-wrapper > section.docx-pii {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    border-color: var(--border-strong);
    background: #fafafa !important;
  }
  .pii-doc-rich-body .pii-rich-mark {
    cursor: pointer;
    border-radius: 2px;
    padding: 0;
    margin: 0;
    transition: background 0.12s, box-shadow 0.12s;
    background: rgba(255, 193, 7, 0.22);
    box-shadow: inset 0 -2px 0 rgba(251, 191, 36, 0.75);
    font: inherit;
    font-family: inherit !important;
    font-size: inherit !important;
    font-weight: inherit !important;
    font-style: inherit !important;
    line-height: inherit !important;
    letter-spacing: inherit !important;
    text-decoration: inherit;
    color: inherit !important;
    vertical-align: baseline;
  }
  .pii-doc-rich-body .pii-rich-mark:hover {
    background: rgba(255, 193, 7, 0.34);
  }
  .pii-doc-rich-body .pii-rich-mark.pii-cat-person { box-shadow: inset 0 -2px 0 rgba(59, 130, 246, 0.75); background: rgba(147, 197, 253, 0.28); }
  .pii-doc-rich-body .pii-rich-mark.pii-cat-contact { box-shadow: inset 0 -2px 0 rgba(245, 158, 11, 0.8); background: rgba(251, 191, 36, 0.28); }
  .pii-doc-rich-body .pii-rich-mark.pii-cat-id { box-shadow: inset 0 -2px 0 rgba(249, 115, 22, 0.8); background: rgba(251, 146, 60, 0.24); }
  .pii-doc-rich-body .pii-rich-mark.pii-cat-location { box-shadow: inset 0 -2px 0 rgba(34, 197, 94, 0.75); background: rgba(74, 222, 128, 0.22); }
  .pii-doc-rich-body .pii-rich-mark.pii-cat-amount { box-shadow: inset 0 -2px 0 rgba(168, 85, 247, 0.75); background: rgba(192, 132, 252, 0.22); }
  .pii-doc-rich-body .pii-rich-mark.pii-cat-bank { box-shadow: inset 0 -2px 0 rgba(236, 72, 153, 0.75); background: rgba(244, 114, 182, 0.22); }
  .pii-doc-rich-body .pii-rich-mark.pii-rejected {
    opacity: 0.45; text-decoration: line-through; box-shadow: none;
    background: rgba(0, 0, 0, 0.06);
  }
  .pii-attach-warn-overlay {
    display: none; position: fixed; inset: 0; z-index: 10005;
    background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(4px);
    align-items: center; justify-content: center; padding: 24px;
  }
  .pii-attach-warn-overlay.open { display: flex; }
  .pii-attach-warn-card {
    width: min(420px, 100%);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
    overflow: hidden;
    animation: piiWarnIn 0.22s ease-out;
  }
  @keyframes piiWarnIn {
    from { opacity: 0; transform: translateY(10px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
  }
  .pii-attach-warn-head {
    padding: 22px 22px 0;
    display: flex; gap: 14px; align-items: flex-start;
  }
  .pii-attach-warn-icon {
    width: 40px; height: 40px; flex-shrink: 0;
    border-radius: 12px;
    background: rgba(255, 193, 7, 0.14);
    color: #e6a817;
    display: flex; align-items: center; justify-content: center;
  }
  .pii-attach-warn-icon svg { width: 20px; height: 20px; stroke: currentColor; fill: none; }
  .pii-attach-warn-title {
    margin: 0 0 6px; font-size: 17px; font-weight: 500;
    color: var(--text-primary); letter-spacing: -0.02em;
  }
  .pii-attach-warn-text {
    margin: 0; font-size: 14px; line-height: 1.55; color: var(--text-muted);
  }
  .pii-attach-warn-body { padding: 14px 22px 20px; }
  .pii-attach-warn-tip {
    margin: 0; padding: 12px 14px; border-radius: 10px;
    background: var(--bg-elevated); border: 1px solid var(--border);
    font-size: 13px; line-height: 1.5; color: var(--text-secondary);
  }
  .pii-attach-warn-actions {
    display: flex; gap: 10px; padding: 0 22px 22px;
  }
  .pii-attach-warn-actions .btn { flex: 1; text-align: center; padding: 10px 14px; border-radius: 12px; }
  .pii-attach-warn-actions .btn-warn {
    background: rgba(255, 193, 7, 0.16);
    color: #e6a817;
    border: 1px solid rgba(255, 193, 7, 0.35);
  }
  .pii-attach-warn-actions .btn-warn:hover { background: rgba(255, 193, 7, 0.24); }
  .pii-doc-empty {
    text-align: center; padding: 80px 24px; color: var(--text-faint); font-size: 13px;
    line-height: 1.6;
  }
  #piiDocSurface { white-space: pre-wrap; word-break: break-word; outline: none; min-height: 120px; }
  #piiDocEdit {
    width: 100%; min-height: 100%; padding: 0; border: none; outline: none;
    background: transparent; color: var(--text-primary);
    font-family: inherit; font-size: 15px; line-height: 1.7; resize: none;
    display: block; white-space: pre-wrap; word-break: break-word;
  }
  .pii-doc-plain { white-space: pre-wrap; }
  .pii-span {
    cursor: pointer; border-radius: 2px; padding: 0 1px;
    background: rgba(255, 255, 255, 0.05);
    box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.18);
    transition: background 0.12s;
  }
  .pii-span:hover { background: rgba(255, 255, 255, 0.1); }
  .pii-cat-person { box-shadow: inset 0 -1px 0 rgba(147, 197, 253, 0.45); }
  .pii-cat-contact { box-shadow: inset 0 -1px 0 rgba(251, 191, 36, 0.45); }
  .pii-cat-id { box-shadow: inset 0 -1px 0 rgba(251, 146, 60, 0.45); }
  .pii-cat-location { box-shadow: inset 0 -1px 0 rgba(74, 222, 128, 0.4); }
  .pii-cat-amount { box-shadow: inset 0 -1px 0 rgba(192, 132, 252, 0.4); }
  .pii-cat-bank { box-shadow: inset 0 -1px 0 rgba(244, 114, 182, 0.4); }
  .pii-rejected { opacity: 0.35; text-decoration: line-through; box-shadow: none; }
  .pii-mask-token {
    font-family: ui-monospace, 'SF Mono', monospace; font-size: 0.88em;
    color: var(--text-muted); letter-spacing: -0.02em;
  }
  .pii-preview-mode { color: var(--text-secondary); }
  .stream-tail {
    color: var(--text-muted);
    opacity: 0.72;
  }
  .stream-cursor::after {
    content: '';
    display: inline-block;
    width: 2px;
    height: 1.05em;
    margin-left: 1px;
    vertical-align: text-bottom;
    background: var(--text-muted);
    opacity: 0.55;
    animation: streamCaretBlink 1.05s step-end infinite;
  }
  @keyframes streamCaretBlink {
    50% { opacity: 0; }
  }
  .stream-table-partial {
    opacity: 1;
  }
  .message-assistant-text.is-streaming-active .citation-link {
    pointer-events: auto;
    cursor: pointer;
  }

  .pii-aside {
    width: 248px; flex-shrink: 0; display: flex; flex-direction: column;
    border-left: 1px solid var(--border); min-height: 0;
  }
  .pii-aside-head {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 14px 16px 12px; flex-shrink: 0;
  }
  .pii-aside-label {
    font-size: 10px; font-weight: 600; letter-spacing: 0.08em;
    text-transform: uppercase; color: var(--text-faint);
  }
  .pii-filter-wrap { position: relative; flex-shrink: 0; }
  .pii-filter-trigger {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 12px; color: var(--text-muted); cursor: pointer;
    padding: 6px 10px; border-radius: 12px; border: 1px solid #2a2a2a;
    background: #1a1a1a; font-family: inherit;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
  }
  .pii-filter-trigger:hover { background: #222; border-color: #3a3a3a; color: var(--text-primary); }
  .pii-filter-trigger.active { background: #222; border-color: #444; color: var(--text-primary); }
  .pii-filter-trigger svg {
    width: 12px; height: 12px; opacity: 0.6; transition: transform 0.2s;
  }
  .pii-filter-trigger.active svg { transform: rotate(180deg); }
  .pii-filter-menu {
    position: absolute; top: calc(100% + 6px); right: 0; min-width: 148px;
    background: #1a1a1a; border: 1px solid #2a2a2a; border-radius: 12px;
    padding: 4px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    display: none; z-index: 20;
  }
  .pii-filter-menu.show { display: block; }
  .pii-filter-opt {
    padding: 8px 12px; border-radius: 8px; font-size: 12px;
    color: var(--text-secondary); cursor: pointer;
    transition: background 0.15s, color 0.15s;
  }
  .pii-filter-opt:hover { background: #252525; color: var(--text-primary); }
  .pii-filter-opt.active { background: #252525; color: var(--text-primary); font-weight: 500; }
  #piiSidebarList { flex: 1; overflow-y: auto; min-height: 0; }
  .pii-sidebar-empty {
    padding: 20px 16px; font-size: 12px; line-height: 1.55; color: var(--text-faint);
  }
  .pii-hit-item {
    display: flex; align-items: flex-start; gap: 10px; width: 100%;
    padding: 11px 16px; border: none; border-top: 1px solid var(--border);
    background: transparent; text-align: left; cursor: pointer; font-family: inherit;
    transition: background 0.12s;
  }
  .pii-hit-item:hover { background: var(--bg-hover); }
  .pii-hit-dot {
    width: 6px; height: 6px; border-radius: 50%; margin-top: 6px; flex-shrink: 0;
    background: var(--text-faint);
  }
  .pii-hit-item.cat-person .pii-hit-dot { background: rgba(147, 197, 253, 0.8); }
  .pii-hit-item.cat-contact .pii-hit-dot { background: rgba(251, 191, 36, 0.8); }
  .pii-hit-item.cat-id .pii-hit-dot { background: rgba(251, 146, 60, 0.8); }
  .pii-hit-item.cat-location .pii-hit-dot { background: rgba(74, 222, 128, 0.7); }
  .pii-hit-item.cat-amount .pii-hit-dot { background: rgba(192, 132, 252, 0.7); }
  .pii-hit-item.cat-bank .pii-hit-dot { background: rgba(244, 114, 182, 0.7); }
  .pii-hit-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
  .pii-hit-type { font-size: 10px; color: var(--text-faint); letter-spacing: 0.04em; margin-bottom: 3px; display: block; }
  .pii-hit-text {
    font-size: 12px; color: var(--text-secondary); line-height: 1.45;
    word-break: break-word; display: block;
  }

  .pii-selection-toolbar {
    position: fixed; z-index: 10002; display: none; align-items: center; gap: 2px;
    padding: 4px; background: #1a1a1a; border: 1px solid #2a2a2a;
    border-radius: 14px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
  }
  .pii-sel-btn {
    border: none; background: transparent; color: var(--text-muted);
    font-size: 12px; padding: 6px 12px; border-radius: 10px; cursor: pointer;
    font-family: inherit; transition: color 0.12s, background 0.12s;
  }
  .pii-sel-btn:hover { color: var(--text-primary); background: #252525; }

  [data-theme="light"] .pii-foot-btn,
  [data-theme="light"] .pii-filter-trigger,
  [data-theme="light"] .pii-filter-menu,
  [data-theme="light"] .pii-selection-toolbar {
    background: var(--input-bg); border-color: var(--input-border);
  }
  [data-theme="light"] .pii-foot-btn:hover,
  [data-theme="light"] .pii-foot-btn.active,
  [data-theme="light"] .pii-filter-trigger:hover,
  [data-theme="light"] .pii-filter-trigger.active {
    background: var(--bg-hover); border-color: var(--border-strong);
  }
  [data-theme="light"] .pii-filter-menu { box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12); }
  [data-theme="light"] .pii-filter-opt:hover,
  [data-theme="light"] .pii-filter-opt.active { background: var(--bg-hover); }
  [data-theme="light"] .pii-sel-btn:hover { background: var(--bg-hover); }
  [data-theme="light"] .pii-span {
    background: rgba(0, 0, 0, 0.04);
    box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.12);
  }
  [data-theme="light"] .pii-span:hover { background: rgba(0, 0, 0, 0.07); }
  @media (max-width: 860px) {
    .pii-aside { width: 200px; }
    .pii-bar { padding: 0 16px; }
    .pii-doc-scroll { padding: 24px 16px 40px; }
    .pii-bar-title { font-size: 17px; }
    .pii-bar-count { font-size: 15px; }
    .pii-foot { padding: 12px 16px 16px; }
  }
  @media (max-width: 640px) {
    .pii-aside { display: none; }
  }
  .new-project-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

  .sidebar-scroll {
    overflow-y: hidden;
    overflow-x: hidden;
    flex: 1;
    min-height: 0;
    width: 100%;
    scrollbar-width: none;
    padding: 0;
    display: flex;
    flex-direction: column;
  }
  .sidebar:not(.expanded) .sidebar-section-body {
    display: none;
  }
  .sidebar.expanded .sidebar-scroll {
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
  }
  .sidebar-section-block {
    width: 100%;
  }
  .sidebar-section-body {
    padding: 0 0 4px;
    transition: opacity 0.18s ease;
  }
  .sidebar-section.collapsed .sidebar-section-body {
    display: none;
  }
  .sidebar.expanded .sidebar-scroll::-webkit-scrollbar { width: 6px; }
  .sidebar.expanded .sidebar-scroll::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 6px;
  }
  .sidebar-scroll::-webkit-scrollbar { width: 0; height: 0; }

  .sidebar-bottom {
    position: relative;
    margin-top: auto;
    width: 100%;
    padding: 8px 6px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    align-items: center;
  }
  .sidebar.expanded .sidebar-bottom { align-items: flex-start; }

  .expand-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 7px;
    cursor: pointer;
    color: var(--text-muted);
    border: none;
    background: transparent;
    border-radius: 8px;
    transition: background var(--motion-fast), color var(--motion-fast);
    width: 32px;
    height: 32px;
  }
  .expand-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

  .avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #6b21a8;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 4px;
  }

  /* ─── MAIN ── */
  .main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
  }

  /* ─── TOPBAR ─── */
  .topbar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 10px 18px;
    gap: 8px;
    position: absolute;
    top: 0; right: 0;
    z-index: 5;
  }
  .topbar-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #999;
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 8px;
    transition: background 0.15s, color 0.15s;
  }
  .topbar-btn:hover { background: #1a1a1a; color: #fff; }
  .topbar-btn svg { width: 15px; height: 15px; }

  /* ─── VIEWS ─── */
  .view { display: none; flex: 1; flex-direction: column; overflow: hidden; }
  .view.active { display: flex; }

  /* HOME: logo + input centered together */
  .home-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 28px;
    margin-top: -15vh;
  }

  .Protocol-logo {
    display: flex;
    align-items: center;
    gap: 18px;
    font-size: 56px;
    font-weight: 500;
    letter-spacing: -0.3px;
    color: var(--logo-fill);
  }
  .Protocol-logo span {
    color: var(--text-primary);
    text-transform: capitalize;
    transform: translateY(0.14em);
  }

  .Protocol-logo svg {
    color: var(--logo-fill);
    height: 96px;
    width: auto;
    flex-shrink: 0;
  }

  /* Планшеты */
  @media (max-width: 1024px) {
    .Protocol-logo svg {
      height: 72px;
    }
    .Protocol-logo {
      font-size: 44px;
    }
  }

  /* Мобильные */
  @media (max-width: 768px) {
    .Protocol-logo svg {
      height: 56px;
    }
    .Protocol-logo {
      font-size: 34px;
    }
  }

  /* Маленькие мобильные */
  @media (max-width: 480px) {
    .Protocol-logo svg {
      height: 46px;
    }
    .Protocol-logo {
      font-size: 28px;
      gap: 12px;
    }
  }

  /* Input bar shared styles */
  .input-bar {
    display: flex;
    align-items: center;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius-xl);
    padding: 7px 12px;
    gap: 8px;
    width: 100%;
    max-width: 700px;
    transition: border-color var(--motion-fast) var(--ease-out), background var(--motion-fast), box-shadow var(--motion-fast);
    position: relative;
    overflow: visible;
  }
  .input-bar:focus-within { border-color: var(--input-focus-border); }

  /* Home input wrapper — centered in page */
  .home-input-wrapper {
    width: 100%;
    max-width: 740px;
    padding: 0 20px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  /* ─── CHAT ─── */
  .chat-layout {
    flex: 1;
    display: flex;
    min-height: 0;
    overflow: hidden;
    position: relative;
  }
  .chat-area-shell {
    flex: 1;
    position: relative;
    min-height: 0;
    display: flex;
    min-width: 0;
  }
  .chat-area {
    flex: 1;
    overflow-y: auto;
    scroll-behavior: auto;
    padding: 64px 36px 16px 20px;
    min-width: 0;
  }
  .chat-nav-rail-wrap {
    position: absolute;
    right: 4px;
    top: 0;
    bottom: 0;
    width: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    z-index: 4;
  }
  .chat-nav-rail-wrap.is-empty { display: none; }
  .chat-nav-rail {
    position: static;
    right: auto;
    top: auto;
    bottom: auto;
    height: max-content;
    max-height: calc(100% - 24px);
    margin: 0;
    width: 26px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    pointer-events: auto;
  }
  .chat-nav-rail.is-empty { display: none; }
  .chat-nav-rail > * { pointer-events: auto; }
  .chat-nav-rail-wrap:hover .chat-nav-arrow,
  .chat-nav-rail-wrap:focus-within .chat-nav-arrow {
    opacity: 1;
    transform: scale(1);
  }
  .chat-nav-rail-wrap:hover .chat-nav-arrow:disabled,
  .chat-nav-rail-wrap:focus-within .chat-nav-arrow:disabled {
    opacity: 0.28;
    cursor: default;
  }
  .chat-nav-arrow {
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border-radius: 5px;
    flex-shrink: 0;
    opacity: 0;
    visibility: visible;
    transform: scale(0.9);
    transition: opacity 0.18s ease, transform 0.18s ease, color 0.12s, background 0.12s;
  }
  .chat-nav-arrow svg { width: 14px; height: 14px; stroke: currentColor; fill: none; }
  .chat-nav-arrow:hover:not(:disabled) { color: var(--text-primary); background: var(--bg-hover); }
  .chat-nav-track {
    flex: 0 0 auto;
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 5px 0;
  }
  .chat-nav-marks {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    padding: 1px 0;
    max-height: min(52vh, 360px);
    overflow-y: auto;
    scrollbar-width: none;
  }
  .chat-nav-marks::-webkit-scrollbar { width: 0; height: 0; }
  .chat-nav-mark {
    position: relative;
    width: 26px;
    height: 10px;
    min-height: 10px;
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
    background: transparent;
    opacity: 1;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    border-radius: 3px;
  }
  .chat-nav-mark::before {
    content: '';
    display: block;
    height: 1px;
    background: var(--text-muted);
    opacity: 0.7;
    flex-shrink: 0;
    transition: background 0.16s ease, opacity 0.16s ease, width 0.16s ease, height 0.16s ease;
  }
  .chat-nav-mark.user::before { width: 8px; }
  .chat-nav-mark.assistant::before { width: 14px; }
  .chat-nav-mark.current::before {
    height: 2px;
    opacity: 0.95;
    background: var(--text-primary);
  }
  .chat-nav-mark:hover::before {
    background: var(--text-primary);
    opacity: 1;
  }
  .chat-nav-mark.user:hover::before { width: 11px; }
  .chat-nav-mark.assistant:hover::before { width: 19px; }
  .chat-nav-mark.current.user::before { width: 9px; }
  .chat-nav-mark.current.assistant::before { width: 16px; }
  .chat-nav-mark.current.user:hover::before { width: 12px; }
  .chat-nav-mark.current.assistant:hover::before { width: 21px; }
  .chat-nav-preview {
    position: fixed;
    z-index: 10020;
    width: max-content;
    max-width: 280px;
    min-width: 200px;
    padding: 10px 14px;
    border-radius: 14px;
    background: color-mix(in srgb, var(--text-muted) 16%, var(--bg-elevated));
    border: 1px solid color-mix(in srgb, var(--border-strong) 70%, transparent);
    color: var(--text-primary);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.12s ease;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.22);
  }
  .chat-nav-preview-label {
    font-size: 11px;
    line-height: 1.2;
    color: var(--text-muted);
    margin-bottom: 5px;
  }
  .chat-nav-preview-body {
    font-size: 12px;
    line-height: 1.45;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    white-space: normal;
    word-break: break-word;
  }
  .chat-nav-preview.is-plain .chat-nav-preview-body {
    -webkit-line-clamp: 1;
  }
  .chat-nav-preview.visible {
    opacity: 1;
  }
  .message-user.chat-nav-highlight .message-user-bubble,
  .message-assistant.chat-nav-highlight .message-assistant-col {
    box-shadow: 0 0 0 1px var(--border-strong);
    border-radius: 12px;
  }
  .messages-view {
    display: flex;
    flex-direction: column;
    max-width: 740px;
    margin: 0 auto;
    width: 100%;
  }

  .message-user {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 16px;
  }
  .message-user-bubble {
    background: var(--bg-bubble);
    border: 1px solid var(--border-strong);
    border-radius: 16px;
    padding: 11px 16px;
    font-size: 14px;
    max-width: 68%;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
  }

  .message-assistant {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    align-items: flex-start;
  }
  .assistant-icon {
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
    color: var(--text-primary);
  }
  .protocol-avatar { width: 26px; height: 26px; display: block; }
  .protocol-avatar .orb { transform-origin: center; }
  .protocol-avatar.is-thinking .orb-p1 { animation: orbImpulse 1.5s ease-in-out infinite; transform-origin: 7px 5px; }
  .protocol-avatar.is-thinking .orb-p2 { animation: orbImpulse 1.5s ease-in-out 0.25s infinite; transform-origin: 13px 5px; }
  .protocol-avatar.is-thinking .orb-p3 { animation: orbImpulse 1.5s ease-in-out 0.5s infinite; transform-origin: 15px 9px; }
  .protocol-avatar.is-thinking .orb-p4 { animation: orbImpulse 1.5s ease-in-out 0.75s infinite; transform-origin: 12px 13px; }
  .protocol-avatar.is-thinking .orb-p5 { animation: orbImpulse 1.5s ease-in-out 1s infinite; transform-origin: 7px 13px; }
  .protocol-avatar.is-thinking .orb-p6 { animation: orbImpulse 1.5s ease-in-out 1.25s infinite; transform-origin: 7px 21px; }
  .protocol-avatar.is-thinking .orb-link-1 { animation: linkPulse 1.5s ease-in-out 0.12s infinite; }
  .protocol-avatar.is-thinking .orb-link-2 { animation: linkPulse 1.5s ease-in-out 0.37s infinite; }
  .protocol-avatar.is-thinking .orb-link-3 { animation: linkPulse 1.5s ease-in-out 0.62s infinite; }
  .protocol-avatar.is-thinking .orb-link-4 { animation: linkPulse 1.5s ease-in-out 0.87s infinite; }
  .protocol-avatar.is-thinking .orb-link-5 { animation: linkPulse 1.5s ease-in-out 1.12s infinite; }
  .protocol-avatar.is-streaming .orb-p1,
  .protocol-avatar.is-streaming .orb-p2,
  .protocol-avatar.is-streaming .orb-p3,
  .protocol-avatar.is-streaming .orb-p4,
  .protocol-avatar.is-streaming .orb-p5,
  .protocol-avatar.is-streaming .orb-p6 {
    animation: orbImpulse 1.4s ease-in-out infinite;
  }
  .message-assistant-text.is-streaming-active .md-rendered {
    white-space: normal;
    word-break: break-word;
    line-height: 1.65;
    color: var(--text-secondary);
    min-height: 1.65em;
    contain: layout style;
  }
  .message-assistant-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding-top: 3px;
  }
  .message-assistant-text {
    font-size: 14px;
    line-height: 1.65;
    color: var(--text-secondary);
    word-break: break-word;
    min-width: 0;
  }
  /* В светлой теме текст ответа делаем почти чёрным (был сероватый), +чуть темнее muted-подписи/кнопки. */
  [data-theme="light"] { --text-muted: #585858; --text-faint: #6e6e6e; }
  [data-theme="light"] .message-assistant-text,
  [data-theme="light"] .message-assistant-text .md-rendered { color: #161616; }
  .message-assistant-text .md-rendered {
    display: block;
    min-width: 0;
  }
  .message-assistant-text .table-wrap {
    overflow-x: hidden;
    max-width: 100%;
    margin: 12px 0;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-surface);
  }
  .message-assistant-text table.md-table {
    border-collapse: collapse;
    table-layout: fixed;
    width: 100%;
    max-width: 100%;
    font-size: 13px;
  }
  .message-assistant-text table.md-table th {
    border: 1px solid var(--table-border);
    padding: 6px 10px;
    vertical-align: middle;
    text-align: left;
    white-space: normal;
    word-break: break-word;
    min-width: 0;
    font-size: 12px;
    background: var(--table-header-bg);
    color: var(--text-primary);
    font-weight: 600;
  }
  .message-assistant-text table.md-table td {
    border: 1px solid var(--table-border);
    padding: 6px 10px;
    vertical-align: top;
    text-align: left;
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
    overflow: visible;
    text-overflow: unset;
    max-width: none;
    min-width: 0;
    color: var(--text-secondary);
  }
  .reply-extras {
    width: 100%;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--border-soft);
    flex-shrink: 0;
  }
  .message-assistant-text h2,
  .message-assistant-text h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 12px 0 6px;
  }
  .message-assistant-text h2:first-child,
  .message-assistant-text h3:first-child { margin-top: 0; }
  .message-assistant-text p { margin: 0 0 8px; }
  .message-assistant-text ul, .message-assistant-text ol {
    margin: 0 0 8px;
    padding-left: 1.25em;
  }
  .message-assistant-text a { color: var(--link); text-decoration: underline; }
  .message-assistant-text code {
    background: #1a1a1a;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 13px;
  }
  .corpus-hint, .sources-hint, .model-hint {
    font-size: 12px;
    color: #666;
    margin-top: 8px;
    line-height: 1.45;
    font-style: italic;
  }
  .sources-hint a { color: var(--link); }
  .theme-toggle-btn { margin-left: 4px; }

  .thinking-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 6px;
    min-height: 20px;
    transition: opacity 0.25s ease;
  }
  .thinking-row.is-fading { opacity: 0; }
  .thinking-row .ui-status-text { flex: 0 1 auto; }
  /* Thinking dots */
  .thinking-dots {
    display: flex;
    gap: 4px;
    align-items: center;
    padding-top: 6px;
  }
  .thinking-dots.inline {
    padding-top: 0;
    flex-shrink: 0;
  }
  .thinking-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: #555;
    animation: blink 1.2s ease-in-out infinite;
  }
  .thinking-dot:nth-child(2) { animation-delay: 0.2s; }
  .thinking-dot:nth-child(3) { animation-delay: 0.4s; }
  @keyframes blink {
    0%, 80%, 100% { opacity: 0.2; transform: scale(0.85); }
    40% { opacity: 1; transform: scale(1); }
  }

  .no-answer {
    font-size: 13px;
    color: #444;
    font-style: italic;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding-left: 38px;
  }

  .error-box {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #0e0e0e;
    border: 1px solid #252525;
    border-radius: 10px;
    padding: 14px 16px;
    max-width: 560px;
    margin-left: 38px;
  }
  .error-box svg { color: #d97706; width: 17px; height: 17px; flex-shrink: 0; }
  .error-text { flex: 1; }
  .error-title { font-size: 13px; font-weight: 500; color: #d0d0d0; margin-bottom: 3px; }
  .error-sub { font-size: 12px; color: #555; }

  .retry-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #1a1a1a;
    border: 1px solid #303030;
    border-radius: 8px;
    padding: 7px 13px;
    font-size: 13px;
    color: #bbb;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
  }
  .retry-btn:hover { background: #222; color: #fff; }
  .retry-btn svg { width: 13px; height: 13px; }

  /* ─── BOTTOM INPUT (chat mode) ─── */
  .input-wrapper {
    padding: 0 20px 22px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    max-width: 740px;
    margin: 0 auto;
    width: 100%;
    position: relative;
    z-index: 40;
    overflow: visible;
    flex-shrink: 0;
  }

  .attach-menu-wrap {
    position: relative;
    flex-shrink: 0;
  }
  .attach-menu {
    display: none;
    position: absolute;
    left: 0;
    bottom: calc(100% + 10px);
    min-width: 240px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    padding: 6px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
    z-index: 120;
  }
  .attach-menu.show { display: block; }
  .attach-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    transition: background 0.15s, color 0.15s;
  }
  .attach-menu-item:hover { background: var(--bg-hover); color: var(--text-primary); }
  .attach-menu-item svg { width: 16px; height: 16px; flex-shrink: 0; stroke: currentColor; fill: none; }
  .attach-menu-gen-wrap {
    position: relative;
  }
  .attach-gen-flyout {
    display: none;
    position: absolute;
    left: calc(100% + 6px);
    top: 0;
    min-width: 120px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    padding: 4px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
    z-index: 130;
  }
  .attach-menu-gen-wrap:hover .attach-gen-flyout,
  .attach-menu-gen-wrap:focus-within .attach-gen-flyout { display: block; }
  .attach-gen-opt {
    display: block;
    width: 100%;
    padding: 8px 12px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
  }
  .attach-gen-opt:hover { background: var(--bg-hover); color: var(--text-primary); }
  .attachment-chip-generate {
    border-style: dashed;
    color: var(--text-muted);
  }
  .attachment-chip-generate.is-ready {
    border-style: solid;
    color: var(--text-sec);
  }

  /* shared input parts */
  .input-plus {
    width: 26px; height: 26px;
    border-radius: 50%;
    border: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-primary);
    flex-shrink: 0;
    transition: background var(--motion-fast), color var(--motion-fast);
  }
  .input-plus:hover { background: var(--bg-hover); color: var(--text-primary); }

  .input-field {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--input-text);
    font-size: 14px;
    font-family: inherit;
    resize: none;
    overflow-y: auto;
    max-height: 200px;
    line-height: 1.4;
    padding: 8px 0;
    min-height: 24px;
  }
  .input-field::placeholder { color: var(--input-placeholder); }

  /* ─── MODEL SELECTOR DROPDOWN ─── */
  .model-selector-wrapper {
    position: relative;
    flex-shrink: 0;
    z-index: 50;
  }

  .model-selector {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 12px;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    font-family: inherit;
  }
  .model-selector:hover { background: var(--bg-hover); border-color: var(--border-strong); }
  .model-selector.active { background: var(--bg-hover); border-color: var(--border-strong); }
  .model-selector svg { 
    width: 14px; 
    height: 14px;
    transition: transform 0.2s;
  }
  .model-selector.active svg {
    transform: rotate(180deg);
  }
  .model-selector-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: var(--text-muted);
  }
  .model-selector-icon svg { width: 14px; height: 14px; stroke: currentColor; fill: none; }

  .model-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: auto;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    padding: 6px;
    min-width: 220px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    display: none;
    z-index: 200;
  }
  .model-dropdown.open-up {
    top: auto;
    bottom: calc(100% + 8px);
    left: 0;
  }
  .model-dropdown.show {
    display: block;
  }

  .model-option {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
  }
  .model-option:hover {
    background: var(--bg-hover);
  }
  .model-option.active {
    background: var(--bg-hover);
  }

  .model-option-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 1px;
  }
  .model-option-icon svg {
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    stroke: currentColor;
    fill: none;
  }
  .model-option.active .model-option-icon svg {
    color: var(--text-primary);
  }

  .model-option-content {
    flex: 1;
  }

  .model-option-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 2px;
  }

  .model-option-desc {
    font-size: 12px;
    color: var(--text-muted);
  }

  .model-option.active .model-option-desc {
    color: var(--text-secondary);
  }

  /* ─── Protocol modals (unified) ─── */
  .protocol-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 10005;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
    padding: 24px;
  }
  .protocol-modal-overlay.open { display: flex; }
  #historyBrowserModal { z-index: 10010; }
  .protocol-modal-overlay.confirm-on-top { z-index: 10025; }
  .protocol-modal-card {
    width: min(440px, 100%);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
    overflow: hidden;
    animation: piiWarnIn 0.22s ease-out;
    font-family: var(--font-ui);
  }
  .protocol-modal-card.wide { width: min(640px, 100%); max-height: 80vh; display: flex; flex-direction: column; }
  .protocol-modal-card.history-browser-card {
    width: min(1080px, 92vw);
    max-width: 92vw;
    height: min(760px, 86vh);
    max-height: 86vh;
    display: flex;
    flex-direction: column;
    transition: width 0.22s ease, height 0.22s ease, max-width 0.22s ease;
  }
  .protocol-modal-card.history-browser-card.preview-collapsed-mode {
    width: min(620px, 92vw);
    max-width: 92vw;
    height: min(640px, 80vh);
    max-height: 80vh;
  }
  .protocol-modal-head {
    padding: 22px 22px 0;
    display: flex;
    gap: 14px;
    align-items: flex-start;
  }
  .protocol-modal-icon {
    width: 40px; height: 40px; flex-shrink: 0;
    border-radius: 12px;
    background: rgba(255, 193, 7, 0.14);
    color: #e6a817;
    display: flex; align-items: center; justify-content: center;
  }
  .protocol-modal-icon.info { background: rgba(158, 203, 255, 0.14); color: var(--link); }
  .protocol-modal-icon svg { width: 20px; height: 20px; stroke: currentColor; fill: none; }
  .protocol-modal-title {
    margin: 0 0 6px; font-size: 17px; font-weight: 500;
    color: var(--text-primary); letter-spacing: -0.02em;
  }
  .protocol-modal-text {
    margin: 0; font-size: 14px; line-height: 1.55; color: var(--text-muted);
  }
  .protocol-modal-body { padding: 14px 22px 20px; }
  .protocol-modal-input {
    width: 100%; padding: 10px 12px; border-radius: 10px;
    border: 1px solid var(--input-border); background: var(--input-bg);
    color: var(--text-primary); font-size: 14px; font-family: inherit;
    box-sizing: border-box;
  }
  .protocol-modal-textarea {
    width: 100%; min-height: 160px; max-height: 50vh; padding: 10px 12px;
    border-radius: 10px; border: 1px solid var(--input-border);
    background: var(--input-bg); color: var(--text-primary);
    font-size: 14px; font-family: inherit; line-height: 1.45;
    resize: vertical; box-sizing: border-box;
  }
  .protocol-modal-card.protocol-confirm-card {
    width: min(400px, 100%);
    border-radius: 14px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
  }
  .protocol-modal-card.protocol-confirm-card .protocol-modal-head {
    padding: 20px 20px 0;
    gap: 12px;
    align-items: center;
  }
  .protocol-modal-card.protocol-confirm-card .protocol-modal-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: color-mix(in srgb, #e57373 12%, var(--bg-elevated));
    color: #e57373;
  }
  .protocol-modal-card.protocol-confirm-card .protocol-modal-title {
    font-size: 16px;
    margin-bottom: 4px;
  }
  .protocol-modal-card.protocol-confirm-card .protocol-modal-text {
    font-size: 13px;
    line-height: 1.5;
  }
  .protocol-modal-card.protocol-confirm-card .protocol-modal-actions {
    padding: 16px 20px 20px;
    gap: 8px;
  }
  .protocol-modal-actions .btn {
    font-size: 13px;
    font-weight: 500;
    border-radius: 10px;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
  }
  .protocol-modal-actions .btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
  }
  .protocol-modal-actions .btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
  }
  .protocol-modal-actions .btn-danger {
    background: color-mix(in srgb, #e57373 14%, var(--bg-elevated));
    color: #e57373;
    border: 1px solid color-mix(in srgb, #e57373 28%, var(--border));
  }
  .protocol-modal-actions .btn-danger:hover {
    background: color-mix(in srgb, #e57373 22%, var(--bg-elevated));
    border-color: color-mix(in srgb, #e57373 40%, var(--border));
  }
  .protocol-modal-actions {
    display: flex; gap: 10px; padding: 0 22px 22px;
  }
  .protocol-modal-card.protocol-prompt-card {
    width: min(420px, 100%);
  }
  .protocol-modal-card.protocol-prompt-card .protocol-modal-head {
    padding: 22px 22px 0;
    align-items: center;
  }
  .protocol-modal-card.protocol-prompt-card .protocol-modal-head-text {
    flex: 1;
    min-width: 0;
  }
  .protocol-modal-card.protocol-prompt-card .protocol-modal-body.protocol-prompt-body {
    padding: 16px 22px 0;
  }
  .protocol-modal-card.protocol-prompt-card .protocol-modal-actions {
    padding: 18px 22px 22px;
    gap: 10px;
    border-top: 1px solid var(--border);
    margin-top: 18px;
  }
  .protocol-modal-card.protocol-prompt-card .protocol-modal-input {
    margin: 0;
  }
  .protocol-modal-card.protocol-prompt-card .protocol-modal-input:focus {
    outline: none;
    border-color: var(--input-focus-border);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--input-focus-border) 18%, transparent);
  }
  .protocol-modal-actions .btn { flex: 1; text-align: center; padding: 10px 14px; border-radius: 12px; }
  .protocol-modal-scroll {
    padding: 20px; overflow-y: auto; flex: 1;
    font-size: 14px; line-height: 1.55; color: var(--text-primary);
    white-space: pre-wrap;
  }
  .protocol-modal-footer {
    padding: 12px 20px; border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end; gap: 10px;
  }
  .auth-tabs {
    display: flex; gap: 8px; margin-top: 10px;
  }
  .auth-tabs button {
    flex: 1; padding: 8px 10px; border-radius: 10px;
    border: 1px solid var(--border); background: transparent;
    color: var(--text-secondary); font-size: 13px; cursor: pointer;
    font-family: inherit; transition: background 0.15s, color 0.15s;
  }
  .auth-tabs button.active {
    background: var(--bg-active); color: var(--text-primary);
    border-color: var(--border-strong);
  }
  .protocol-field-label {
    display: block; font-size: 12px; color: var(--text-muted);
    margin: 0 0 6px;
  }
  .protocol-field-label + .protocol-modal-input { margin-bottom: 12px; }
  .protocol-check-row {
    display: flex; align-items: center; gap: 8px;
    font-size: 13px; color: var(--text-secondary); margin: 8px 0 12px;
  }
  .protocol-error {
    color: #e55; font-size: 13px; margin-top: 8px;
  }
  .artifact-card {
    border: 1px solid var(--border); border-radius: 12px;
    padding: 14px; background: var(--bg-elevated);
  }
  .artifact-card-title { font-weight: 500; margin-bottom: 6px; color: var(--text-primary); }
  .artifact-card-meta { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
  .artifact-preview {
    background: var(--bg-surface); border: 1px solid var(--border);
    border-radius: 10px; padding: 10px; margin-bottom: 12px;
    max-height: 200px; overflow-y: auto; font-size: 13px; color: var(--text-primary);
  }
  .artifact-card-actions { display: flex; gap: 10px; }

  .sources-list {
    display: flex; flex-direction: column; gap: 8px; margin-top: 8px;
  }
  .sources-list a {
    display: block; font-size: 13px; line-height: 1.45;
  }

  .mic-btn {
    width: 30px; height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    background: transparent;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    flex-shrink: 0;
  }
  .mic-btn:hover { background: var(--bg-hover); }
  .mic-btn.is-recording { background: #c0392b; color: #fff; animation: micPulse 1.2s ease-in-out infinite; }
  .mic-btn svg { width: 15px; height: 15px; }
  @keyframes micPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.65; } }
  .mic-btn.is-processing { background: var(--bg-active); color: var(--text-primary); }

  /* ── Голосовой режим: встроен в чат (как обычный чат, без перекрытия) ── */
  /* Оверлей лежит внутри .main (position:relative), прозрачен и не блокирует интерфейс. */
  .voice-mode-overlay {
    position: absolute; inset: 0; z-index: 60;
    display: none; background: transparent; pointer-events: none;
  }
  .voice-mode-overlay.open { display: block; }
  /* Скрываем обычную строку ввода — её заменяет голосовая. */
  body.voice-active .input-wrapper { display: none !important; }
  /* Чтобы сообщения не уходили под голосовую строку. */
  body.voice-active .messages-view { padding-bottom: 120px; }

  /* Центральный индикатор (волна + подсказка) — только в пустом чате (idle). */
  .voice-mode-stage {
    position: absolute; inset: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 24px 20px 160px;
    pointer-events: none;
  }
  .voice-mode-overlay.has-messages .voice-mode-stage { display: none; }
  .voice-mode-visual { text-align: center; color: var(--text-primary); }

  /* Минималистичный волновой индикатор вместо сферы (стиль Grok). */
  .voice-wave {
    display: flex; align-items: center; justify-content: center; gap: 5px;
    height: 44px; margin: 0 auto 16px;
  }
  .voice-wave span {
    width: 4px; height: 12px; border-radius: 4px;
    background: var(--text-faint);
    transition: background 0.2s;
  }
  .voice-mode-overlay.is-listening .voice-wave span { background: #6ea8ff; animation: voiceWave 1.1s ease-in-out infinite; }
  .voice-mode-overlay.is-speaking .voice-wave span { background: #6ea8ff; animation: voiceWave 0.6s ease-in-out infinite; }
  .voice-wave span:nth-child(1) { animation-delay: 0s; }
  .voice-wave span:nth-child(2) { animation-delay: 0.12s; }
  .voice-wave span:nth-child(3) { animation-delay: 0.24s; }
  .voice-wave span:nth-child(4) { animation-delay: 0.36s; }
  .voice-wave span:nth-child(5) { animation-delay: 0.48s; }
  @keyframes voiceWave {
    0%, 100% { height: 12px; }
    50% { height: 34px; }
  }
  @media (prefers-reduced-motion: reduce) {
    .voice-wave span { animation: none !important; }
  }

  .voice-mode-hint { font-size: 15px; color: var(--text-muted); margin: 0; letter-spacing: -0.01em; }
  /* Текст ответа, печатается по мере озвучивания. */
  .voice-mode-text {
    max-width: 680px; margin: 22px auto 0; padding: 0 16px;
    font-size: 19px; line-height: 1.5; color: var(--text-primary);
    text-align: center; letter-spacing: -0.01em;
    max-height: 42vh; overflow-y: auto;
    opacity: 0; transition: opacity 0.25s;
  }
  .voice-mode-text.visible { opacity: 1; }

  .voice-mode-bar-wrap {
    position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%);
    width: min(740px, calc(100% - 40px));
    pointer-events: auto;
  }
  /* Мягкое многоцветное свечение под строкой ввода. */
  .voice-mode-bar-wrap::before {
    content: ''; position: absolute; inset: -16px -8px -22px; z-index: -1;
    border-radius: 40px; pointer-events: none;
    background: linear-gradient(100deg, #3a6fd8, #18b3a6 40%, #7b5cff 75%, #d05ce0);
    filter: blur(34px); opacity: 0.45;
    transition: opacity 0.3s;
  }
  .voice-mode-overlay.is-listening .voice-mode-bar-wrap::before,
  .voice-mode-overlay.is-speaking .voice-mode-bar-wrap::before { opacity: 0.65; }
  .voice-mode-bar {
    position: relative;
    background: color-mix(in srgb, var(--bg-elevated) 80%, transparent);
    border: 1px solid var(--border-strong);
    border-radius: 24px;
    padding: 14px 16px 12px;
    box-shadow: 0 12px 48px rgba(0,0,0,0.45);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  }
  .voice-mode-input {
    width: 100%; border: none; background: transparent;
    color: var(--text-primary); font-size: 15px; line-height: 1.45; font-family: inherit;
    resize: none; min-height: 22px; max-height: 120px; margin-bottom: 12px;
  }
  .voice-mode-input:focus { outline: none; }
  .voice-mode-input::placeholder { color: var(--input-placeholder); }
  .voice-mode-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
  .voice-mode-tool {
    width: 38px; height: 38px; border-radius: 50%;
    border: 1px solid var(--border-strong); background: transparent;
    color: var(--text-secondary); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.12s;
  }
  .voice-mode-tool:hover { background: var(--bg-hover); color: var(--text-primary); transform: translateY(-1px); }
  .voice-mode-tool.active {
    background: color-mix(in srgb, var(--private-accent) 20%, transparent);
    color: #6ea8ff; border-color: color-mix(in srgb, #6ea8ff 45%, transparent);
  }
  .voice-mode-tool.mic-recording {
    background: #d64a3f; color: #fff; border-color: transparent;
    animation: voiceMicPulse 1.4s ease-in-out infinite;
  }
  @keyframes voiceMicPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(214,74,63,0.5); }
    50% { box-shadow: 0 0 0 6px rgba(214,74,63,0); }
  }
  .voice-mode-tool svg { width: 18px; height: 18px; }
  .voice-mode-character {
    height: 38px; min-width: 0;
    border-radius: 19px; border: 1px solid var(--border-strong);
    background: var(--bg-hover); color: var(--text-primary);
    cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    font-size: 13px; padding: 0 14px; white-space: nowrap; transition: background 0.15s, border-color 0.15s;
  }
  .voice-mode-character:hover { border-color: var(--accent-muted); }
  .voice-mode-character svg { width: 14px; height: 14px; opacity: 0.7; }
  /* «Остановить» — у правого края строки (как в Grok). */
  .voice-mode-stop {
    margin-left: auto;
    height: 38px; padding: 0 20px; border-radius: 19px;
    border: none; background: var(--text-primary); color: var(--bg-surface);
    font-size: 13px; font-weight: 600; cursor: pointer;
    transition: opacity 0.15s, transform 0.12s;
  }
  .voice-mode-stop:hover { opacity: 0.9; transform: translateY(-1px); }
  .voice-character-sheet {
    position: absolute; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(8px);
    width: min(360px, calc(100% - 32px));
    background: var(--bg-elevated); border: 1px solid var(--border-strong);
    border-radius: 18px; padding: 16px;
    box-shadow: 0 16px 48px rgba(0,0,0,0.4);
    opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
    z-index: 70;
  }
  .voice-character-sheet.open { opacity: 1; pointer-events: auto; transform: translateX(-50%) translateY(0); }
  .voice-character-sheet h4 { margin: 0 0 12px; font-size: 13px; font-weight: 600; color: var(--text-secondary); }
  .voice-character-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .voice-character-card {
    border: 1px solid var(--border-strong); border-radius: 13px; padding: 12px;
    cursor: pointer; background: transparent; text-align: left; color: var(--text-primary);
    transition: border-color 0.15s, background 0.15s, transform 0.12s;
  }
  .voice-character-card:hover { background: var(--bg-hover); transform: translateY(-1px); }
  .voice-character-card.active {
    border-color: color-mix(in srgb, #6ea8ff 55%, transparent);
    background: color-mix(in srgb, var(--private-accent) 12%, transparent);
  }
  .voice-character-card strong { display: block; font-size: 14px; margin-bottom: 3px; }
  .voice-character-card span { font-size: 12px; color: var(--text-muted); }

  .trace-copy { cursor: pointer; text-decoration: underline dotted; }
  .trace-copy:hover { opacity: 1 !important; }

  .voice-btn {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--voice-btn-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s, opacity 0.15s;
    color: var(--voice-btn-fg);
  }
  .voice-btn:hover { opacity: 0.88; }
  .voice-btn .wave-bar { background: currentColor; }

  .wave-icon {
    display: flex;
    align-items: center;
    gap: 2px;
    height: 14px;
  }
  .wave-bar {
    width: 2.5px;
    border-radius: 2px;
    background: currentColor;
    animation: wave 0.9s ease-in-out infinite;
  }
  .wave-bar:nth-child(1) { height: 5px; animation-delay: 0s; }
  .wave-bar:nth-child(2) { height: 10px; animation-delay: 0.15s; }
  .wave-bar:nth-child(3) { height: 14px; animation-delay: 0.3s; }
  .wave-bar:nth-child(4) { height: 10px; animation-delay: 0.45s; }
  .wave-bar:nth-child(5) { height: 5px; animation-delay: 0.6s; }

  @keyframes wave {
    0%, 100% { transform: scaleY(1); }
    50% { transform: scaleY(0.4); }
  }







  /* ─── CASE LAW VIEW ─── */
  #caseLawView {
    display: none;
    flex: 1;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-main);
  }
  #caseLawView.active { display: flex; }

  .case-law-header {
    padding: 28px 32px 20px;
    border-bottom: 1px solid var(--border);
    max-width: 920px;
    width: 100%;
    margin: 0 auto;
    box-sizing: border-box;
  }
  .case-law-title {
    font-size: 22px;
    font-weight: 500;
    margin: 0 0 8px;
    color: var(--text-primary);
    letter-spacing: -0.02em;
  }
  .case-law-subtitle {
    margin: 0 0 18px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-muted);
    max-width: 640px;
  }

  .case-law-search-bar { display: flex; gap: 10px; align-items: stretch; min-width: 0; }
  .case-law-search-wrap {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 12px;
    padding: 0 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
    overflow: hidden;
  }
  .case-law-search-wrap:focus-within {
    border-color: var(--input-focus-border);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--input-focus-border) 18%, transparent);
  }
  .case-law-search-wrap svg {
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    flex-shrink: 0;
  }
  .case-law-input {
    flex: 1;
    min-width: 0;
    width: 100%;
    background: transparent;
    border: none;
    padding: 12px 0;
    color: var(--input-text);
    font-size: 14px;
    outline: none;
    font-family: inherit;
  }
  .case-law-input::placeholder { color: var(--text-muted); }

  .case-law-search-btn {
    background: var(--text-primary);
    color: var(--bg-surface);
    border: none;
    border-radius: 12px;
    padding: 0 20px;
    cursor: pointer;
    transition: opacity 0.15s;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    white-space: nowrap;
  }
  .case-law-search-btn:hover { opacity: 0.9; }
  .case-law-search-btn:disabled { opacity: 0.45; cursor: default; }

  .case-law-results-wrap {
    flex: 1;
    overflow-y: auto;
    padding: 20px 32px 28px;
  }
  .case-law-results-inner {
    max-width: 920px;
    margin: 0 auto;
  }
  .case-law-results-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 14px;
    display: none;
  }
  .case-law-results-meta.visible { display: block; }

  .case-law-result-item {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 18px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.12s;
  }
  .case-law-result-item:hover {
    background: var(--bg-hover);
    border-color: var(--border-strong);
    transform: translateY(-1px);
  }
  .case-law-result-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
  }
  .case-law-result-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.35;
  }
  .case-law-result-score {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 72px;
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 6px 10px;
    flex-shrink: 0;
    white-space: nowrap;
    line-height: 1.2;
    text-align: center;
  }
  .case-law-result-score-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: 2px;
  }
  .case-law-result-score-value {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.02em;
  }
  .case-law-result-score.is-high {
    border-color: color-mix(in srgb, #16a34a 45%, var(--border));
    background: color-mix(in srgb, #16a34a 12%, var(--bg-surface));
  }
  .case-law-result-score.is-high .case-law-result-score-value { color: #22c55e; }
  .case-law-result-score.is-mid {
    border-color: color-mix(in srgb, #d97706 45%, var(--border));
    background: color-mix(in srgb, #d97706 10%, var(--bg-surface));
  }
  .case-law-result-score.is-mid .case-law-result-score-value { color: #f59e0b; }
  .case-law-result-score.is-low .case-law-result-score-value { color: var(--text-secondary); }
  .case-law-result-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
  }
  .case-law-result-meta .case-law-dot { opacity: 0.5; }
  .case-law-result-outcome {
    color: var(--text-secondary);
    background: color-mix(in srgb, var(--text-muted) 10%, transparent);
    border-radius: 6px;
    padding: 2px 7px;
    font-size: 11px;
    font-weight: 500;
  }
  .case-law-result-outcome.is-granted {
    color: #22c55e;
    background: color-mix(in srgb, #22c55e 12%, transparent);
  }
  .case-law-result-outcome.is-partial {
    color: #f59e0b;
    background: color-mix(in srgb, #f59e0b 12%, transparent);
  }
  .case-law-result-outcome.is-denied {
    color: #ef4444;
    background: color-mix(in srgb, #ef4444 10%, transparent);
  }
  .case-law-result-snippet {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.55;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-clamp: 2;
    margin-bottom: 10px;
  }
  .case-law-result-action {
    font-size: 12px;
    color: var(--link);
    font-weight: 500;
  }

  .case-law-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 280px;
    color: var(--text-muted);
    font-size: 14px;
    text-align: center;
    padding: 40px 20px;
    line-height: 1.5;
  }
  .case-law-loading { display: flex; justify-content: center; padding: 48px; }

  /* ═══ JUDGES ANALYTICS (граф судей) — современный UI ═══ */
  /* Не задаём display здесь: видимость экрана контролирует .view/.view.active.
     Раньше «#judgesView { display:flex }» (id > class) показывал экран всегда —
     аналитика вылезала снизу главной. */
  #judgesView { min-height: 0; }
  #judgesView.active { flex-direction: column; }
  .jx-mode { display: flex; flex-direction: column; min-height: 0; flex: 1; }

  .jx-header {
    padding: 30px 32px 18px;
    max-width: 1080px;
    width: 100%;
    margin: 0 auto;
    box-sizing: border-box;
  }
  .jx-title-group { display: flex; align-items: center; gap: 11px; margin-bottom: 18px; }
  .jx-title-icon {
    flex-shrink: 0;
    width: 34px; height: 34px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 10px;
    background: color-mix(in srgb, var(--private-accent) 16%, transparent);
    color: var(--private-accent);
  }
  .jx-title-icon svg { width: 18px; height: 18px; }
  .jx-title { font-size: 23px; font-weight: 600; letter-spacing: -0.02em; margin: 0; color: var(--text-primary); }
  .jx-subtitle { margin: 3px 0 0; font-size: 13.5px; line-height: 1.45; color: var(--text-muted); max-width: 680px; }

  .jx-controls { display: flex; gap: 10px; flex-wrap: wrap; }
  .jx-search {
    flex: 1 1 260px;
    display: flex; align-items: center; gap: 9px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 13px;
    padding: 0 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
  }
  .jx-search:focus-within {
    border-color: var(--input-focus-border);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--input-focus-border) 16%, transparent);
  }
  .jx-search svg { width: 16px; height: 16px; color: var(--text-muted); flex-shrink: 0; }
  .jx-search input {
    flex: 1; min-width: 0; background: transparent; border: none; outline: none;
    padding: 9px 0; font-size: 13.5px; font-family: inherit; color: var(--input-text);
  }
  .jx-search input::placeholder { color: var(--text-muted); }

  .jx-select-wrap { position: relative; display: inline-flex; }
  .jx-select-wrap select {
    appearance: none; -webkit-appearance: none;
    background: var(--input-bg);
    color: var(--text-secondary);
    border: 1px solid var(--input-border);
    border-radius: 13px;
    padding: 0 34px 0 14px;
    height: 100%; min-height: 38px;
    font-size: 12.5px; font-family: inherit; cursor: pointer; outline: none;
    transition: border-color 0.2s, color 0.2s;
  }
  .jx-select-wrap select:hover { color: var(--text-primary); border-color: var(--border-strong); }
  .jx-select-wrap select:focus { border-color: var(--input-focus-border); }
  .jx-select-chevron {
    position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
    width: 15px; height: 15px; color: var(--text-muted); pointer-events: none;
  }

  .jx-scroll { flex: 1; overflow-y: auto; padding: 6px 32px 32px; min-height: 0; scrollbar-gutter: stable both-edges; }
  /* 1016 = 1080 − 2×32: совпадает с контентом шапки (она max-width 1080 с padding 32),
     чтобы карточки/мета были той же ширины, что поиск и фильтры. */
  .jx-inner { max-width: 1016px; margin: 0 auto; }

  .jx-meta-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px; flex-wrap: wrap; margin-bottom: 16px;
  }
  .jx-meta { font-size: 12px; color: var(--text-muted); }
  .jx-legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--text-muted); }
  .jx-legend-item { display: inline-flex; align-items: center; gap: 6px; }

  .judge-swatch { width: 9px; height: 9px; border-radius: 3px; display: inline-block; flex-shrink: 0; }
  .judge-swatch.is-granted, .judge-bar-seg.is-granted { background: #3fb950; }
  .judge-swatch.is-partial, .judge-bar-seg.is-partial { background: #d29922; }
  .judge-swatch.is-denied, .judge-bar-seg.is-denied { background: #f85149; }
  .judge-swatch.is-terminated, .judge-bar-seg.is-terminated { background: #8b949e; }

  .jx-empty {
    display: flex; align-items: center; justify-content: center; gap: 10px;
    min-height: 200px; color: var(--text-muted); font-size: 14px; text-align: center; padding: 36px 20px;
  }
  .jx-empty.is-error { color: #d97706; }
  .jx-spinner {
    width: 16px; height: 16px; border-radius: 50%;
    border: 2px solid var(--border-strong); border-top-color: var(--text-secondary);
    animation: jx-spin 0.7s linear infinite;
  }
  @keyframes jx-spin { to { transform: rotate(360deg); } }

  /* Сетка карточек судей */
  .jx-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
    gap: 12px;
  }
  .judge-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px 18px;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.14s var(--ease-out), box-shadow 0.15s, background 0.15s;
  }
  .judge-card:hover {
    border-color: var(--border-strong);
    background: var(--bg-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px -10px rgba(0,0,0,0.5);
  }
  .judge-card:focus-visible { outline: 2px solid var(--private-accent); outline-offset: 2px; }
  .judge-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
  .judge-identity { min-width: 0; }
  .judge-name {
    font-size: 15px; font-weight: 600; color: var(--text-primary); letter-spacing: -0.01em;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .judge-court { font-size: 12.5px; color: var(--text-muted); margin-top: 3px; }
  .judge-headline-rate { text-align: right; flex-shrink: 0; }
  .judge-rate-value { font-size: 22px; font-weight: 700; color: var(--text-primary); line-height: 1; letter-spacing: -0.02em; }
  .judge-rate-pct { font-size: 13px; font-weight: 600; color: var(--text-muted); margin-left: 1px; }
  .judge-rate-label { font-size: 10.5px; color: var(--text-muted); margin-top: 4px; }

  .judge-bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--bg-sub); }
  .judge-bar-seg { height: 100%; min-width: 0; transition: filter 0.15s; }
  .judge-bar-seg:hover { filter: brightness(1.18); }

  .judge-card-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; }
  .judge-foot { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--text-secondary); }
  .judge-foot-item { display: inline-flex; align-items: center; gap: 5px; }
  .judge-card-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
  .judge-mini-btn {
    display: inline-flex; align-items: center; gap: 5px;
    background: transparent; border: 1px solid var(--border-soft, var(--border));
    color: var(--text-muted); border-radius: 8px; padding: 5px 10px;
    font-size: 12px; font-family: inherit; cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
  }
  .judge-mini-btn svg { width: 13px; height: 13px; }
  .judge-mini-btn:hover { background: var(--bg-active); color: var(--text-primary); border-color: var(--border-strong); }
  .judge-open-hint { color: var(--text-faint); display: inline-flex; transition: transform 0.14s, color 0.15s; }
  .judge-open-hint svg { width: 16px; height: 16px; }
  .judge-card:hover .judge-open-hint { color: var(--text-secondary); transform: translateX(2px); }

  /* ── Детальный экран судьи ── */
  .jx-back {
    display: inline-flex; align-items: center; gap: 6px;
    background: transparent; border: none; cursor: pointer;
    color: var(--text-muted); font-size: 13px; font-family: inherit;
    padding: 6px 0; margin-bottom: 14px; transition: color 0.15s;
  }
  .jx-back svg { width: 16px; height: 16px; }
  .jx-back:hover { color: var(--text-primary); }

  .jx-judge-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
  .jx-judge-name { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; margin: 0; color: var(--text-primary); }
  .jx-judge-sub { font-size: 13px; color: var(--text-muted); margin-top: 5px; }
  .jx-analyze-btn {
    display: inline-flex; align-items: center; gap: 8px; flex-shrink: 0;
    background: var(--text-primary); color: var(--bg-surface);
    border: none; border-radius: 11px; padding: 11px 18px;
    font-size: 13.5px; font-weight: 600; font-family: inherit; cursor: pointer;
    transition: opacity 0.15s, transform 0.14s var(--ease-out);
  }
  .jx-analyze-btn svg { width: 16px; height: 16px; }
  .jx-analyze-btn:hover { opacity: 0.9; transform: translateY(-1px); }

  .jx-judge-stats {
    display: flex; gap: 28px; align-items: center; flex-wrap: wrap;
    margin: 22px 0 8px; padding: 18px 20px;
    background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 14px;
  }
  .jx-stat { flex-shrink: 0; }
  .jx-stat-value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; color: var(--text-primary); line-height: 1; }
  .jx-stat-label { font-size: 11.5px; color: var(--text-muted); margin-top: 5px; }
  .jx-stat-bar { flex: 1; min-width: 200px; }
  .jx-stat-bar .judge-bar { height: 10px; border-radius: 5px; }
  .jx-legend-inline { margin-top: 10px; }

  .jx-cases-head { font-size: 14px; font-weight: 600; color: var(--text-primary); margin: 24px 0 12px; }
  .jx-case-row {
    display: flex; align-items: center; gap: 14px;
    background: var(--bg-elevated); border: 1px solid var(--border);
    border-radius: 11px; padding: 13px 16px; margin-bottom: 8px; cursor: pointer;
    transition: border-color 0.15s, background 0.15s, transform 0.12s;
  }
  .jx-case-row:hover { border-color: var(--border-strong); background: var(--bg-hover); transform: translateX(2px); }
  .jx-case-row:focus-visible { outline: 2px solid var(--private-accent); outline-offset: 2px; }
  .jx-case-main { flex: 1; min-width: 0; }
  .jx-case-no { font-size: 13.5px; font-weight: 500; color: var(--text-primary); }
  .jx-case-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
  .jx-case-outcome {
    font-size: 11.5px; font-weight: 500; padding: 3px 9px; border-radius: 7px; flex-shrink: 0;
    background: var(--bg-sub); color: var(--text-secondary);
  }
  .jx-case-outcome.is-granted { background: color-mix(in srgb, #3fb950 16%, transparent); color: #3fb950; }
  .jx-case-outcome.is-partial { background: color-mix(in srgb, #d29922 18%, transparent); color: #d29922; }
  .jx-case-outcome.is-denied { background: color-mix(in srgb, #f85149 16%, transparent); color: #f85149; }
  .jx-case-arrow { color: var(--text-faint); display: inline-flex; flex-shrink: 0; }
  .jx-case-arrow svg { width: 16px; height: 16px; }

  /* ── Поиск практики: строка поиска и empty в современном стиле ── */
  .cl-search-bar { display: flex; gap: 10px; align-items: stretch; }
  .cl-search { flex: 1 1 auto; }
  .cl-search-btn {
    flex-shrink: 0;
    background: var(--text-primary);
    color: var(--bg-surface);
    border: none;
    border-radius: 11px;
    padding: 0 22px;
    cursor: pointer;
    font-size: 13.5px;
    font-weight: 600;
    font-family: inherit;
    white-space: nowrap;
    transition: opacity 0.15s, transform 0.14s var(--ease-out);
  }
  .cl-search-btn:hover { opacity: 0.9; transform: translateY(-1px); }
  .cl-search-btn:disabled { opacity: 0.45; cursor: default; transform: none; }

  .jx-empty-lg { flex-direction: column; min-height: 320px; }
  .jx-empty-lg svg { color: var(--text-muted); opacity: 0.5; margin-bottom: 4px; }

  /* Карточки результатов — единый «приподнятый» стиль (как карточки судей) */
  .case-law-result-item { border-radius: 14px; padding: 16px 18px; }
  .case-law-result-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px -10px rgba(0,0,0,0.5);
  }

































    .case-viewer-modal {
      position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
      z-index: 9999; display: flex; align-items: center; justify-content: center;
    }
    .case-viewer-overlay {
      position: absolute; top: 0; left: 0; width: 100%; height: 100%;
      background: rgba(0, 0, 0, 0.72);
      backdrop-filter: blur(16px) brightness(0.82);
      -webkit-backdrop-filter: blur(16px) brightness(0.82);
    }
    [data-theme="light"] .case-viewer-overlay {
      background: rgba(245, 245, 247, 0.72);
      backdrop-filter: blur(12px);
      -webkit-backdrop-filter: blur(12px);
    }
    .case-viewer-content {
      position: relative; width: 90vw; height: 90vh; max-width: 1200px;
      background: var(--bg-surface); border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,0.45);
      display: flex; flex-direction: column; overflow: hidden;
      border: 1px solid var(--border);
    }
    [data-theme="light"] .case-viewer-content {
      box-shadow: 0 20px 60px rgba(0,0,0,0.18);
    }
    .case-viewer-header {
      padding: 16px 20px; border-bottom: 1px solid var(--border);
      display: flex; justify-content: space-between; align-items: center;
      gap: 10px; background: var(--bg-elevated);
    }
    .case-viewer-header h3 { margin: 0; font-size: 1.1rem; color: var(--text-primary); flex: 1; }
    .case-viewer-doc-type-badge {
      font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: 10px;
      background: var(--bg-hover); color: var(--text-muted); border: 1px solid var(--border);
      white-space: nowrap; flex-shrink: 0;
    }
    .case-viewer-header .close-btn {
      background: none; border: none; font-size: 1.5rem; color: var(--text-secondary); cursor: pointer;
    }
    .case-viewer-body {
      display: flex; flex: 1; overflow: hidden;
    }
    .case-viewer-main {
      flex: 1; padding: 20px; overflow-y: auto;
    }
    .case-viewer-sidebar {
      width: 300px; border-left: 1px solid var(--border); background: var(--bg-elevated);
      padding: 20px; overflow-y: auto; font-size: 0.9rem;
    }
    .case-viewer-sidebar .sidebar-block { margin-bottom: 20px; }
    .case-viewer-sidebar h4 { margin-top: 0; margin-bottom: 10px; color: var(--text-primary); font-size: 1rem; }
    .case-viewer-sidebar p { margin: 5px 0; color: var(--text-secondary); }
    .case-viewer-sidebar strong { color: var(--text-primary); }
    .case-viewer-excerpt {
      margin-bottom: 16px; padding: 12px 14px; border-radius: 8px;
      background: rgba(255, 193, 7, 0.12); border-left: 3px solid var(--color-warn, #d97706);
      font-size: 13px; line-height: 1.5; color: var(--text-primary);
    }
    [data-theme="light"] .case-viewer-excerpt {
      background: rgba(217, 119, 6, 0.08);
    }
    .case-viewer-excerpt-label { font-size: 11px; font-weight: 600; text-transform: uppercase;
      color: var(--color-warn, #d97706); margin-bottom: 6px; letter-spacing: 0.04em; }
    .case-viewer-full-label {
      font-size: 11px; font-weight: 600; text-transform: uppercase;
      color: var(--text-muted); margin: 16px 0 8px; letter-spacing: 0.04em;
    }
    .case-viewer-main .case-text {
      white-space: pre-wrap;
      font-family: var(--font-ui);
      font-size: 14px;
      line-height: 1.65;
      color: var(--text-primary);
    }
    .case-text-highlight {
      background: rgba(255, 210, 0, 0.35);
      border-radius: 3px;
      padding: 1px 0;
      scroll-margin-top: 80px;
    }
    .attachment-chips {
      display: flex; flex-wrap: wrap; gap: 6px; padding: 0 4px 8px; min-height: 0;
    }
    .attachment-chips:empty { display: none; padding: 0; }
    .attachment-chip {
      display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px;
      border-radius: 16px; font-size: 12px; background: var(--bg-sub);
      border: 1px solid var(--border); color: var(--text-sec); max-width: 220px;
    }
    .attachment-chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .attachment-chip-remove {
      background: none; border: none; cursor: pointer; color: var(--text-muted);
      font-size: 14px; line-height: 1; padding: 0 2px;
    }
    .attachment-chip-remove:hover { color: var(--text-main); }
    .attachment-chip-practice {
      max-width: 280px;
      border-style: dashed;
      color: var(--text-muted);
    }
    .attachment-chip-practice.is-ready {
      border-style: solid;
      color: var(--text-sec);
    }
    .attachment-chip-practice .attachment-chip-icon {
      flex-shrink: 0;
      font-size: 11px;
      opacity: 0.85;
    }
    .practice-match-banner {
      margin-top: 10px; padding: 10px 12px; border-radius: 8px;
      background: var(--bg-sub); border: 1px solid var(--border); font-size: 13px;
    }
    .practice-match-banner h4 { margin: 0 0 8px; font-size: 13px; font-weight: 600; }
    .practice-match-banner ul { margin: 0; padding-left: 18px; }

  .btn {
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    font-family: var(--font-ui);
    cursor: pointer;
    transition: background var(--motion-fast), color var(--motion-fast);
  }
  .btn-primary {
    background: var(--text-primary);
    color: var(--bg-surface);
    border: none;
  }
  .btn-primary:hover { opacity: 0.9; }
  .btn-ghost {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border);
  }
  .btn-ghost:hover { background: var(--bg-hover); }
  .doc-modal-content {
    background: var(--bg-surface);
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    border: 1px solid var(--border);
  }
  .doc-modal-header, .doc-modal-footer {
    padding: 16px 20px;
    border-color: var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .doc-modal-header { border-bottom: 1px solid var(--border); }
  .doc-modal-footer { border-top: 1px solid var(--border); justify-content: flex-end; gap: 12px; }
  .doc-modal-body { padding: 20px; overflow-y: auto; flex: 1; }
  .doc-field-label {
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    font-weight: 600;
    margin-bottom: 8px;
    display: block;
  }
  .doc-textarea, .doc-preview-box {
    width: 100%;
    padding: 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--input-border);
    background: var(--input-bg);
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 13px;
  }
  .doc-textarea { height: 180px; resize: vertical; }
  .doc-preview-box { height: 180px; white-space: pre-wrap; overflow-y: auto; background: var(--bg-elevated); }
  .dashboard-panel {
    margin-top: 15px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px;
    background: var(--bg-elevated);
  }
  .dashboard-panel h3 { margin-top: 0; color: var(--text-primary); }
  .dashboard-panel h4 { color: var(--text-primary); margin: 12px 0 6px; font-size: 14px; }
  .dashboard-bar-track {
    width: 100%;
    background: var(--border);
    height: 10px;
    border-radius: 5px;
    margin-top: 5px;
    overflow: hidden;
  }
  .dashboard-bar-fill {
    height: 100%;
    background: var(--link);
    border-radius: 5px;
  }
  .dashboard-outcome-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 6px 0;
    font-size: 13px;
  }
  .dashboard-outcome-row .dashboard-bar-track {
    flex: 1;
    margin-top: 0;
    height: 8px;
  }
  .dashboard-outcome-label {
    min-width: 120px;
    color: var(--text-sec);
  }
  .dashboard-chart-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 8px;
  }
  .dashboard-judge-row {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-soft);
    font-size: 13px;
  }
  .dashboard-judge-row:last-child { border-bottom: none; }
  .dashboard-judge-name { font-weight: 500; color: var(--text-primary); flex: 1 1 140px; }
  .dashboard-judge-tone {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--bg-hover);
    color: var(--text-secondary);
  }
  .dashboard-judge-tone.tone-ok { background: rgba(59, 130, 246, 0.12); color: var(--link); }
  .dashboard-judge-tone.tone-bad { background: rgba(196, 92, 92, 0.12); color: #c45c5c; }
  .dashboard-judge-tone.tone-warn { background: rgba(201, 162, 39, 0.12); color: #a8841a; }
  .dashboard-judge-val { font-size: 12px; color: var(--text-muted); }
  .dashboard-donut-wrap {
    display: flex;
    align-items: center;
    gap: 16px;
    margin: 10px 0 14px;
    flex-wrap: wrap;
  }
  .dashboard-donut {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    flex-shrink: 0;
  }
  .dashboard-donut-legend { flex: 1; min-width: 160px; }
  .dashboard-donut-legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    margin: 4px 0;
    color: var(--text-secondary);
  }
  .dashboard-donut-swatch {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
  }
  .chart-block {
    margin: 14px 0 0;
    padding: 14px 16px 16px;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-md);
    background: var(--bg-main);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
  }
  .chart-block:first-of-type { margin-top: 10px; }
  .viz-charts-stack {
    display: flex;
    flex-direction: column;
    gap: 0;
  }
  .chart-block.viz-chart-pending {
    opacity: 0;
    transform: translateY(20px) scale(0.985);
    max-height: 0;
    margin-top: 0;
    margin-bottom: 0;
    padding-top: 0;
    padding-bottom: 0;
    border-color: transparent;
    overflow: hidden;
    pointer-events: none;
  }
  .chart-block.viz-chart-visible {
    opacity: 1;
    transform: none;
    max-height: 720px;
    margin-top: 14px;
    padding: 14px 16px 16px;
    border-color: var(--border-soft);
    transition:
      opacity 0.62s cubic-bezier(0.22, 1, 0.36, 1),
      transform 0.62s cubic-bezier(0.22, 1, 0.36, 1),
      max-height 0.68s cubic-bezier(0.22, 1, 0.36, 1),
      padding 0.55s ease,
      margin 0.55s ease,
      border-color 0.45s ease;
  }
  .message-viz-panel .dashboard-panel.viz-header-enter {
    opacity: 0;
    transform: translateY(6px);
  }
  .message-viz-panel .dashboard-panel.viz-header-ready {
    opacity: 1;
    transform: none;
    transition: opacity 0.45s ease, transform 0.45s ease;
  }
  .dashboard-bar-fill,
  .chart-bar-v-fill {
    transition:
      width 0.82s cubic-bezier(0.22, 1, 0.36, 1),
      height 0.82s cubic-bezier(0.22, 1, 0.36, 1);
  }
  .dashboard-donut {
    transition:
      transform 0.78s cubic-bezier(0.34, 1.15, 0.64, 1),
      opacity 0.62s ease;
  }
  .dashboard-donut.viz-donut-pending {
    transform: scale(0.7) rotate(-72deg);
    opacity: 0;
  }
  .dashboard-donut-legend-item {
    opacity: 0;
    transform: translateX(-10px);
    transition:
      opacity 0.45s ease,
      transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
  }
  .viz-chart-visible .dashboard-donut-legend-item {
    opacity: 1;
    transform: none;
  }
  .viz-chart-visible .dashboard-donut-legend-item:nth-child(1) { transition-delay: 0.12s; }
  .viz-chart-visible .dashboard-donut-legend-item:nth-child(2) { transition-delay: 0.2s; }
  .viz-chart-visible .dashboard-donut-legend-item:nth-child(3) { transition-delay: 0.28s; }
  .viz-chart-visible .dashboard-donut-legend-item:nth-child(4) { transition-delay: 0.36s; }
  .viz-chart-visible .dashboard-donut-legend-item:nth-child(5) { transition-delay: 0.44s; }
  .viz-chart-visible .dashboard-donut-legend-item:nth-child(6) { transition-delay: 0.52s; }
  .dashboard-outcome-row {
    opacity: 0;
    transform: translateX(-8px);
    transition:
      opacity 0.42s ease,
      transform 0.42s cubic-bezier(0.22, 1, 0.36, 1);
  }
  .viz-chart-visible .dashboard-outcome-row {
    opacity: 1;
    transform: none;
  }
  .chart-bar-v-col {
    opacity: 0;
    transform: translateY(10px);
    transition:
      opacity 0.45s ease,
      transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
  }
  .viz-chart-visible .chart-bar-v-col {
    opacity: 1;
    transform: none;
  }
  .chart-block-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 10px;
  }
  .chart-kind-tag {
    font-size: 10px;
    color: var(--text-muted);
    font-weight: 500;
    margin-left: 8px;
  }
  .chart-bar-v-wrap {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    min-height: 140px;
    padding: 8px 4px 0;
    border-bottom: 1px solid var(--border);
  }
  .chart-bar-v-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
  }
  .chart-bar-v-track {
    width: 100%;
    max-width: 48px;
    height: 110px;
    display: flex;
    align-items: flex-end;
    justify-content: center;
  }
  .chart-bar-v-fill {
    width: 72%;
    min-height: 2px;
    border-radius: 4px 4px 0 0;
    transition: height 0.2s ease;
  }
  .chart-bar-v-val {
    font-size: 10px;
    color: var(--text-muted);
    text-align: center;
  }
  .chart-bar-v-label {
    font-size: 10px;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.25;
    max-height: 2.5em;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
  .chart-histogram-wrap .chart-bar-v-fill { border-radius: 3px 3px 0 0; }
  .message-viz-panel {
    margin-top: 12px;
  }
  .stream-table-partial {
    overflow-x: hidden;
    max-width: 100%;
    margin: 12px 0;
  }
  .stream-table-partial table.md-table {
    width: 100%;
    max-width: 100%;
    table-layout: fixed;
  }
  .stream-table-partial .stream-table-growing td {
    border: 1px solid var(--table-border);
    padding: 6px 10px;
    vertical-align: top;
    color: var(--text-secondary);
    font-size: 13px;
  }
  .stream-table-partial .stream-table-pad {
    border: 1px solid var(--table-border);
    padding: 6px 10px;
    vertical-align: top;
    min-width: 24px;
  }
  .message-assistant-text.is-streaming-active .md-rendered {
    overflow-anchor: none;
  }
  .stream-scroll-anchor {
    overflow-anchor: auto;
    height: 2px;
    width: 100%;
    pointer-events: none;
    flex-shrink: 0;
    display: block;
  }
  .message-assistant-text.is-streaming-active {
    overflow-anchor: none;
  }
  .reply-actions {
    display: flex;
    gap: 4px;
    margin-top: 8px;
    flex-wrap: wrap;
    align-items: center;
  }
  .reply-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    padding: 0;
    border-radius: 6px;
    border: 1px solid var(--border-soft, var(--border));
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-family: var(--font-ui);
    transition: background 0.15s, color 0.15s, border-color 0.15s;
  }
  .reply-action-btn svg {
    width: 13px;
    height: 13px;
    flex-shrink: 0;
  }
  .reply-action-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-strong, var(--border));
  }
  /* Обратная связь 👍/👎: отделяем от экспортных кнопок и подсвечиваем выбор. */
  .reply-feedback {
    display: inline-flex;
    gap: 4px;
    margin-left: 6px;
    padding-left: 8px;
    border-left: 1px solid var(--border-soft, var(--border));
  }
  .reply-fb-up.is-active {
    color: #3fb950;
    border-color: #3fb950;
    background: color-mix(in srgb, #3fb950 14%, transparent);
  }
  .reply-fb-down.is-active {
    color: #f85149;
    border-color: #f85149;
    background: color-mix(in srgb, #f85149 14%, transparent);
  }
  /* «Висячий» запрос без ответа — минималистичная панель повтора. */
  .dangling-retry {
    display: flex; align-items: center; gap: 12px;
    margin: 4px 0 8px; padding: 10px 14px;
    border: 1px solid var(--border); border-radius: 12px;
    background: var(--bg-elevated); font-size: 13px; color: var(--text-muted);
  }
  .dangling-retry-text { flex: 1; }
  .dangling-retry-btn {
    display: inline-flex; align-items: center; gap: 7px;
    background: transparent; border: 1px solid var(--border-strong);
    color: var(--text-primary); border-radius: 9px; padding: 7px 13px;
    font-size: 12.5px; font-family: inherit; cursor: pointer; white-space: nowrap;
    transition: background 0.15s, border-color 0.15s, transform 0.12s;
  }
  .dangling-retry-btn svg { width: 14px; height: 14px; }
  .dangling-retry-btn:hover { background: var(--bg-hover); border-color: var(--accent-muted); transform: translateY(-1px); }
  .sources-collapsible summary {
    cursor: pointer;
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
  }
  .sources-collapsible summary::-webkit-details-marker { display: none; }
  .message-assistant-text.is-streaming-active .citation-link {
    pointer-events: auto;
    cursor: pointer;
  }
  .user-attachment-tag {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
  }
  .followup-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
  .followup-chip {
    padding: 5px 10px;
    font-size: 12px;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    cursor: pointer;
  }
  .followup-chip:hover { background: var(--bg-hover); color: var(--text-primary); }

  /* ── Privacy notice banner ── */
  .privacy-banner {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 18px; font-size: 12.5px;
    background: var(--bg-elevated); border-top: 1px solid var(--border);
    color: var(--text-muted); position: relative; z-index: 10;
    flex-shrink: 0;
  }
  .privacy-banner.warning { background: rgba(255,170,0,0.07); border-color: rgba(255,170,0,0.2); }
  .privacy-banner .privacy-icon { flex-shrink: 0; opacity: 0.65; }
  .privacy-banner .privacy-text { flex: 1; line-height: 1.45; max-width: 900px; margin: 0 auto; text-align: center; }
  .privacy-banner .privacy-pii-link {
    color: var(--link); cursor: pointer; text-decoration: underline; white-space: nowrap;
  }
  .privacy-banner .privacy-pii-link:hover { opacity: 0.8; }
  .privacy-banner .privacy-dismiss {
    background: none; border: none; color: var(--text-faint); cursor: pointer;
    font-size: 16px; line-height: 1; padding: 0 2px; flex-shrink: 0;
  }
  .privacy-banner .privacy-dismiss:hover { color: var(--text-muted); }
  .privacy-banner { animation: slideUp 0.2s ease; }
  @keyframes slideUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

  /* Voice mode input becomes editable when STT unavailable */
  .voice-mode-input:not([readonly]) {
    background: var(--bg-elevated) !important;
    border: 1px solid var(--border-strong) !important;
    color: var(--text-primary) !important;
    cursor: text !important;
  }
