/* ============================================================
   Gapura RAG — Mobile-First Design System
   Background: oklch(0.99 0.01 90)  |  Accent: oklch(0.70 0.16 160)
   Breakpoints: 640px (tablet), 1024px (desktop)
   ============================================================ */

:root {
    --bg-page: oklch(0.99 0.01 90);
    --bg-sidebar: oklch(0.96 0.01 90);
    --bg-surface: oklch(0.97 0.005 90);
    --bg-surface-raised: oklch(1.0 0 0);
    --bg-input: oklch(0.96 0.005 90);

    --accent: oklch(0.70 0.16 160);
    --accent-soft: oklch(0.92 0.06 160);
    --accent-hover: oklch(0.62 0.16 160);
    --accent-glow: oklch(0.70 0.16 160 / 0.15);

    --text-primary: oklch(0.22 0.02 240);
    --text-secondary: oklch(0.50 0.01 240);
    --text-muted: oklch(0.65 0.01 240);
    --text-inverse: oklch(0.96 0.005 90);

    --border: oklch(0.90 0.01 90);
    --border-focus: var(--accent);

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-pill: 100px;

    --shadow-sm: 0 1px 3px oklch(0.20 0.02 240 / 0.04);
    --shadow-md: 0 4px 16px oklch(0.20 0.02 240 / 0.06);
    --shadow-lg: 0 8px 32px oklch(0.20 0.02 240 / 0.08);
    --shadow-glow: 0 0 24px var(--accent-glow);

    --font-display: 'Libre Baskerville', Georgia, serif;
    --font-body: 'Outfit', system-ui, sans-serif;

    --header-height: 56px;
    --bottom-nav-height: 60px;

    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
    font-family: var(--font-body);
    background: var(--bg-page);
    color: var(--text-primary);
    height: 100dvh;
    overflow: hidden;
}

/* ===== MOBILE-FIRST BASE (< 640px) ===== */

/* ── App Shell ── */
.app-shell {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    position: relative;
}

/* ── Sidebar — hidden drawer on mobile ── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: oklch(0.10 0.01 240 / 0.4);
    z-index: 90;
    opacity: 0;
    transition: opacity 0.3s var(--ease-out);
}

.sidebar-overlay.open {
    display: block;
    opacity: 1;
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px 16px;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.35s var(--ease-out);
}

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

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 4px 20px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
}

.logo {
    width: 120px;
    height: auto;
}

.btn-close-sidebar {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-close-sidebar:hover {
    background: var(--bg-input);
    color: var(--text-primary);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-body);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s var(--ease-out);
    position: relative;
}

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

.nav-btn.active {
    background: var(--accent-soft);
    color: var(--accent-hover);
}

.nav-btn.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 20px;
    background: var(--accent);
    border-radius: 0 3px 3px 0;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.lang-switcher {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
}

.lang-switcher label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.lang-switcher select {
    background: var(--bg-surface-raised);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-family: var(--font-body);
    font-size: 0.9rem;
    cursor: pointer;
    transition: border-color 0.2s;
    -webkit-appearance: none;
    appearance: none;
}

.lang-switcher select:focus {
    outline: none;
    border-color: var(--accent);
}

.stats-mini {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 6px 0;
    line-height: 1.6;
}

/* ── Main Content ── */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

.panel {
    display: none;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.panel.active {
    display: flex;
}

/* ── Panel Header ── */
.panel-header {
    height: var(--header-height);
    padding: 0 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-surface-raised);
    flex-shrink: 0;
}

.btn-menu {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.btn-menu:active {
    background: var(--bg-input);
}

.header-title {
    flex: 1;
    min-width: 0;
}

.header-title h1 {
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-title h1 em {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 400;
    color: var(--accent);
}

.header-sub {
    display: none;
}

.btn-icon {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.btn-icon:active {
    background: var(--bg-input);
    color: var(--text-primary);
}

/* ── Chat Container ── */
.chat-container {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
}

.chat-container::-webkit-scrollbar { width: 3px; }
.chat-container::-webkit-scrollbar-track { background: transparent; }
.chat-container::-webkit-scrollbar-thumb {
    background: oklch(0.85 0.01 90);
    border-radius: 10px;
}

/* ── Welcome Screen ── */
.chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 12px;
    padding: 24px 20px;
    animation: welcome-in 0.8s var(--ease-out) both;
}

.chat-welcome.hidden { display: none; }

@keyframes welcome-in {
    from { opacity: 0; transform: translateY(16px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.welcome-icon {
    width: 64px;
    height: 64px;
    border-radius: var(--radius-md);
    background: var(--accent-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 4px;
    box-shadow: var(--shadow-glow);
}

.welcome-logo {
    width: 40px;
    height: auto;
    object-fit: contain;
}

.chat-welcome h2 {
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 400;
    color: var(--text-primary);
    text-align: center;
}

.chat-welcome > p {
    color: var(--text-secondary);
    font-size: 0.88rem;
    max-width: 320px;
    text-align: center;
    line-height: 1.5;
}

.welcome-hints {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
    width: 100%;
    max-width: 320px;
}

.hint-chip {
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-surface-raised);
    color: var(--text-secondary);
    font-family: var(--font-body);
    font-size: 0.88rem;
    cursor: pointer;
    transition: all 0.25s var(--ease-out);
    text-align: left;
    -webkit-tap-highlight-color: transparent;
}

.hint-chip:active {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-glow);
}

/* ── Messages ── */
.messages {
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    display: flex;
    gap: 10px;
    max-width: 100%;
    animation: msg-in 0.4s var(--ease-spring) both;
}

@keyframes msg-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
}

.message.assistant .msg-avatar {
    background: var(--accent-soft);
    color: var(--accent);
}

.message.user .msg-avatar {
    background: oklch(0.88 0.01 240);
    color: oklch(0.40 0.01 240);
}

.msg-body {
    flex: 1;
    min-width: 0;
}

.msg-bubble {
    padding: 12px 14px;
    border-radius: var(--radius-md);
    line-height: 1.6;
    font-size: 0.9rem;
    word-break: break-word;
}

.message.assistant .msg-bubble {
    background: var(--bg-surface-raised);
    border: 1px solid var(--border);
    border-radius: 4px var(--radius-md) var(--radius-md) var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.message.user .msg-bubble {
    background: var(--accent);
    color: var(--text-inverse);
    border-radius: var(--radius-md) 4px var(--radius-md) var(--radius-md);
}

.msg-citations {
    margin-top: 8px;
    padding: 8px 12px;
    background: var(--bg-surface);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.msg-citations strong {
    color: var(--text-primary);
    font-weight: 600;
    display: block;
    margin-bottom: 4px;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.msg-citation-item {
    padding: 2px 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.msg-citation-item::before {
    content: '';
    width: 4px;
    height: 4px;
    background: var(--accent);
    border-radius: 50%;
    flex-shrink: 0;
}

/* ── Typing Indicator ── */
.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 12px 14px;
}

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

.typing-dot:nth-child(2) { animation-delay: 0.16s; }
.typing-dot:nth-child(3) { animation-delay: 0.32s; }

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

/* ── Chat Input ── */
.chat-input-area {
    padding: 10px 12px calc(10px + var(--safe-bottom));
    flex-shrink: 0;
    background: var(--bg-page);
}

.chat-form {
    max-width: 780px;
    margin: 0 auto;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-surface-raised);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    padding: 6px 6px 6px 14px;
    transition: all 0.25s var(--ease-out);
    box-shadow: var(--shadow-sm);
}

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

#chat-input {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    font-family: var(--font-body);
    font-size: 1rem;
    color: var(--text-primary);
    padding: 8px 0;
    line-height: 1.5;
    max-height: 100px;
    outline: none;
}

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

.btn-send {
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 12px;
    background: var(--accent);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s var(--ease-out);
    -webkit-tap-highlight-color: transparent;
}

.btn-send:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: scale(0.92);
}

.btn-send:not(:disabled):active {
    background: var(--accent-hover);
    transform: scale(0.95);
}

/* ── Upload Panel ── */
.upload-area {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s var(--ease-out);
    background: var(--bg-surface);
    -webkit-tap-highlight-color: transparent;
}

.drop-zone:active,
.drop-zone.dragover {
    border-color: var(--accent);
    background: var(--accent-glow);
}

.drop-icon {
    color: var(--text-muted);
    margin-bottom: 12px;
    transition: color 0.3s;
}

.drop-zone:active .drop-icon,
.drop-zone.dragover .drop-icon {
    color: var(--accent);
}

.drop-text {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.drop-hint {
    font-size: 0.82rem;
    color: var(--text-muted);
}

.upload-log {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.upload-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--bg-surface-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    animation: msg-in 0.3s var(--ease-spring) both;
}

.upload-item .upload-status { font-size: 1.2rem; flex-shrink: 0; }

.upload-item .upload-info { flex: 1; min-width: 0; }

.upload-item .upload-filename {
    font-weight: 600;
    font-size: 0.88rem;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.upload-item .upload-detail {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.upload-item.error {
    border-color: oklch(0.65 0.20 25);
    background: oklch(0.97 0.02 25);
}

.upload-item.success {
    border-color: oklch(0.75 0.12 160);
    background: oklch(0.97 0.02 160);
}

/* ── Bottom Nav (mobile) ── */
.bottom-nav {
    display: flex;
    align-items: center;
    justify-content: space-around;
    height: var(--bottom-nav-height);
    padding-bottom: var(--safe-bottom);
    background: var(--bg-surface-raised);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.bottom-nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 6px 16px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: var(--font-body);
    font-size: 0.68rem;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.2s;
    -webkit-tap-highlight-color: transparent;
    position: relative;
}

.bottom-nav-btn.active {
    color: var(--accent);
}

.bottom-nav-btn.active::after {
    content: '';
    position: absolute;
    top: -1px;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 3px;
    background: var(--accent);
    border-radius: 0 0 3px 3px;
}

/* ===== TABLET (≥ 640px) ===== */
@media (min-width: 640px) {
    .panel-header {
        padding: 0 20px;
    }

    .header-title h1 { font-size: 1.15rem; }
    .header-sub { display: block; font-size: 0.78rem; color: var(--text-muted); margin-top: 1px; }

    .messages { padding: 20px 24px; gap: 18px; }

    .chat-input-area { padding: 14px 24px calc(14px + var(--safe-bottom)); }

    .welcome-hints {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        max-width: 500px;
    }

    .hint-chip { text-align: center; white-space: nowrap; }

    .hint-chip:hover {
        border-color: var(--accent);
        color: var(--accent);
        background: var(--accent-glow);
        transform: translateY(-2px);
        box-shadow: var(--shadow-sm);
    }

    .btn-send:not(:disabled):hover {
        background: var(--accent-hover);
        transform: scale(1.05);
        box-shadow: var(--shadow-glow);
    }

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

    .upload-area { padding: 24px; }
    .drop-zone { padding: 50px 30px; }

    .drop-zone:hover {
        border-color: var(--accent);
        background: var(--accent-glow);
    }

    .drop-zone:hover .drop-icon { color: var(--accent); }
}

/* ===== DESKTOP (≥ 1024px) ===== */
@media (min-width: 1024px) {
    :root {
        --header-height: 68px;
    }

    .app-shell {
        flex-direction: row;
    }

    /* Sidebar is always visible on desktop */
    .sidebar {
        position: static;
        transform: none;
        width: 260px;
        transition: none;
        flex-shrink: 0;
        padding: 24px 16px;
    }

    .sidebar-overlay { display: none !important; }
    .btn-close-sidebar { display: none; }
    .btn-menu { display: none; }
    .bottom-nav { display: none; }

    .sidebar-header {
        padding: 0 8px 24px;
    }

    .logo { width: 140px; }

    .panel-header {
        padding: 0 32px;
    }

    .header-title h1 { font-size: 1.25rem; }

    .messages {
        padding: 24px 32px;
        gap: 20px;
    }

    .message { max-width: 780px; }

    .chat-input-area {
        padding: 16px 32px 24px;
    }

    .input-wrapper {
        padding: 8px 8px 8px 18px;
    }

    #chat-input { max-height: 120px; }

    .btn-send {
        width: 44px;
        height: 44px;
    }

    .chat-welcome h2 { font-size: 1.5rem; }
    .chat-welcome > p { font-size: 0.95rem; max-width: 400px; }

    .welcome-icon { width: 80px; height: 80px; border-radius: var(--radius-lg); }
    .welcome-logo { width: 50px; }

    .upload-area { padding: 32px; }
    .drop-zone { padding: 60px 40px; }
    .drop-zone.dragover { transform: scale(1.01); box-shadow: var(--shadow-glow); }
}
