/* ============================================================
   Municipality of Jalajala — AI Student Assistant
   Premium LGU Design | Mobile-first | All viewports
   ============================================================ */

:root {
    /* Brand */
    --accent:        #dc2626;
    --accent-hover:  #b91c1c;
    --accent-active: #991b1b;
    --accent-ring:   rgba(220, 38, 38, 0.18);
    --navy:          #1e3a5f;
    --gold:          #d97706;

    /* Surfaces */
    --bg:            #f6f8fb;
    --surface:       #ffffff;
    --surface-2:     #f8fafc;

    /* Borders */
    --border:        #e2e8f0;
    --border-light:  #f1f5f9;

    /* Text */
    --text:          #0f172a;
    --text-secondary:#334155;
    --text-muted:    #64748b;
    --text-subtle:   #94a3b8;

    /* Shadows */
    --shadow-xs: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-sm: 0 1px 4px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.08), 0 2px 6px rgba(0,0,0,0.04);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.10), 0 4px 12px rgba(0,0,0,0.06);

    /* Radii */
    --r-sm:   8px;
    --r-md:   12px;
    --r-lg:   16px;
    --r-xl:   20px;
    --r-full: 9999px;

    /* Bubble radii */
    --bubble-user: 18px 18px 5px 18px;
    --bubble-ai:   18px 18px 18px 5px;

    /* Safe areas */
    --safe-top:    env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html {
    -webkit-text-size-adjust: 100%;
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    height: 100%;
    position: fixed;
    inset: 0;
    width: 100%;
    font-size: 15px;
    line-height: 1.5;
}

/* ── App Shell ──────────────────────────────────────────────── */
.app-shell {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    overflow: hidden;
}

/* ── Top Accent Bar ─────────────────────────────────────────── */
.top-accent-bar {
    flex-shrink: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--navy) 0%, var(--accent) 55%, var(--gold) 100%);
}

/* ── Header ─────────────────────────────────────────────────── */
.premium-header {
    flex-shrink: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.safe-top  { padding-top:    max(0.75rem, var(--safe-top)); }
.safe-bottom { padding-bottom: max(0.75rem, var(--safe-bottom)); }

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.65rem 1rem 0.75rem;
    min-height: 0;
    overflow: hidden;
}

@media (min-width: 640px) {
    .header-inner {
        padding: 0.85rem 1.5rem 0.9rem;
        gap: 1.25rem;
    }
}

/* Seal + Title group */
.header-brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    min-width: 0;
    flex: 1;
    overflow: hidden;
}

@media (min-width: 640px) {
    .header-brand { gap: 0.9rem; }
}

/* Seal */
.seal-wrapper {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.seal-img {
    height: 42px;
    width: auto;
    object-fit: contain;
    display: block;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.12));
}

@media (min-width: 640px) {
    .seal-img {
        height: 50px;
    }
}

.seal-fallback {
    display: none;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    background: #e2e8f0;
    color: #64748b;
}

/* Header text */
.header-text {
    min-width: 0;
    flex: 1;
    overflow: hidden;
}

.header-republic {
    font-size: 0.58rem;
    font-weight: 600;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--text-muted);
    line-height: 1;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (min-width: 640px) {
    .header-republic { font-size: 0.63rem; }
}

.header-title {
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.02em;
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (min-width: 640px) {
    .header-title { font-size: 1.1rem; }
}

.header-subtitle {
    font-size: 0.68rem;
    font-weight: 500;
    color: var(--text-muted);
    line-height: 1.2;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (min-width: 640px) {
    .header-subtitle { font-size: 0.73rem; }
}

/* Status badge */
.status-badge {
    flex-shrink: 0;
    display: none;
    align-items: center;
    gap: 0.4rem;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #15803d;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.3rem 0.75rem;
    border-radius: var(--r-full);
    letter-spacing: 0.01em;
    white-space: nowrap;
}

@media (min-width: 640px) {
    .status-badge { display: flex; }
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #22c55e;
    display: inline-block;
    animation: pulse-dot 2.2s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1;   transform: scale(1); }
    50%       { opacity: 0.55; transform: scale(0.8); }
}

/* ── Body Layout ────────────────────────────────────────────── */
.body-layout {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
    display: none;
    width: 240px;
    flex-shrink: 0;
    flex-direction: column;
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow: hidden;
}

@media (min-width: 768px) {
    .sidebar { display: flex; }
}

.sidebar-section {
    padding: 1.1rem 1.15rem;
}

.sidebar-about {
    border-bottom: 1px solid var(--border-light);
}

.sidebar-label {
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-subtle);
    margin-bottom: 0.5rem;
}

.sidebar-text {
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.65;
}

.sidebar-powered-name {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0.65rem;
}

.sidebar-tags {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.sidebar-tag {
    display: block;
    font-size: 0.71rem;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--bg);
    border: 1px solid var(--border-light);
    border-radius: var(--r-sm);
    padding: 0.32rem 0.6rem;
    line-height: 1.4;
}

.sidebar-footer {
    margin-top: auto;
    padding: 0.85rem 1.15rem;
    border-top: 1px solid var(--border-light);
    font-size: 0.65rem;
    color: var(--text-subtle);
    text-align: center;
}

/* ── Chat Main ──────────────────────────────────────────────── */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: var(--bg);
    overflow: hidden;
}

/* ── Chat Messages ──────────────────────────────────────────── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}

@media (min-width: 640px) {
    .chat-messages {
        padding: 1.5rem 1.75rem;
        gap: 1.35rem;
    }
}

@media (min-width: 768px) {
    .chat-messages {
        padding: 2rem 2.25rem;
    }
}

/* Scrollbar */
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}
.chat-messages::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ── Welcome Screen ─────────────────────────────────────────── */
.welcome-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
    min-height: 220px;
    padding: 1.5rem 0.5rem;
}

@media (min-width: 640px) {
    .welcome-wrapper { min-height: 340px; padding: 2rem 1rem; }
}

.welcome-card {
    text-align: center;
    max-width: 420px;
    width: 100%;
}

.welcome-icon {
    width: 62px;
    height: 62px;
    margin: 0 auto 1.1rem;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (min-width: 640px) {
    .welcome-icon {
        width: 72px;
        height: 72px;
        margin-bottom: 1.25rem;
    }
}

.welcome-icon-svg {
    width: 30px;
    height: 30px;
    color: var(--accent);
    flex-shrink: 0;
}

@media (min-width: 640px) {
    .welcome-icon-svg { width: 34px; height: 34px; }
}

.welcome-title {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.025em;
    line-height: 1.2;
    margin-bottom: 0.55rem;
}

@media (min-width: 640px) {
    .welcome-title { font-size: 1.45rem; }
}

.welcome-subtitle {
    font-size: 0.83rem;
    color: var(--text-muted);
    line-height: 1.7;
    padding: 0 0.25rem;
}

@media (min-width: 640px) {
    .welcome-subtitle { font-size: 0.88rem; }
}

/* ── Suggestion Chips ───────────────────────────────────────── */
.suggestion-chips {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1.25rem;
}

@media (min-width: 640px) {
    .suggestion-chips { margin-top: 1.5rem; gap: 0.6rem; }
}

.chip {
    display: inline-flex;
    align-items: center;
    padding: 0.45rem 0.9rem;
    border-radius: var(--r-full);
    font-size: 0.76rem;
    font-weight: 600;
    font-family: inherit;
    background: var(--surface);
    border: 1.5px solid var(--border);
    color: var(--text-secondary);
    box-shadow: var(--shadow-xs);
    cursor: pointer;
    transition: background 0.16s, border-color 0.16s, color 0.16s, box-shadow 0.16s, transform 0.14s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    line-height: 1.3;
}

.chip:hover {
    background: #fff1f2;
    border-color: #fca5a5;
    color: var(--accent);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

.chip:active {
    transform: translateY(0);
    background: #fee2e2;
    border-color: var(--accent);
}

/* ── Message Bubbles ────────────────────────────────────────── */
.message-user {
    background: linear-gradient(135deg, #dc2626 0%, #991b1b 100%);
    color: #fff;
    border-radius: var(--bubble-user);
    box-shadow: var(--shadow-md);
    max-width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message-ai {
    background: var(--surface);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--bubble-ai);
    box-shadow: var(--shadow-xs);
    max-width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

@media (max-width: 639px) {
    .message-user { border-radius: 14px 14px 4px 14px; }
    .message-ai   { border-radius: 14px 14px 14px 4px; }
}

/* ── Input Area ─────────────────────────────────────────────── */
.input-area {
    flex-shrink: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 0.75rem 0.85rem;
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -4px 20px rgba(0,0,0,0.04);
    position: relative;
    z-index: 10;
}

@media (min-width: 640px) {
    .input-area { 
        padding: 1rem 1.5rem; 
        padding-bottom: max(1rem, env(safe-area-inset-bottom, 0px));
    }
}

@media (min-width: 768px) {
    .input-area { 
        padding: 1.1rem 2rem; 
        padding-bottom: max(1.1rem, env(safe-area-inset-bottom, 0px));
    }
}

/* Image Preview */
.image-preview-container {
    display: none;
    margin-bottom: 10px;
    position: relative;
    width: fit-content;
}

.image-preview {
    max-height: 100px;
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    display: block;
}

.remove-image-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    padding: 0;
    line-height: 1;
}

.input-inner {
    width: 100%;
    max-width: 760px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

@media (min-width: 640px) {
    .input-inner { gap: 0.7rem; }
}

/* Model row */
.model-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
}

.model-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    flex-shrink: 0;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.model-select {
    flex: 1;
    min-width: 0;
    min-height: 40px;
    padding: 0.45rem 0.75rem;
    border-radius: var(--r-md);
    border: 1.5px solid var(--border);
    background: var(--surface-2);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    outline: none;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
    touch-action: manipulation;
    -webkit-appearance: none;
    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.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.65rem center;
    padding-right: 2rem;
}

.model-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-ring);
}

@media (min-width: 640px) {
    .model-select {
        font-size: 0.82rem;
        min-height: 38px;
    }
}

/* Chat form */
.chat-form {
    display: flex;
    gap: 0.5rem;
    min-width: 0;
    width: 100%;
    align-items: flex-end;
}

@media (min-width: 640px) {
    .chat-form { gap: 0.65rem; }
}

/* Upload Button */
.upload-btn {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-2);
    border: 1.5px solid var(--border);
    border-radius: var(--r-lg);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    padding: 0;
}

.upload-btn:hover {
    background: #fff;
    border-color: var(--accent);
    color: var(--accent);
}

.upload-icon {
    width: 22px;
    height: 22px;
}

@media (min-width: 640px) {
    .upload-btn {
        width: 46px;
        height: 46px;
    }
}

.chat-input {
    flex: 1;
    min-width: 0;
    width: 0;
    min-height: 48px;
    padding: 0.7rem 1rem;
    border-radius: var(--r-lg);
    border: 1.5px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 400;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.chat-input::placeholder {
    color: var(--text-subtle);
    font-weight: 400;
}

.chat-input:focus {
    background: var(--surface);
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-ring);
}

.chat-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

@media (min-width: 640px) {
    .chat-input {
        min-height: 46px;
        font-size: 0.88rem;
    }
}

/* Send button */
.send-btn {
    flex-shrink: 0;
    min-height: 48px;
    min-width: 48px;
    padding: 0.7rem 1rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--r-lg);
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    box-shadow: 0 2px 8px rgba(220,38,38,0.30), 0 1px 3px rgba(220,38,38,0.20);
    transition: background 0.15s, box-shadow 0.15s, transform 0.12s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.send-btn:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 14px rgba(220,38,38,0.35), 0 2px 5px rgba(220,38,38,0.20);
    transform: translateY(-1px);
}

.send-btn:active {
    background: var(--accent-active);
    transform: translateY(0);
    box-shadow: 0 1px 4px rgba(220,38,38,0.25);
}

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

.send-label {
    display: none;
}

@media (min-width: 640px) {
    .send-btn {
        min-height: 46px;
        padding: 0.7rem 1.25rem;
    }
    .send-label { display: inline; }
}

.send-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

@media (min-width: 640px) {
    .send-icon { width: 18px; height: 18px; }
}

/* End chat row */
.end-chat-row {
    text-align: center;
}

.end-chat-btn {
    font-family: inherit;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-subtle);
    background: none;
    border: none;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
    padding: 0.2rem 0.4rem;
    border-radius: var(--r-sm);
    transition: color 0.15s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.end-chat-btn:hover { color: var(--accent); }
.end-chat-btn:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    color: var(--accent);
}

/* ── Focus States (Accessibility) ───────────────────────────── */
.chat-input:focus,
.model-select:focus {
    outline: none;
}

.send-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ── Animations ─────────────────────────────────────────────── */
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

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

.animate-fade-in  { animation: fadeIn  0.4s ease-out forwards; }
.animate-slide-up { animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards; }

/* ── Typing Indicator ───────────────────────────────────────── */
.typing-dot {
    animation: typingPulse 1.4s ease-in-out infinite both;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingPulse {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.45; }
    40%           { transform: scale(1);   opacity: 1; }
}
