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

/* П.23: змінні з fallback-значеннями, щоб стилі не "падали" при конфлікті з іншими таблицями */
:root {
    --primary: #6566F1;
    --primary-hover: #885DF6;
    --bg: #0f0a2e;
    --surface: rgba(255,255,255,0.04);
    --text: #e2e8f0;
    --text-dim: #94a3b8;
    --text-muted: #64748b;
    --border: rgba(255,255,255,0.08);
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --radius: 8px;
    /* Дублювання для сумісності з іншими сторінками проєкту */
    --primary-color: var(--primary);
    --text-primary: var(--text);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    background: linear-gradient(160deg, #0f0a2e 0%, #1a1050 30%, #15103a 60%, #0d0825 100%);
    background-attachment: fixed;
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

body::before {
    content: '';
    position: fixed;
    top: -30%; left: -20%;
    width: 60%; height: 60%;
    background: radial-gradient(ellipse, rgba(136,93,246,0.08) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
}

/* ============================================
   TOP NAVIGATION BAR (уніфіковано з головною сторінкою)
   ============================================ */
/* П.18: три панелі завжди фіксовані зверху — навігація fixed, шапки панелей sticky */
.top-nav,
.top-nav-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    background: rgba(15, 10, 46, 0.98);
    border-bottom: 1px solid var(--border);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    flex-shrink: 0;
    flex-wrap: wrap;
    width: 100%;
}

.top-nav-btn {
    padding: 8px 18px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    color: var(--text);
    border: 1px solid rgba(255,255,255,0.15);
    background: rgba(255,255,255,0.04);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    font-family: inherit;
}

.top-nav-btn:hover {
    background: rgba(255,255,255,0.08);
    border-color: rgba(255,255,255,0.25);
}

.top-nav-btn-active,
.top-nav-btn.active {
    background: var(--primary) !important;
    color: white !important;
    border-color: var(--primary) !important;
    font-weight: 600;
}

/* П.9: три стани кнопки AI чат */
.top-nav-btn.top-nav-btn-ai-chat:not(.active):not(.top-nav-btn-ai-chat-ready) {
    opacity: 0.8;
    color: #94a3b8;
}
.top-nav-btn.top-nav-btn-ai-chat-ready {
    background: rgba(245, 158, 11, 0.2);
    border-color: rgba(245, 158, 11, 0.5);
    color: var(--text);
}
.top-nav-btn.top-nav-btn-ai-chat-ready::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #f59e0b;
    margin-left: 6px;
    vertical-align: middle;
}

.top-nav-btn-lex {
    /* Без margin-left: auto — однакове відображення на всіх сторінках (п.13) */
}

.top-nav-btn-disabled {
    opacity: 0.4;
    cursor: default;
    pointer-events: none;
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar-toggle-btn {
    position: fixed;
    top: 12px;
    left: 10px;
    z-index: 1002;
    width: 36px; height: 36px;
    border-radius: 8px;
    background: rgba(26, 16, 80, 0.95);
    border: 1px solid rgba(255,255,255,0.1);
    color: var(--text-dim);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s;
}

.sidebar-toggle-btn:hover {
    background: rgba(101,102,241,0.25);
    color: #c4b5fd;
}

.sidebar-panel {
    position: fixed;
    left: 0; top: 0;
    width: 240px;
    height: 100vh;
    background: rgba(15, 10, 46, 0.98);
    border-right: 1px solid var(--border);
    z-index: 1001;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.sidebar-panel.open {
    transform: translateX(0);
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
    border-bottom: 1px solid var(--border);
}

.sidebar-sessions-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.sidebar-session-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: 2px;
}

.sidebar-session-item:hover {
    background: rgba(255,255,255,0.06);
}

.sidebar-session-item.active {
    background: rgba(101,102,241,0.15);
}

.sidebar-session-icon {
    width: 28px; height: 28px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
}

.sidebar-session-info {
    flex: 1;
    min-width: 0;
}

.sidebar-session-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-session-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.sidebar-session-delete {
    opacity: 0;
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    flex-shrink: 0;
    display: flex;
}

.sidebar-session-item:hover .sidebar-session-delete {
    opacity: 1;
}

.sidebar-session-delete:hover {
    color: var(--error);
}

.sidebar-mobile-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.sidebar-mobile-overlay.visible {
    opacity: 1;
    visibility: visible;
}

/* ============================================
   SPLIT LAYOUT (П.18: відступ зверху під fixed top-nav-bar)
   ============================================ */
.split-layout {
    flex: 1;
    min-height: 0;
    height: calc(100vh - 49px);
    max-height: calc(100vh - 49px);
    display: flex;
    overflow: hidden;
    position: relative;
    z-index: 1;
    margin-top: 49px; /* висота .top-nav-bar щоб не ховатись під нею */
}

/* LEFT: PP Panel — 40% ширини; мінімальна висота 0 щоб flex-скрол працював */
.pp-panel {
    flex: 0 0 40%;
    min-width: 280px;
    min-height: 0;
    max-width: 50%;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    overflow: hidden;
}

.pp-panel-header {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    flex-shrink: 0;
    background: rgba(15,10,46,0.5);
    position: sticky;
    top: 0;
    z-index: 10;
}
.pp-panel-limit-wrap {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.pp-panel-limit-label {
    font-size: 12px;
    color: var(--text-dim);
    white-space: nowrap;
}
.pp-panel-limit-select {
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.06);
    color: var(--text);
    cursor: pointer;
    font-family: inherit;
}
.pp-panel-limit-select:hover,
.pp-panel-limit-select:focus {
    border-color: rgba(101,102,241,0.5);
    outline: none;
}

.pp-panel-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.pp-panel-select-links {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
}

.pp-panel-select-sep {
    color: var(--text-muted);
    user-select: none;
}

.pp-panel-select-link {
    background: none;
    border: none;
    padding: 0;
    font-size: 12px;
    color: var(--primary);
    cursor: pointer;
    font-family: inherit;
    text-decoration: none;
}

.pp-panel-select-link:hover {
    text-decoration: underline;
    color: var(--primary-hover);
}

.pp-panel-bookmark-btn {
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-dim);
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.pp-panel-bookmark-btn:hover:not(:disabled) {
    background: rgba(101,102,241,0.2);
    color: #a5b4fc;
    border-color: rgba(101,102,241,0.4);
}

.pp-panel-bookmark-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.pp-panel-clear-btn {
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-dim);
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.pp-panel-clear-btn:hover:not(:disabled) {
    background: rgba(255,255,255,0.1);
    color: var(--text);
    border-color: rgba(255,255,255,0.2);
}

.pp-panel-clear-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.pp-panel-title {
    font-size: 13px;
    color: var(--text-dim);
}

.pp-panel-title strong {
    color: var(--text);
}

/* Кількість ПП — помітніше (орієнтація на обсяг масиву) */
.pp-panel-title-prominent {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}
.pp-panel-title-prominent strong {
    color: var(--success);
    font-size: 1.15em;
}

.pp-panel-subtitle {
    font-size: 11px;
    color: var(--text-muted);
}

/* Вартість обробки запиту (ліва панель) */
.pp-panel-cost-wrap {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    padding: 6px 12px;
    border-radius: var(--radius);
    border: 1px solid rgba(101,102,241,0.35);
    background: rgba(255,255,255,0.03);
}
.pp-panel-cost-label {
    font-size: 12px;
    color: var(--text);
}
.pp-panel-cost-value {
    font-size: 14px;
    font-weight: 700;
    color: var(--success);
}
.pp-panel-cost-currency {
    font-size: 12px;
    color: var(--text);
}

/* Кнопка довідки (?) на панелі ПП — як на панелі пошуку */
.pp-help-icon {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.25);
    background: rgba(255,255,255,0.06);
    color: var(--text-dim);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-family: inherit;
    line-height: 1;
}
.pp-help-icon:hover {
    background: rgba(101,102,241,0.2);
    color: var(--text);
    border-color: rgba(101,102,241,0.4);
}

.pp-help-tooltip {
    position: fixed;
    max-width: 320px;
    padding: 10px 14px;
    background: rgba(15,10,46,0.98);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 12px;
    line-height: 1.5;
    z-index: 2001;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s, visibility 0.15s;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}
.pp-help-tooltip.visible {
    opacity: 1;
    visibility: visible;
}

/* Нормальний список: чіткі відступи між елементами, окремі картки */
.pp-cards-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.pp-cards-list::-webkit-scrollbar { width: 5px; }
.pp-cards-list::-webkit-scrollbar-track { background: transparent; }
.pp-cards-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 3px; }

.pp-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
    font-size: 13px;
    gap: 12px;
}

.pp-empty-state svg {
    opacity: 0.4;
}

/* PP Card — один елемент списку: чітка картка з відступами, не стискати */
.pp-card {
    display: flex;
    flex-shrink: 0;
    gap: 12px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    overflow: hidden;
    transition: border-color 0.2s, background 0.2s;
    padding: 14px 16px;
}

.pp-card:hover {
    border-color: rgba(255,255,255,0.12);
}

.pp-card.pp-card-highlight {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(101,102,241,0.3);
}

.pp-card-checkbox-wrap {
    display: flex;
    align-items: flex-start;
    padding-top: 2px;
    cursor: pointer;
    flex-shrink: 0;
}

.pp-card-checkbox {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    cursor: pointer;
}

.pp-card-num {
    width: 28px;
    height: 28px;
    min-width: 28px;
    border-radius: 50%;
    background: rgba(167, 139, 250, 0.35);
    color: #e9d5ff;
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.pp-card-inner {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.pp-card-meta-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

.pp-card-pill {
    font-size: 11px;
    font-weight: 500;
    padding: 4px 8px;
    border-radius: 6px;
    white-space: nowrap;
}

.pp-card-pill-date {
    background: rgba(74, 222, 128, 0.25);
    color: #bbf7d0;
}

.pp-card-pill-case {
    background: rgba(255, 255, 255, 0.12);
    color: var(--text);
}

.pp-card-pill-type {
    background: rgba(255, 255, 255, 0.12);
    color: var(--text);
}

.pp-card-actions {
    margin-left: auto;
    display: flex;
    gap: 4px;
}

.pp-card-action {
    width: 26px;
    height: 26px;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 6px;
    background: rgba(255,255,255,0.04);
    color: var(--text-dim);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    text-decoration: none;
}

.pp-card-action:hover {
    background: rgba(255,255,255,0.08);
    color: var(--text);
}

.pp-card-remove {
    color: var(--error) !important;
    border-color: rgba(239,68,68,0.2) !important;
}

.pp-card-remove:hover {
    background: rgba(239,68,68,0.1) !important;
}

.pp-card-summary {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.45;
    user-select: text;
    -webkit-user-select: text;
}

/* Не більше 4 рядків змісту ПП (не короткої назви) — далі «Читати детальніше» */
.pp-card-body {
    font-size: 12px;
    color: var(--text-dim);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 4;
    overflow: hidden;
    position: relative;
    user-select: text;
    -webkit-user-select: text;
}

.pp-card-body::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 24px;
    background: linear-gradient(transparent, rgba(15,10,46,0.92));
    pointer-events: none;
}

.pp-card-read-more {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--primary);
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    margin-top: 2px;
    transition: color 0.15s;
    font-family: inherit;
    text-align: left;
}

.pp-card-read-more:hover {
    color: #a5b4fc;
    text-decoration: underline;
}

.pp-card-read-more svg {
    flex-shrink: 0;
}

/* Modal: повний текст ПП */
.pp-full-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.pp-full-modal[hidden] {
    display: none !important;
}

.pp-full-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    cursor: pointer;
}

.pp-full-modal-box {
    position: relative;
    width: 100%;
    max-width: 640px;
    max-height: 85vh;
    background: rgba(15, 10, 46, 0.98);
    border: 1px solid var(--border);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.pp-full-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.pp-full-modal-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

.pp-full-modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-dim);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: all 0.15s;
}

.pp-full-modal-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
}

.pp-full-modal-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px 18px;
}

.pp-full-modal-loading {
    color: var(--text-muted);
    font-size: 14px;
}

.pp-full-modal-content {
    font-size: 14px;
    line-height: 1.7;
    color: var(--text);
    word-break: break-word;
    user-select: text;
    -webkit-user-select: text;
}

.pp-full-modal-content p {
    margin: 0 0 0.75em;
}

.pp-full-modal-content p:last-child {
    margin-bottom: 0;
}

.pp-full-modal-content strong, .pp-full-modal-content b {
    font-weight: 700;
}

.pp-full-modal-content ul, .pp-full-modal-content ol {
    margin: 0.5em 0 0.75em 1.25em;
    padding: 0;
}

.pp-full-modal-content li {
    margin-bottom: 0.25em;
}

.pp-full-modal-content div {
    margin-bottom: 0.5em;
}

.pp-full-modal-link-wrap {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}

.pp-full-modal-links-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1em;
}

.pp-full-modal-link {
    font-size: 13px;
    color: var(--primary);
    text-decoration: none;
}

.pp-full-modal-link:hover {
    text-decoration: underline;
    color: #a5b4fc;
}

/* ============================================
   VERDICT ANALYSIS MODAL (Аналіз вироку 1 інстанції)
   ============================================ */
.verdict-analysis-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.verdict-analysis-modal[hidden] {
    display: none !important;
}

.verdict-analysis-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    cursor: pointer;
}

.verdict-analysis-box {
    position: relative;
    width: 100%;
    max-width: 640px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    overflow: hidden;
}

.verdict-analysis-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.verdict-analysis-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

.verdict-analysis-close {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.verdict-analysis-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
}

.verdict-analysis-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 18px;
}

.verdict-analysis-desc {
    font-size: 14px;
    color: var(--text-dim);
    margin-bottom: 16px;
    line-height: 1.5;
}

.verdict-analysis-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.verdict-analysis-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}

.verdict-analysis-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    font-size: 14px;
}

.verdict-analysis-input::placeholder {
    color: var(--text-muted);
}

.verdict-analysis-textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    resize: vertical;
    min-height: 120px;
}

.verdict-analysis-textarea::placeholder {
    color: var(--text-muted);
}

.verdict-analysis-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.verdict-analysis-submit {
    padding: 10px 20px;
    border-radius: var(--radius);
    border: none;
    background: var(--primary);
    color: white;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.verdict-analysis-submit:hover:not(:disabled) {
    background: var(--primary-hover);
}

.verdict-analysis-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.verdict-analysis-status {
    font-size: 13px;
    color: var(--text-muted);
}

.verdict-analysis-result {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.verdict-analysis-result-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text);
}

.verdict-analysis-result-content {
    font-size: 14px;
    line-height: 1.7;
    color: var(--text);
    white-space: pre-wrap;
    max-height: 400px;
    overflow-y: auto;
}

.chat-verdict-btn {
    margin-right: 8px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.chat-verdict-btn-teaser:disabled,
.chat-verdict-btn-locked:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}
.chat-verdict-lock-icon {
    flex-shrink: 0;
    opacity: 0.85;
}
.chat-model-choice option:disabled {
    color: var(--text-muted);
}

/* RIGHT: Chat Panel — 60%. Панель введення завжди прикріплена внизу (як у ChatGPT), скролиться лише область повідомлень */
.chat-panel {
    flex: 1;
    min-height: 0;
    min-width: 340px;
    display: grid;
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
        "chat-header"
        "chat-messages"
        "chat-input-bottom";
    overflow: hidden;
    background: rgba(15,10,46,0.6);
    border-left: 1px solid var(--border);
}

.chat-header {
    grid-area: chat-header;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    background: rgba(15,10,46,0.5);
    position: sticky;
    top: 0;
    z-index: 10;
    flex-shrink: 0;
}

.chat-input-bottom {
    grid-area: chat-input-bottom;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    padding: 12px 16px 16px;
    background: rgba(15,10,46,0.98);
    border-top: 1px solid var(--border);
    /* Прикріплена до низу екрану (як у ChatGPT) — завжди видна без скролу */
    position: fixed;
    bottom: 0;
    left: 40%;
    right: 0;
    z-index: 50;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.25);
}

.chat-messages {
    grid-area: chat-messages;
}

.chat-context-pp {
    font-size: 13px;
    color: var(--text-dim);
}
.chat-context-pp strong {
    color: var(--success);
    font-weight: 700;
}

.chat-balance {
    font-size: 14px;
    color: var(--text-dim);
}
.chat-balance strong {
    color: var(--success);
    font-weight: 700;
}

.chat-counter {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
}

.chat-counter.warning {
    color: var(--warning);
}

.chat-counter.exhausted {
    color: var(--error);
}

.chat-model-select {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-model-label {
    font-size: 12px;
    color: var(--text-dim);
    white-space: nowrap;
}

.chat-model-choice {
    padding: 4px 8px;
    font-size: 12px;
    color: var(--text);
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
}

.chat-model-choice:focus {
    outline: none;
    border-color: var(--primary);
}

/* Неактивні пункти випадаючого списку — темний фон, щоб було видно */
.chat-model-choice option {
    background: var(--bg);
    color: var(--text);
}

.chat-model-choice option:checked {
    background: var(--primary);
    color: white;
}

.chat-new-btn {
    padding: 6px 16px;
    border-radius: 6px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.12);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.chat-new-btn:hover {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.2);
}

/* Messages area — прокручується; відступ знизу, щоб останнє повідомлення не ховалось під фіксованою панеллю введення */
.chat-messages {
    grid-area: chat-messages;
    min-height: 0;
    overflow-y: auto;
    padding: 16px 16px 160px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-messages::-webkit-scrollbar { width: 5px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 3px; }

/* Welcome state */
.chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    text-align: center;
    padding: 40px 20px;
    gap: 16px;
    color: var(--text-muted);
}

.chat-welcome-icon {
    width: 64px; height: 64px;
    border-radius: 50%;
    background: rgba(101,102,241,0.1);
    border: 1px solid rgba(101,102,241,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #a5b4fc;
}

.chat-welcome-text {
    font-size: 14px;
    line-height: 1.7;
    max-width: 360px;
}

/* Chat message — не стискати, щоб довга відповідь не обрізалась */
.chat-msg {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
    animation: msgIn 0.3s ease-out;
}

@keyframes msgIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-msg.user-msg {
    flex-direction: row-reverse;
}

.chat-msg-avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 12px;
    flex-shrink: 0;
}

.ai-msg .chat-msg-avatar {
    background: linear-gradient(135deg, #06b6d4, #0891b2);
    color: white;
}

.user-msg .chat-msg-avatar {
    background: linear-gradient(135deg, #eab308, #ca8a04);
    color: white;
}

.chat-msg-body {
    flex: 1 1 auto;
    max-width: 82%;
    min-width: 0;
    min-height: 0;
    overflow: visible;
}

.chat-msg-bubble {
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 13px;
    line-height: 1.65;
    word-break: break-word;
    overflow-wrap: break-word;
    user-select: text;
    -webkit-user-select: text;
}

.ai-msg .chat-msg-bubble {
    background: rgba(255,255,255,0.06);
    color: var(--text);
    border: 1px solid rgba(255,255,255,0.06);
    border-top-left-radius: 2px;
}

.user-msg .chat-msg-bubble {
    background: rgba(234, 179, 8, 0.12);
    border: 1px solid rgba(234, 179, 8, 0.18);
    color: var(--text);
    border-top-right-radius: 2px;
}

.chat-msg-bubble p { margin: 0 0 0.75em; line-height: 1.65; }
.chat-msg-bubble p:last-child { margin-bottom: 0; }
.chat-msg-bubble p + p { margin-top: 0.25em; }

/* П.23: посилання на справи — явні значення, щоб стилі не падали */
.chat-msg-bubble .chat-pp-ref,
.chat-msg-bubble a.chat-pp-ref {
    color: #6566F1;
    color: var(--primary);
    text-decoration: underline;
    cursor: pointer;
}
.chat-msg-bubble .chat-pp-ref:hover,
.chat-msg-bubble a.chat-pp-ref:hover {
    color: #a5b4fc;
    color: var(--primary-hover);
}
.chat-msg-bubble ul, .chat-msg-bubble ol { margin: 8px 0 8px 20px; padding-left: 4px; }
.chat-msg-bubble li { margin-bottom: 10px; line-height: 1.65; }
.chat-msg-bubble li:last-child { margin-bottom: 0; }
.chat-msg-bubble strong { color: #c4b5fd; }
.chat-msg-bubble code {
    background: rgba(0,0,0,0.3);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 12px;
}
.chat-msg-bubble blockquote {
    border-left: 3px solid var(--primary);
    padding-left: 10px;
    margin: 6px 0;
    color: var(--text-dim);
}

/* Заголовки в відповідях AI (##, ###, "Група N:") */
.chat-msg-bubble .chat-md-h2,
.chat-msg-bubble h3.chat-md-h2 {
    font-size: 14px;
    font-weight: 700;
    color: var(--primary);
    margin: 14px 0 10px;
    line-height: 1.4;
}
.chat-msg-bubble .chat-md-h2:first-child,
.chat-msg-bubble h3.chat-md-h2:first-child { margin-top: 0; }
.chat-msg-bubble .chat-md-h3,
.chat-msg-bubble h4.chat-md-h3 {
    font-size: 13px;
    font-weight: 600;
    color: #c4b5fd;
    margin: 12px 0 8px;
    line-height: 1.4;
}
.chat-msg-bubble .chat-md-h3:first-child,
.chat-msg-bubble h4.chat-md-h3:first-child { margin-top: 0; }

/* Highlighted words in AI responses */
.chat-msg-bubble mark,
.chat-msg-bubble .chat-highlight {
    background: #facc15;
    color: #1a1145;
    padding: 1px 3px;
    border-radius: 3px;
    font-weight: 600;
}

.chat-msg-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 3px;
    padding: 0 4px;
}

.chat-msg-label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
}

.chat-msg-copy {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 5px;
    border-radius: 3px;
    font-size: 10px;
    transition: all 0.15s;
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 3px;
}

.chat-msg-copy:hover {
    color: var(--text);
    background: rgba(255,255,255,0.06);
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 14px;
}

.typing-indicator span {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--text-dim);
    animation: bounce 1.4s infinite both;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.3; }
    40% { transform: scale(1); opacity: 1; }
}

/* Limit reached */
.chat-limit-msg {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: rgba(245,158,11,0.08);
    border: 1px solid rgba(245,158,11,0.2);
    border-radius: 10px;
    color: #fbbf24;
    font-size: 13px;
}

.chat-limit-msg svg { flex-shrink: 0; }

/* Експерименти з промптом */
.chat-prompt-experiment {
    flex-shrink: 0;
    border-top: 1px solid var(--border);
    background: rgba(15,10,46,0.4);
}

.chat-prompt-experiment-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: color 0.15s;
}

.chat-prompt-experiment-toggle:hover {
    color: var(--text);
}

.chat-prompt-experiment-chevron {
    flex-shrink: 0;
    transition: transform 0.2s;
}

.chat-prompt-experiment-toggle.open .chat-prompt-experiment-chevron {
    transform: rotate(180deg);
}

.chat-input-bottom .chat-prompt-experiment {
    margin-bottom: 8px;
}

.chat-input-bottom .chat-prompt-experiment-body {
    padding: 0 16px 12px;
    max-height: 75vh;
    overflow-y: auto;
}

.chat-prompt-experiment-body[hidden] {
    display: none !important;
}

.chat-prompt-experiment-body::-webkit-scrollbar { width: 6px; }
.chat-prompt-experiment-body::-webkit-scrollbar-track { background: transparent; }
.chat-prompt-experiment-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }

.chat-prompt-override {
    width: 100%;
    min-height: 520px;
    max-height: 70vh;
    padding: 10px 12px;
    font-size: 12px;
    font-family: inherit;
    line-height: 1.5;
    color: var(--text);
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    resize: vertical;
    display: block;
    overflow-y: auto;
    box-sizing: border-box;
}

.chat-prompt-override::placeholder {
    color: var(--text-muted);
}

.chat-prompt-override:focus {
    outline: none;
    border-color: rgba(101,102,241,0.4);
}

.chat-prompt-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 10px;
}

.chat-prompt-save-btn {
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    background: rgba(101,102,241,0.25);
    border: 1px solid rgba(101,102,241,0.5);
    border-radius: 8px;
    cursor: pointer;
}

.chat-prompt-save-btn:hover {
    background: rgba(101,102,241,0.35);
}

.chat-prompt-save-status {
    font-size: 13px;
}

.chat-prompt-save-status.success {
    color: var(--success, #22c55e);
}

.chat-prompt-save-status.error {
    color: var(--error, #ef4444);
}

.chat-prompt-restore-btn {
    padding: 8px 14px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-dim);
    background: transparent;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 8px;
    cursor: pointer;
}

.chat-prompt-restore-btn:hover {
    color: var(--text);
    border-color: rgba(255,255,255,0.35);
}

.chat-input-area {
    padding: 10px 16px 14px;
    flex-shrink: 0;
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    padding: 6px 6px 6px 14px;
    transition: border-color 0.2s;
}

.chat-input-wrapper:focus-within {
    border-color: rgba(101,102,241,0.4);
}

.chat-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    line-height: 1.5;
    resize: none;
    max-height: 100px;
    padding: 4px 0;
}

.chat-input::placeholder { color: var(--text-muted); }

.chat-send-btn {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--primary);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}

.chat-send-btn:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: scale(1.05);
}

.chat-send-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.chat-stop-btn {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.2);
    color: var(--text);
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}

.chat-stop-btn:hover {
    background: rgba(239,68,68,0.2);
    border-color: var(--error);
    color: var(--error);
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 900px) {
    .split-layout {
        flex-direction: column;
    }

    .pp-panel {
        width: 100%;
        min-width: 0;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .chat-panel {
        min-width: 0;
    }

    .chat-input-bottom {
        left: 0;
    }

    .top-nav {
        padding-left: 46px;
        gap: 4px;
    }

    .top-nav-btn {
        padding: 6px 12px;
        font-size: 11px;
    }
}

@media (max-width: 600px) {
    .pp-panel {
        max-height: 30vh;
    }

    .chat-msg-body {
        max-width: 90%;
    }
}

/* ============================================
   SCROLLBAR for sidebar
   ============================================ */
.sidebar-sessions-list::-webkit-scrollbar { width: 4px; }
.sidebar-sessions-list::-webkit-scrollbar-track { background: transparent; }
.sidebar-sessions-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 2px; }
