/* ── Reset & Base ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #16213e;
    --bg-input: #12122a;
    --border: #2a2a4a;
    --border-focus: #e94560;
    --text-primary: #e0e0e0;
    --text-secondary: #888899;
    --text-muted: #555577;
    --accent-blue: #3498db;
    --accent-green: #1b8a5a;
    --accent-green-hover: #22a66e;
    --accent-red: #c23152;
    --accent-red-hover: #e94560;
    --accent-navy: #0f3460;
    --accent-navy-hover: #1a4a7a;
    --user-bubble: #0f3460;
    --assistant-bubble: #1a1a2e;
    --thinking-bg: #111128;
    --scrollbar-track: #0f0f1a;
    --scrollbar-thumb: #2a2a4a;
    --radius: 8px;
    --radius-lg: 12px;
    /* Glass surfaces (aligned with voice entry bar) */
    --ui-teal: rgba(64, 214, 198, 0.55);
    --ui-teal-muted: rgba(64, 214, 198, 0.28);
    --ui-teal-soft: rgba(64, 214, 198, 0.12);
    --ui-teal-faint: rgba(64, 214, 198, 0.06);
    --glass-edge: rgba(255, 255, 255, 0.08);
    --glass-edge-faint: rgba(255, 255, 255, 0.04);
    --glass-surface: linear-gradient(
        165deg,
        rgba(30, 32, 52, 0.94) 0%,
        rgba(22, 24, 42, 0.97) 45%,
        rgba(18, 20, 36, 0.98) 100%
    );
    --glass-surface-mid: linear-gradient(
        165deg,
        rgba(26, 28, 48, 0.92) 0%,
        rgba(20, 22, 40, 0.96) 100%
    );
    --glass-blur: 14px;
    --glass-shadow-up: 0 -8px 32px rgba(0, 0, 0, 0.35);
    --glass-inset-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

html, body {
    height: 100%;
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px;
    color: var(--text-primary);
    background:
        radial-gradient(ellipse 120% 80% at 50% -20%, rgba(64, 214, 198, 0.07), transparent 55%),
        radial-gradient(ellipse 90% 60% at 100% 100%, rgba(52, 152, 219, 0.05), transparent 50%),
        var(--bg-primary);
    overflow: hidden;
    touch-action: manipulation;
}

/* ── Scrollbar ────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #3a3a5a; }

/* ── Login screen ─────────────────────────────────────────────────── */
#login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background:
        radial-gradient(ellipse 120% 80% at 50% -20%, rgba(64, 214, 198, 0.08), transparent 55%),
        var(--bg-primary);
}

.login-card {
    position: relative;
    background: var(--glass-surface);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-edge-faint);
    border-top-color: var(--glass-edge);
    border-radius: 14px;
    padding: 40px;
    width: 420px;
    max-width: 90vw;
    box-shadow:
        0 24px 64px rgba(0, 0, 0, 0.45),
        0 0 0 1px var(--ui-teal-faint) inset,
        var(--glass-inset-highlight);
}

.login-card h1 {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 24px;
    text-align: center;
    color: var(--text-primary);
}

.mode-buttons {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

.mode-btn {
    flex: 1;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    text-align: center;
}

.mode-btn:hover { border-color: var(--ui-teal-muted); }
.mode-btn.active-admin { background: var(--accent-navy); border-color: var(--accent-blue); }
.mode-btn.active-user { background: var(--accent-green); border-color: var(--accent-green-hover); }

.login-field {
    margin-bottom: 16px;
}

.login-field label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.login-field input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s;
}

.login-field input:focus {
    border-color: var(--ui-teal-muted);
    box-shadow: 0 0 0 1px var(--ui-teal-faint);
}

.password-wrapper {
    position: relative;
}
.password-wrapper input {
    padding-right: 40px;
}
.pw-toggle {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
}
.pw-toggle:hover { color: var(--text-primary); }

.login-btn {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: var(--radius);
    background: var(--accent-blue);
    color: white;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.login-btn:hover { background: #2980b9; }
.login-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.login-link-btn {
    display: block;
    width: 100%;
    margin-top: 10px;
    padding: 8px;
    border: none;
    background: transparent;
    color: var(--accent-blue);
    font-size: 13px;
    cursor: pointer;
    text-align: center;
}

.login-link-btn:hover {
    text-decoration: underline;
}

.login-error {
    color: var(--accent-red);
    font-size: 12px;
    margin-top: 10px;
    text-align: center;
    min-height: 18px;
}

.login-success {
    color: var(--accent-green);
    font-size: 12px;
    margin-top: 10px;
    text-align: center;
    min-height: 18px;
}

.field-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 5px;
}

/* ── App layout ───────────────────────────────────────────────────── */
#app-screen {
    display: none;
    height: 100vh;
    height: 100dvh; /* dynamic viewport height – better on mobile */
    flex-direction: column;
}

.top-bar-wrap {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.top-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    background: var(--glass-surface-mid);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border-bottom: 1px solid var(--glass-edge-faint);
    box-shadow: 0 1px 0 var(--ui-teal-faint), var(--glass-inset-highlight);
}

.top-bar-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin-right: auto;
}

.top-bar-secondary {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 7px 16px 9px;
    background: var(--glass-surface);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border-bottom: 1px solid var(--glass-edge-faint);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
}

.top-bar-secondary-status {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.top-bar-status-text {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    max-width: min(40vw, 280px);
    overflow: hidden;
    text-overflow: ellipsis;
}

.top-bar-model-select {
    flex: 1;
    min-width: 0;
    padding: 6px 10px;
    border: 1px solid var(--glass-edge-faint);
    border-radius: var(--radius);
    background: rgba(12, 14, 28, 0.65);
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.top-bar-model-select:focus {
    border-color: var(--ui-teal-muted);
    box-shadow: 0 0 0 1px var(--ui-teal-faint);
}

.top-bar-model-label {
    padding: 5px 10px;
    border: 1px solid var(--glass-edge-faint);
    border-radius: var(--radius);
    background: rgba(12, 14, 28, 0.65);
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
}

.mic-prime-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    padding: 6px 16px;
    background: var(--ui-teal-soft);
    border-bottom: 1px solid var(--glass-edge-faint);
    font-size: 12px;
    color: var(--text-secondary);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.mic-prime-bar-text {
    flex: 1;
    min-width: 160px;
    line-height: 1.35;
}

.mic-prime-bar-btn {
    flex-shrink: 0;
    padding: 6px 14px;
    border: none;
    border-radius: var(--radius);
    background: var(--accent-blue);
    color: white;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}

.mic-prime-bar-btn:hover {
    filter: brightness(1.08);
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
}

.status-dot.ready { background: var(--accent-green); }
.status-dot.loading { background: #f39c12; animation: pulse 1.5s infinite; }
.status-dot.error { background: var(--accent-red); }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.top-bar-btn {
    padding: 5px 14px;
    border: none;
    border-radius: var(--radius);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

/* Circular glass avatar — first two letters of username (admin) */
#account-panel-btn.top-bar-btn.admin-avatar-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    padding: 0;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    line-height: 1;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: linear-gradient(
        155deg,
        rgba(64, 214, 198, 0.14) 0%,
        rgba(28, 34, 54, 0.72) 48%,
        rgba(14, 18, 32, 0.85) 100%
    );
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: rgba(200, 248, 240, 0.95);
    text-shadow: 0 0 14px rgba(64, 214, 198, 0.28);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.12),
        0 0 0 1px var(--ui-teal-faint),
        0 2px 10px rgba(0, 0, 0, 0.22);
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease, color 0.18s ease,
        transform 0.15s ease;
}

#account-panel-btn.top-bar-btn.admin-avatar-btn:hover {
    border-color: var(--ui-teal-muted);
    color: #f6fffd;
    background: linear-gradient(
        155deg,
        rgba(64, 214, 198, 0.26) 0%,
        rgba(36, 44, 68, 0.78) 50%,
        rgba(18, 22, 38, 0.9) 100%
    );
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.14),
        0 0 0 1px var(--ui-teal-soft),
        0 0 20px rgba(64, 214, 198, 0.12);
}

#account-panel-btn.top-bar-btn.admin-avatar-btn:active {
    transform: scale(0.96);
}

.btn-danger {
    background: var(--accent-red);
    color: white;
}

.btn-danger:hover { background: var(--accent-red-hover); }

/* ── Main content area ────────────────────────────────────────────── */
.main-area {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────────────── */
.sidebar {
    width: 260px;
    background: var(--glass-surface-mid);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border-right: 1px solid var(--glass-edge-faint);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    box-shadow: inset -1px 0 0 var(--ui-teal-faint);
}

.sidebar-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--glass-edge-faint);
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--glass-inset-highlight);
}

.sidebar-header h3 {
    font-size: 13px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.new-chat-btn {
    padding: 4px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    transition: all 0.15s;
    line-height: 1;
}

.new-chat-btn:hover {
    background: rgba(64, 214, 198, 0.08);
    color: var(--text-primary);
    border-color: var(--ui-teal-muted);
}

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

.conv-item {
    padding: 10px 12px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 2px;
    transition: background 0.1s, color 0.1s, border-color 0.1s, box-shadow 0.1s;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.conv-item:hover {
    background: rgba(64, 214, 198, 0.06);
    color: var(--text-primary);
}
.conv-item.active {
    background: linear-gradient(135deg, rgba(15, 52, 96, 0.85) 0%, rgba(18, 22, 42, 0.95) 100%);
    color: var(--text-primary);
    border-color: var(--ui-teal-faint);
    box-shadow: inset 0 0 0 1px rgba(64, 214, 198, 0.08);
}

.conv-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    padding: 2px 4px;
}

.conv-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}
.conv-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}
.conv-delete:hover { color: var(--accent-red); }

.conv-save-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 4px;
    transition: opacity 0.1s, color 0.1s;
    display: flex;
    align-items: center;
}
.conv-save-btn.active {
    opacity: 1;
    color: var(--accent-green);
}
.conv-save-btn:hover { color: var(--accent-blue); }

/* ── Chat area ────────────────────────────────────────────────────── */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background:
        radial-gradient(ellipse 80% 50% at 50% 0%, rgba(64, 214, 198, 0.04), transparent 60%),
        var(--bg-primary);
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.message {
    display: flex;
    margin-bottom: 16px;
    gap: 12px;
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
}

.message.user { justify-content: flex-end; }
.message.assistant { justify-content: flex-start; }

.bubble-header {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin: -12px -16px 8px -16px;
    padding: 4px 8px;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    min-height: 28px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.message.user .bubble-header {
    background: rgba(255, 255, 255, 0.06);
}
.message.assistant .bubble-header {
    background: rgba(255, 255, 255, 0.04);
}

.msg-edit-btn, .msg-regen-btn {
    opacity: 0.7;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 2px 6px;
    transition: opacity 0.15s, color 0.15s;
    flex-shrink: 0;
    line-height: 1;
    font-size: 16px;
}
.msg-edit-btn:disabled, .msg-regen-btn:disabled {
    opacity: 0.2;
    cursor: not-allowed;
    pointer-events: none;
}
.msg-edit-btn:hover, .msg-regen-btn:hover { opacity: 1 !important; color: var(--accent-blue); }

.edit-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 14px;
    background: var(--accent-navy);
    border: 1px solid var(--accent-blue);
    border-radius: var(--radius);
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.edit-banner button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
}

.edit-banner button:hover {
    color: var(--accent-red);
    background: rgba(194, 49, 82, 0.15);
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    margin-top: 4px;
}

.message.user .message-avatar { background: var(--accent-navy); order: 2; }
.message.assistant .message-avatar { background: var(--accent-green); }

.message-content {
    width: 75%;
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message.user .message-content {
    background: linear-gradient(135deg, rgba(15, 52, 96, 0.9) 0%, rgba(12, 40, 72, 0.95) 100%);
    border: 1px solid rgba(64, 214, 198, 0.12);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.message.assistant .message-content {
    background: linear-gradient(
        165deg,
        rgba(30, 32, 52, 0.55) 0%,
        rgba(22, 24, 42, 0.75) 100%
    );
    border: 1px solid var(--glass-edge-faint);
    box-shadow: var(--glass-inset-highlight);
}

.code-block-wrap {
    margin: 8px 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.code-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 12px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
}

.code-block-lang {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.code-copy-btn {
    padding: 2px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 11px;
    cursor: pointer;
    transition: all 0.15s;
}

.code-copy-btn:hover {
    background: var(--bg-input);
    color: var(--text-primary);
    border-color: var(--accent-blue);
}

.code-block-wrap pre {
    background: var(--bg-primary);
    padding: 12px;
    overflow-x: auto;
    font-size: 13px;
    margin: 0;
    border: none;
    border-radius: 0;
}

.message-content pre {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    overflow-x: auto;
    margin: 8px 0;
    font-size: 13px;
}

.message-content code {
    font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
    font-size: 13px;
}

.message-content :not(pre) > code {
    background: var(--bg-primary);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
}

/* KaTeX display math */
.message-content .katex-display {
    overflow-x: auto;
    overflow-y: hidden;
    padding: 8px 0;
    margin: 4px 0;
}

.message-content .katex {
    font-size: 1.05em;
}

.timing-stats {
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.2px;
}

.truncation-warning {
    margin-top: 10px;
    padding: 8px 12px;
    background: rgba(233, 69, 96, 0.1);
    border: 1px solid var(--accent-red);
    border-radius: var(--radius);
    color: var(--accent-red-hover);
    font-size: 12px;
    line-height: 1.4;
}

.message-content p { margin: 4px 0; }
.message-content ul, .message-content ol { margin: 8px 0 8px 20px; }

.thinking-block {
    background: rgba(12, 14, 28, 0.6);
    border: 1px solid var(--glass-edge-faint);
    border-radius: var(--radius);
    margin-bottom: 8px;
    overflow: hidden;
    box-shadow: var(--glass-inset-highlight);
}

.thinking-header {
    padding: 6px 12px;
    font-size: 11px;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 6px;
}

.thinking-header:hover { color: var(--text-secondary); }

.thinking-body {
    padding: 8px 12px;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
    max-height: 300px;
    overflow-y: auto;
    display: none;
    border-top: 1px solid var(--border);
}

.thinking-block.expanded .thinking-body { display: block; }

.message-image {
    max-width: 400px;
    max-height: 400px;
    border-radius: var(--radius);
    margin: 8px 0;
    cursor: pointer;
}

/* ── Input area ───────────────────────────────────────────────────── */
/* Context usage bar */
.context-bar-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 20px 10px;
    max-width: 940px;
    margin: 0 auto;
    flex-shrink: 0;
}
.context-bar {
    flex: 1;
    height: 4px;
    background: var(--bg-primary);
    border-radius: 2px;
    overflow: hidden;
    border: 1px solid var(--border);
}
.context-bar-fill {
    height: 100%;
    width: 0%;
    border-radius: 2px;
    background: linear-gradient(90deg, var(--ui-teal), var(--accent-blue));
    transition: width 0.3s ease, background 0.3s ease;
}
.context-bar-fill.warning { background: #e6a700; }
.context-bar-fill.critical { background: var(--accent-red); }
.context-bar-label {
    font-size: 10px;
    color: var(--text-muted);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    min-width: 90px;
    text-align: right;
}

.input-area {
    padding: 12px 20px max(16px, calc(12px + env(safe-area-inset-bottom, 0px)));
    background: var(--glass-surface);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border-top: 1px solid var(--glass-edge);
    box-shadow: var(--glass-shadow-up), 0 0 0 1px var(--ui-teal-faint) inset;
}

.input-wrapper {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    gap: 10px;
    align-items: center;
}

.input-box-wrapper {
    flex: 1;
    position: relative;
}

.image-preview-row {
    display: flex;
    gap: 8px;
    padding: 8px 8px 0;
    flex-wrap: wrap;
}

.image-preview-item {
    position: relative;
    width: 60px;
    height: 60px;
}

.image-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
}

.image-preview-item .remove-img {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent-red);
    color: white;
    border: none;
    font-size: 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

#chat-input {
    width: 100%;
    min-height: 44px;
    max-height: 200px;
    padding: 10px 14px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    background: linear-gradient(
        165deg,
        rgba(34, 38, 58, 0.42) 0%,
        rgba(18, 20, 34, 0.62) 48%,
        rgba(12, 14, 26, 0.72) 100%
    );
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    resize: none;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
    line-height: 1.5;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.07),
        inset 0 -1px 0 rgba(0, 0, 0, 0.12),
        0 2px 10px rgba(0, 0, 0, 0.18);
}

#chat-input:focus {
    border-color: var(--ui-teal-muted);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.09),
        inset 0 -1px 0 rgba(0, 0, 0, 0.1),
        0 0 0 1px var(--ui-teal-faint),
        0 0 24px rgba(64, 214, 198, 0.1);
}

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

.input-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.input-btn {
    width: 40px;
    height: 40px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    background: linear-gradient(
        165deg,
        rgba(34, 38, 58, 0.5) 0%,
        rgba(18, 22, 38, 0.78) 100%
    );
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, color 0.18s ease, background 0.18s ease;
    flex-shrink: 0;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.08),
        0 1px 6px rgba(0, 0, 0, 0.16);
}

.input-btn:hover:not(:disabled) {
    color: var(--text-primary);
    border-color: var(--ui-teal-muted);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.1),
        0 0 0 1px var(--ui-teal-faint),
        0 2px 12px rgba(64, 214, 198, 0.08);
}

/* Submit — same border language as #chat-input, teal glass (not green) */
.send-btn {
    background: linear-gradient(
        155deg,
        rgba(64, 214, 198, 0.16) 0%,
        rgba(26, 32, 52, 0.72) 45%,
        rgba(14, 18, 32, 0.82) 100%
    );
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: rgba(200, 248, 240, 0.95);
    font-size: 20px;
    line-height: 1;
    text-shadow: 0 0 18px rgba(64, 214, 198, 0.25);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.12),
        inset 0 -1px 0 rgba(0, 0, 0, 0.1),
        0 0 0 1px var(--ui-teal-faint),
        0 2px 10px rgba(0, 0, 0, 0.2);
}

.send-btn:hover:not(:disabled) {
    border-color: var(--ui-teal-muted);
    color: #f0fffc;
    background: linear-gradient(
        155deg,
        rgba(64, 214, 198, 0.28) 0%,
        rgba(32, 42, 62, 0.78) 50%,
        rgba(18, 22, 38, 0.88) 100%
    );
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.14),
        0 0 0 1px var(--ui-teal-soft),
        0 0 22px rgba(64, 214, 198, 0.14);
}

.send-btn:disabled {
    opacity: 0.38;
    cursor: not-allowed;
    filter: saturate(0.7);
    text-shadow: none;
}

/* Voice trigger — in chat column above composer (below context bar); ~10% slimmer than prior fixed bar */
.voice-entry-bar {
    --voice-accent: var(--ui-teal);
    --voice-accent-soft: var(--ui-teal-soft);
    display: none;
    position: relative;
    overflow: hidden;
    width: 100%;
    flex-shrink: 0;
    min-height: 50px;
    padding: 7px 18px;
    margin: 0;
    border: none;
    border-radius: 0;
    border-top: 1px solid var(--glass-edge-faint);
    border-bottom: 1px solid var(--glass-edge-faint);
    background: var(--glass-surface);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    color: var(--text-primary);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    box-shadow:
        0 2px 16px rgba(0, 0, 0, 0.18),
        0 0 0 1px var(--ui-teal-faint) inset,
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.voice-entry-bar:not(.hidden) {
    display: flex;
    align-items: center;
    justify-content: center;
}

.voice-entry-bar-glow {
    position: absolute;
    top: 0;
    left: 10%;
    right: 10%;
    height: 2px;
    border-radius: 2px;
    background: linear-gradient(
        90deg,
        transparent,
        var(--voice-accent),
        rgba(100, 200, 255, 0.45),
        var(--voice-accent),
        transparent
    );
    opacity: 0.85;
    pointer-events: none;
}

.voice-entry-bar-inner {
    position: relative;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.voice-entry-bar-title {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: rgba(200, 248, 240, 0.95);
    text-shadow: 0 0 24px rgba(64, 214, 198, 0.35);
}

.voice-entry-bar:hover:not(.voice-entry-bar--busy) {
    border-top-color: var(--ui-teal-muted);
    border-bottom-color: var(--glass-edge);
    box-shadow:
        0 3px 22px rgba(0, 0, 0, 0.22),
        0 0 0 1px var(--ui-teal-soft) inset,
        inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.voice-entry-bar:active:not(.voice-entry-bar--busy) {
    transform: scale(0.992);
}

/* Busy = still visible (no disappearing); native disabled is not used */
.voice-entry-bar--busy {
    cursor: not-allowed;
    opacity: 0.92;
    filter: saturate(0.75);
}

.voice-entry-bar--busy .voice-entry-bar-title {
    color: var(--text-secondary);
    text-shadow: none;
}

.voice-entry-bar--busy .voice-entry-bar-glow {
    opacity: 0.35;
}

/* ── Voice overlay (squircle) ─────────────────────────────────────── */
.voice-overlay {
    position: fixed;
    inset: 0;
    z-index: 70;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(12px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px))
        max(12px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
    box-sizing: border-box;
    pointer-events: auto;
}

.voice-overlay.hidden {
    display: none !important;
}

/* No backdrop blur — keep the conversation readable behind the overlay */
.voice-overlay-backdrop {
    position: absolute;
    inset: 0;
    background: transparent;
    pointer-events: auto;
}

/* vmin keeps a true square in landscape and portrait (80vw alone stretched on phones sideways) */
.voice-overlay-squircle {
    position: relative;
    z-index: 1;
    box-sizing: border-box;
    width: min(76vmin, 480px);
    height: min(76vmin, 480px);
    max-width: min(76vmin, 480px);
    max-height: min(76vmin, 480px);
    aspect-ratio: 1;
    flex-shrink: 0;
    border-radius: 28%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    cursor: pointer;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    background: linear-gradient(
        155deg,
        rgba(64, 214, 198, 0.22) 0%,
        rgba(36, 42, 68, 0.42) 42%,
        rgba(18, 20, 34, 0.55) 100%
    );
    border: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow:
        0 0 0 1px rgba(64, 214, 198, 0.2) inset,
        inset 0 1px 0 rgba(255, 255, 255, 0.12),
        0 16px 48px rgba(0, 0, 0, 0.42),
        0 0 60px rgba(64, 214, 198, 0.08);
    transition:
        transform 0.12s ease,
        background 0.12s ease,
        border-color 0.12s ease,
        box-shadow 0.12s ease;
    animation: voice-squircle-pulse 2.8s ease-in-out infinite;
}

.voice-overlay-squircle.voice-squircle--pressed {
    transform: scale(0.96);
    animation: none;
    background: linear-gradient(
        155deg,
        rgba(100, 235, 218, 0.45) 0%,
        rgba(48, 90, 95, 0.55) 50%,
        rgba(24, 32, 48, 0.65) 100%
    );
    border-color: rgba(200, 255, 248, 0.45);
    box-shadow:
        0 0 0 1px rgba(180, 255, 248, 0.25) inset,
        inset 0 1px 0 rgba(255, 255, 255, 0.18),
        0 10px 36px rgba(45, 195, 185, 0.25);
}

/* After release: purple glass until assistant reply finishes */
.voice-overlay-squircle.voice-squircle--awaiting {
    animation: voice-squircle-awaiting-pulse 0.75s ease-in-out infinite;
    background: linear-gradient(
        155deg,
        rgba(150, 110, 220, 0.28) 0%,
        rgba(48, 38, 78, 0.45) 50%,
        rgba(22, 18, 38, 0.55) 100%
    );
    border-color: rgba(200, 175, 255, 0.35);
    cursor: wait;
    transform: scale(1);
    box-shadow:
        0 0 0 1px rgba(190, 160, 255, 0.15) inset,
        inset 0 1px 0 rgba(255, 255, 255, 0.08),
        0 16px 44px rgba(0, 0, 0, 0.38);
}

.voice-overlay-squircle.voice-squircle--pressed.voice-squircle--awaiting {
    animation: none;
    transform: scale(0.96);
    background: linear-gradient(
        155deg,
        rgba(180, 140, 245, 0.42) 0%,
        rgba(72, 52, 112, 0.55) 100%
    );
    border-color: rgba(220, 195, 255, 0.5);
}

/* After first assistant text token: neutral glass until stream completes */
.voice-overlay-squircle.voice-squircle--streaming {
    animation: voice-squircle-streaming-pulse 1.1s ease-in-out infinite;
    background: linear-gradient(
        155deg,
        rgba(120, 128, 150, 0.22) 0%,
        rgba(38, 42, 56, 0.48) 50%,
        rgba(20, 22, 32, 0.58) 100%
    );
    border-color: rgba(170, 178, 200, 0.28);
    cursor: wait;
    transform: scale(1);
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.06) inset,
        inset 0 1px 0 rgba(255, 255, 255, 0.1),
        0 14px 40px rgba(0, 0, 0, 0.36);
}

.voice-overlay-squircle.voice-squircle--pressed.voice-squircle--streaming {
    animation: none;
    transform: scale(0.96);
    background: linear-gradient(
        155deg,
        rgba(140, 148, 168, 0.38) 0%,
        rgba(56, 60, 76, 0.55) 100%
    );
    border-color: rgba(190, 198, 215, 0.4);
}

@keyframes voice-squircle-streaming-pulse {
    0%, 100% {
        opacity: 0.48;
        transform: scale(1);
    }
    50% {
        opacity: 0.8;
        transform: scale(1.04);
    }
}

@keyframes voice-squircle-awaiting-pulse {
    0%, 100% {
        opacity: 0.45;
        transform: scale(1);
    }
    50% {
        opacity: 0.78;
        transform: scale(1.05);
    }
}

@keyframes voice-squircle-pulse {
    0%, 100% {
        opacity: 0.88;
        transform: scale(1);
    }
    50% {
        opacity: 1;
        transform: scale(1.03);
    }
}

.stop-btn {
    background: linear-gradient(
        165deg,
        rgba(210, 60, 90, 0.88) 0%,
        rgba(150, 35, 58, 0.92) 100%
    );
    border: 1px solid rgba(255, 120, 140, 0.35);
    color: white;
    text-shadow: none;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.18),
        0 2px 12px rgba(194, 49, 82, 0.35);
}

.stop-btn:hover:not(:disabled) {
    background: linear-gradient(
        165deg,
        rgba(233, 69, 96, 0.92) 0%,
        rgba(180, 45, 72, 0.95) 100%
    );
    border-color: rgba(255, 160, 175, 0.45);
}

/* ── Admin panel (overlay) ────────────────────────────────────────── */
.admin-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 100;
    align-items: center;
    justify-content: center;
}

.admin-overlay.visible {
    display: flex;
}

.admin-panel {
    background: var(--glass-surface);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-edge-faint);
    border-top-color: var(--glass-edge);
    border-radius: 14px;
    width: 800px;
    max-width: 95vw;
    max-height: 90vh;
    overflow-y: auto;
    padding: 24px;
    box-shadow:
        0 32px 80px rgba(0, 0, 0, 0.55),
        0 0 0 1px var(--ui-teal-faint) inset,
        var(--glass-inset-highlight);
}

.admin-panel h2 {
    font-size: 18px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.admin-panel.user-panel {
    width: 440px;
    max-width: 94vw;
}

.user-panel-intro {
    font-size: 14px;
    margin: -8px 0 20px;
    line-height: 1.45;
}

.panel-footer-actions {
    margin-top: 8px;
    padding-top: 20px;
    border-top: 1px solid var(--glass-edge-faint);
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 10px;
}

.admin-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    padding: 4px 8px;
    min-width: 40px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.admin-close:hover { color: var(--text-primary); }

.admin-section {
    margin-bottom: 24px;
}

.admin-section h3 {
    font-size: 14px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

.gpu-list {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.gpu-card {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 16px;
    font-size: 13px;
}

.gpu-card .gpu-name { font-weight: 600; color: var(--text-primary); }
.gpu-card .gpu-mem { color: var(--text-secondary); font-size: 12px; }

.model-table {
    width: 100%;
    border-collapse: collapse;
}

.model-table th {
    text-align: left;
    padding: 8px 12px;
    font-size: 12px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

.model-table td {
    padding: 8px 12px;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}

.model-table tr:hover { background: var(--bg-tertiary); }

.model-actions {
    display: flex;
    gap: 6px;
}

.small-btn {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 11px;
    cursor: pointer;
    transition: all 0.1s;
}

.small-btn:hover {
    background: var(--accent-navy);
    color: var(--text-primary);
}

.small-btn.load-btn:hover { background: var(--accent-green); color: white; }
.small-btn.delete-btn:hover { background: var(--accent-red); color: white; }

.model-table tr.model-loaded { background: rgba(27, 138, 90, 0.12); }
.model-table tr.model-loaded:hover { background: rgba(27, 138, 90, 0.2); }
.model-table tr.model-selected { background: rgba(52, 152, 219, 0.15); border-left: 3px solid var(--accent-blue); }
.model-table tr.model-selected:hover { background: rgba(52, 152, 219, 0.25); }
.model-table tr.model-selected.model-loaded { background: rgba(27, 138, 90, 0.15); border-left: 3px solid var(--accent-green); }

/* Cached models — source → repo → file tree */
.model-cache-tree {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.model-cache-tree details {
    margin: 0;
}

.model-cache-tree .mct-body {
    border-top: 1px solid var(--border);
}

.mct-grid {
    display: grid;
    grid-template-columns: minmax(120px, 1fr) 72px 52px 64px 76px 84px;
    gap: 6px 10px;
    align-items: center;
    padding: 8px 12px;
    font-size: 13px;
}

.mct-header.mct-grid {
    background: var(--bg-secondary);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    border-bottom: 1px solid var(--border);
}

.mct-h-name { min-width: 0; }
.mct-h-num { text-align: right; }
.mct-h-status { text-align: center; }
.mct-h-action { text-align: right; }

.mct-node > summary {
    list-style: none;
    cursor: pointer;
    user-select: none;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}

.mct-node > summary::-webkit-details-marker { display: none; }

.mct-node > summary::before {
    content: '▸';
    display: inline-block;
    width: 1em;
    margin-right: 4px;
    color: var(--text-muted);
    transition: transform 0.12s;
}

.mct-node[open] > summary::before {
    transform: rotate(90deg);
}

.mct-node > summary:hover {
    background: var(--bg-tertiary);
}

.mct-source > summary {
    padding: 9px 12px 9px 10px;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 13px;
}

.mct-repo > summary {
    padding: 7px 12px 7px 22px;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 12px;
}

.mct-children {
    border-left: 1px solid var(--border);
    margin-left: 14px;
}

.mct-file-row.mct-grid {
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    margin: 0;
}

.mct-file-row.mct-grid:last-child {
    border-bottom: none;
}

.mct-file-row:hover {
    background: var(--bg-tertiary);
}

.mct-file-row.model-loaded {
    background: rgba(27, 138, 90, 0.12);
}

.mct-file-row.model-loaded:hover {
    background: rgba(27, 138, 90, 0.2);
}

.mct-file-row.model-selected {
    background: rgba(52, 152, 219, 0.15);
    box-shadow: inset 3px 0 0 var(--accent-blue);
}

.mct-file-row.model-selected:hover {
    background: rgba(52, 152, 219, 0.25);
}

.mct-file-row.model-selected.model-loaded {
    background: rgba(27, 138, 90, 0.15);
    box-shadow: inset 3px 0 0 var(--accent-green);
}

.mct-cell-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-primary);
}

.mct-cell-num {
    text-align: right;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.mct-cell-status {
    text-align: center;
    font-size: 12px;
    font-weight: 600;
}

.mct-cell-status.mct-loaded {
    color: var(--accent-green);
}

.mct-cell-status.mct-idle {
    color: var(--text-muted);
    font-weight: 400;
}

.mct-cell-action {
    text-align: right;
}

.mct-empty, .mct-error, .mct-loading {
    padding: 10px 12px;
    font-size: 13px;
}

.mct-error {
    color: var(--accent-red);
}

.selected-model-info {
    margin-top: 10px;
    min-height: 20px;
}

.selected-model-label {
    font-size: 13px;
    color: var(--text-secondary);
}

.selected-model-label strong {
    color: var(--text-primary);
}

/* ── Settings panel in sidebar ────────────────────────────────────── */
.sidebar-settings {
    border-top: 1px solid var(--border);
    padding: 12px 16px;
}

.sidebar-settings summary {
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    user-select: none;
    padding: 4px 0;
}

.sidebar-settings summary:hover { color: var(--text-secondary); }

.param-group {
    margin-top: 10px;
}

.param-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.param-row.slider {
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
}

.param-row.slider label {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.param-val {
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    min-width: 42px;
    text-align: right;
}

.param-row label {
    font-size: 12px;
    color: var(--text-secondary);
}

.param-row input[type="range"] {
    width: 100%;
    accent-color: var(--accent-blue);
}

.param-row input[type="number"] {
    width: 70px;
    padding: 3px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 12px;
    text-align: right;
    outline: none;
}

.param-row input[type="number"]:focus { border-color: var(--accent-blue); }

.param-row input[type="checkbox"] {
    accent-color: var(--accent-blue);
}

.system-prompt-area {
    margin-top: 10px;
}

.system-prompt-area label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.reset-defaults-btn {
    display: block;
    width: 100%;
    margin-top: 12px;
    padding: 6px 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-muted);
    font-size: 11px;
    cursor: pointer;
    transition: all 0.15s;
}

.reset-defaults-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--accent-blue);
}

.system-prompt-area textarea {
    width: 100%;
    min-height: 60px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 12px;
    font-family: inherit;
    resize: vertical;
    outline: none;
}

.system-prompt-area textarea:focus { border-color: var(--accent-blue); }

/* ── Admin launch form ────────────────────────────────────────────── */
.launch-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.launch-form .form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.launch-form .form-group.full-width {
    grid-column: 1 / -1;
}

.launch-form label {
    font-size: 12px;
    color: var(--text-secondary);
}

.launch-form input, .launch-form select {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
}

.launch-form input:focus, .launch-form select:focus, .launch-form textarea:focus {
    border-color: var(--accent-blue);
}

.launch-form textarea {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
    width: 100%;
    box-sizing: border-box;
}

/* ── Download mode toggle ─────────────────────────────────────────── */
.download-mode-toggle {
    display: flex;
    gap: 4px;
    margin-bottom: 10px;
}
.mode-btn {
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 12px;
    transition: all 0.15s;
}
.mode-btn:hover { color: var(--text-primary); border-color: var(--accent-blue); }
.mode-btn.active {
    background: var(--accent-navy);
    color: var(--text-primary);
    border-color: var(--accent-blue);
}

.snippet-parsed {
    margin-top: 6px;
    font-size: 12px;
    color: var(--accent-green);
    font-family: var(--font-mono);
}
.snippet-parsed.error { color: var(--accent-red); }

/* ── Download progress bar ────────────────────────────────────────── */
.download-progress {
    margin: 10px 0 6px;
}
.download-progress-bar {
    width: 100%;
    height: 18px;
    background: var(--bg-input);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
}
.download-progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-green));
    border-radius: var(--radius);
    transition: width 0.4s ease;
}
.download-progress-text {
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

/* ── Slider row in admin form ─────────────────────────────────────── */
.slider-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.slider-row input[type="range"] {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 3px;
    outline: none;
}

.slider-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent-blue);
    cursor: pointer;
    border: 2px solid var(--bg-secondary);
    box-shadow: 0 0 4px rgba(52, 152, 219, 0.4);
}

.slider-row input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent-blue);
    cursor: pointer;
    border: 2px solid var(--bg-secondary);
    box-shadow: 0 0 4px rgba(52, 152, 219, 0.4);
}

/* ── Tensor split (multi-handle slider) ─────────────────────────── */
.tensor-split-sliders {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.multi-slider {
    position: relative;
    width: 100%;
    padding: 8px 0;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

.multi-slider-track {
    position: relative;
    width: 100%;
    height: 28px;
}

.multi-slider-segments {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 6px;
    overflow: hidden;
}

.multi-slider-segment {
    position: absolute;
    top: 0;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.multi-slider-segment .segment-label {
    font-size: 11px;
    font-weight: 600;
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    pointer-events: none;
    white-space: nowrap;
}

.multi-slider-handle {
    position: absolute;
    top: 50%;
    width: 14px;
    height: 34px;
    margin-left: -7px;
    margin-top: -17px;
    background: var(--text-primary);
    border: 2px solid var(--bg-secondary);
    border-radius: 4px;
    cursor: ew-resize;
    z-index: 2;
    box-shadow: 0 1px 4px rgba(0,0,0,0.4);
    transition: box-shadow 0.15s, transform 0.1s;
}

.multi-slider-handle:hover,
.multi-slider-handle.active {
    box-shadow: 0 2px 8px rgba(0,0,0,0.6);
    transform: scaleY(1.1);
}

.multi-slider-labels {
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
    gap: 4px 12px;
}

.multi-slider-gpu-label {
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.loaded-model-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 10px;
    padding: 8px 12px;
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.launch-actions {
    display: flex;
    gap: 10px;
    margin-top: 8px;
}

.launch-btn {
    padding: 8px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.launch-btn.start { background: var(--accent-green); color: white; }
.launch-btn.start:hover { background: var(--accent-green-hover); }
.launch-btn.stop { background: var(--accent-red); color: white; }
.launch-btn.stop:hover { background: var(--accent-red-hover); }
.launch-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.admin-status {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 8px;
    min-height: 20px;
}

.progress-bar {
    width: 100%;
    height: 20px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-top: 8px;
    display: none;
}

.progress-bar-fill {
    height: 100%;
    background: var(--accent-blue);
    width: 0%;
    transition: width 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    color: white;
    font-weight: 600;
}

/* ── GPU Monitor Charts ──────────────────────────────────────────── */
.gpu-charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.gpu-chart-wrap {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
}

.gpu-chart-wrap canvas {
    width: 100%;
    height: 170px;
    display: block;
}

.disk-chart-wrap canvas {
    height: 170px;
}

/* ── Hamburger button (hidden on desktop) ─────────────────────────── */
.hamburger-btn {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 7px 8px;
    cursor: pointer;
    flex-shrink: 0;
}

.hamburger-btn span {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--text-secondary);
    border-radius: 1px;
    transition: background 0.15s;
}

.hamburger-btn:hover span { background: var(--text-primary); }

/* Sidebar close button (hidden on desktop) */
.sidebar-close {
    display: none;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 22px;
    cursor: pointer;
    padding: 2px 6px;
    line-height: 1;
}

.sidebar-close:hover { color: var(--text-primary); }

/* Sidebar backdrop (hidden by default) */
.sidebar-backdrop { display: none; }

/* ── Current user display ─────────────────────────────────────────── */
.current-user-display {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
}

/* ── User management (admin) ─────────────────────────────────────── */
.user-mgmt-sub h4 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.user-card {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 6px;
    font-size: 13px;
}

.user-name {
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-card .user-email {
    flex: 1 1 100%;
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-date {
    color: var(--text-muted);
    font-size: 11px;
    white-space: nowrap;
}

.user-online-label {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}

.user-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.user-status-dot.online { background: var(--accent-green); }
.user-status-dot.offline { background: var(--text-muted); }

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

.approve-btn {
    background: var(--accent-green) !important;
    color: white !important;
}

.approve-btn:hover { background: var(--accent-green-hover) !important; }

/* ── Responsive ───────────────────────────────────────────────────── */
@media (max-width: 768px) {
    /* Show mobile-only controls */
    .hamburger-btn { display: flex; }
    .sidebar-close { display: block; }

    /* Sidebar as overlay — above voice entry bar (z-index 55) so the drawer is never covered */
    .sidebar {
        display: none;
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 300px;
        max-width: 85vw;
        z-index: 62;
        box-shadow: 4px 0 20px rgba(0,0,0,0.5);
        padding-top: env(safe-area-inset-top, 0px);
        box-sizing: border-box;
    }

    .sidebar.mobile-open { display: flex; }

    .sidebar-backdrop.visible {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 61;
    }

    /* Top bar — keep hamburger below notch / status bar */
    .top-bar {
        gap: 6px;
        padding: max(6px, env(safe-area-inset-top, 0px)) 10px 6px;
    }
    .top-bar-title { font-size: 14px; }
    .top-bar-secondary { gap: 8px; padding: 6px 10px; flex-wrap: wrap; }
    .top-bar-status-text { display: none; }
    .top-bar-model-select { font-size: 12px; }
    .mic-prime-bar { padding: 6px 10px; }
    .top-bar-btn { padding: 4px 10px; font-size: 11px; }
    #account-panel-btn.top-bar-btn.admin-avatar-btn {
        width: 34px;
        height: 34px;
        min-width: 34px;
        padding: 0;
        font-size: 10px;
    }

    /* Chat */
    .message-content { width: 90%; }
    .input-area { padding: 8px 12px max(12px, env(safe-area-inset-bottom, 0px)); }
    .context-bar-wrap { padding: 4px 12px 8px; }
    .voice-entry-bar {
        padding-left: 13px;
        padding-right: 13px;
        min-height: 46px;
        padding-top: 6px;
        padding-bottom: 6px;
    }
    .msg-edit-btn, .msg-regen-btn { opacity: 0.7; font-size: 15px; }

    /* Admin panel – full screen on mobile */
    .admin-panel {
        padding: 12px;
        border-radius: 0;
        max-width: 100vw;
        max-height: 100vh;
        max-height: 100dvh;
        width: 100vw;
        height: 100vh;
        height: 100dvh;
    }

    .admin-panel h2 {
        margin: -12px -12px 16px -12px;
        padding: 12px;
    }

    .admin-section { overflow-x: auto; }
    .launch-form { grid-template-columns: 1fr; }
    .model-table th, .model-table td { padding: 6px 6px; font-size: 11px; }
    .mct-grid {
        grid-template-columns: minmax(72px, 1fr) 58px 40px 52px 56px 64px;
        gap: 4px 6px;
        padding: 6px 8px;
        font-size: 11px;
    }
    .mct-header.mct-grid { font-size: 11px; }
    .mct-source > summary { font-size: 12px; padding: 8px 10px; }
    .mct-repo > summary { font-size: 11px; padding: 6px 10px 6px 16px; }

    /* GPU charts single column on mobile */
    .gpu-charts-grid { grid-template-columns: 1fr; }
    .gpu-chart-wrap canvas { height: 140px; }

    /* Prevent auto-zoom on input focus (requires >= 16px) */
    input, select, textarea { font-size: 16px !important; }
}

/* ── Utilities ────────────────────────────────────────────────────── */
.hidden { display: none !important; }

.typing-indicator span {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    margin: 0 2px;
    animation: bounce 1.4s infinite ease-in-out both;
}
.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.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); }
    40% { transform: scale(1); }
}
