:root {
    --bg: #f7f7f8;
    --panel: #f9f9f9;
    --panel-strong: #ffffff;
    --text: #0d0d0d;
    --muted: #676767;
    --border: #e5e5e5;
    --accent: #375338;
    --accent-2: #b08a3c;
    --accent-soft: #eef3ee;
    --user-bg: #ececec;
    --danger: #a33c3c;
    --shadow: 0 8px 24px rgba(0, 0, 0, .06);
    --thread-width: 768px;
    --radius: 16px;
}

[data-theme="dark"] {
    --bg: #212121;
    --panel: #171717;
    --panel-strong: #2f2f2f;
    --text: #ececec;
    --muted: #b4b4b4;
    --border: #3f3f3f;
    --accent: #9cc486;
    --accent-2: #d3b15f;
    --accent-soft: #2a332a;
    --user-bg: #303030;
    --danger: #ff9b9b;
    --shadow: 0 8px 24px rgba(0, 0, 0, .35);
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

body.chat-body {
    height: 100%;
    overflow: hidden;
}

body.admin-body {
    overflow-y: auto;
}

.auth-page {
    overflow: auto;
}

.auth-page-shell {
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-card {
    width: min(100%, 520px);
    margin: 0;
}

.app-shell {
    display: grid;
    grid-template-columns: 270px 1fr;
    height: 100dvh;
    overflow: hidden;
}

.sidebar {
    background: var(--panel);
    border-right: 1px solid var(--border);
    padding: 8px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100dvh;
    overflow: hidden;
    transition: transform .25s ease;
}

.brand {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 6px;
    padding: 2px 4px;
}

.brand-mark {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    color: white;
    background: linear-gradient(135deg, #375338, #9c7a31);
    font-weight: 700;
    font-size: .72rem;
}

.sattvik-logo {
    display: block;
    object-fit: contain;
    flex-shrink: 0;
}

.welcome-state {
    max-width: var(--thread-width);
    width: 100%;
    margin: 12vh auto 0;
    padding: 0 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: rise .2s ease;
}

.welcome-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    width: 100%;
    max-width: 480px;
    margin: 0 auto 24px;
    gap: 10px;
}

.welcome-logo {
    margin: 0 0 4px;
}

.welcome-state h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
    letter-spacing: -.02em;
    width: 100%;
}

.welcome-copy {
    color: var(--muted);
    font-size: .92rem;
    margin: 0;
    width: 100%;
    line-height: 1.5;
}

.chat-header-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex: 1;
}

.chat-header-brand h1 {
    margin: 0;
}

.profile-avatar-logo {
    padding: 2px;
    background: var(--panel-strong);
}

.profile-avatar-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 6px;
}

.brand-mark.mini {
    width: 34px;
    height: 34px;
    border-radius: 11px;
    font-size: .78rem;
}


.new-chat-btn,
.side-action,
.primary-wide,
.send-btn,
.stop-btn {
    border: 0;
    border-radius: 8px;
    min-height: 32px;
    font-weight: 600;
    font-size: .8125rem;
    transition: background .15s ease, opacity .15s ease;
}

.new-chat-btn,
.primary-wide,
.send-btn {
    color: white;
    background: var(--accent);
}

.new-chat-btn {
    width: 100%;
    margin-bottom: 6px;
    padding: 0 10px;
}

.search-shell {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--panel-strong);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 5px 8px;
    margin-bottom: 6px;
    font-size: .8125rem;
}

.search-shell input {
    background: transparent;
    border: 0;
    color: var(--text);
    outline: 0;
    width: 100%;
}

.history-group {
    color: var(--muted);
    font-size: .625rem;
    font-weight: 600;
    letter-spacing: .05em;
    text-transform: uppercase;
    margin: 10px 8px 2px;
    line-height: 1;
}

.conversation-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0 2px 0 0;
    -webkit-overflow-scrolling: touch;
}

.conversation-item {
    border: 0;
    background: transparent;
    border-radius: 8px;
    height: 40px;
    min-height: 40px;
    max-height: 40px;
    padding: 0 8px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 4px;
    position: relative;
}

.conversation-item.active,
.conversation-item:hover {
    background: var(--panel-strong);
}

.conversation-title {
    font-size: .8125rem;
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.chat-row-actions {
    opacity: 0;
    display: flex;
    gap: 0;
    flex-shrink: 0;
    transition: opacity .12s ease;
}

.conversation-item:hover .chat-row-actions,
.conversation-item:focus-within .chat-row-actions {
    opacity: 1;
}

.chat-row-actions button {
    border: 0;
    background: transparent;
    color: var(--muted);
    width: 22px;
    height: 22px;
    padding: 0;
    font-size: .72rem;
    line-height: 1;
}

.empty-history {
    color: var(--muted);
    padding: 10px;
    font-size: .84rem;
}

.sidebar-footer {
    margin-top: auto;
    display: grid;
    gap: 4px;
    padding-top: 6px;
}

.profile-card,
.guest-meter {
    border: 1px solid var(--border);
    background: var(--panel-strong);
    border-radius: 8px;
    padding: 6px 8px;
}

.profile-card {
    display: flex;
    align-items: center;
    gap: 8px;
}

.profile-details {
    flex: 1;
    min-width: 0;
}

.profile-details strong,
.profile-details span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.profile-logout {
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: .75rem;
    padding: 4px 0;
    flex-shrink: 0;
}

.profile-logout:hover {
    color: var(--text);
}

.side-action.subtle {
    opacity: .85;
}

.profile-card span,
.guest-meter span {
    display: block;
    color: var(--muted);
    font-size: .78rem;
}

.profile-avatar {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 700;
    font-size: .82rem;
}

.side-action {
    background: var(--panel-strong);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 8px;
    font-size: .8125rem;
}

.side-action.danger {
    color: var(--danger);
}

.chat-main {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100dvh;
    overflow: hidden;
}

.chat-header {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg);
    flex-shrink: 0;
}

.chat-header h1 {
    font-size: .95rem;
    font-weight: 600;
    flex: 0;
    text-align: center;
}

.header-spacer {
    width: 32px;
    flex-shrink: 0;
}

.icon-btn {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    background: var(--panel-strong);
    color: var(--text);
    border-radius: 8px;
    font-size: .9rem;
}

.mobile-only {
    display: none;
}

.messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 16px 16px 8px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}


.suggestion-list {
    display: grid;
    gap: 8px;
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
}

.suggestion,
.follow-up {
    background: var(--panel-strong);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    text-align: left;
    font-size: .88rem;
    font-weight: 500;
    transition: background .15s ease;
}

.suggestion:hover,
.follow-up:hover {
    background: var(--accent-soft);
}

.message {
    max-width: var(--thread-width);
    margin: 0 auto 12px;
    display: flex;
}

.message.user {
    justify-content: flex-end;
}

.message.assistant {
    justify-content: flex-start;
}

.message.user .bubble,
.message.assistant .bubble {
    border: 1px solid var(--border);
    box-shadow: none;
    max-width: min(94%, 720px);
    padding: 10px 14px;
}

.message.user .bubble {
    background: var(--user-bg);
    border-radius: 18px 18px 4px 18px;
}

.message.assistant .bubble {
    background: var(--panel-strong);
    border-radius: 4px 18px 18px 18px;
    width: auto;
}

[data-theme="dark"] .message.user .bubble {
    border-color: var(--border);
    background: var(--user-bg);
}

[data-theme="dark"] .message.assistant .bubble {
    border-color: var(--border);
    background: var(--panel-strong);
}

.bubble {
    border-radius: 12px;
}

.message-content {
    font-size: .95rem;
    line-height: 1.55;
}

.message-content p {
    margin: 0 0 .65em;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content h1,
.message-content h2,
.message-content h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: .8em 0 .4em;
}

.message-content ul,
.message-content ol {
    margin: .4em 0 .65em;
    padding-left: 1.25em;
}

.bubble pre {
    background: var(--panel);
    color: var(--text);
    padding: 10px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: .84rem;
    border: 1px solid var(--border);
}

.message-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
    opacity: 0;
    transition: opacity .15s ease;
}

.message:hover .message-actions {
    opacity: 1;
}

.action-btn,
.link-btn {
    border: 0;
    background: transparent;
    color: var(--muted);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: .78rem;
    font-weight: 500;
}

.action-btn:hover,
.link-btn:hover {
    background: var(--panel-strong);
    color: var(--text);
}

.related-questions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.follow-up {
    padding: 7px 10px;
    border-radius: 999px;
    font-size: .82rem;
}

.typing-dots {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 0;
}

.typing-dots span {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--muted);
    animation: pulse 1s infinite ease-in-out;
}

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

@keyframes pulse {
    0%, 100% { opacity: .35; transform: translateY(0); }
    50% { opacity: 1; transform: translateY(-2px); }
}

.composer-wrap {
    padding: 10px 16px 14px;
    border-top: 1px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
}

.composer {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    max-width: var(--thread-width);
    margin: 0 auto;
    background: var(--panel-strong);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 6px 8px 6px 6px;
    box-shadow: var(--shadow);
}

.attach-btn {
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--muted);
    font-size: 1.1rem;
    flex-shrink: 0;
    opacity: .45;
}

.composer textarea {
    border: 0;
    outline: 0;
    resize: none;
    background: transparent;
    color: var(--text);
    min-height: 24px;
    max-height: 140px;
    padding: 8px 4px;
    flex: 1;
    font-size: .95rem;
    line-height: 1.4;
}

.send-btn,
.stop-btn {
    width: 32px;
    height: 32px;
    min-height: 32px;
    padding: 0;
    border-radius: 50%;
    flex-shrink: 0;
    display: grid;
    place-items: center;
    font-size: 1rem;
}

.stop-btn {
    width: auto;
    min-width: 56px;
    border-radius: 16px;
    padding: 0 12px;
    color: var(--danger);
    background: rgba(163, 60, 60, .1);
    border: 1px solid rgba(163, 60, 60, .2);
    font-size: .82rem;
}

.premium-input,
.form-control,
.form-select {
    background: var(--panel-strong);
    border-color: var(--border);
    color: var(--text);
}

.premium-input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 12px 14px;
    margin: 6px 0 14px;
}

.primary-wide {
    width: 100%;
}

.login-modal {
    border-radius: 28px;
    border: 1px solid var(--border);
    background: var(--panel-strong);
    color: var(--text);
    box-shadow: var(--shadow);
}

.login-modal .modal-body {
    max-height: min(70vh, 560px);
    overflow-y: auto;
}

.auth-status {
    color: var(--muted);
    margin-top: 12px;
    font-size: .9rem;
}

.toastlet {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translate(-50%, 20px);
    opacity: 0;
    background: var(--text);
    color: var(--bg);
    border-radius: 999px;
    padding: 10px 16px;
    z-index: 2000;
    transition: .2s ease;
}

.toastlet.show {
    transform: translate(-50%, 0);
    opacity: 1;
}

@keyframes rise {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.admin-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 260px 1fr;
    align-items: start;
}

.admin-nav {
    background: var(--panel);
    border-right: 1px solid var(--border);
    padding: 20px;
    position: sticky;
    top: 0;
    height: 100vh;
    max-height: 100vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.admin-content {
    padding: 28px;
    min-width: 0;
}

.stat-card {
    background: var(--panel-strong);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 18px;
    box-shadow: var(--shadow);
}

.admin-pagination {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.admin-content nav[role="navigation"],
.admin-content .admin-pagination nav {
    width: 100%;
}

.admin-content .pagination {
    margin-bottom: 0;
    gap: 4px;
    flex-wrap: wrap;
}

.admin-content .pagination .page-link {
    border-radius: 8px;
    color: var(--text);
    border-color: var(--border);
    background: var(--panel);
    min-width: 36px;
    text-align: center;
    padding: .4rem .75rem;
    line-height: 1.25;
}

.admin-content .pagination .page-item.active .page-link {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    z-index: 1;
}

.admin-content .pagination .page-link:hover {
    background: var(--accent-soft);
    border-color: var(--border);
    color: var(--text);
}

.admin-content .pagination .page-item.disabled .page-link {
    background: var(--panel);
    color: var(--muted);
    opacity: .7;
}

.admin-content nav .small.text-muted {
    color: var(--muted) !important;
    margin-bottom: 0;
}

@media (max-width: 900px) {
    .admin-shell {
        grid-template-columns: 1fr;
    }

    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(86vw, 270px);
        height: 100dvh;
        z-index: 1000;
        transform: translateX(-105%);
        box-shadow: var(--shadow);
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

    .mobile-scrim {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.35);
        opacity: 0;
        pointer-events: none;
        z-index: 999;
        transition: opacity .2s ease;
    }

    body.sidebar-open .mobile-scrim {
        opacity: 1;
        pointer-events: auto;
    }

    .admin-nav {
        display: none;
    }

    .mobile-only {
        display: block;
    }

    .chat-header,
    .messages,
    .composer-wrap {
        padding-left: 12px;
        padding-right: 12px;
    }

    .messages {
        padding-top: 12px;
    }

    .welcome-state {
        margin-top: 8vh;
    }

    .message.user .bubble,
    .message.assistant .bubble {
        max-width: 96%;
    }
}
