:root {
    --bg: #f4ece5;
    --bg-top: #fbf5f0;
    --panel: rgba(255, 250, 246, 0.82);
    --panel-strong: rgba(255, 255, 255, 0.9);
    --panel-dark: #221c1d;
    --text: #211615;
    --muted: #6f5b57;
    --muted-soft: rgba(33, 22, 21, 0.46);
    --line: rgba(96, 56, 51, 0.12);
    --line-strong: rgba(96, 56, 51, 0.2);
    --accent: #8c141d;
    --accent-deep: #6d1017;
    --accent-soft: #b4434c;
    --accent-glow: rgba(140, 20, 29, 0.22);
    --surface-shadow: 0 24px 64px rgba(78, 38, 35, 0.12);
    --radius-xl: 32px;
    --radius-lg: 24px;
    --radius-md: 18px;
    --radius-sm: 14px;
    --max-width: 1440px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Manrope", "Avenir Next", "Segoe UI Variable", sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at 12% 10%, rgba(181, 67, 76, 0.18), transparent 26%),
        radial-gradient(circle at 88% 8%, rgba(114, 28, 34, 0.14), transparent 22%),
        linear-gradient(180deg, var(--bg-top) 0%, var(--bg) 48%, #ece3db 100%);
}

body.modal-open {
    overflow: hidden;
}

img {
    display: block;
    max-width: 100%;
}

button,
input,
textarea {
    font: inherit;
}

a {
    color: inherit;
    text-decoration: none;
}

.ambient {
    position: fixed;
    inset: auto;
    border-radius: 999px;
    filter: blur(40px);
    pointer-events: none;
    opacity: 0.95;
}

.ambient-a {
    width: 300px;
    height: 300px;
    top: 84px;
    left: -40px;
    background: radial-gradient(circle at center, rgba(180, 68, 77, 0.28), transparent 72%);
}

.ambient-b {
    width: 320px;
    height: 320px;
    right: -50px;
    bottom: 40px;
    background: radial-gradient(circle at center, rgba(47, 52, 55, 0.14), transparent 74%);
}

.page-shell {
    width: min(calc(100% - 28px), var(--max-width));
    margin: 0 auto;
    padding: 20px 0 28px;
    position: relative;
}

.site-header {
    position: sticky;
    top: 12px;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 18px;
    margin-bottom: 18px;
    border: 1px solid rgba(255, 255, 255, 0.56);
    border-radius: 999px;
    background: rgba(255, 249, 244, 0.78);
    backdrop-filter: blur(22px);
    box-shadow: 0 12px 32px rgba(91, 49, 44, 0.08);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.brand-logo {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 18px;
    box-shadow: 0 16px 28px rgba(90, 42, 39, 0.12);
}

.brand-copy {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.brand-copy strong,
.header-status,
.eyebrow,
.pill,
.auth-tab,
.method-chip,
.panel-head h2,
.conversation-meta h2,
.story-card h2,
.auth-story h1,
.auth-card h2,
.empty-state h2 {
    font-family: "Space Grotesk", "Avenir Next Condensed", sans-serif;
    letter-spacing: -0.04em;
}

.brand-copy strong {
    font-size: 1.02rem;
}

.brand-copy small {
    font-size: 0.74rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
}

.header-status {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 0.95rem;
    color: rgba(33, 22, 21, 0.82);
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 8px rgba(140, 20, 29, 0.1);
}

.workspace {
    min-height: calc(100vh - 120px);
}

.auth-layout,
.chat-screen {
    display: grid;
    grid-template-columns: minmax(360px, 0.82fr) minmax(380px, 0.78fr);
    gap: 18px;
}

.chat-screen {
    grid-template-columns: minmax(310px, 360px) minmax(0, 1fr);
}

.auth-story,
.auth-card,
.sidebar-card,
.conversation-panel,
.modal-panel {
    border: 1px solid rgba(255, 255, 255, 0.58);
    border-radius: var(--radius-xl);
    background: var(--panel);
    backdrop-filter: blur(16px);
    box-shadow: var(--surface-shadow);
}

.auth-story,
.auth-card,
.sidebar-card,
.conversation-panel {
    padding: 28px;
}

.auth-story {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 28px;
}

.eyebrow {
    margin: 0 0 12px;
    font-size: 0.82rem;
    font-weight: 800;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--accent);
}

.auth-story h1,
.auth-card h2,
.empty-state h2 {
    margin: 0;
    line-height: 0.98;
}

.auth-story h1 {
    font-size: clamp(3rem, 5.6vw, 5.4rem);
}

.lead,
.story-card p,
.helper-text,
.empty-state p,
.message-meta,
.chat-preview,
.search-result p,
.current-user-card p,
.conversation-subtitle,
.empty-chat-note {
    color: var(--muted);
    line-height: 1.7;
}

.lead {
    margin: 22px 0 0;
    font-size: 1.05rem;
    max-width: 48rem;
}

.story-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

.story-card,
.search-result,
.chat-card,
.message-bubble,
.current-user-strip,
.server-strip {
    border: 1px solid rgba(104, 61, 56, 0.08);
    border-radius: var(--radius-lg);
    background: rgba(255, 255, 255, 0.7);
}

.story-card {
    padding: 20px;
}

.story-card span,
.pill,
.chat-unread,
.message-role {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 0 12px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.story-card span {
    margin-bottom: 14px;
    color: var(--accent);
    background: rgba(140, 20, 29, 0.08);
}

.story-card h2 {
    margin: 0 0 10px;
    font-size: 1.34rem;
}

.auth-card {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.card-head h2 {
    font-size: clamp(2.1rem, 3vw, 3rem);
}

.field-label {
    display: block;
    font-size: 0.94rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.text-input,
.composer-input {
    width: 100%;
    min-height: 54px;
    padding: 0 18px;
    border: 1px solid rgba(104, 61, 56, 0.12);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.72);
    color: var(--text);
    outline: none;
    transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.text-input:focus,
.composer-input:focus {
    border-color: rgba(140, 20, 29, 0.28);
    box-shadow: 0 0 0 4px rgba(140, 20, 29, 0.08);
}

.server-row,
.search-form,
.sidebar-actions,
.conversation-controls {
    display: flex;
    gap: 12px;
}

.server-row .text-input,
.search-form .text-input {
    flex: 1;
}

.helper-text {
    margin: -6px 0 2px;
    font-size: 0.92rem;
}

.auth-tabs,
.method-switch {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.auth-tab,
.method-chip,
.icon-button {
    border: 0;
    cursor: pointer;
    transition: transform 160ms ease, background-color 160ms ease, color 160ms ease;
}

.auth-tab,
.method-chip {
    min-height: 50px;
    border-radius: 18px;
    color: rgba(33, 22, 21, 0.82);
    background: rgba(255, 255, 255, 0.72);
    font-size: 1rem;
    font-weight: 700;
}

.auth-tab:hover,
.method-chip:hover,
.icon-button:hover,
.chat-card:hover {
    transform: translateY(-1px);
}

.auth-tab.is-active,
.method-chip.is-active {
    color: #fff8f4;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
}

.auth-form {
    display: grid;
    gap: 12px;
}

.auth-error {
    min-height: 1.5em;
    margin: 0;
    color: var(--accent);
    font-weight: 700;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 52px;
    padding: 0 20px;
    border: 0;
    border-radius: 999px;
    font-weight: 800;
    cursor: pointer;
    transition: transform 160ms ease, box-shadow 160ms ease, background-color 160ms ease, color 160ms ease;
}

.button:hover,
.button:focus-visible {
    transform: translateY(-2px);
}

.button:disabled {
    cursor: not-allowed;
    opacity: 0.6;
    transform: none;
}

.button-primary {
    color: #fff8f4;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
    box-shadow: 0 18px 36px rgba(140, 20, 29, 0.22);
}

.button-secondary {
    color: var(--text);
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(104, 61, 56, 0.12);
}

.button-small {
    min-height: 42px;
    padding: 0 16px;
    border-radius: 16px;
}

.auth-submit {
    width: 100%;
    margin-top: 8px;
}

.sidebar {
    display: grid;
    gap: 18px;
}

.current-user-card {
    display: grid;
    gap: 18px;
}

.current-user-strip,
.server-strip {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
}

.avatar,
.chat-avatar,
.search-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    color: #fff8f4;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent-soft) 0%, var(--accent) 100%);
}

.avatar {
    width: 52px;
    height: 52px;
    border-radius: 18px;
}

.chat-avatar,
.search-avatar {
    width: 48px;
    height: 48px;
    border-radius: 16px;
}

.current-user-meta strong,
.chat-main strong,
.search-result strong,
.panel-head h2,
.conversation-meta h2,
.modal-head h2 {
    font-size: 1.32rem;
}

.current-user-meta strong,
.chat-main strong,
.search-result strong,
.panel-head h2,
.conversation-meta h2,
.modal-head h2,
.empty-state h2 {
    display: block;
    margin: 0;
    font-family: "Space Grotesk", "Avenir Next Condensed", sans-serif;
}

.current-user-meta p,
.server-strip p {
    margin: 4px 0 0;
}

.server-strip code {
    display: inline-block;
    margin-top: 4px;
    font-size: 0.86rem;
    color: var(--muted-soft);
    word-break: break-all;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.pill {
    color: var(--accent);
    background: rgba(140, 20, 29, 0.08);
}

.pill-dark {
    color: #fff8f4;
    background: var(--panel-dark);
}

.chat-list,
.messages,
.search-results {
    display: grid;
    gap: 12px;
}

.chat-card {
    width: 100%;
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr) auto;
    gap: 14px;
    align-items: center;
    padding: 14px;
    text-align: left;
    cursor: pointer;
}

.chat-card.is-active {
    border-color: rgba(140, 20, 29, 0.2);
    box-shadow: 0 16px 28px rgba(88, 44, 40, 0.08);
    transform: translateX(4px);
}

.chat-main {
    min-width: 0;
}

.chat-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 4px;
}

.chat-time {
    flex: 0 0 auto;
    font-size: 0.86rem;
    color: var(--muted-soft);
}

.chat-preview {
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-unread {
    color: #fff8f4;
    background: var(--accent);
}

.conversation-panel {
    min-height: calc(100vh - 150px);
    display: flex;
    flex-direction: column;
}

.empty-state,
.active-chat-shell {
    flex: 1;
}

.empty-state {
    display: flex;
    flex-direction: column;
    justify-content: center;
    max-width: 620px;
    margin: 0 auto;
    text-align: center;
}

.active-chat-shell {
    display: flex;
    flex-direction: column;
    gap: 18px;
    min-height: 0;
}

.conversation-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--line);
}

.conversation-meta p,
.conversation-meta h2 {
    margin: 0;
}

.conversation-subtitle {
    margin-top: 6px;
}

.messages {
    flex: 1;
    min-height: 420px;
    align-content: flex-start;
    overflow: auto;
    padding-right: 8px;
}

.message-row {
    display: flex;
}

.message-row.self {
    justify-content: flex-end;
}

.message-bubble {
    max-width: min(72%, 620px);
    padding: 16px 18px;
    box-shadow: 0 14px 28px rgba(74, 37, 34, 0.07);
}

.message-row.self .message-bubble {
    color: #fff8f4;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-soft) 100%);
}

.message-row.self .message-body,
.message-row.self .message-footer,
.message-row.self .message-role {
    color: inherit;
}

.message-role {
    margin-bottom: 10px;
    color: var(--accent);
    background: rgba(140, 20, 29, 0.08);
}

.message-row.self .message-role {
    background: rgba(255, 255, 255, 0.16);
}

.message-body {
    margin: 0;
    line-height: 1.68;
    white-space: pre-wrap;
    word-break: break-word;
}

.message-footer {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-top: 10px;
    font-size: 0.82rem;
    color: var(--muted-soft);
}

.composer {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.composer-input {
    resize: none;
    min-height: 58px;
    max-height: 200px;
    padding: 16px 18px;
}

.composer-send {
    align-self: flex-end;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 30;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(23, 17, 16, 0.34);
    backdrop-filter: blur(10px);
}

.modal-panel {
    position: relative;
    z-index: 1;
    width: min(calc(100% - 24px), 760px);
    margin: 60px auto 24px;
    padding: 24px;
}

.modal-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.icon-button {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.72);
    color: var(--text);
    font-size: 1.6rem;
}

.search-result {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px;
}

.search-result-main {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.search-result-copy {
    min-width: 0;
}

.search-result p {
    margin: 4px 0 0;
}

.empty-chat-note {
    padding: 16px;
    text-align: center;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%);
    z-index: 40;
    min-width: min(90vw, 380px);
    padding: 14px 18px;
    border-radius: 18px;
    color: #fff8f4;
    background: rgba(34, 28, 29, 0.94);
    box-shadow: 0 20px 34px rgba(24, 18, 18, 0.24);
}

.is-hidden {
    display: none !important;
}

@media (max-width: 1180px) {
    .auth-layout,
    .chat-screen {
        grid-template-columns: 1fr;
    }

    .chat-screen {
        gap: 14px;
    }

    .conversation-panel {
        min-height: auto;
    }

    .story-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 780px) {
    .page-shell {
        width: min(calc(100% - 18px), var(--max-width));
    }

    .site-header {
        position: static;
        flex-direction: column;
        align-items: flex-start;
        border-radius: 28px;
    }

    .auth-story,
    .auth-card,
    .sidebar-card,
    .conversation-panel,
    .modal-panel {
        padding: 20px;
    }

    .auth-story h1 {
        font-size: clamp(2.5rem, 12vw, 4rem);
    }

    .server-row,
    .search-form,
    .sidebar-actions,
    .conversation-controls,
    .conversation-header,
    .search-result {
        flex-direction: column;
        align-items: stretch;
    }

    .chat-card {
        grid-template-columns: 44px minmax(0, 1fr) auto;
    }

    .chat-avatar,
    .search-avatar {
        width: 44px;
        height: 44px;
        border-radius: 14px;
    }

    .message-bubble {
        max-width: 88%;
    }

    .composer {
        grid-template-columns: 1fr;
    }

    .modal-panel {
        margin-top: 18px;
    }
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
}
