* {
    box-sizing: border-box;
}

:root {
    --bg: #f5f7fb;              
    --panel: #ffffff;          
    --panel-2: #eef2f7;        
    --border: rgba(0, 0, 0, 0.08);
    --text: #1a1f36;           
    --muted: #6b7280;          
    --accent: #0056b3;         
    --accent-2: #007bff;       
    --user: #0056b3;           
    --bot: #eef2f7;            
    --danger: #e53935;
    --shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
    --font: 'DM Sans', system-ui, -apple-system, sans-serif;
}

html,
body {
    margin: 0;
    padding: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    height: 100%;
    overflow: hidden;
}

.app {
    height: 100vh;
    height: 100dvh; 
    display: grid;
    grid-template-columns: 300px 1fr;
    overflow: hidden;
}

.sidebar {
    border-right: 1px solid var(--border);
    background: var(--panel);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    padding: 24px 18px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.sidebar-close {
    display: none;
}

.sidebar-overlay {
    display: none;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.brand-badge {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: #08111d;
    display: grid;
    place-items: center;
    font-weight: 800;
    font-size: 14px;
    flex-shrink: 0;
}

.brand h1 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
}

.brand p {
    margin: 4px 0 0;
    font-size: 12px;
    color: var(--muted);
}

.sidebar-section {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 14px;
}

.sidebar-section h2 {
    margin: 0 0 8px;
    font-size: 14px;
    font-weight: 600;
}

.sidebar-section p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.55;
}

.suggestions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.suggestion-btn {
    width: 100%;
    text-align: left;
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    cursor: pointer;
    transition: 0.2s ease;
    font-size: 13px;
    font-family: var(--font);
    line-height: 1.4;
}

.suggestion-btn:hover {
    background: rgba(0, 123, 255, 0.1);
    border-color: rgba(138, 215, 255, 0.35);
}

.suggestion-btn:active {
    transform: scale(0.98);
}

.status-card {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
    font-size: 13px;
}

.status-dot {
    width: 9px;
    height: 9px;
    border-radius: 999px;
    background: #f5c451;
    flex-shrink: 0;
}

.status-dot.online {
    background: #49d17d;
    box-shadow: 0 0 8px rgba(73, 209, 125, 0.4);
}

.status-dot.offline {
    background: var(--danger);
}

.chat-area {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    min-width: 0;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--panel);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    flex-shrink: 0;
    z-index: 10;
    gap: 12px;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.menu-btn {
    display: none;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 10px;
    width: 40px;
    height: 40px;
    cursor: pointer;
    place-items: center;
    flex-shrink: 0;
    transition: 0.2s ease;
}

.menu-btn:hover {
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.04);
}

.chat-header h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
}

.chat-header p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.clear-btn {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 14px;
    cursor: pointer;
    transition: 0.2s ease;
    white-space: nowrap;
    font-family: var(--font);
    font-size: 13px;
    flex-shrink: 0;
}

.clear-btn:hover {
    color: var(--text);
    border-color: rgba(255, 255, 255, 0.2);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}

.chat-messages::-webkit-scrollbar {
    width: 5px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.message {
    display: flex;
    gap: 10px;
    max-width: 800px;
    animation: fadeSlideIn 0.3s ease;
}

.message.user {
    margin-left: auto;
    flex-direction: row-reverse;
}

@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.avatar {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
    background: #dbeafe;
    color: #0056b3;
}

.message.user .avatar {
    background: #3559ff;
    color: white;
}

.bubble {
    padding: 12px 15px;
    border-radius: 16px;
    line-height: 1.6;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    max-width: min(100%, 680px);
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 14.5px;
}

.message.bot .bubble {
    background: #eef2f7;
    color: var(--text);
}

.message.user .bubble {
    background: var(--accent);
    color: #ffffff;
}

.bubble p {
    margin: 0;
}

.loading-bubble {
    padding: 14px 20px;
}

.typing-indicator {
    display: inline-flex;
    gap: 5px;
    align-items: center;
    height: 18px;
}

.typing-indicator span {
    width: 7px;
    height: 7px;
    background: var(--accent);
    border-radius: 999px;
    display: inline-block;
    animation: bounce 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) {
    animation-delay: 0s;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.16s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.32s;
}

@keyframes bounce {
    0%, 80%, 100% {
        opacity: 0.35;
        transform: scale(0.8) translateY(0);
    }
    40% {
        opacity: 1;
        transform: scale(1) translateY(-5px);
    }
}

.chat-input-area {
    padding: 14px 20px 16px;
    border-top: 1px solid var(--border);
    background: var(--panel);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    flex-shrink: 0;
    z-index: 10;
}

.input-wrap {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

textarea {
    flex: 1;
    resize: none;
    min-height: 48px;
    max-height: 150px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: #ffffff;
    color: var(--text);
    padding: 13px 16px;
    font-family: var(--font);
    font-size: 14.5px;
    outline: none;
    line-height: 1.45;
    transition: border-color 0.2s ease;
    -webkit-appearance: none;
}

textarea::placeholder {
    color: var(--muted);
    opacity: 0.6;
}

textarea:focus {
    border-color: rgba(138, 215, 255, 0.45);
}

#sendBtn {
    height: 48px;
    min-width: 90px;
    border: none;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: white;
    font-weight: 700;
    cursor: pointer;
    transition: 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 14px;
    font-family: var(--font);
    flex-shrink: 0;
}

#sendBtn .send-icon {
    display: none;
}

#sendBtn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(90, 174, 255, 0.3);
}

#sendBtn:active {
    transform: scale(0.97);
}

#sendBtn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.spin-icon {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.input-footer {
    margin-top: 8px;
    color: var(--muted);
    font-size: 11.5px;
    line-height: 1.4;
    opacity: 0.7;
}

@media (max-width: 980px) {
    .app {
        grid-template-columns: 1fr;
    }

    .menu-btn {
        display: grid;
    }

    .sidebar {
        position: fixed;
        inset: 0;
        width: min(320px, 85vw);
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        padding-top: 60px;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-close {
        display: grid;
        place-items: center;
        position: absolute;
        top: 16px;
        right: 16px;
        width: 36px;
        height: 36px;
        background: rgba(255, 255, 255, 0.06);
        border: 1px solid var(--border);
        border-radius: 10px;
        color: var(--muted);
        cursor: pointer;
        transition: 0.2s;
    }

    .sidebar-close:hover {
        color: var(--text);
        border-color: rgba(255, 255, 255, 0.2);
    }

    .sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.55);
        z-index: 999;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    .sidebar-overlay.active {
        opacity: 1;
        pointer-events: auto;
    }
}

/* ════════════════════════════════════════════════════
   RESPONSIVE — MOBILE
   ════════════════════════════════════════════════════ */

@media (max-width: 640px) {
    .chat-header {
        padding: 12px 14px;
    }

    .chat-header h2 {
        font-size: 17px;
    }

    .chat-header p {
        font-size: 11.5px;
        margin-top: 2px;
    }

    .clear-btn {
        padding: 7px 10px;
        font-size: 12px;
        border-radius: 8px;
    }

    .chat-messages {
        padding: 14px 12px;
        gap: 12px;
    }

    .message {
        gap: 8px;
    }

    .avatar {
        width: 32px;
        height: 32px;
        border-radius: 10px;
        font-size: 11px;
    }

    .bubble {
        padding: 10px 13px;
        border-radius: 14px;
        font-size: 14px;
        line-height: 1.55;
        max-width: calc(100% - 42px);
    }

    .chat-input-area {
        padding: 10px 12px 12px;
    }

    .input-wrap {
        gap: 8px;
    }

    textarea {
        min-height: 44px;
        padding: 11px 14px;
        font-size: 14px;
        border-radius: 12px;
    }

    #sendBtn {
        height: 44px;
        min-width: 44px;
        width: 44px;
        border-radius: 12px;
        padding: 0;
    }

    #sendBtn .send-label {
        display: none;
    }

    #sendBtn .send-icon {
        display: block;
    }

    .input-footer small {
        font-size: 10.5px;
    }

    .menu-btn {
        width: 36px;
        height: 36px;
        border-radius: 8px;
    }

    .loading-bubble {
        padding: 12px 16px;
    }

    .typing-indicator span {
        width: 6px;
        height: 6px;
    }
}

/* ════════════════════════════════════════════════════
   RESPONSIVE — VERY SMALL PHONES
   ════════════════════════════════════════════════════ */

@media (max-width: 380px) {
    .chat-header h2 {
        font-size: 15px;
    }

    .chat-header p {
        display: none;
    }

    .bubble {
        font-size: 13.5px;
        padding: 9px 11px;
    }

    textarea {
        font-size: 13.5px;
        padding: 10px 12px;
    }
}


.brand-logo {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    overflow: hidden;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 1px solid var(--border);
}

.brand-logo img {
    width: 100%;
    height: 100%;
}

/* ── Safe area for notched phones ───────────────── */

@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .chat-input-area {
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }
}

.message.bot .bubble a {
    color: var(--accent);
    font-weight: 700;
    text-decoration: underline;
    word-break: break-word;
}

.message.bot .bubble a:hover {
    color: var(--accent-2);
}