:root{
    --bg-primary:#131314;
    --bg-secondary:#1e1f20;
    --bg-tertiary:#282a2c;
    --bg-hover:#333537;
    --bg-input:#1e1f20;
    --border-color:#3c4043;
    --text-primary:#e3e3e3;
    --text-secondary:#9aa0a6;
    --text-muted:#5f6368;
    --accent:#8ab4f8;
    --accent-strong:#a8c7fa;
    --grad-1:#4285f4;
    --grad-2:#9b72cb;
    --grad-3:#d96570;
    --danger:#f28b82;
    --success:#81c995;
    --radius:16px;
    --radius-sm:10px;
    font-size:16px;
}
*{box-sizing:border-box;margin:0;padding:0;}
html,body{height:100%;}
body{
    font-family:'Segoe UI',Roboto,-apple-system,BlinkMacSystemFont,Arial,sans-serif;
    background:var(--bg-primary);
    color:var(--text-primary);
    -webkit-font-smoothing:antialiased;
    overflow-x:hidden;
}
a{color:inherit;text-decoration:none;}
button{font-family:inherit;cursor:pointer;}
.icon{width:20px;height:20px;flex-shrink:0;}
.icon-sm{width:16px;height:16px;}
.icon-xl{width:56px;height:56px;}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar{width:8px;height:8px;}
::-webkit-scrollbar-track{background:transparent;}
::-webkit-scrollbar-thumb{background:#3c4043;border-radius:8px;}
::-webkit-scrollbar-thumb:hover{background:#4a4d50;}

/* ================= AUTH PAGE ================= */
.auth-wrapper{
    min-height:100vh;
    display:flex;
    align-items:center;
    justify-content:center;
    padding:20px;
    background:radial-gradient(circle at 20% 20%, rgba(66,133,244,0.08), transparent 40%),
               radial-gradient(circle at 80% 80%, rgba(155,114,203,0.08), transparent 40%),
               var(--bg-primary);
}
.auth-box{
    width:100%;
    max-width:420px;
    background:var(--bg-secondary);
    border:1px solid var(--border-color);
    border-radius:24px;
    padding:36px 32px;
}
.brand{
    display:flex;
    align-items:center;
    justify-content:center;
    gap:10px;
    margin-bottom:8px;
}
.brand-logo{
    width:40px;height:40px;
    border-radius:12px;
    background:linear-gradient(135deg,var(--grad-1),var(--grad-2) 60%,var(--grad-3));
    display:flex;align-items:center;justify-content:center;
    color:#fff;
}
.brand-name{
    font-size:24px;
    font-weight:600;
    background:linear-gradient(90deg,var(--grad-1),var(--grad-2),var(--grad-3));
    -webkit-background-clip:text;
    background-clip:text;
    -webkit-text-fill-color:transparent;
}
.auth-subtitle{
    text-align:center;
    color:var(--text-secondary);
    font-size:14px;
    margin-bottom:28px;
}
.form-group{margin-bottom:16px;}
.form-group label{
    display:block;
    font-size:13px;
    color:var(--text-secondary);
    margin-bottom:6px;
}
.input-wrap{
    position:relative;
    display:flex;
    align-items:center;
}
.input-wrap .icon{
    position:absolute;
    left:14px;
    color:var(--text-muted);
}
.input-wrap input{
    width:100%;
    padding:12px 14px 12px 42px;
    background:var(--bg-tertiary);
    border:1px solid var(--border-color);
    border-radius:var(--radius-sm);
    color:var(--text-primary);
    font-size:14px;
    outline:none;
    transition:border-color .15s;
}
.input-wrap input:focus{border-color:var(--accent);}
.row-2{display:flex;gap:12px;}
.row-2 .form-group{flex:1;}

.btn{
    display:flex;
    align-items:center;
    justify-content:center;
    gap:8px;
    width:100%;
    padding:12px 16px;
    border:none;
    border-radius:var(--radius-sm);
    font-size:14px;
    font-weight:600;
    transition:opacity .15s, background .15s;
}
.btn-primary{
    background:linear-gradient(90deg,var(--grad-1),var(--grad-2));
    color:#fff;
}
.btn-primary:hover{opacity:.9;}
.btn-secondary{
    background:var(--bg-tertiary);
    color:var(--text-primary);
    border:1px solid var(--border-color);
}
.btn-secondary:hover{background:var(--bg-hover);}
.btn-danger{background:var(--danger);color:#2a0d0b;}
.btn-sm{padding:8px 12px;font-size:13px;width:auto;}

.auth-switch{
    text-align:center;
    margin-top:20px;
    font-size:13px;
    color:var(--text-secondary);
}
.btn-link{
    color:var(--accent);
    font-weight:600;
    cursor:pointer;
    background:none;
    border:none;
}
.alert{
    padding:10px 14px;
    border-radius:var(--radius-sm);
    font-size:13px;
    margin-bottom:16px;
}
.alert-error{background:rgba(242,139,130,0.12);color:var(--danger);border:1px solid rgba(242,139,130,0.3);}
.alert-success{background:rgba(129,201,149,0.12);color:var(--success);border:1px solid rgba(129,201,149,0.3);}

.hidden{display:none !important;}

/* ================= STATUS PAGES ================= */
.center-page{min-height:100vh;display:flex;align-items:center;justify-content:center;padding:20px;}
.status-card{
    text-align:center;
    max-width:420px;
    background:var(--bg-secondary);
    border:1px solid var(--border-color);
    border-radius:24px;
    padding:44px 32px;
}
.status-icon{color:var(--accent);margin-bottom:18px;display:flex;justify-content:center;}
.status-card-danger .status-icon{color:var(--danger);}
.status-card h1{font-size:20px;margin-bottom:10px;}
.status-card p{color:var(--text-secondary);font-size:14px;line-height:1.6;}

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

.sidebar{
    width:280px;
    background:var(--bg-secondary);
    border-right:1px solid var(--border-color);
    display:flex;
    flex-direction:column;
    transition:margin-left .2s ease;
    flex-shrink:0;
}
.sidebar-header{
    display:flex;
    align-items:center;
    gap:10px;
    padding:16px;
}
.sidebar-header .brand-name{font-size:18px;}
.sidebar-header .brand-logo{width:32px;height:32px;border-radius:9px;}
.sidebar-header .icon-xl{width:28px;height:28px;}

.new-chat-btn{
    margin:6px 16px 12px 16px;
    display:flex;
    align-items:center;
    gap:10px;
    padding:11px 14px;
    background:var(--bg-tertiary);
    border:1px solid var(--border-color);
    border-radius:var(--radius-sm);
    color:var(--text-primary);
    font-size:14px;
}
.new-chat-btn:hover{background:var(--bg-hover);}

.chat-history{
    flex:1;
    overflow-y:auto;
    padding:4px 12px;
}
.chat-history-label{
    font-size:12px;
    color:var(--text-muted);
    padding:10px 8px 6px 8px;
}
.chat-history-item{
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:6px;
    padding:10px 12px;
    border-radius:var(--radius-sm);
    font-size:13.5px;
    color:var(--text-secondary);
    cursor:pointer;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
    margin-bottom:2px;
}
.chat-history-item:hover{background:var(--bg-tertiary);color:var(--text-primary);}
.chat-history-item.active{background:var(--bg-tertiary);color:var(--text-primary);}
.chat-history-item span.title{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;flex:1;}
.chat-history-item .del-btn{opacity:0;color:var(--text-muted);flex-shrink:0;}
.chat-history-item:hover .del-btn{opacity:1;}
.chat-history-item .del-btn:hover{color:var(--danger);}
.empty-history{color:var(--text-muted);font-size:13px;padding:10px 8px;}

.sidebar-footer{
    padding:12px;
    border-top:1px solid var(--border-color);
    display:flex;
    flex-direction:column;
    gap:4px;
}
.sidebar-footer-item{
    display:flex;
    align-items:center;
    gap:10px;
    padding:10px 12px;
    border-radius:var(--radius-sm);
    font-size:13.5px;
    color:var(--text-secondary);
}
.sidebar-footer-item:hover{background:var(--bg-tertiary);color:var(--text-primary);}
.user-chip{display:flex;align-items:center;gap:10px;padding:8px 12px;}
.user-avatar{
    width:30px;height:30px;border-radius:50%;
    background:linear-gradient(135deg,var(--grad-1),var(--grad-3));
    display:flex;align-items:center;justify-content:center;
    font-size:13px;font-weight:700;color:#fff;flex-shrink:0;
}
.user-chip-info{overflow:hidden;}
.user-chip-name{font-size:13px;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
.user-chip-email{font-size:11px;color:var(--text-muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}

/* Main chat area */
.main-panel{
    flex:1;
    display:flex;
    flex-direction:column;
    min-width:0;
    position:relative;
}
.topbar{
    display:flex;
    align-items:center;
    gap:14px;
    padding:14px 20px;
    border-bottom:1px solid var(--border-color);
    flex-shrink:0;
}
.hamburger-btn{
    background:none;border:none;color:var(--text-primary);
    padding:8px;border-radius:50%;
    display:flex;align-items:center;justify-content:center;
}
.hamburger-btn:hover{background:var(--bg-tertiary);}
.topbar-title{font-size:18px;font-weight:600;
    background:linear-gradient(90deg,var(--grad-1),var(--grad-2),var(--grad-3));
    -webkit-background-clip:text;background-clip:text;-webkit-text-fill-color:transparent;
}

.chat-area{
    flex:1;
    overflow-y:auto;
    padding:24px 0 12px 0;
}
.chat-inner{
    max-width:820px;
    margin:0 auto;
    padding:0 20px;
    display:flex;
    flex-direction:column;
    gap:22px;
}
.welcome-screen{
    flex:1;
    display:flex;
    flex-direction:column;
    align-items:center;
    justify-content:center;
    text-align:center;
    height:100%;
    padding:20px;
}
.welcome-screen .brand-logo{width:56px;height:56px;border-radius:16px;margin-bottom:18px;}
.welcome-screen h2{
    font-size:28px;
    font-weight:600;
    background:linear-gradient(90deg,var(--grad-1),var(--grad-2),var(--grad-3));
    -webkit-background-clip:text;background-clip:text;-webkit-text-fill-color:transparent;
    margin-bottom:8px;
}
.welcome-screen p{color:var(--text-secondary);font-size:14px;}

.msg-row{display:flex;gap:14px;align-items:flex-start;}
.msg-row.user{flex-direction:row-reverse;}
.msg-avatar{
    width:32px;height:32px;border-radius:50%;flex-shrink:0;
    display:flex;align-items:center;justify-content:center;color:#fff;
}
.msg-avatar.ai{background:linear-gradient(135deg,var(--grad-1),var(--grad-2) 60%,var(--grad-3));}
.msg-avatar.user{background:var(--bg-tertiary);color:var(--text-primary);font-size:13px;font-weight:700;}
.msg-bubble{
    max-width:78%;
    padding:12px 16px;
    border-radius:18px;
    font-size:14.5px;
    line-height:1.65;
    word-wrap:break-word;
}
.msg-row.user .msg-bubble{background:var(--bg-tertiary);border-top-right-radius:4px;}
.msg-row.ai .msg-bubble{background:transparent;padding:6px 0;border-top-left-radius:4px;max-width:92%;}
.msg-bubble img.msg-image{max-width:260px;border-radius:12px;margin-top:8px;display:block;}
.msg-bubble p{margin-bottom:10px;}
.msg-bubble p:last-child{margin-bottom:0;}
.msg-bubble ul,.msg-bubble ol{margin:8px 0 8px 20px;}
.msg-bubble strong{color:#fff;}

.code-block-wrap{
    background:#0d0e10;
    border:1px solid var(--border-color);
    border-radius:12px;
    margin:10px 0;
    overflow:hidden;
}
.code-block-head{
    display:flex;
    align-items:center;
    justify-content:space-between;
    padding:8px 14px;
    background:#1a1b1c;
    font-size:12px;
    color:var(--text-secondary);
}
.copy-btn{
    display:flex;
    align-items:center;
    gap:6px;
    background:none;
    border:none;
    color:var(--text-secondary);
    font-size:12px;
    padding:4px 8px;
    border-radius:6px;
}
.copy-btn:hover{background:var(--bg-hover);color:var(--text-primary);}
.copy-btn.copied{color:var(--success);}
.code-block-wrap pre{
    margin:0;
    padding:14px;
    overflow-x:auto;
    font-family:'Consolas','Monaco',monospace;
    font-size:13px;
    line-height:1.55;
    color:#e3e3e3;
}
.msg-bubble code:not(pre code){
    background:var(--bg-tertiary);
    padding:2px 6px;
    border-radius:6px;
    font-size:13px;
    font-family:'Consolas','Monaco',monospace;
}

.typing-dots{display:flex;gap:4px;padding:8px 0;}
.typing-dots span{
    width:7px;height:7px;border-radius:50%;background:var(--text-muted);
    animation:blink 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2){animation-delay:.2s;}
.typing-dots span:nth-child(3){animation-delay:.4s;}
@keyframes blink{0%,80%,100%{opacity:.25;}40%{opacity:1;}}

/* Input area */
.input-area{
    padding:12px 20px 20px 20px;
    flex-shrink:0;
}
.input-inner{
    max-width:820px;
    margin:0 auto;
}
.image-preview-wrap{
    display:flex;
    gap:10px;
    margin-bottom:8px;
    flex-wrap:wrap;
}
.image-preview{
    position:relative;
    width:64px;height:64px;
    border-radius:10px;
    overflow:hidden;
    border:1px solid var(--border-color);
}
.image-preview img{width:100%;height:100%;object-fit:cover;}
.image-preview .remove-img{
    position:absolute;top:2px;right:2px;
    background:rgba(0,0,0,0.6);
    border-radius:50%;
    width:18px;height:18px;
    display:flex;align-items:center;justify-content:center;
    color:#fff;
}
.file-preview-chip{
    display:flex;align-items:center;gap:8px;
    background:var(--bg-tertiary);
    border:1px solid var(--border-color);
    padding:6px 10px;border-radius:10px;
    font-size:12.5px;color:var(--text-secondary);
    margin-bottom:8px;
}

.input-box{
    display:flex;
    align-items:flex-end;
    gap:8px;
    background:var(--bg-input);
    border:1px solid var(--border-color);
    border-radius:26px;
    padding:8px 8px 8px 16px;
}
.input-box textarea{
    flex:1;
    background:none;
    border:none;
    outline:none;
    resize:none;
    color:var(--text-primary);
    font-size:14.5px;
    font-family:inherit;
    max-height:160px;
    padding:8px 0;
    line-height:1.5;
}
.input-box textarea::placeholder{color:var(--text-muted);}
.icon-btn{
    background:none;
    border:none;
    color:var(--text-secondary);
    width:38px;height:38px;
    border-radius:50%;
    display:flex;align-items:center;justify-content:center;
    flex-shrink:0;
}
.icon-btn:hover{background:var(--bg-tertiary);color:var(--text-primary);}
.send-btn{
    background:linear-gradient(135deg,var(--grad-1),var(--grad-2));
    color:#fff;
}
.send-btn:disabled{opacity:.4;cursor:default;}
.send-btn:hover:not(:disabled){opacity:.9;}
.input-hint{
    text-align:center;
    font-size:11px;
    color:var(--text-muted);
    margin-top:8px;
}

/* Overlay for mobile sidebar */
.sidebar-overlay{
    display:none;
    position:fixed;
    inset:0;
    background:rgba(0,0,0,0.5);
    z-index:40;
}

/* ================= RESPONSIVE ================= */
@media (max-width:900px){
    .sidebar{
        position:fixed;
        top:0;left:0;bottom:0;
        z-index:50;
        margin-left:-280px;
        box-shadow:0 0 30px rgba(0,0,0,0.4);
    }
    .sidebar.open{margin-left:0;}
    .sidebar.open ~ .sidebar-overlay{display:block;}
    .msg-bubble{max-width:88%;}
    .row-2{flex-direction:column;gap:0;}
}
@media (max-width:520px){
    .auth-box{padding:26px 20px;border-radius:18px;}
    .topbar{padding:12px 14px;}
    .chat-inner{padding:0 12px;}
    .input-area{padding:8px 10px 14px 10px;}
}
