/* =========================================================
   TIER 1 — RAW PALETTE
   Named by appearance. Theme-agnostic. Components never use these directly.
   ========================================================= */
:root {
    /* Cream ramp (warm paper) — lightest to darkest */
    --cream-0:   #F8F1E3;  /* warm light paper, not pure white */
    --cream-100: #EFE4CF;  /* main warm surface */
    --cream-200: #E3D4B8;  /* page background / soft rows */
    --cream-300: #D2C2A5;  /* hairline borders */
    --cream-400: #B8A88C;  /* stronger edges / dividers */

    /* Green ramp (from #36513F) */
    --green-300: #8FB08C;  /* lifted sage-green, for dark-theme actions */
    --green-500: #4A6B53;  /* mid */
    --green-700: #36513F;  /* logo green — primary action */
    --green-900: #1E2622;  /* near-black warm green, dark-theme bg */

    /* Sage ramp (from #A7B8A6) */
    --sage-200: #C2CFC1;
    --sage-400: #A7B8A6;   /* logo sage */
    --sage-600: #7E9180;

    /* Slate ramp (from #394754) — text/ink */
    --slate-500: #5F675C;  /* muted warm gray-green text */
    --slate-700: #3F4C4A;  /* logo slate */
    --slate-900: #2D3938;  /* primary warm ink */

    /* Dark surfaces (warm green-gray, NOT black) */
    --forest-900: #1E2622; /* dark bg base */
    --forest-800: #262E29; /* lifted surface */
    --forest-700: #39443C; /* dark borders */

    /* Error (muted clay-red — survives a Japandi palette) */
    --clay-500: #9B4D4D;   /* the red you already used for #recipientError */
    --clay-300: #C77B7B;   /* lighter, for dark theme */
}

/* =========================================================
   TIER 2 — SEMANTIC ALIASES
   Named by role. This is what your components actually use.
   Each one points at a tier-1 value.
   ========================================================= */
:root {
    --color-bg:          var(--cream-200);
    --color-surface:     var(--cream-0);   /* light paper surfaces */
    --color-app-surface: var(--cream-100);
    --color-panel:       var(--cream-100);
    --color-canvas:      var(--cream-0);
    --color-input-bg:    var(--cream-0);
    --color-soft-surface: var(--cream-200);
    --color-border:      var(--cream-300);
    --color-text:        var(--slate-900);
    --color-text-muted:  var(--slate-500);
    --color-action:      var(--green-700); /* button fill */
    --color-on-action:   var(--cream-100); /* text on the button */
    --color-link:        var(--green-700);
    --color-accent:      var(--sage-400);  /* focus rings, avatars */
    --color-error:       var(--clay-500);
    --color-shadow: rgb(from var(--slate-900) r g b / 0.15);
    --color-focus-shadow: rgb(from var(--color-accent) r g b / 0.25);
    --color-overlay: rgb(from var(--slate-900) r g b / 0.35);
}

[data-theme="dark"] {
    --color-bg:          var(--forest-900);
    --color-surface:     var(--forest-800);
    --color-app-surface: var(--forest-800);
    --color-panel:       var(--forest-800);
    --color-canvas:      var(--forest-900);
    --color-input-bg:    var(--forest-800);
    --color-soft-surface: var(--forest-700);
    --color-border:      var(--forest-700);
    --color-text:        var(--cream-100);
    --color-text-muted:  var(--sage-600);
    --color-action:      var(--green-300); /* lighter green reads better on dark */
    --color-on-action:   var(--forest-900);
    --color-link:        var(--green-300);
    --color-accent:      var(--sage-400);
    --color-error:       var(--clay-300);
}

/* =========================================================
   1. Reset / Base
   ========================================================= */

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    min-height: 100%;
}

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

/* =========================================================
   2. Utilities
   ========================================================= */

.hidden {
    display: none !important;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* =========================================================
   3. Shared Form Elements
   ========================================================= */

input {
    font: inherit;
    outline: none;
}

button {
    font: inherit;
    border: none;
    cursor: pointer;
}

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

/* =========================================================
   4. Auth Pages
   ========================================================= */

#username-page,
#register-page {
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 24px;
    position: relative;
    overflow: hidden;
}

.auth-form {
    width: 100%;
    max-width: 320px;
    margin: 0 auto;
}

.auth-card {
    width: min(1100px, 92vw);
    min-height: 620px;
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    overflow: hidden;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 24px;
    box-shadow: 0 20px 50px var(--color-shadow);
}

.auth-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 64px;
    transform: translateY(-12px)
}

.auth-content {
    width: 100%;
    max-width: 390px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.auth-logo {
    width: 210px;
    height: auto;
}

.auth-visual {
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: var(--cream-100);
}

.auth-feather {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    opacity: 0.8;
}

.auth-divider {
    width: 44px;
    height: 1px;
    background: var(--cream-400);
    margin: 0 auto 22px;
}

.auth-subtitle {
    margin: 0 0 28px;
    color: var(--color-text-muted);
}

.form-group {
    margin-bottom: 16px;
}

.form-control {
    width: 100%;
    min-height: 40px;
    padding: 10px 14px;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    background: var(--color-input-bg);
    font-size: 15px;
}

.form-control:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-focus-shadow);
}

.auth-submit {
    width: 100%;
    min-height: 40px;
    padding: 10px 14px;
    border-radius: 12px;
    background: var(--color-action);
    color: var(--color-on-action);
    font-weight: 600;
}

#loginError,
#registerError {
    color: var(--color-error);
    font-size: 15px;
    min-height: 25px;
    margin-top: 4px;
    margin-bottom: 6px;
}

#goToRegister,
#goToLogin {
    background: transparent;
    border: none;
    padding: 0;
    color: var(--color-link);
    font-weight: 600;
}

#goToRegister:hover,
#goToLogin:hover {
   opacity: 0.8;
}

#goToRegister:focus-visible,
#goToLogin:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 3px;
}


/* =========================================================
   5. Main Chat Layout
   ========================================================= */

#chat-page {
    height: 100vh;
    display: flex;
    background: var(--color-app-surface);
}

.app-shell {
    display: flex;
    width: 100%;
    height: 100vh;
    background: var(--color-app-surface);
    overflow: hidden;
}


/* =========================================================
   6. Sidebar
   ========================================================= */

.sidebar {
    width: 320px;
    height: 100vh;
    padding: 24px;
    border-right: 1px solid var(--color-border);
    background: var(--color-panel);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.brand {
    margin-bottom: 28px;
    text-align: center;
}

.brand-logo {
    width: 180px;
    height: auto;
}

.brand p {
    margin: 0;
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    font-weight: 500;
    color: var(--color-text-muted);
}

#recipientUsername {
    width: 100%;
    padding: 12px 14px;
    margin-bottom: 12px;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    background: var(--color-input-bg);
    font-size: 15px;
}

#recipientUsername:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-focus-shadow);
}

#startConversationButton {
    width: 100%;
    padding: 10px 12px;
    margin-bottom: 24px;
    border-radius: 12px;
    background: var(--color-soft-surface);
    color: var(--color-link);
    font-weight: 600;
}

#startConversationButton:hover {
    background: var(--sage-200);
}

#recipientError {
    margin-bottom: 16px;
    color: var(--color-error);
    font-size: 14px;
}

.conversation-section-label {
    margin-bottom: 10px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--color-text-muted);
}

#conversationList {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
    overflow-y: auto;
}

#conversationList button {
    width: 100%;
    padding: 10px 14px;
    border-radius: 14px;
    background: transparent;
    color: var(--color-text);
    text-align: left;
    transition: background 120ms ease, box-shadow 120ms ease;
}

#conversationList button:not(.conversation-item--active):hover {
    background: var(--color-soft-surface);
}

#conversationList button:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

#conversationList button.conversation-item--active {
    background: var(--color-soft-surface);
}

#conversationList button.conversation-item--active .conversation-avatar {
    background: var(--color-action);
    color: var(--color-on-action);
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: 12px;
}

.conversation-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--color-accent);
    color: var(--color-on-action);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 700;
    flex-shrink: 0;
}

.conversation-text {
    min-width: 0;
    flex: 1;
}

.conversation-name {
    min-width: 0;
    flex: 1;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conversation-preview {
    margin-top: 2px;
    font-size: 0.82rem;
    line-height: 1.25;
    color: var(--color-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#conversationList button.conversation-item--active .conversation-preview {
    color: var(--color-text-muted);
}

.conversation-top-line {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
}

.conversation-lastMessageTime {
    margin-left: auto;
    flex-shrink: 0;
    color: var(--color-text-muted);
    font-size: 0.7rem;
    line-height: 1.2;
    font-weight: 400;
    opacity: 0.8;
    letter-spacing: -0.02em;
}

.conversation-attention-dot {
    width: 0.45rem;
    height: 0.45rem;
    border-radius: 999px;
    background-color: var(--color-action);
    flex-shrink: 0;
    opacity: 0.85;
}

.conversation-item--needs-attention .conversation-preview {
    color: var(--color-text);
}


/* Account menu */

.account-menu {
    position: relative;
    margin-top: auto;
    padding-top: 18px;
    border-top: 1px solid var(--color-border);
}

.account-menu__trigger {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px;
    border-radius: 14px;
    background: transparent;
    color: var(--color-text);
    text-align: left;
}

.account-menu__trigger:hover {
    background: var(--color-soft-surface);
}

.account-menu__trigger:focus-visible,
.account-dropdown button:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

.account-avatar {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--color-action);
    color: var(--color-on-action);
    font-size: 0.9rem;
    font-weight: 700;
}

.account-avatar--large {
    width: 44px;
    height: 44px;
    font-size: 1rem;
}

.account-menu__trigger-text {
    min-width: 0;
    display: flex;
    flex: 1;
    flex-direction: column;
}

.account-display-name {
    overflow: hidden;
    color: var(--color-text);
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.1;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.account-username {
    overflow: hidden;
    color: var(--color-text-muted);
    font-size: 0.78rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.account-menu__chevron {
    color: var(--color-text-muted);
    font-size: 0.85rem;
    transition: transform 140ms ease;
}


/* Dropdown panel */

.account-dropdown {
    position: absolute;
    bottom: calc(100% + 10px);
    left: 0;
    z-index: 20;
    width: 272px;
    padding: 10px;
    border: 1px solid var(--color-border);
    border-radius: 16px;
    background: var(--color-surface);
    box-shadow: 0 12px 30px var(--color-shadow);
}

.account-dropdown__profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px;
}

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

.account-dropdown__name-row {
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.account-dropdown__edit {
    width: auto;
    height: auto;
    padding: 0;
    background: transparent;
    color: var(--color-text-muted);
    font-size: 0.75rem;
    font-weight: 500;
}

.account-dropdown__edit:hover {
    background: transparent;
    color: var(--color-text);
}

.account-dropdown__divider {
    height: 1px;
    margin: 8px 4px;
    background: var(--color-border);
}

.account-dropdown__action {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: 10px;
    background: transparent;
    color: var(--color-text);
    text-align: left;
}

.account-dropdown__action:hover {
    background: var(--color-soft-surface);
}

.account-dropdown__action--danger {
    color: var(--color-error);
}

#displayNameForm {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    width: 100%;
}

#displayNameInput {
    width: 100%;
    min-width: 0;
}

.display-name-actions {
    display: flex;
    gap: 6px;
    margin-top: 6px;
}

.display-name-actions button {
    padding: 6px 8px;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 600;
}

#displayNameSubmitButton {
    background: var(--color-action);
    color: var(--color-on-action);
}

#cancelDisplayNameButton {
    background: var(--color-soft-surface);
    color: var(--color-text-muted);
}

#displayNameError:empty {
    display: none;
}

#displayNameInput:focus {
    outline: 2px solid var(--color-accent);
    outline-offset: 1px;
}

#displayNameView {
    display: inline-flex;
    align-items: baseline;
    gap: 8px;
}


/* Account settings panel */

.password-modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: var(--color-overlay);
}

.password-panel {
    width: 100%;
    max-width: 380px;
    padding: 24px;
    border: 1px solid var(--color-border);
    border-radius: 16px;
    background: var(--color-surface);
    box-shadow: 0 16px 40px var(--color-shadow);
}

.password-panel h2 {
    margin: 0 0 20px;
    font-size: 1.25rem;
}

#changePasswordForm {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#changePasswordForm label {
    margin-top: 6px;
    color: var(--color-text);
    font-size: 0.85rem;
    font-weight: 600;
}

#changePasswordForm input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    background: var(--color-input-bg);
    color: var(--color-text);
}

#changePasswordForm input:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-focus-shadow);
}

#passwordError {
    min-height: 22px;
    color: var(--color-error);
    font-size: 0.85rem;
}

.password-panel__actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 6px;
}

.password-panel__actions button {
    padding: 9px 14px;
    border-radius: 10px;
    font-weight: 600;
}

.password-panel__cancel {
    background: var(--color-soft-surface);
    color: var(--color-text);
}

.password-panel__save {
    background: var(--color-action);
    color: var(--color-on-action);
}

.settings-modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: var(--color-overlay);
}

.settings-panel {
    width: 100%;
    max-width: 400px;
    padding: 22px;
    border: 1px solid var(--color-border);
    border-radius: 16px;
    background: var(--color-surface);
    box-shadow: 0 16px 40px var(--color-shadow);
}

.settings-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 22px;
}

.settings-panel__header h2 {
    margin: 0;
    font-size: 1.25rem;
}

#closeSettingsButton {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: transparent;
    color: var(--color-text-muted);
    font-size: 1.4rem;
}

#closeSettingsButton:hover {
    background: var(--color-soft-surface);
    color: var(--color-text);
}

.settings-section {
    margin-top: 18px;
}

.settings-section h3 {
    margin: 0 0 8px;
    color: var(--color-text-muted);
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.settings-option {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    border-radius: 10px;
    background: transparent;
    color: var(--color-text);
    text-align: left;
}

.settings-option:hover {
    background: var(--color-soft-surface);
}

.settings-option span:first-child {
    display: flex;
    flex-direction: column;
}

.settings-option strong {
    font-size: 0.9rem;
}

.settings-option small {
    color: var(--color-text-muted);
    font-size: 0.78rem;
}


/* User search form */

.user-search-form {
    margin-bottom: 8px;
}

.user-search-label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--color-text-muted);
}

.user-search-input-row {
    display: flex;
    gap: 8px;
}

.user-search-input {
    min-width: 0;
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    background: var(--color-input-bg);
    color: var(--color-text);
    font-size: 0.875rem;
}

.user-search-input:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-focus-shadow);
}

.user-search-error {
    min-height: 20px;
    margin-bottom: 8px;
    color: var(--color-error);
    font-size: 0.8rem;
}

.user-search-result {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 12px;
    margin-bottom: 18px;
    border: 1px solid var(--color-border);
    border-radius: 14px;
    background: var(--color-surface);
}

.user-search-identity {
    min-width: 0;
    flex: 1;
}

.user-search-display-name {
    overflow: hidden;
    font-size: 0.92rem;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-search-username {
    overflow: hidden;
    color: var(--color-text-muted);
    font-size: 0.78rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-search-action {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--color-text-muted);
    font-size: 0.8rem;
}

.user-search-action-button {
    padding: 7px 10px;
    border-radius: 10px;
    background: var(--color-action);
    color: var(--color-on-action);
    font-size: 0.8rem;
    font-weight: 600;
}

.user-search-action-button--secondary {
    background: var(--color-soft-surface);
    color: var(--color-text);
}

.user-search-action-button:focus-visible,
.user-search-submit:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}


/* Sidebar tabs */

.sidebar-tabs {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    margin-bottom: 12px;
    border-bottom: 1px solid var(--color-border);
}

.sidebar-tab {
    position: relative;
    width: 100%;
    padding: 8px 0;
    background: transparent;
    color: var(--color-text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;

}

.sidebar-tab--active {
    color: var(--color-text);
}

.sidebar-tab--active::after {
    content: "";
    position: absolute;
    right: 0;
    bottom: -1px;
    left: 0;
    height: 2px;
    background: var(--color-action);
}

.sidebar-tab:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 3px;
}


/* Connection sections */

.connections-section-label {
    margin: 12px 0 8px;
    color: var(--color-text-muted);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

#incomingConnectionsList,
#acceptedConnectionsList {
    display: flex;
    flex-direction: column;
    gap: 6px;
}


/* Connection rows */

.connection-item {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    padding: 10px 14px;
    border-radius: 12px;
}

.connection-item:hover {
    background: var(--color-soft-surface);
}

.connection-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--color-accent);
    color: var(--color-on-action);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 700;
    flex-shrink: 0;
}

.connection-identity {
    min-width: 0;
    flex: 1;
}

.connection-display-name {
    min-width: 0;
    flex: 1;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.connection-username {
    overflow: hidden;
    color: var(--color-text-muted);
    font-size: 0.78rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}


/* Request actions */

.connection-actions {
    display: flex;
    gap: 5px;
    flex-shrink: 0;
}

.connection-action {
    padding: 6px 8px;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 600;
}

.connection-action--accept {
    background: var(--color-action);
    color: var(--color-on-action);
}

.connection-action--reject {
    background: var(--color-soft-surface);
    color: var(--color-text-muted);
}

.connection-action:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

.connections-empty-state {
    padding: 12px 4px;
    color: var(--color-text-muted);
    font-size: 0.82rem;
}


/* Connections to messages button */

.connection-controls {
    display: flex;
    align-items: center;
    gap: 1px;
    flex-shrink: 0;
    transform: translateX(4px);
}

.connection-message-button,
.connection-options-button {
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--color-text-muted);
}

.connection-message-button:hover,
.connection-options-button:hover {
    background: var(--color-soft-surface);
    color: var(--color-text);
}

.connection-message-button svg,
.connection-options-button svg {
    width: 18px;
    height: 18px;
}


/* =========================================================
   7. Chat Panel
   ========================================================= */

.chat-panel {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 24px 28px 20px;
    background: var(--color-canvas);
}


.chat-header {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    width: 100%;
    padding-bottom: 18px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--color-border);
}

.chat-header-avatar {
    width: 2.4rem;
    height: 2.4rem;
    border-radius: 999px;
    display: grid;
    place-items: center;
    background: var(--color-soft-surface);
    color: var(--color-text);
    font-weight: 600;
    flex-shrink: 0;
    overflow: hidden;
}

.chat-header-avatar:has(img) {
    background: transparent;
    border-radius: 0;
}

.chat-header-avatar img {
    width: 2rem;
    height: 2rem;
    object-fit: contain;
    display: block;
}

.chat-header-text {
    display: flex;
    flex: 1;
    flex-direction: column;
    justify-content: center;
    gap: 0.15rem;
    min-height: 3.7rem;
}

.chat-header-text h2 {
    margin: 0;
}


/* =========================================================
   8. Message Area
   ========================================================= */

#messageArea {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    list-style: none;
    margin: 0;
    padding: 22px 20px;
    overflow-y: auto;
}

.chat-message {
    max-width: 60%;
    padding: 10px 14px;
    border-radius: 16px;
    overflow-wrap: anywhere;
}

.chat-message--incoming {
    align-self: flex-start;
    background: var(--color-soft-surface);
}

.chat-message--outgoing {
    align-self: flex-end;
    background: var(--color-action);
}

.chat-message p {
    margin: 0;
    line-height: 1.45;
    color: var(--color-text);
}

.chat-message--outgoing p {
    color: var(--color-on-action);
}

.message-time {
    display: block;
    margin-top: 4px;
    font-size: 0.72rem;
    line-height: 1;
    color: var(--color-text-muted);
    opacity: 0.8;
}

.chat-message--outgoing .message-time {
    color: var(--color-on-action);
    opacity: 0.75;
}

.event-message {
    text-align: center;
    color: var(--color-text-muted);
    font-size: 14px;
}

.event-message p {
    margin: 0;
}

.empty-chat-state {
    height: 100%;
    max-width: 480px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--color-text-muted);
    text-align: center;
}

.empty-chat-icon {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 18px;
    border-radius: 50%;
    background: var(--color-panel);
    border: 1px solid var(--color-border);
    color: var(--green-700);
}

.empty-chat-icon svg {
    width: 20px;
    height: 20px;
}

.empty-chat-state h3 {
    margin: 0 0 8px;
    font-size: 1.2rem;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: -0.01em;
    color: var(--color-text);
}

.empty-chat-state p {
    margin: 0;
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--color-text-muted);
}

#conversationError {
    margin: 0 0 0.75rem;
    padding: 0.25rem 0.1rem;
    color: var(--color-error);
    font-size: 0.9rem;
    line-height: 1.4;
}

#conversationError:empty {
    display: none;
}

#conversationError.hidden {
    display: none;
}
/* =========================================================
   9. Message Form
   ========================================================= */

#messageForm {
    margin-top: 12px;
}

#messageForm .form-group {
    margin-bottom: 0;
}

.input-group {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border: 1px solid var(--color-border);
    border-radius: 18px;
    background: var(--color-input-bg);
}

.input-group:focus-within {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-focus-shadow);
}

#messageInput {
    flex: 1;
    min-height: 40px;
    padding: 8px 10px;
    border: none;
    border-radius: 12px;
    background: transparent;
    font-size: 0.875rem;
}

#messageInput:focus {
    box-shadow: none;
}

#messageForm button {
    min-height: 40px;
    padding: 0 18px;
    border-radius: 12px;
    background: var(--color-action);
    color: var(--color-on-action);
    font-weight: 600;
    font-size: 0.875rem;
}

#messageInput:disabled {
    color: var(--color-text-muted);
    cursor: not-allowed;
}

.input-group:has(#messageInput:disabled) {
    opacity: 0.75;
}

/* =========================================================
   10. Connection Status
   ========================================================= */

/* =========================================================
   11. Responsive
   ========================================================= */

@media screen and (max-width: 800px) {
    .app-shell {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }

    .auth-card {
        width: 100%;
        min-height: 620px;
        grid-template-columns: 1fr;
    }

    .auth-panel {
        padding: 48px 28px;
    }

    .auth-visual {
        display: none;
    }

    .sidebar {
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
    }
}

@media screen and (max-width: 480px) {
    .app-shell {
        min-height: 100vh;
    }


    .chat-panel {
        padding: 16px;
    }

    .input-group {
        flex-direction: column;
    }

    #messageForm button {
        width: 100%;
    }
}
