/* === Jarvis — стили === */

:root {
    --bg:           #0c1015;
    --bg-elevated:  #141b23;
    --panel:        #1a2330;
    --panel-strong: #243142;
    --border:       rgba(255, 255, 255, 0.08);
    --border-strong:rgba(255, 255, 255, 0.18);
    --text:         #e6edf3;
    --text-muted:   #8b96a5;
    --accent:       #64c8ff;
    --accent-strong:#3aa8e8;
    --user-bubble:  #1c2e44;
    --assistant-bubble: #1a2330;
    --danger:       #ff6464;
    --success:      #64dca0;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
                 Arial, "PingFang SC", "Hiragino Sans GB", sans-serif;
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

body { display: flex; flex-direction: column; }

button { font-family: inherit; }

/* --- Auth page --- */

.auth-shell {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background:
        radial-gradient(circle at 30% 20%, rgba(100, 200, 255, 0.08), transparent 50%),
        radial-gradient(circle at 70% 80%, rgba(60, 168, 232, 0.06), transparent 50%),
        var(--bg);
}

.auth-card {
    width: 100%;
    max-width: 360px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 36px 28px 28px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.auth-logo-img {
    display: block;
    width: 140px;
    height: 140px;
    margin: 0 auto 14px;
    border-radius: 18px;
    object-fit: cover;
    filter: drop-shadow(0 6px 24px rgba(100, 200, 255, 0.25));
}

.auth-tagline {
    text-align: center;
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 1.4px;
    margin-bottom: 28px;
    background: linear-gradient(135deg, #64c8ff 0%, #b08fff 100%);
    -webkit-background-clip: text;
            background-clip: text;
    -webkit-text-fill-color: transparent;
}

.auth-field { margin-bottom: 16px; }
.auth-field label {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 6px;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}
.auth-field input {
    width: 100%;
    padding: 11px 14px;
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s, background 0.2s;
}
.auth-field input:focus {
    border-color: var(--accent);
    background: var(--panel-strong);
}

.auth-submit {
    width: 100%;
    padding: 12px;
    margin-top: 12px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
    color: #0a1420;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.05s;
}
.auth-submit:hover { opacity: 0.92; }
.auth-submit:active { transform: scale(0.98); }
.auth-submit:disabled { opacity: 0.5; cursor: wait; }

.auth-error {
    margin-top: 14px;
    color: var(--danger);
    font-size: 13px;
    min-height: 18px;
    text-align: center;
}
.auth-info {
    margin-top: 10px;
    padding: 10px 12px;
    background: rgba(100, 200, 255, 0.08);
    border: 1px solid rgba(100, 200, 255, 0.25);
    border-radius: 10px;
    font-size: 13px;
    line-height: 1.45;
    color: var(--text);
}
.auth-info strong { color: var(--accent); }

/* --- Chat shell --- */

/* === Плавающее меню в углу: круглая кнопка-логотип + dropdown-таблетка === */
.topbar-menu {
    position: fixed;
    top: 14px;
    left: 14px;
    z-index: 100;
}

.topbar-logo-btn {
    position: relative;
    width: 60px;
    height: 60px;
    padding: 0;
    background: transparent;
    background-color: #000;
    border: 2px solid rgba(100, 200, 255, 0.55);
    border-radius: 50%;
    cursor: pointer;
    overflow: hidden;
    /* «Живой» эффект — мерцание ободка и halo между голубым и фиолетовым.
       Цикл 4 с, плавный ease-in-out — ассоциация с дыханием/связью. */
    animation: jarvis-alive 4s ease-in-out infinite;
    transition: filter 0.2s, transform 0.1s;
}
.topbar-logo-btn img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
}
.topbar-logo-btn:hover { filter: brightness(1.1); }
.topbar-logo-btn:active { transform: scale(0.97); }

@keyframes jarvis-alive {
    0%, 100% {
        border-color: rgba(100, 200, 255, 0.65);
        box-shadow:
            0 0 0 2px rgba(100, 200, 255, 0.18),
            0 4px 22px rgba(100, 200, 255, 0.35);
    }
    50% {
        border-color: rgba(176, 143, 255, 0.75);
        box-shadow:
            0 0 0 2px rgba(176, 143, 255, 0.22),
            0 6px 26px rgba(176, 143, 255, 0.45);
    }
}
@media (prefers-reduced-motion: reduce) {
    .topbar-logo-btn { animation: none; }
}

/* Bridge — невидимая полоса 12px между логотипом и dropdown,
   чтобы курсор мог перейти между ними без потери :hover на родителе. */
.topbar-menu::before {
    content: '';
    position: absolute;
    top: 60px;
    left: 0;
    width: 60px;
    height: 12px;
    pointer-events: none;
}
.topbar-menu:hover::before,
.topbar-menu.open::before { pointer-events: auto; }

/* Dropdown — вертикальная таблетка с круглыми кнопками */
.topbar-dropdown {
    position: absolute;
    top: 72px;
    left: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 8px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 32px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
    opacity: 0;
    pointer-events: none;
    transform: translateY(-6px);
    transition: opacity 0.16s, transform 0.16s;
}
.topbar-menu:hover .topbar-dropdown,
.topbar-menu:focus-within .topbar-dropdown,
.topbar-menu.open .topbar-dropdown {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

/* Кнопки внутри dropdown */
.icon-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 50%;
    color: var(--text-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    position: relative;
}
.icon-btn:hover {
    color: var(--text);
    border-color: var(--border-strong);
    background: var(--panel);
}

/* Тултип справа от любого [data-tooltip] внутри .topbar-menu */
.topbar-menu [data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 12px);
    top: 50%;
    transform: translate(-6px, -50%);
    padding: 5px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 14px;
    color: var(--text);
    font-size: 13px;
    line-height: 1.3;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
    transition: opacity 0.15s 0.05s, transform 0.15s 0.05s;
    z-index: 110;
}
.topbar-menu [data-tooltip]:hover::after,
.topbar-menu [data-tooltip]:focus-visible::after {
    opacity: 1;
    transform: translate(0, -50%);
}

/* --- Chat container --- */

#chat-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    /* Сверху резервируем место под плавающую кнопку-логотип (top:14, size:60). */
    padding: 92px 20px 12px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
}

#chat-container::-webkit-scrollbar { width: 8px; }
#chat-container::-webkit-scrollbar-track { background: transparent; }
#chat-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 4px;
}
#chat-container::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.18); }

.chat-empty {
    text-align: center;
    margin: auto;
    padding: 40px 20px;
    color: var(--text-muted);
}

/* --- Sentinel для подгрузки старых сообщений --- */
.history-sentinel {
    align-self: center;
    width: 28px;
    height: 28px;
    margin: 6px 0 4px;
    flex-shrink: 0;
    position: relative;
}
.history-sentinel::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid transparent;
    border-top-color: var(--accent);
    opacity: 0;
    transition: opacity 0.15s;
}
.history-sentinel.loading::before {
    opacity: 1;
    animation: jarvis-tts-spin 0.9s linear infinite;
}
.chat-empty-title {
    font-size: 22px;
    color: var(--text);
    margin-bottom: 8px;
    font-weight: 500;
}
.chat-empty-hint { font-size: 14px; }

/* --- Message bubbles --- */

.msg {
    max-width: 78%;
    padding: 12px 16px 14px;
    border-radius: 14px;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    position: relative;
    animation: msg-in 0.18s ease-out;
}
@keyframes msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.msg.user {
    align-self: flex-end;
    background: var(--user-bubble);
    border: 1px solid rgba(100, 200, 255, 0.15);
    border-bottom-right-radius: 4px;
}
.msg.assistant {
    align-self: flex-start;
    background: var(--assistant-bubble);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.msg-content { white-space: pre-wrap; }
.msg-content p { margin: 0 0 10px; }
.msg-content p:last-child { margin-bottom: 0; }

.msg-content h1, .msg-content h2, .msg-content h3 {
    margin: 12px 0 6px;
    font-weight: 600;
}
.msg-content h1 { font-size: 18px; }
.msg-content h2 { font-size: 17px; }
.msg-content h3 { font-size: 16px; }

.msg-content ul, .msg-content ol {
    margin: 6px 0 10px;
    padding-left: 22px;
}
.msg-content li { margin-bottom: 4px; }

.msg-content code {
    background: rgba(255, 255, 255, 0.08);
    padding: 1px 6px;
    border-radius: 4px;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 13px;
}
.msg-content pre {
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    overflow-x: auto;
    margin: 8px 0;
}
.msg-content pre code {
    background: transparent;
    padding: 0;
    font-size: 13px;
    line-height: 1.5;
}
.msg-content a {
    color: var(--accent);
    text-decoration: none;
}
.msg-content a:hover { text-decoration: underline; }
.msg-content blockquote {
    border-left: 3px solid var(--border-strong);
    margin: 6px 0;
    padding-left: 10px;
    color: var(--text-muted);
}

.msg.assistant.streaming::after {
    content: '▊';
    display: inline-block;
    animation: cursor-blink 0.9s steps(2) infinite;
    color: var(--accent);
    margin-left: 2px;
}
@keyframes cursor-blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.msg-copy {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 24px;
    height: 24px;
    padding: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s, color 0.2s, background 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.msg:hover .msg-copy { opacity: 0.7; }
.msg-copy:hover {
    opacity: 1 !important;
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
}
.msg-copy.copied { color: var(--success); opacity: 1 !important; }

/* --- Input area --- */

/* === Input area — копия из Photon-а (прямоугольные 36×36 кнопки, белые иконки) === */
#input-area {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 14px;
    background: var(--bg-elevated);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 20;
}

#file-preview-bar {
    width: 100%;
    display: none;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 6px;
}
#file-preview-bar:not(:empty) { display: flex; }

.file-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px 4px 4px;
    background: var(--panel-strong);
    border: 1px solid var(--border);
    border-radius: 18px;
    font-size: 12px;
    max-width: 220px;
}
.file-chip-thumb { width: 28px; height: 28px; border-radius: 14px; object-fit: cover; }
.file-chip-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px; height: 28px;
    background: var(--accent);
    color: #0a1420;
    border-radius: 14px;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.3px;
}
.file-chip-name {
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 140px;
}
.file-chip-remove {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 0 4px;
    border-radius: 50%;
}
.file-chip-remove:hover { color: var(--text); }

#input-text {
    flex: 1;
    min-width: 0;
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    outline: none;
    resize: none;
    max-height: 100px;
    overflow-y: auto;
    /* Скрываем полосу прокрутки во всех движках — поле остаётся
       скроллабельным изнутри (клавиши/touch), но без визуального бара. */
    scrollbar-width: none;          /* Firefox */
    -ms-overflow-style: none;       /* IE/legacy Edge */
    transition: border-color 0.2s;
}
#input-text::-webkit-scrollbar { display: none; }  /* Chrome / Safari / Edge */
#input-text:focus { border-color: rgba(100, 200, 255, 0.4); }
#input-text::placeholder { color: var(--text-muted); }

/* --- Кнопки input-area: квадрат 36×36 с закруглением 8px, белые иконки --- */
.attachBtn,
.ttsToggleBtn,
.micBtn,
.sendBtn {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    padding: 0;
    background: var(--panel-strong);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s, transform 0.05s;
}
.attachBtn img,
.ttsToggleBtn img,
.micBtn img,
.sendBtn img {
    width: 18px;
    height: 18px;
    opacity: 0.85;
    pointer-events: none;
    transition: opacity 0.2s;
}
.attachBtn:hover,
.ttsToggleBtn:hover,
.micBtn:hover {
    border-color: var(--border-strong);
}
.attachBtn:hover img,
.ttsToggleBtn:hover img,
.micBtn:hover img { opacity: 1; }

/* Send — голубой акцент, как в Photon */
.sendBtn {
    background: #1f2e36;
    border-color: rgba(100, 200, 255, 0.25);
    color: rgba(100, 200, 255, 0.9);
}
.sendBtn:hover:not(:disabled) {
    background: #476271;
    color: #64c8ff;
}
.sendBtn:active { transform: scale(0.96); }
.sendBtn:disabled { opacity: 0.4; cursor: not-allowed; }
.sendBtn img { opacity: 1; }

/* Активное состояние авто-TTS */
.ttsToggleBtn.active {
    background: var(--accent);
    border-color: var(--accent);
}
.ttsToggleBtn.active img { opacity: 1; }

/* Микрофон в режиме записи — пульсирующее красное кольцо */
.micBtn.recording {
    border-color: #ff6b6b;
    animation: jarvis-mic-pulse 1.2s ease-in-out infinite;
}
@keyframes jarvis-mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 107, 107, 0.55); }
    100%     { box-shadow: 0 0 0 8px rgba(255, 107, 107, 0); }
}

/* --- Footer сообщения: время + стоимость + длительность + actions --- */
.msg-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 10px;
    padding-top: 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.2;
}
body.light .msg-footer { border-top-color: rgba(0, 0, 0, 0.08); }
.msg-meta {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex: 1 1 auto;
    min-width: 0;
    flex-wrap: wrap;
}
.msg-actions {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

/* TTS и copy — всегда видимые, компактные --- */
.msg-tts-btn, .msg-copy-btn {
    position: relative;
    width: 26px;
    height: 26px;
    padding: 4px;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 50%;
    cursor: pointer;
    opacity: 0.75;
    transition: opacity 0.15s, border-color 0.15s, background 0.15s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
body.light .msg-tts-btn, body.light .msg-copy-btn { border-color: rgba(0,0,0,0.12); }
.msg-tts-btn img, .msg-copy-btn img {
    width: 14px;
    height: 14px;
    filter: invert(1);
    opacity: 0.7;
}
body.light .msg-tts-btn img, body.light .msg-copy-btn img { filter: none; }
.msg-tts-btn:hover, .msg-copy-btn:hover {
    opacity: 1;
    border-color: rgba(100, 200, 255, 0.4);
    background: rgba(100, 200, 255, 0.08);
}
.msg-copy-btn.copied {
    opacity: 1;
    border-color: var(--success);
}
.msg-tts-btn.playing {
    opacity: 1;
    border-color: rgba(100, 200, 255, 0.5);
    background: rgba(100, 200, 255, 0.1);
    animation: jarvis-tts-pulse 1.5s infinite;
}
@keyframes jarvis-tts-pulse {
    0%, 100% { box-shadow: 0 0 5px rgba(100, 200, 255, 0.2); }
    50% { box-shadow: 0 0 15px rgba(100, 200, 255, 0.4); }
}
/* Loading-ring во время обработки TTS — статичная иконка + крутится кольцо вокруг */
.msg-tts-btn.loading { opacity: 0.6; }
.msg-tts-btn.loading::before {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    border: 2px solid transparent;
    border-top-color: #64c8ff;
    animation: jarvis-tts-spin 0.9s linear infinite;
    pointer-events: none;
}
@keyframes jarvis-tts-spin { to { transform: rotate(360deg); } }

/* --- Вложения в сообщениях --- */
.msg-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}
.msg-attachment-img {
    max-width: 280px;
    max-height: 220px;
    border-radius: 10px;
    cursor: pointer;
    border: 1px solid var(--border);
}
.msg-attachment-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(100, 200, 255, 0.08);
    color: var(--accent);
    text-decoration: none;
    border: 1px solid rgba(100, 200, 255, 0.18);
    border-radius: 14px;
    font-size: 13px;
}
.msg-attachment-link:hover { background: rgba(100, 200, 255, 0.15); }

/* --- Модалка просмотра картинок --- */
.image-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(5, 8, 16, 0.92);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    align-items: center;
    justify-content: center;
    padding: 40px 24px 60px;
    animation: jarvis-image-modal-fade 0.18s ease-out;
}
.image-modal.open { display: flex; }
@keyframes jarvis-image-modal-fade { from { opacity: 0; } to { opacity: 1; } }

.image-modal-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
    cursor: default;
    user-select: none;
    -webkit-user-drag: none;
}
.image-modal-caption {
    position: absolute;
    left: 50%;
    bottom: 16px;
    transform: translateX(-50%);
    max-width: 90vw;
    color: rgba(255, 255, 255, 0.85);
    font-size: 14px;
    text-align: center;
    line-height: 1.4;
    padding: 6px 14px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 8px;
    pointer-events: none;
}
.image-modal-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: #fff;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    border-radius: 50%;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.image-modal-close:hover {
    background: rgba(255, 107, 107, 0.22);
    border-color: rgba(255, 107, 107, 0.55);
    color: #ff6b6b;
}
.image-modal-download {
    position: absolute;
    top: 14px;
    right: 64px;
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: #fff;
    font-size: 20px;
    line-height: 1;
    text-decoration: none;
    border-radius: 50%;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.image-modal-download:hover {
    background: rgba(100, 200, 255, 0.22);
    border-color: rgba(100, 200, 255, 0.55);
    color: var(--accent);
}
body.image-modal-open { overflow: hidden; }

@media (max-width: 600px) {
    .image-modal { padding: 16px 8px 40px; }
    .image-modal-close { top: 10px; right: 10px; }
    .image-modal-download { top: 10px; right: 58px; }
    .image-modal-caption { font-size: 13px; bottom: 8px; }
}

/* --- Settings modal --- */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 100;
    backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none; }

.modal-content {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 16px;
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
}
.modal-header h2 {
    margin: 0;
    font-size: 17px;
    font-weight: 600;
}
.modal-close {
    width: 30px;
    height: 30px;
    padding: 0;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.2s;
}
.modal-close:hover {
    background: var(--panel);
    color: var(--text);
}

.modal-body {
    padding: 18px 22px;
    overflow-y: auto;
    flex: 1;
}

.modal-field { margin-bottom: 20px; }
.modal-field:last-child { margin-bottom: 0; }
.modal-field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}
.modal-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
}
.modal-field textarea,
.modal-field input[type="password"],
.modal-field input[type="text"] {
    width: 100%;
    padding: 10px 12px;
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    outline: none;
    transition: border-color 0.2s, background 0.2s;
}
.modal-field textarea {
    resize: vertical;
    min-height: 80px;
}
.modal-field input { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
/* Маскируем секретное поле, даже если оно textarea (для удобной вставки JSON). */
#api-key-input {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    -webkit-text-security: disc;
    text-security: disc;
    white-space: pre-wrap;
    word-break: break-all;
}
.modal-field textarea:focus,
.modal-field input:focus {
    border-color: var(--accent);
    background: var(--panel-strong);
}
.modal-hint a { color: var(--accent); text-decoration: none; }
.modal-hint a:hover { text-decoration: underline; }

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 14px;
    padding: 14px 22px;
    border-top: 1px solid var(--border);
}

.primary-btn {
    padding: 9px 20px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
    color: #0a1420;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.05s;
}
.primary-btn:hover { opacity: 0.92; }
.primary-btn:active { transform: scale(0.98); }

.modal-status {
    font-size: 13px;
    color: var(--text-muted);
}
.modal-status.success { color: var(--success); }
.modal-status.error { color: var(--danger); }
