:root {
    --bg: #f5f7fb;
    --panel: #ffffff;
    --text: #111827;
    --muted: #6b7280;
    --border: #e5e7eb;
    --accent: #38bdf8;
}

html[data-theme="dark"] {
    --bg: #0f172a;
    --panel: #111827;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --border: #1f2937;
    --accent: #38bdf8;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Arial, Helvetica, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.app-header {
    height: 64px;
    padding: 0 24px;
    border-bottom: 1px solid var(--border);
    background: var(--panel);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
}

.brand-dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: var(--accent);
    box-shadow: 0 0 18px var(--accent);
}

.theme-toggle {
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    border-radius: 10px;
    padding: 8px 12px;
    cursor: pointer;
}

.app-main {
    width: 100%;
    min-height: calc(100vh - 64px);
}

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 24px;
}

.muted {
    color: var(--muted);
}
.auth-card {
    max-width: 420px;
    margin: 60px auto;
}

.form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 24px;
}

.form label {
    font-size: 14px;
    color: var(--muted);
}

.form input {
    width: 100%;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    border-radius: 12px;
    padding: 12px 14px;
    outline: none;
}

.form input:focus {
    border-color: var(--accent);
}

.btn-primary {
    margin-top: 10px;
    border: 0;
    border-radius: 12px;
    padding: 12px 16px;
    background: var(--accent);
    color: #03111c;
    font-weight: 700;
    cursor: pointer;
}

.alert {
    margin-top: 18px;
    padding: 12px 14px;
    border-radius: 12px;
    font-size: 14px;
}

.alert-error {
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.35);
    color: #fecaca;
}

html[data-theme="light"] .alert-error {
    color: #991b1b;
}
.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-link {
    color: var(--muted);
    text-decoration: none;
    font-size: 14px;
}

.nav-link:hover {
    color: var(--text);
}
.chat-shell {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 20px;
    min-height: calc(100vh - 130px);
}

.chat-sidebar h2,
.chat-panel h1 {
    margin-top: 0;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 18px;
}

.field label {
    font-size: 14px;
    color: var(--muted);
}

.field select {
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    border-radius: 12px;
    padding: 10px 12px;
    outline: none;
}

.btn-secondary {
    width: 100%;
    margin-top: 24px;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 11px 14px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
}

.chat-panel {
    display: flex;
    flex-direction: column;
    min-height: 620px;
}

.chat-header {
    border-bottom: 1px solid var(--border);
    padding-bottom: 16px;
    margin-bottom: 16px;
}

.chat-messages {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-y: auto;
    padding: 6px 4px 18px;
}

.message {
    max-width: 78%;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 14px 16px;
}

.message p {
    margin-bottom: 0;
}

.message.assistant {
    background: var(--bg);
}

.message.user {
    align-self: flex-end;
    background: rgba(56, 189, 248, 0.12);
    border-color: rgba(56, 189, 248, 0.35);
}

.chat-input {
    display: flex;
    gap: 12px;
    border-top: 1px solid var(--border);
    padding-top: 16px;
}

.chat-input textarea {
    flex: 1;
    resize: none;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    border-radius: 14px;
    padding: 12px 14px;
    outline: none;
    font-family: inherit;
}

.btn-link {
    display: block;
    text-align: center;
    text-decoration: none;
}
.conversation-list {
    margin-top: 28px;
    border-top: 1px solid var(--border);
    padding-top: 18px;
}

.conversation-list h3 {
    margin: 0 0 12px;
    font-size: 14px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.conversation-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 12px;
    border-radius: 12px;
    color: var(--text);
    text-decoration: none;
    border: 1px solid transparent;
}

.conversation-item:hover {
    background: var(--bg);
    border-color: var(--border);
}

.conversation-item.active {
    background: rgba(56, 189, 248, 0.12);
    border-color: rgba(56, 189, 248, 0.35);
}

.conversation-item span {
    font-size: 14px;
    line-height: 1.25;
}

.conversation-item small,
.small-text {
    font-size: 12px;
    color: var(--muted);
}
.conversation-row {
    display: grid;
    grid-template-columns: 1fr 34px;
    gap: 6px;
    align-items: stretch;
}
.conversation-archive {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    color: var(--muted);
    text-decoration: none;
    font-size: 20px;
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
    font-family: inherit;
}

.conversation-archive:hover {
    color: #fecaca;
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.35);
}
.logout-form {
    margin: 0;
}

.nav-button {
    border: 0;
    background: transparent;
    cursor: pointer;
    font-family: inherit;
    padding: 0;
}
.new-chat-form {
    margin: 0;
}

.new-chat-form .btn-secondary {
    width: 100%;
    font-family: inherit;
}
/* =========================
   Mobile sidebar app layout
   ========================= */

html,
body {
    overflow-x: hidden;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-toggle {
    display: none;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    width: 42px;
    height: 42px;
    border-radius: 999px;
    cursor: pointer;
    font-size: 22px;
    line-height: 1;
}

.sidebar-backdrop {
    display: none;
}

/* Desktop */
.chat-shell {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 0;
    min-height: calc(100vh - 64px);
    width: 100%;
}

.chat-sidebar {
    height: calc(100vh - 64px);
    border-radius: 0;
    border-top: 0;
    border-bottom: 0;
    border-left: 0;
    padding: 28px;
    overflow-y: auto;
}

.chat-panel {
    height: calc(100vh - 64px);
    border-radius: 0;
    border-top: 0;
    border-right: 0;
    border-bottom: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
}

/* Mobile */
@media (max-width: 768px) {
    .app-header {
        height: 64px;
        padding: 0 14px;
        position: sticky;
        top: 0;
        z-index: 100;
        background: var(--bg);
        border-bottom: 0;
    }

    .sidebar-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .brand {
        background: var(--panel);
        border: 1px solid var(--border);
        border-radius: 999px;
        padding: 10px 18px;
        font-size: 18px;
        box-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
    }

    .brand-dot {
        display: none;
    }

    .header-actions {
        gap: 8px;
    }

    .theme-toggle {
        width: 42px;
        height: 42px;
        padding: 0;
        border-radius: 999px;
        font-size: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .theme-toggle::after {
        content: "◐";
        font-size: 20px;
    }

    .app-main {
        min-height: calc(100vh - 64px);
    }

    .chat-shell {
        display: block;
        width: 100%;
        min-height: calc(100vh - 64px);
    }

    .chat-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: min(78vw, 320px);
        height: 100vh;
        z-index: 200;
        transform: translateX(-100%);
        transition: transform 0.24s ease;
        border-radius: 0 24px 24px 0;
        border-top: 0;
        border-bottom: 0;
        border-left: 0;
        padding: 68px 18px 22px;
        overflow-y: auto;
        box-shadow: 18px 0 50px rgba(0, 0, 0, 0.38);
    }

    body.sidebar-open .chat-sidebar {
        transform: translateX(0);
    }

    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        z-index: 150;
        background: rgba(0, 0, 0, 0.55);
        display: none;
    }

    body.sidebar-open .sidebar-backdrop {
        display: block;
    }

    .chat-panel {
        width: 100%;
        height: calc(100vh - 64px);
        min-height: calc(100vh - 64px);
        border: 0;
        border-radius: 0;
        padding: 18px 16px;
        display: flex;
        flex-direction: column;
    }

    .chat-header {
        border-bottom: 0;
        padding-bottom: 6px;
        margin-bottom: 8px;
    }

    .chat-header h1,
    .chat-panel h1 {
        font-size: 24px;
        margin: 0 0 6px;
    }

    .chat-messages {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        padding: 8px 2px 14px;
    }

    .message {
        max-width: 100%;
        font-size: 15px;
        padding: 12px 14px;
    }

    .chat-input {
        flex-direction: column;
        gap: 10px;
        border-top: 1px solid var(--border);
        padding-top: 12px;
        background: var(--bg);
    }

    .chat-input textarea {
        width: 100%;
        min-height: 90px;
        font-size: 16px;
    }

    .chat-input .btn-primary {
        width: 100%;
        min-height: 44px;
        margin-top: 0;
    }

    .chat-sidebar h2 {
        font-size: 26px;
        margin-bottom: 16px;
    }
    
    .chat-sidebar p {
        font-size: 15px;
        line-height: 1.35;
        margin-bottom: 18px;
    }
    
    .chat-sidebar .field {
        margin-top: 14px;
    }
    
    .chat-sidebar .field label {
        font-size: 13px;
    }
    
    .chat-sidebar .field select {
        min-height: 44px;
        font-size: 15px;
    }
    
    .chat-sidebar .btn-secondary {
        min-height: 44px;
        margin-top: 18px;
        font-size: 14px;
    }
    
    .conversation-list {
        margin-top: 22px;
        padding-top: 16px;
    }
    
    .conversation-list h3 {
        font-size: 12px;
        letter-spacing: 0.12em;
    }
    
    .conversation-item {
        padding: 10px 12px;
    }
    
    .conversation-item span {
        font-size: 15px;
    }
    
    .conversation-item small,
    .small-text {
        font-size: 11px;
    }

    .profile-avatar {
        width: 42px;
        height: 42px;
        font-size: 14px;
    }
    
    .logout-form {
        display: none;
    }

    .conversation-archive {
        font-size: 18px;
        border-radius: 12px;
    }
}

.profile-avatar {
    width: 38px;
    height: 38px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--accent);
    color: #03111c;
    font-weight: 800;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.profile-menu {
    position: relative;
}

.profile-dropdown {
    position: absolute;
    top: calc(100% + 12px);
    right: 0;
    width: 260px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
    padding: 10px;
    z-index: 300;
    display: none;
}

body.profile-menu-open .profile-dropdown {
    display: block;
}

.profile-dropdown-header {
    padding: 10px 10px 12px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
}

.profile-dropdown-header strong {
    display: block;
    font-size: 14px;
    color: var(--text);
}

.profile-dropdown-header small {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.profile-dropdown-item {
    width: 100%;
    border: 0;
    background: transparent;
    color: var(--text);
    padding: 11px 10px;
    border-radius: 12px;
    text-align: left;
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-decoration: none;
}

.profile-dropdown-item:hover {
    background: var(--bg);
}

.profile-dropdown-item:disabled {
    cursor: not-allowed;
    color: var(--muted);
}

.profile-dropdown-item span {
    font-size: 11px;
    color: var(--muted);
}

.profile-dropdown-item.danger {
    color: #fca5a5;
}

.profile-dropdown-item.danger:hover {
    background: rgba(239, 68, 68, 0.12);
}

.profile-logout-form {
    margin: 0;
}


@media (max-width: 768px) {
    .profile-avatar {
        width: 42px;
        height: 42px;
        font-size: 14px;
    }

    .profile-dropdown {
        position: fixed;
        top: 70px;
        right: 12px;
        width: min(280px, calc(100vw - 24px));
        border-radius: 18px;
    }
}
.alert-success {
    background: rgba(34, 197, 94, 0.12);
    border: 1px solid rgba(34, 197, 94, 0.35);
    color: #bbf7d0;
}

html[data-theme="light"] .alert-success {
    color: #166534;
}