/* =====================
   CSS VARIABLES / TEMA
   ===================== */
:root {
    --bg-primary: #131314;
    --bg-secondary: #1e1f20;
    --bg-hover: #2a2b2d;
    --bg-input: #1e1f20;
    --text-primary: #e3e3e3;
    --text-secondary: #9aa0a6;
    --text-muted: #6b7280;
    --border-color: #3c3f41;
    --accent-blue: #4f9cf9;
    --accent-gradient: linear-gradient(90deg, #4285f4, #9b72cb, #d96570);
    --send-btn-bg: #4f9cf9;
    --send-btn-disabled: #3c3f41;
    --profile-bg: #c8392b;
    --sidebar-width: 280px;
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 28px;
    --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

[data-tema="terang"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f0f4f9;
    --bg-hover: #e2e8f0;
    --bg-input: #f0f4f9;
    --text-primary: #1f2937;
    --text-secondary: #4b5563;
    --text-muted: #9ca3af;
    --border-color: #d1d5db;
    --send-btn-disabled: #d1d5db;
}

/* =====================
   RESET & BASE
   ===================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Google Sans', 'Segoe UI', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    transition: background-color 0.3s, color 0.3s;
}

/* =====================
   LAYOUT
   ===================== */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* =====================
   SIDEBAR
   ===================== */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    padding: 8px;
    transition: transform 0.3s cubic-bezier(0.4,0,0.2,1), width 0.3s;
    overflow: hidden;
    flex-shrink: 0;
    height: 100vh;
}

.sidebar.collapsed {
    width: 0;
    padding: 0;
    overflow: hidden;
}

.sidebar-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 4px;
    margin-bottom: 8px;
}

.sidebar-welcome {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}

.sidebar-section-title {
    font-size: 0.75rem;
    color: var(--text-secondary);
    padding: 8px 12px;
    font-weight: 500;
    letter-spacing: 0.02em;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-primary);
    transition: background 0.15s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item:hover,
.history-item.active-item {
    background-color: var(--bg-hover);
}

.history-title-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-delete-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px;
    border-radius: 4px;
    display: none;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.history-delete-btn .material-symbols-outlined {
    font-size: 16px;
}

.history-delete-btn:hover {
    color: var(--text-primary);
    background-color: var(--border-color);
}

.history-item:hover .history-delete-btn {
    display: flex;
}

.history-icon {
    font-size: 18px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

/* Sidebar Bottom */
.sidebar-bottom {
    margin-top: auto;
    border-top: 1px solid var(--border-color);
    padding-top: 8px;
    position: relative;
}

.settings-icon-btn {
    width: 40px;
    height: 40px;
    margin: 0 4px;
}

/* Popup Setelan */
.setelan-popup {
    display: none;
    position: absolute;
    bottom: 52px;
    left: 8px;
    width: 240px;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    overflow: hidden;
    z-index: 20;
    animation: fadeIn 0.15s ease;
}

.setelan-popup.open {
    display: block;
}

.sidebar-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 12px;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: 'Google Sans', sans-serif;
    font-size: 0.875rem;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
    white-space: nowrap;
}

.sidebar-menu-item:hover {
    background-color: var(--bg-hover);
}

.sidebar-menu-item .material-symbols-outlined {
    font-size: 20px;
    color: var(--text-secondary);
}

.arrow-icon {
    margin-left: auto;
    font-size: 18px !important;
    transition: transform 0.2s;
}

.arrow-icon.rotated {
    transform: rotate(90deg);
}

/* Tema Submenu */
.tema-submenu {
    display: none;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    margin: 4px 8px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.tema-submenu.open {
    display: block;
}

.tema-option {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 14px;
    background: none;
    border: none;
    color: var(--text-primary);
    font-family: 'Google Sans', sans-serif;
    font-size: 0.875rem;
    cursor: pointer;
    transition: background 0.15s;
}

.tema-option:hover {
    background-color: var(--bg-hover);
}

.tema-option .material-symbols-outlined {
    font-size: 18px;
}

/* =====================
   MAIN CONTENT
   ===================== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* =====================
   TOP NAV
   ===================== */
.top-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    flex-shrink: 0;
}

.top-nav-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
}

.brand-name {
    font-size: 1.25rem;
    font-weight: 500;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.brand-badge {
    font-size: 0.7rem;
    background-color: var(--bg-hover);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    padding: 2px 8px;
    border-radius: 20px;
    font-weight: 500;
}

/* =====================
   ICON BUTTONS
   ===================== */
.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    flex-shrink: 0;
}

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

.icon-btn .material-symbols-outlined {
    font-size: 22px;
}

/* =====================
   PROFILE BUTTON
   ===================== */
.profile-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
}

.profile-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: var(--profile-bg);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: 'Google Sans', sans-serif;
}

/* =====================
   WELCOME SCREEN
   ===================== */
.welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
}

.welcome-greeting {
    font-family: 'Google Sans Display', 'Google Sans', sans-serif;
    font-size: 2.8rem;
    font-weight: 500;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-align: center;
    margin-bottom: 8px;
}

.welcome-sub {
    font-size: 1.8rem;
    font-weight: 400;
    color: var(--text-secondary);
    text-align: center;
}

/* =====================
   CHAT AREA
   ===================== */
.chat-area {
    flex: 1;
    padding: 20px 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
    align-self: stretch;
}

.message {
    max-width: 85%;
    line-height: 1.6;
    font-size: 0.95rem;
    word-wrap: break-word;
}

.user-message {
    align-self: flex-end;
    background-color: var(--bg-secondary);
    padding: 12px 18px;
    border-radius: 22px;
    color: var(--text-primary);
}

.ai-message {
    align-self: flex-start;
    color: var(--text-primary);
    padding: 4px 0;
    max-width: 100%;
}

/* Markdown styling dalam pesan AI */
.ai-message p { margin-bottom: 8px; }
.ai-message ul, .ai-message ol { padding-left: 20px; margin-bottom: 8px; }
.ai-message li { margin-bottom: 4px; }
.ai-message strong { font-weight: 600; }
.ai-message h1, .ai-message h2, .ai-message h3 {
    margin: 12px 0 6px;
    font-weight: 600;
}
.ai-message a {
    color: var(--accent-blue);
    text-decoration: none;
}
.ai-message a:hover { text-decoration: underline; }
.ai-message code {
    background: var(--bg-hover);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-family: monospace;
}
.ai-message pre {
    background: var(--bg-hover);
    padding: 12px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 8px 0;
}

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

.typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary);
    animation: bounce 1.2s infinite;
}

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

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* =====================
   INPUT CONTAINER
   ===================== */
.input-container {
    padding: 12px 16px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
}

.input-box {
    width: 100%;
    max-width: 780px;
    background-color: var(--bg-input);
    border-radius: var(--radius-lg);
    padding: 12px 12px 12px 20px;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    border: 1px solid var(--border-color);
    transition: border-color 0.2s;
}

.input-box:focus-within {
    border-color: var(--accent-blue);
}

.input-box textarea {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary);
    outline: none;
    padding: 6px 0;
    resize: none;
    overflow-y: hidden;
    line-height: 1.5;
    max-height: 180px;
    font-family: 'Google Sans', sans-serif;
    font-size: 0.95rem;
    min-height: 28px;
}

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

.input-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

/* Send Button */
.send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background-color: var(--send-btn-bg);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.1s;
    flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
    filter: brightness(1.1);
    transform: scale(1.05);
}

.send-btn:disabled {
    background-color: var(--send-btn-disabled);
    cursor: default;
    transform: none;
}

.send-btn .material-symbols-outlined {
    font-size: 20px;
}

.disclaimer {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 10px;
    max-width: 780px;
}

/* =====================
   PROFILE MODAL
   ===================== */
.profile-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: none;
    justify-content: flex-end;
    align-items: flex-start;
    padding: 60px 12px 0 0;
}

.profile-modal-overlay.open {
    display: flex;
}

.profile-modal {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 24px 20px 16px;
    width: 300px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    animation: fadeIn 0.15s ease;
}

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

.profile-modal-close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.15s;
}

.profile-modal-close:hover {
    background-color: var(--bg-hover);
}

.profile-modal-email {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.profile-modal-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background-color: var(--profile-bg);
    color: white;
    font-size: 1.6rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
    font-family: 'Google Sans', sans-serif;
}

.profile-modal-name {
    font-size: 1.1rem;
    font-weight: 500;
    margin-bottom: 14px;
    color: var(--text-primary);
}

.profile-modal-manage {
    display: block;
    padding: 8px 20px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    color: var(--accent-blue);
    text-decoration: none;
    font-size: 0.85rem;
    margin-bottom: 16px;
    transition: background 0.15s;
}

.profile-modal-manage:hover {
    background-color: var(--bg-hover);
}

.profile-modal-actions {
    display: flex;
    gap: 8px;
    width: 100%;
    margin-bottom: 16px;
}

.profile-action-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px;
    background-color: var(--bg-hover);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: 'Google Sans', sans-serif;
    font-size: 0.82rem;
    cursor: pointer;
    transition: background 0.15s;
}

.profile-action-btn:hover {
    background-color: var(--border-color);
}

.profile-action-btn .material-symbols-outlined {
    font-size: 16px;
}

.profile-modal-links {
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: 0.75rem;
}

.profile-modal-links a {
    color: var(--text-muted);
    text-decoration: none;
}

.profile-modal-links a:hover {
    text-decoration: underline;
}

.profile-modal-links span {
    color: var(--text-muted);
}

/* =====================
   SCROLLBAR
   ===================== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* =====================
   RESPONSIVE
   ===================== */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100%;
        z-index: 50;
        transform: translateX(0);
    }

    .sidebar.collapsed {
        transform: translateX(-100%);
        width: var(--sidebar-width);
    }

    .message { max-width: 95%; }

    .welcome-greeting { font-size: 2rem; }
    .welcome-sub { font-size: 1.3rem; }
}