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

/* ─── Tokens ─────────────────────────────────────────────── */
:root {
    /* Purple scale */
    --p50:  #faf5ff;
    --p100: #f3e8ff;
    --p200: #e9d5ff;
    --p300: #d8b4fe;
    --p400: #c084fc;
    --p500: #a855f7;
    --p600: #9333ea;
    --p700: #7e22ce;
    --p800: #6b21a8;
    --p900: #4c1d95;

    /* Neutrals */
    --n50:  #f9fafb;
    --n100: #f3f4f6;
    --n200: #e5e7eb;
    --n300: #d1d5db;
    --n400: #9ca3af;
    --n500: #6b7280;
    --n600: #4b5563;
    --n700: #374151;
    --n800: #1f2937;

    --white: #ffffff;
    --sidebar-w: 272px;
    --hdr-h: 68px;
    --radius: 14px;
    --ease: all .18s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background: var(--p900);
    height: 100vh;
    overflow: hidden;
    color: var(--n800);
}

.hidden { display: none !important; }

/* ─── Auth Screen ────────────────────────────────────────── */
.auth-screen {
    position: fixed; inset: 0;
    background: linear-gradient(135deg, var(--p900) 0%, var(--p800) 40%, var(--p700) 100%);
    display: flex; align-items: center; justify-content: center;
    z-index: 500;
}

/* Subtle animated blobs */
.auth-screen::before,
.auth-screen::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: .35;
    pointer-events: none;
}
.auth-screen::before {
    width: 480px; height: 480px;
    background: var(--p500);
    top: -100px; right: -100px;
    animation: blob 8s ease-in-out infinite alternate;
}
.auth-screen::after {
    width: 360px; height: 360px;
    background: var(--p300);
    bottom: -60px; left: -80px;
    animation: blob 10s ease-in-out infinite alternate-reverse;
}

@keyframes blob {
    from { transform: scale(1) translate(0, 0); }
    to   { transform: scale(1.15) translate(30px, -20px); }
}

.auth-card {
    background: var(--white);
    border-radius: 24px;
    padding: 48px 44px;
    width: 100%; max-width: 420px;
    box-shadow: 0 32px 64px rgba(0,0,0,.28);
    position: relative; z-index: 1;
}

.auth-logo { text-align: center; margin-bottom: 36px; }
.auth-logo-icon { font-size: 52px; margin-bottom: 10px; }
.auth-logo h1 {
    font-size: 28px; font-weight: 800; letter-spacing: -.5px;
    color: var(--p800);
    margin-bottom: 6px;
}
.auth-logo p { color: var(--n500); font-size: 14px; }

.field { margin-bottom: 20px; }
.field label {
    display: block;
    font-size: 13px; font-weight: 600;
    color: var(--n700);
    margin-bottom: 7px;
    text-transform: uppercase; letter-spacing: .4px;
}
.field input {
    width: 100%;
    padding: 13px 16px;
    border: 2px solid var(--n200);
    border-radius: 11px;
    font-size: 15px;
    color: var(--n800);
    outline: none;
    transition: var(--ease);
    background: var(--n50);
}
.field input:focus {
    border-color: var(--p500);
    background: var(--white);
    box-shadow: 0 0 0 4px rgba(168,85,247,.12);
}

.btn-start {
    width: 100%;
    padding: 15px;
    background: linear-gradient(135deg, var(--p600), var(--p800));
    color: var(--white);
    border: none; border-radius: 12px;
    font-size: 16px; font-weight: 700;
    cursor: pointer;
    transition: var(--ease);
    letter-spacing: .2px;
    margin-top: 4px;
}
.btn-start:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(126,34,206,.45);
}
.btn-start:active { transform: translateY(0); }

.auth-note {
    text-align: center;
    font-size: 12px; color: var(--n400);
    margin-top: 24px; line-height: 1.6;
}

.powered-by {
    display: flex; align-items: center; justify-content: center; gap: 6px;
    margin-top: 18px;
    font-size: 11px; color: var(--n400);
    letter-spacing: .2px;
}
.sg-logo {
    height: 18px;
    width: auto;
    object-fit: contain;
    vertical-align: middle;
}
.sg-logo-light {
    filter: brightness(0) invert(1);
    opacity: .7;
}
.sidebar-powered {
    margin-top: 14px;
    justify-content: center;
    padding: 8px 0 2px;
    border-top: 1px solid rgba(255,255,255,.07);
}
.sidebar-powered span:first-child {
    color: rgba(255,255,255,.3);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .6px;
}
.sg-logo-fallback {
    color: rgba(255,255,255,.55);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .2px;
}

/* ─── App Shell ──────────────────────────────────────────── */
.app { display: flex; height: 100vh; }

/* ─── Sidebar ────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--p900);
    display: flex; flex-direction: column;
    flex-shrink: 0;
    border-right: 1px solid rgba(255,255,255,.08);
}

.sidebar-top {
    padding: 20px 16px 16px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.brand {
    display: flex; align-items: center; gap: 9px;
    margin-bottom: 16px;
}
.brand-sg-logo {
    height: 24px;
    width: auto;
    object-fit: contain;
    filter: brightness(0) invert(1);
    opacity: .9;
    flex-shrink: 0;
}
.brand-flag { font-size: 22px; }
.brand-name {
    color: var(--white);
    font-size: 17px; font-weight: 700;
    letter-spacing: -.2px;
}

.btn-new-chat {
    width: 100%;
    display: flex; align-items: center; gap: 8px;
    padding: 10px 14px;
    background: rgba(255,255,255,.08);
    color: rgba(255,255,255,.9);
    border: 1px solid rgba(255,255,255,.15);
    border-radius: 10px;
    font-size: 14px; font-weight: 500;
    cursor: pointer;
    transition: var(--ease);
}
.btn-new-chat svg { width: 15px; height: 15px; }
.btn-new-chat:hover { background: rgba(255,255,255,.15); }

.conv-label {
    padding: 16px 20px 8px;
    font-size: 11px; font-weight: 600;
    color: rgba(255,255,255,.3);
    text-transform: uppercase; letter-spacing: .8px;
}

.conv-list {
    flex: 1; overflow-y: auto;
    padding: 0 8px 8px;
}
.conv-list::-webkit-scrollbar { width: 4px; }
.conv-list::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,.15);
    border-radius: 2px;
}

.conv-item {
    display: flex; align-items: center; gap: 9px;
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: var(--ease);
    color: rgba(255,255,255,.6);
    font-size: 14px;
    margin-bottom: 2px;
    position: relative;
}
.conv-item:hover { background: rgba(255,255,255,.07); color: rgba(255,255,255,.9); }
.conv-item.active {
    background: rgba(168,85,247,.22);
    color: var(--white);
}
.conv-item-icon { font-size: 14px; flex-shrink: 0; }
.conv-item-title {
    flex: 1;
    word-break: break-word;
}
.conv-del {
    opacity: 0;
    background: none; border: none;
    color: rgba(255,255,255,.35);
    cursor: pointer;
    border-radius: 6px;
    padding: 3px 5px;
    font-size: 12px;
    transition: var(--ease);
    flex-shrink: 0;
}
.conv-item:hover .conv-del { opacity: 1; }
.conv-del:hover { color: #ff7b7b; background: rgba(255,100,100,.15); }

.conv-empty {
    padding: 32px 16px;
    text-align: center;
    color: rgba(255,255,255,.25);
    font-size: 13px;
    line-height: 1.7;
}

.sidebar-bottom {
    padding: 14px 16px;
    border-top: 1px solid rgba(255,255,255,.08);
}
.user-badge {
    color: rgba(255,255,255,.6);
    font-size: 13px;
    margin-bottom: 10px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.btn-logout {
    width: 100%;
    padding: 9px;
    background: transparent;
    color: rgba(255,255,255,.35);
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    transition: var(--ease);
}
.btn-logout:hover { color: rgba(255,255,255,.7); border-color: rgba(255,255,255,.3); }

/* ─── Chat Panel ─────────────────────────────────────────── */
.chat-panel {
    flex: 1;
    background: var(--white);
    display: flex; flex-direction: column;
    overflow: hidden;
}

/* ─── Header ─────────────────────────────────────────────── */
.chat-header {
    height: var(--hdr-h);
    padding: 0 24px;
    background: var(--white);
    border-bottom: 1px solid var(--n200);
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px;
    flex-shrink: 0;
}

.chat-title {
    font-size: 15px; font-weight: 600;
    color: var(--n800);
    word-break: break-word;
}

/* ─── Country Buttons ────────────────────────────────────── */
.country-row {
    display: flex; gap: 8px;
    flex-shrink: 0;
}

.country-btn {
    display: flex; align-items: center; gap: 7px;
    padding: 9px 18px;
    border: 2px solid var(--n200);
    border-radius: 50px;
    background: var(--white);
    color: var(--n600);
    font-size: 13px; font-weight: 500;
    cursor: pointer;
    transition: var(--ease);
    white-space: nowrap;
}
.country-btn:hover {
    border-color: var(--p400);
    color: var(--p700);
    background: var(--p50);
}
.country-btn.active {
    background: linear-gradient(135deg, var(--p600), var(--p800));
    border-color: transparent;
    color: var(--white);
    box-shadow: 0 4px 14px rgba(126,34,206,.4);
}
.cflag { font-size: 17px; }
.clabel { font-size: 13px; }

/* ─── Messages Container ─────────────────────────────────── */
.msg-container {
    flex: 1;
    overflow-y: auto;
    padding: 28px 24px;
    display: flex; flex-direction: column;
    background: var(--n50);
}
.msg-container::-webkit-scrollbar { width: 6px; }
.msg-container::-webkit-scrollbar-thumb {
    background: var(--n300); border-radius: 3px;
}

/* ─── Welcome ────────────────────────────────────────────── */
.welcome {
    flex: 1;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    text-align: center;
    padding: 48px 16px;
}
.welcome-flag { font-size: 64px; margin-bottom: 18px; }
.welcome h2 {
    font-size: 24px; font-weight: 700;
    color: var(--p800);
    margin-bottom: 10px; letter-spacing: -.3px;
}
.welcome p {
    color: var(--n500); font-size: 15px;
    max-width: 380px; line-height: 1.7;
    margin-bottom: 36px;
}

.quick-qs {
    display: flex; flex-direction: column; gap: 10px;
    width: 100%; max-width: 500px;
}
.quick-btn {
    padding: 13px 20px;
    background: var(--white);
    border: 1.5px solid var(--p200);
    border-radius: 12px;
    color: var(--p700);
    font-size: 14px;
    cursor: pointer;
    text-align: left;
    transition: var(--ease);
    line-height: 1.4;
}
.quick-btn:hover {
    background: var(--p50);
    border-color: var(--p400);
    transform: translateX(5px);
    box-shadow: 0 2px 12px rgba(147,51,234,.1);
}

/* ─── Message List ───────────────────────────────────────── */
.msg-list {
    display: flex; flex-direction: column;
    gap: 18px;
}

.msg-empty {
    text-align: center;
    color: var(--n400);
    font-size: 14px;
    padding: 40px 16px;
}

/* ─── Message Bubble ─────────────────────────────────────── */
.message {
    display: flex; gap: 11px;
    max-width: 78%;
    animation: msgIn .25s ease;
}
@keyframes msgIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

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

.msg-avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; flex-shrink: 0;
    margin-top: 3px;
}
.message.user .msg-avatar {
    background: linear-gradient(135deg, var(--p600), var(--p800));
    color: var(--white);
    font-size: 12px; font-weight: 700;
}
.message.assistant .msg-avatar {
    background: linear-gradient(135deg, var(--p100), var(--p200));
    font-size: 18px;
}

.msg-bubble {
    padding: 13px 17px;
    border-radius: 18px;
    font-size: 14.5px;
    line-height: 1.65;
    word-break: break-word;
    max-width: 100%;
}
.message.user .msg-bubble {
    background: linear-gradient(135deg, var(--p600), var(--p800));
    color: var(--white);
    border-bottom-right-radius: 4px;
}
.message.assistant .msg-bubble {
    background: var(--white);
    color: var(--n800);
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,.07);
}

/* Inline markdown */
.msg-bubble strong { font-weight: 600; }
.msg-bubble em { font-style: italic; }
.msg-bubble code {
    background: var(--p100);
    color: var(--p800);
    padding: 2px 6px;
    border-radius: 5px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 13px;
}
.message.user .msg-bubble code {
    background: rgba(255,255,255,.2);
    color: var(--white);
}
.msg-bubble p { margin-bottom: 6px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble ul, .msg-bubble ol {
    padding-left: 18px;
    margin: 6px 0;
}
.msg-bubble li { margin-bottom: 3px; }

/* Streaming cursor */
.streaming::after {
    content: '▋';
    color: var(--p400);
    animation: blink .9s step-end infinite;
    margin-left: 2px;
}
@keyframes blink { 50% { opacity: 0; } }

/* ─── Typing Indicator ───────────────────────────────────── */
.typing {
    display: flex; gap: 5px;
    align-items: center;
    padding: 14px 18px;
    background: var(--white);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,.07);
    align-self: flex-start;
    margin-left: 45px;
}
.typing-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--p400);
    animation: dot-bounce 1.3s ease infinite;
}
.typing-dot:nth-child(2) { animation-delay: .15s; }
.typing-dot:nth-child(3) { animation-delay: .3s; }
@keyframes dot-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: .4; }
    30%            { transform: translateY(-8px); opacity: 1; }
}

/* ─── Input Bar ──────────────────────────────────────────── */
.input-bar {
    padding: 14px 22px 18px;
    background: var(--white);
    border-top: 1px solid var(--n200);
    flex-shrink: 0;
}

.input-wrap {
    display: flex; align-items: flex-end; gap: 10px;
    background: var(--n50);
    border: 2px solid var(--n200);
    border-radius: 16px;
    padding: 11px 14px;
    transition: var(--ease);
}
.input-wrap:focus-within {
    border-color: var(--p400);
    background: var(--white);
    box-shadow: 0 0 0 4px rgba(168,85,247,.1);
}

#msg-input {
    flex: 1;
    border: none; background: transparent;
    font-size: 15px; color: var(--n800);
    outline: none; resize: none;
    max-height: 120px;
    line-height: 1.5;
    font-family: inherit;
}
#msg-input::placeholder { color: var(--n400); }
#msg-input:disabled { opacity: .5; }

.btn-send {
    width: 38px; height: 38px;
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--p600), var(--p800));
    color: var(--white);
    border: none; border-radius: 11px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: var(--ease);
}
.btn-send svg { width: 16px; height: 16px; }
.btn-send:hover:not(:disabled) {
    transform: scale(1.06);
    box-shadow: 0 4px 14px rgba(126,34,206,.45);
}
.btn-send:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.input-hint {
    font-size: 12px; color: var(--n400);
    margin-top: 8px; text-align: center;
}

/* ─── Toast ──────────────────────────────────────────────── */
.toast {
    position: fixed; bottom: 24px; right: 24px;
    padding: 12px 20px;
    border-radius: 10px;
    font-size: 14px; font-weight: 500;
    box-shadow: 0 6px 24px rgba(0,0,0,.2);
    z-index: 999;
    animation: toastIn .25s ease;
    max-width: 360px;
}
.toast.error { background: #ef4444; color: var(--white); }
.toast.success { background: var(--p600); color: var(--white); }
@keyframes toastIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 820px) {
    .sidebar { width: 230px; }
    .clabel { display: none; }
    .country-btn { padding: 9px 13px; }
}
@media (max-width: 600px) {
    .sidebar { display: none; }
    .message { max-width: 88%; }
}
