:root {
    --bg: #070b18;
    --panel: rgba(255, 255, 255, .055);
    --panel-2: rgba(255, 255, 255, .085);
    --line: rgba(160, 200, 255, .16);
    --text: #eaf0ff;
    --muted: #9fb0d0;
    --accent: #38bdf8;
    --accent-2: #8b5cf6;
    --radius: 18px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Nastaliq Urdu", sans-serif;
    overscroll-behavior: none;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        radial-gradient(70vw 50vh at -10% -10%, rgba(34, 211, 238, .16), transparent 60%),
        radial-gradient(70vw 55vh at 110% 0%, rgba(139, 92, 246, .18), transparent 60%),
        linear-gradient(180deg, #0a1024 0%, #070b18 100%);
}

.glass {
    background: linear-gradient(135deg, rgba(255, 255, 255, .075), rgba(255, 255, 255, .03));
    border: 1px solid var(--line);
    backdrop-filter: blur(18px);
}

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------------------------------------------------------------- auth */

body.auth {
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-card {
    width: min(400px, 100%);
    border-radius: 24px;
    padding: 30px 26px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand .dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    box-shadow: 0 0 18px rgba(56, 189, 248, .7);
}

.auth-card h1 {
    font-size: 22px;
    margin: 0;
    letter-spacing: -.02em;
}

.auth-card p { margin: 10px 0 22px; font-size: 14px; }

label {
    display: block;
    font-size: 13px;
    color: var(--muted);
    margin: 14px 0 6px;
}

input, textarea {
    width: 100%;
    padding: 13px 14px;
    font-size: 16px;
    color: var(--text);
    background: rgba(9, 14, 30, .6);
    border: 1px solid var(--line);
    border-radius: 14px;
    outline: none;
    font-family: inherit;
}

input:focus, textarea:focus {
    border-color: rgba(56, 189, 248, .65);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, .18);
}

button {
    font: inherit;
    cursor: pointer;
    color: var(--text);
}

.auth-card button[type=submit] {
    width: 100%;
    margin-top: 22px;
    padding: 14px;
    border: 0;
    border-radius: 14px;
    font-weight: 600;
    color: #04121f;
    background: linear-gradient(135deg, #67e8f9, #38bdf8);
}

.error {
    color: #fda4af;
    background: rgba(244, 63, 94, .12);
    border: 1px solid rgba(244, 63, 94, .3);
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 14px;
}

/* ---------------------------------------------------------------- shell */

.shell {
    display: flex;
    height: 100dvh;
}

.sidebar {
    width: 260px;
    flex: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px 12px;
    border-right: 1px solid var(--line);
    background: rgba(8, 13, 28, .55);
}

.sidebar-head {
    display: flex;
    gap: 8px;
    align-items: center;
}

.ghost {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 14px;
    flex: 1;
    min-height: 44px;
}

.ghost:hover { background: var(--panel-2); }

.ghost.icon {
    flex: none;
    width: 44px;
    display: grid;
    place-items: center;
    font-size: 18px;
    line-height: 1;
}

#close-sidebar { display: none; }

.chats {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 6px;
    border-radius: 12px;
    padding: 2px;
}

.chat-item > button.title {
    flex: 1;
    text-align: left;
    background: none;
    border: 0;
    padding: 10px 10px;
    border-radius: 10px;
    color: var(--text);
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: 40px;
}

.chat-item:hover { background: var(--panel); }
.chat-item.active { background: var(--panel-2); }

.chat-item > button.del {
    background: none;
    border: 0;
    color: var(--muted);
    padding: 8px;
    border-radius: 8px;
    opacity: 0;
}

.chat-item:hover > button.del, .chat-item.active > button.del { opacity: 1; }
.chat-item > button.del:hover { color: #fda4af; }

.sidebar-foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 4px 0;
    border-top: 1px solid var(--line);
}

.sidebar-foot a { color: var(--muted); text-decoration: none; padding: 8px 0; display: inline-block; }
.foot-links { display: flex; gap: 14px; }
.sidebar-foot a:hover { color: var(--text); }

.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: 0;
    border-bottom: 1px solid var(--line);
}

.topbar h1 {
    flex: 1;
    font-size: 15px;
    font-weight: 600;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#open-sidebar, #new-chat-top { display: none; }

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 22px 16px 10px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
}

.empty {
    margin: auto;
    text-align: center;
    max-width: 380px;
}

.empty h2 { margin: 0 0 6px; font-size: 22px; letter-spacing: -.02em; }
.empty p { margin: 0; font-size: 14px; }

.msg {
    max-width: min(720px, 100%);
    width: fit-content;
    padding: 12px 15px;
    border-radius: var(--radius);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.msg.user {
    align-self: flex-end;
    background: linear-gradient(135deg, rgba(56, 189, 248, .22), rgba(139, 92, 246, .22));
    border: 1px solid rgba(120, 190, 255, .28);
    border-bottom-right-radius: 6px;
}

.msg.assistant {
    align-self: flex-start;
    background: rgba(255, 255, 255, .055);
    border: 1px solid var(--line);
    border-bottom-left-radius: 6px;
}

.msg.assistant strong { color: #cfe6ff; }

.typing span {
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-right: 4px;
    border-radius: 50%;
    background: var(--muted);
    animation: blink 1.2s infinite;
}

.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }

@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

.composer {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    margin: 10px 14px calc(12px + env(safe-area-inset-bottom));
    padding: 8px;
    border-radius: 22px;
}

.composer textarea {
    border: 0;
    background: none;
    resize: none;
    max-height: 160px;
    padding: 10px 8px;
}

.composer textarea:focus { box-shadow: none; }

#send {
    flex: none;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    display: grid;
    place-items: center;
    color: #04121f;
    background: linear-gradient(135deg, #67e8f9, #38bdf8);
}

#send:disabled { opacity: .45; cursor: default; }

.backdrop {
    position: fixed;
    inset: 0;
    background: rgba(3, 6, 15, .55);
    z-index: 5;
}

@media (max-width: 760px) {
    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 6;
        transform: translateX(-100%);
        transition: transform .22s ease;
        width: 78vw;
        max-width: 300px;
        background: #0b1226;
        box-shadow: 0 0 40px rgba(0, 0, 0, .6);
    }

    .sidebar.open { transform: none; }
    #close-sidebar, #open-sidebar, #new-chat-top { display: grid; }
    .messages { padding: 16px 12px 6px; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
