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

:root {
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, monospace;

    --accent: #6366f1;
    --accent-2: #a855f7;
    --accent-3: #ec4899;
    --accent-hover: #4f46e5;
    --danger: #ef4444;
    --success: #22c55e;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;

    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
    --shadow-glow: 0 0 40px rgba(99, 102, 241, 0.15);
}

/* Dark theme (default) */
[data-theme="dark"] {
    --sidebar-bg: rgba(15, 17, 23, 0.85);
    --sidebar-border: rgba(255, 255, 255, 0.06);
    --sidebar-text: #f1f5f9;
    --sidebar-muted: #94a3b8;
    --sidebar-hover: rgba(255, 255, 255, 0.06);
    --sidebar-active: rgba(99, 102, 241, 0.15);

    --main-bg: #0b0d12;
    --main-bg-2: #111318;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.12);

    --topbar-bg: rgba(11, 13, 18, 0.8);
    --composer-bg: rgba(11, 13, 18, 0.9);
    --input-bg: rgba(255, 255, 255, 0.04);
    --input-focus: rgba(99, 102, 241, 0.25);

    --user-bubble: rgba(99, 102, 241, 0.12);
    --assistant-bubble: rgba(255, 255, 255, 0.03);
    --code-bg: rgba(0, 0, 0, 0.4);
    --pre-bg: #1a1d27;

    --card-bg: rgba(255, 255, 255, 0.03);
    --card-hover: rgba(255, 255, 255, 0.06);
    --overlay: rgba(0, 0, 0, 0.6);

    --gradient-1: radial-gradient(ellipse 80% 50% at 50% -20%, rgba(99, 102, 241, 0.18), transparent);
    --gradient-2: radial-gradient(ellipse 60% 40% at 80% 100%, rgba(168, 85, 247, 0.1), transparent);
}

/* Light theme */
[data-theme="light"] {
    --sidebar-bg: rgba(255, 255, 255, 0.9);
    --sidebar-border: rgba(0, 0, 0, 0.06);
    --sidebar-text: #0f172a;
    --sidebar-muted: #64748b;
    --sidebar-hover: rgba(0, 0, 0, 0.04);
    --sidebar-active: rgba(99, 102, 241, 0.1);

    --main-bg: #f8fafc;
    --main-bg-2: #ffffff;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: rgba(0, 0, 0, 0.08);
    --border-strong: rgba(0, 0, 0, 0.12);

    --topbar-bg: rgba(248, 250, 252, 0.85);
    --composer-bg: rgba(248, 250, 252, 0.95);
    --input-bg: #ffffff;
    --input-focus: rgba(99, 102, 241, 0.15);

    --user-bubble: rgba(99, 102, 241, 0.08);
    --assistant-bubble: #ffffff;
    --code-bg: rgba(0, 0, 0, 0.05);
    --pre-bg: #1e293b;

    --card-bg: #ffffff;
    --card-hover: #f8fafc;
    --overlay: rgba(0, 0, 0, 0.4);

    --gradient-1: radial-gradient(ellipse 80% 50% at 50% -20%, rgba(99, 102, 241, 0.08), transparent);
    --gradient-2: radial-gradient(ellipse 60% 40% at 80% 100%, rgba(168, 85, 247, 0.06), transparent);
}

html, body {
    height: 100%;
    font-family: var(--font);
    color: var(--text);
    background: var(--main-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: var(--gradient-1), var(--gradient-2);
    pointer-events: none;
    z-index: 0;
}

.app {
    display: flex;
    height: 100vh;
    overflow: hidden;
    position: relative;
    z-index: 1;
}

/* ── Sidebar ── */
.sidebar {
    width: 280px;
    background: var(--sidebar-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 100;
    border-right: 1px solid var(--sidebar-border);
}

.sidebar-header {
    padding: 16px;
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn-new-chat {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 16px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.12), rgba(168, 85, 247, 0.08));
    color: var(--sidebar-text);
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-new-chat:hover {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(168, 85, 247, 0.14));
    border-color: rgba(99, 102, 241, 0.35);
    transform: translateY(-1px);
    box-shadow: var(--shadow-glow);
}

.btn-new-chat:active {
    transform: translateY(0);
}

.sidebar-close {
    display: none;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 12px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.chat-list::-webkit-scrollbar {
    width: 4px;
}

.chat-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: var(--radius-full);
}

.chat-list-empty {
    padding: 24px 12px;
    text-align: center;
    font-size: 13px;
    color: var(--sidebar-muted);
    line-height: 1.5;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 14px;
    color: var(--sidebar-text);
    transition: all var(--transition);
    margin-bottom: 2px;
    border: 1px solid transparent;
}

.chat-item::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--sidebar-muted);
    opacity: 0.4;
    flex-shrink: 0;
    transition: all var(--transition);
}

.chat-item:hover {
    background: var(--sidebar-hover);
}

.chat-item.active {
    background: var(--sidebar-active);
    border-color: rgba(99, 102, 241, 0.2);
}

.chat-item.active::before {
    background: var(--accent);
    opacity: 1;
    box-shadow: 0 0 8px rgba(99, 102, 241, 0.5);
}

.chat-item-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 450;
}

.chat-item-delete {
    opacity: 0;
    background: none;
    border: none;
    color: var(--sidebar-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    display: flex;
    transition: all var(--transition);
}

.chat-item:hover .chat-item-delete {
    opacity: 1;
}

.chat-item-delete:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.12);
}

.btn-clear-all {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 4px 12px 8px;
    padding: 9px 12px;
    border: 1px solid var(--sidebar-border);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--sidebar-muted);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-clear-all:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.3);
    color: var(--danger);
}

.btn-clear-all[hidden] {
    display: none;
}

.sidebar-footer {
    padding: 14px 16px;
    border-top: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    color: var(--sidebar-muted);
    font-weight: 500;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--sidebar-muted);
    flex-shrink: 0;
    transition: all var(--transition);
}

.status-dot.online {
    background: var(--success);
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
    animation: pulse 2s infinite;
}

.status-dot.offline {
    background: var(--danger);
}

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

/* ── Main ── */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: transparent;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    border-bottom: 1px solid var(--border);
    min-height: 56px;
    background: var(--topbar-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.btn-icon:hover {
    background: var(--sidebar-hover);
    color: var(--text);
}

#btnOpenSidebar {
    display: none;
}

.model-select-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.model-select-icon {
    position: absolute;
    left: 12px;
    color: var(--accent);
    pointer-events: none;
    z-index: 1;
}

.model-select {
    padding: 8px 12px 8px 34px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    background: var(--input-bg);
    color: var(--text);
    cursor: pointer;
    transition: all var(--transition);
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
}

.model-select:hover,
.model-select:focus {
    border-color: rgba(99, 102, 241, 0.4);
    outline: none;
    box-shadow: 0 0 0 3px var(--input-focus);
}

.model-select option {
    background: var(--main-bg-2);
    color: var(--text);
}

.topbar-link {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--accent);
    text-decoration: none;
    padding: 7px 12px;
    border-radius: var(--radius-md);
    border: 1px solid rgba(99, 102, 241, 0.2);
    background: rgba(99, 102, 241, 0.06);
    transition: all var(--transition);
}

.topbar-link:hover {
    background: rgba(99, 102, 241, 0.12);
    border-color: rgba(99, 102, 241, 0.35);
}

.theme-toggle .icon-moon { display: none; }
[data-theme="light"] .theme-toggle .icon-sun { display: none; }
[data-theme="light"] .theme-toggle .icon-moon { display: block; }

.topbar-title {
    font-size: 14px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), var(--accent-2), var(--accent-3));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

/* ── Chat area ── */
.chat-area {
    flex: 1;
    overflow-y: auto;
    position: relative;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.chat-area::-webkit-scrollbar {
    width: 6px;
}

.chat-area::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: var(--radius-full);
}

.messages {
    max-width: 800px;
    margin: 0 auto;
    padding: 24px 20px 140px;
    width: 100%;
}

/* Saat belum ada pesan (tampilan sambutan), jangan tambahkan ruang kosong. */
.messages:empty {
    padding: 0;
}

.message {
    display: flex;
    gap: 14px;
    padding: 16px 0;
    animation: fadeInUp 0.3s ease;
}

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

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
    letter-spacing: -0.02em;
}

.message.user .message-avatar {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: white;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.message.assistant .message-avatar {
    background: linear-gradient(135deg, var(--accent-2), var(--accent-3));
    color: white;
    box-shadow: 0 2px 8px rgba(168, 85, 247, 0.3);
}

.message-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message-body {
    line-height: 1.7;
    font-size: 15px;
    white-space: pre-wrap;
    word-break: break-word;
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}

.message.user .message-body {
    background: var(--user-bubble);
    border-color: rgba(99, 102, 241, 0.12);
}

.message.assistant .message-body {
    background: var(--assistant-bubble);
}

.message-edit-btn {
    display: none;
}

.message-hover-actions {
    display: flex;
    gap: 4px;
    min-height: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
}

.message.user .message-hover-actions {
    justify-content: flex-end;
}

.message.assistant .message-hover-actions {
    justify-content: flex-start;
}

.message:hover .message-hover-actions,
.message-hover-actions:focus-within {
    opacity: 1;
    pointer-events: auto;
}

@media (hover: none) {
    .message-hover-actions {
        opacity: 1;
        pointer-events: auto;
    }
}

.message-action-btn {
    width: 30px;
    height: 30px;
    border: none;
    background: var(--main-bg-2);
    color: var(--text-muted);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.message-action-btn:hover {
    background: var(--card-hover);
    color: var(--text);
    border-color: var(--border-strong);
}

.message-action-btn.copied {
    color: var(--success);
    border-color: rgba(34, 197, 94, 0.35);
}

#btnCopyChat[hidden] {
    display: none;
}

.message-edit {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.message-edit-input {
    width: 100%;
    resize: none;
    border: 1px solid var(--border-strong);
    background: var(--input-bg);
    color: var(--text);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    font-family: inherit;
    font-size: 15px;
    line-height: 1.6;
    outline: none;
}

.message-edit-input:focus {
    box-shadow: 0 0 0 3px var(--input-focus);
}

.message-edit-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.message-edit-actions button {
    padding: 7px 14px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background var(--transition), border-color var(--transition);
}

.message-edit-cancel {
    background: transparent;
    border-color: var(--border-strong);
    color: var(--text-muted);
}

.message-edit-cancel:hover {
    background: var(--sidebar-hover);
    color: var(--text);
}

.message-edit-save {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: #fff;
}

.message-edit-save:hover {
    background: linear-gradient(135deg, var(--accent-hover), #7c3aed);
}

.message-body p {
    margin-bottom: 0.75em;
}

.message-body p:last-child {
    margin-bottom: 0;
}

.message-body strong {
    font-weight: 600;
    color: var(--text);
}

.message-body a {
    color: #818cf8;
    text-decoration: none;
    border-bottom: 1px solid rgba(129, 140, 248, 0.35);
    word-break: break-word;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.message-body a:hover {
    color: #a5b4fc;
    border-bottom-color: rgba(165, 180, 252, 0.7);
}

.message-body code {
    background: var(--code-bg);
    padding: 2px 7px;
    border-radius: 5px;
    font-size: 0.88em;
    font-family: var(--font-mono);
    border: 1px solid var(--border);
}

.code-block-wrap {
    position: relative;
    margin: 0.75em 0;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.code-copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    font-size: 12px;
    font-family: var(--font-sans);
    color: #cbd5e1;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.code-copy-btn:hover {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
}

.code-copy-btn.copied {
    color: #86efac;
    border-color: rgba(134, 239, 172, 0.4);
}

.message-body pre {
    background: var(--pre-bg);
    color: #e2e8f0;
    padding: 16px;
    padding-top: 40px;
    border-radius: var(--radius-md);
    overflow-x: auto;
    margin: 0.75em 0;
    font-size: 13px;
    font-family: var(--font-mono);
    border: 1px solid rgba(255, 255, 255, 0.06);
    user-select: text;
    -webkit-user-select: text;
}

.code-block-wrap pre {
    margin: 0;
    border: none;
    border-radius: 0;
}

.message-body pre code {
    background: none;
    padding: 0;
    color: inherit;
    border: none;
    user-select: text;
    -webkit-user-select: text;
}

/* Tabel markdown */
.md-table-wrap {
    margin: 0.85em 0;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    -webkit-overflow-scrolling: touch;
}

.md-table {
    border-collapse: collapse;
    width: 100%;
    font-size: 13.5px;
}

.md-table th,
.md-table td {
    padding: 9px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
    vertical-align: top;
}

.md-table th:last-child,
.md-table td:last-child {
    border-right: none;
}

.md-table tbody tr:last-child td {
    border-bottom: none;
}

.md-table thead th {
    background: var(--card-hover);
    color: var(--text);
    font-weight: 600;
    white-space: nowrap;
}

.md-table tbody tr:nth-child(even) {
    background: var(--card-bg);
}

.md-table code {
    font-size: 0.85em;
}

/* Bagan / diagram Mermaid */
.mermaid-wrap {
    margin: 0.85em 0;
    padding: 14px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow-x: auto;
    text-align: center;
}

.mermaid-wrap .mermaid {
    display: inline-block;
    min-width: 0;
}

.mermaid-wrap svg {
    max-width: 100%;
    height: auto;
}

.typing-indicator {
    display: inline-flex;
    gap: 5px;
    padding: 4px 0;
}

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

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

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

/* ── Welcome screen ── */
.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px 24px 80px;
    max-width: 720px;
    margin: 0 auto;
    animation: fadeInUp 0.5s ease;
}

.welcome.hidden {
    display: none;
}

.welcome-logo {
    width: 72px;
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-xl);
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.12), rgba(236, 72, 153, 0.08));
    border: 1px solid rgba(99, 102, 241, 0.2);
    margin-bottom: 24px;
    box-shadow: var(--shadow-glow);
}

.welcome-title {
    font-size: clamp(1.5rem, 4vw, 2rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    margin-bottom: 10px;
    background: linear-gradient(135deg, var(--text) 30%, var(--accent), var(--accent-3));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-sub {
    font-size: 15px;
    color: var(--text-muted);
    line-height: 1.6;
    max-width: 420px;
    margin-bottom: 36px;
}

.suggestions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    width: 100%;
}

.suggestion-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--card-bg);
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    color: var(--text);
    transition: all var(--transition);
}

.suggestion-card:hover {
    background: var(--card-hover);
    border-color: rgba(99, 102, 241, 0.25);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.suggestion-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    background: color-mix(in srgb, var(--c) 12%, transparent);
    color: var(--c);
    margin-bottom: 4px;
}

.suggestion-title {
    font-size: 14px;
    font-weight: 600;
}

.suggestion-desc {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.4;
}

/* ── Composer ── */
.composer {
    padding: 12px 20px 20px;
    background: var(--composer-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
}

.composer-toolbar {
    max-width: 800px;
    margin: 0 auto 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.mode-switch {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    background: var(--input-bg);
}

.mode-switch .mode-opt {
    padding: 4px 11px;
    border: none;
    border-radius: var(--radius-full);
    background: transparent;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.mode-switch .mode-opt:hover {
    color: var(--text);
}

.mode-switch .mode-opt.active {
    background: rgba(99, 102, 241, 0.15);
    color: var(--accent);
    box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.2);
}

.btn-rag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    background: var(--input-bg);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-rag:hover:not(:disabled) {
    border-color: rgba(16, 185, 129, 0.35);
    color: var(--text);
    background: var(--card-hover);
}

.btn-rag.active {
    border-color: rgba(16, 185, 129, 0.45);
    background: rgba(16, 185, 129, 0.12);
    color: #34d399;
    box-shadow: 0 0 0 1px rgba(16, 185, 129, 0.15);
}

.btn-rag:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.rag-docs-panel {
    margin: 8px 12px 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--input-bg);
    font-size: 12px;
}

.rag-docs-panel summary {
    padding: 10px 12px;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-muted);
    list-style: none;
    user-select: none;
}

.rag-docs-panel summary::-webkit-details-marker {
    display: none;
}

.rag-docs-body {
    padding: 0 12px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.rag-admin-key {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card-bg);
    color: var(--text);
    font-size: 12px;
    font-family: inherit;
}

.rag-doc-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 140px;
    overflow-y: auto;
}

.rag-doc-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
}

.rag-doc-item:last-child {
    border-bottom: none;
}

.rag-doc-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
}

.rag-doc-delete {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
}

.rag-doc-delete:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
}

.rag-doc-empty {
    color: var(--text-muted);
    padding: 4px 0;
}

.rag-docs-hint {
    margin: 0;
    color: var(--text-muted);
    font-size: 11px;
}

.rag-docs-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.btn-rag-pick,
.btn-rag-upload,
.btn-rag-refresh {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card-bg);
    color: var(--text);
    font-size: 11px;
    font-family: inherit;
    cursor: pointer;
}

.btn-rag-upload:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.rag-docs-status {
    margin: 0;
    font-size: 11px;
    color: var(--text-muted);
}

.rag-docs-status.error {
    color: #f87171;
}

.btn-apk-download {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.06);
    color: #ffffff;
    font-size: 12px;
    font-weight: 500;
    font-family: inherit;
    text-decoration: none;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-apk-download:hover {
    border-color: rgba(255, 255, 255, 0.55);
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
}

[data-theme="light"] .btn-apk-download {
    border-color: var(--border);
    background: var(--input-bg);
    color: var(--text);
}

[data-theme="light"] .btn-apk-download:hover {
    border-color: rgba(0, 0, 0, 0.3);
    background: var(--card-hover);
    color: var(--text);
}

.btn-myryda {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.06);
    color: #ffffff;
    font-size: 12px;
    font-weight: 500;
    font-family: inherit;
    text-decoration: none;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-myryda:hover {
    border-color: rgba(255, 255, 255, 0.55);
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
}

[data-theme="light"] .btn-myryda {
    border-color: var(--border);
    background: var(--input-bg);
    color: var(--text);
}

[data-theme="light"] .btn-myryda:hover {
    border-color: rgba(0, 0, 0, 0.3);
    background: var(--card-hover);
    color: var(--text);
}

.searching-label {
    font-size: 13px;
    color: var(--accent);
    margin-bottom: 8px;
    font-weight: 500;
}

/* Thinking (reasoning) block for Deep Thinking model */
.thinking-block {
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--input-bg);
    overflow: hidden;
}

.thinking-block summary {
    cursor: pointer;
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--accent-2);
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
    user-select: none;
}

.thinking-block summary::-webkit-details-marker {
    display: none;
}

.thinking-block summary::before {
    content: '';
    width: 6px;
    height: 6px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(-45deg);
    transition: transform var(--transition);
}

.thinking-block[open] summary::before {
    transform: rotate(45deg);
}

.thinking-content {
    padding: 4px 12px 12px;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    max-height: 320px;
    overflow-y: auto;
    white-space: pre-wrap;
}

/* Alur wajib: Pahami → Berpikir → Kesimpulan → Jawaban */
.reasoning-flow {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 14px;
}

.reasoning-phase {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-2, rgba(0, 0, 0, 0.03));
    overflow: hidden;
}

.reasoning-phase--active {
    border-color: var(--accent, #3b82f6);
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent, #3b82f6) 25%, transparent);
}

.reasoning-phase--done {
    opacity: 0.95;
}

.reasoning-phase-head,
.reasoning-answer-head {
    font-size: 13px;
    font-weight: 600;
    padding: 8px 12px;
    background: var(--surface-3, rgba(0, 0, 0, 0.04));
    border-bottom: 1px solid var(--border);
}

.reasoning-phase-badge {
    font-weight: 500;
    font-size: 12px;
    color: var(--accent, #3b82f6);
}

.reasoning-phase-body,
.reasoning-answer-body {
    padding: 10px 12px 12px;
    font-size: 14px;
    line-height: 1.65;
    color: var(--text);
}

.reasoning-phase-wait {
    color: var(--text-muted);
    font-size: 13px;
    font-style: italic;
}

.reasoning-answer {
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    margin-top: 4px;
}

.reasoning-answer-head {
    color: var(--text);
}

/* Attachment preview */
.attachments {
    max-width: 800px;
    margin: 0 auto 8px;
    display: none;
    flex-wrap: wrap;
    gap: 8px;
}

.attachments.visible {
    display: flex;
}

.attachment-chip {
    position: relative;
    width: 72px;
    height: 72px;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--input-bg);
    flex-shrink: 0;
}

.attachment-chip img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.attachment-remove {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 20px;
    height: 20px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background var(--transition);
}

.attachment-remove:hover {
    background: var(--danger);
}

/* Attach button */
.btn-attach {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition);
}

.btn-attach:hover {
    background: var(--sidebar-hover);
    color: var(--accent);
}

.btn-mic {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition);
}

.btn-mic:hover {
    background: var(--sidebar-hover);
    color: var(--accent);
}

.btn-mic.listening {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.12);
    animation: micPulse 1.2s ease-in-out infinite;
}

@keyframes micPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.45); }
    50% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}

/* Images inside a chat message */
.message-images {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.message-image {
    max-width: 220px;
    max-height: 220px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    object-fit: cover;
    cursor: zoom-in;
}

.composer-inner {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 8px 8px 8px 20px;
    box-shadow: var(--shadow-md);
    transition: all var(--transition);
}

.composer-inner:focus-within {
    border-color: rgba(99, 102, 241, 0.4);
    box-shadow: var(--shadow-md), 0 0 0 3px var(--input-focus);
}

#messageInput {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    font-family: inherit;
    font-size: 15px;
    line-height: 1.5;
    max-height: 200px;
    padding: 8px 0;
    outline: none;
    color: var(--text);
}

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

.btn-send {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.35);
}

.btn-send:hover:not(:disabled) {
    background: linear-gradient(135deg, var(--accent-hover), #7c3aed);
    transform: scale(1.05);
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.45);
}

.btn-send:active:not(:disabled) {
    transform: scale(0.97);
}

.btn-send:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    box-shadow: none;
}

.btn-send.is-stop {
    background: var(--input-bg);
    border: 1px solid var(--border-strong);
    color: var(--text);
}

.btn-send.is-stop:hover:not(:disabled) {
    background: var(--sidebar-hover);
    box-shadow: none;
    transform: scale(1.05);
}

.stopped-note {
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
}

.error-note {
    font-size: 14px;
    line-height: 1.6;
    color: var(--danger);
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: var(--radius-md);
    padding: 10px 12px;
}

/* Action toolbar under assistant messages */
.msg-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.msg-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    background: var(--input-bg);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
}

.msg-action-btn:hover {
    border-color: rgba(99, 102, 241, 0.35);
    color: var(--accent);
    background: var(--card-hover);
}

.msg-action-btn svg {
    flex-shrink: 0;
}

.composer-note {
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 10px;
    opacity: 0.8;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--overlay);
    z-index: 90;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* ── Mobile ── */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: var(--shadow-lg);
    }

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

    .sidebar-close {
        display: flex;
    }

    #btnOpenSidebar {
        display: flex;
    }

    .sidebar-overlay.visible {
        display: block;
    }

    .topbar-title {
        display: none;
    }

    .topbar-link span {
        font-size: 0;
    }

    .topbar-link {
        padding: 8px;
        gap: 0;
    }

    .suggestions {
        grid-template-columns: 1fr;
    }

    .welcome {
        padding: 32px 16px 60px;
    }

    .messages {
        padding: 16px 12px 120px;
    }

    .composer {
        padding: 10px 12px 16px;
    }
}

@media (max-width: 480px) {
    .message-body {
        padding: 10px 12px;
        font-size: 14px;
    }

    .message-avatar {
        width: 32px;
        height: 32px;
        font-size: 11px;
    }
}

/* ── Toast notifikasi ringan ── */
.app-toast {
    position: fixed;
    left: 50%;
    bottom: 88px;
    transform: translate(-50%, 12px);
    z-index: 200;
    max-width: min(90vw, 380px);
    padding: 11px 18px;
    border-radius: var(--radius-full);
    background: rgba(15, 17, 23, 0.92);
    color: #f1f5f9;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
    text-align: center;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.app-toast.visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

[data-theme="light"] .app-toast {
    background: rgba(15, 23, 42, 0.95);
    color: #f8fafc;
}

/* ── Iklan mengambang MyRyda ── */
.myryda-ad {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 120;
    width: 320px;
    max-width: calc(100vw - 32px);
    background: #ffffff;
    border-radius: 18px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28), 0 4px 12px rgba(0, 0, 0, 0.12);
    font-family: var(--font);
    color: #1f2937;
    transform: translateY(24px);
    opacity: 0;
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.4s ease;
}

.myryda-ad.visible {
    transform: translateY(0);
    opacity: 1;
}

.myryda-ad-topbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px 8px 12px;
    background: #f3f4f6;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.myryda-ad-tag {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: #6b7280;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 3px 7px;
}

.myryda-ad-domain {
    margin-left: auto;
    font-size: 12px;
    color: #9ca3af;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 90px;
}

.myryda-ad-countdown {
    flex-shrink: 0;
    min-width: 34px;
    height: 26px;
    padding: 0 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: #6b7280;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: var(--radius-full);
}

.myryda-ad-close {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #4b5563;
    cursor: pointer;
    transition: background 0.15s ease, opacity 0.15s ease;
}

.myryda-ad-close:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.myryda-ad-close:not(:disabled):hover {
    background: rgba(0, 0, 0, 0.07);
    color: #111827;
}

.myryda-ad-body {
    display: block;
    text-decoration: none;
    color: inherit;
}

.myryda-ad-header {
    padding: 22px 20px 20px;
    text-align: center;
    color: #fff;
    background: linear-gradient(135deg, #e11d2a 0%, #b91c1c 100%);
}

.myryda-ad-pill {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.1em;
    padding: 5px 12px;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.18);
    margin-bottom: 12px;
}

.myryda-ad-title {
    font-size: 30px;
    font-weight: 800;
    letter-spacing: 0.04em;
    line-height: 1.1;
    margin-bottom: 10px;
}

.myryda-ad-sub {
    font-size: 13px;
    line-height: 1.45;
    color: rgba(255, 255, 255, 0.92);
    margin: 0 auto;
    max-width: 250px;
}

.myryda-ad-figure {
    padding: 14px 16px 4px;
}

.myryda-ad-figure img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 12px;
}

.myryda-ad-features {
    list-style: none;
    margin: 0;
    padding: 14px 22px 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.myryda-ad-features li {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    font-size: 13px;
    line-height: 1.35;
    color: #374151;
}

.myryda-ad-features svg {
    flex-shrink: 0;
    margin-top: 1px;
    color: #16a34a;
}

.myryda-ad-footer {
    padding: 4px 20px 18px;
    text-align: center;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    padding-top: 16px;
}

.myryda-ad-cta {
    display: block;
    width: 100%;
    padding: 13px 16px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, #e11d2a 0%, #b91c1c 100%);
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    text-decoration: none;
    box-shadow: 0 6px 16px rgba(225, 29, 42, 0.35);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.myryda-ad-cta:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 22px rgba(225, 29, 42, 0.45);
}

.myryda-ad-url {
    display: inline-block;
    margin-top: 12px;
    font-size: 13px;
    font-weight: 600;
    color: #16a34a;
    text-decoration: none;
}

.myryda-ad-url:hover {
    text-decoration: underline;
}

@media (max-width: 480px) {
    .myryda-ad {
        right: 12px;
        left: 12px;
        bottom: 12px;
        width: auto;
    }
}
