* {
    box-sizing: border-box;
}

:root {
    --bg-main: #f4f6f9;
    --bg-sidebar: #101827;
    --bg-sidebar-soft: #182235;
    --bg-card: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --text-light: #f9fafb;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --border: #e5e7eb;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    --radius: 16px;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg-main);
    color: var(--text-main);
}

body {
    overflow: hidden;
}

#app {
    display: grid;
    grid-template-columns: 300px 1fr;
    height: 100vh;
    width: 100vw;
}

/* ================= SIDEBAR ================= */

aside {
    background: linear-gradient(180deg, #0f172a 0%, #111827 100%);
    color: var(--text-light);
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
}

#newBtn {
    width: 100%;
    border: none;
    border-radius: 14px;
    padding: 14px 16px;
    background: var(--primary);
    color: white;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: 0.2s ease;
}

#newBtn:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

#convList {
    flex: 1;
    overflow-y: auto;
    padding-right: 4px;
}

.conversation-item {
    padding: 13px 14px;
    margin-bottom: 8px;
    border-radius: 14px;
    background: transparent;
    color: #d1d5db;
    cursor: pointer;
    font-size: 14px;
    line-height: 1.35;
    transition: 0.2s ease;
    border: 1px solid transparent;
}

.conversation-item:hover {
    background: var(--bg-sidebar-soft);
    border-color: rgba(255, 255, 255, 0.08);
}

.conversation-item.active {
    background: #1e293b;
    color: white;
    border-color: rgba(37, 99, 235, 0.7);
}

.conversation-title {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-date {
    margin-top: 4px;
    font-size: 12px;
    color: #94a3b8;
}

/* ================= MAIN ================= */

main {
    display: grid;
    grid-template-rows: auto 1fr auto;
    height: 100vh;
    overflow: hidden;
    background: var(--bg-main);
}

header {
    background: rgba(255, 255, 255, 0.86);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    padding: 18px 28px;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 14px;
    align-items: center;
}

header h1 {
    margin: 0;
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.02em;
}

#docs {
    grid-column: 1 / -1;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.doc-pill {
    background: #eef2ff;
    color: #3730a3;
    border: 1px solid #c7d2fe;
    border-radius: 999px;
    padding: 7px 11px;
    font-size: 12px;
    font-weight: 600;
}

.upload {
    justify-self: end;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: #111827;
    color: white;
    padding: 11px 15px;
    border-radius: 14px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    transition: 0.2s ease;
}

.upload:hover {
    background: #020617;
    transform: translateY(-1px);
}

.upload input {
    display: none;
}

/* ================= MESSAGES ================= */

#messages {
    overflow-y: auto;
    padding: 28px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.message {
    max-width: 980px;
    padding: 18px 20px;
    border-radius: 18px;
    box-shadow: var(--shadow);
    line-height: 1.6;
    font-size: 15px;
    white-space: pre-wrap;
}

.message.user {
    align-self: flex-end;
    background: #2563eb;
    color: white;
    border-bottom-right-radius: 6px;
}

.message.assistant {
    align-self: flex-start;
    background: white;
    color: var(--text-main);
    border: 1px solid var(--border);
    border-bottom-left-radius: 6px;
}

.message.system {
    align-self: center;
    background: #fff7ed;
    color: #9a3412;
    border: 1px solid #fed7aa;
    box-shadow: none;
    font-size: 14px;
}

.message strong {
    font-weight: 800;
}

.message code {
    background: #f3f4f6;
    padding: 2px 5px;
    border-radius: 6px;
    font-family: "Consolas", "Monaco", monospace;
}

/* ================= FOOTER ================= */

footer {
    padding: 18px 28px;
    background: white;
    border-top: 1px solid var(--border);
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: end;
}

#prompt {
    width: 100%;
    min-height: 54px;
    max-height: 180px;
    resize: vertical;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 15px 17px;
    font-size: 15px;
    line-height: 1.45;
    outline: none;
    font-family: inherit;
    background: #f9fafb;
}

#prompt:focus {
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

#sendBtn {
    border: none;
    border-radius: 16px;
    padding: 0 22px;
    min-height: 54px;
    background: var(--primary);
    color: white;
    font-size: 15px;
    font-weight: 800;
    cursor: pointer;
    transition: 0.2s ease;
}

#sendBtn:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

#sendBtn:disabled {
    background: #94a3b8;
    cursor: not-allowed;
    transform: none;
}

/* ================= SCROLLBAR ================= */

::-webkit-scrollbar {
    width: 9px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 999px;
}

aside ::-webkit-scrollbar-thumb {
    background: #475569;
}

/* ================= RESPONSIVE ================= */

@media (max-width: 900px) {
    #app {
        grid-template-columns: 1fr;
    }

    aside {
        display: none;
    }

    header {
        grid-template-columns: 1fr;
    }

    .upload {
        justify-self: start;
    }

    #messages {
        padding: 18px;
    }

    footer {
        padding: 14px;
        grid-template-columns: 1fr;
    }

    #sendBtn {
        width: 100%;
    }
}