/**
 * Chat-specific layout. Everything else — buttons, forms, alerts, the header —
 * comes from style.css, which is shared verbatim with the Tempo portal, so the
 * two products stay visually identical without a shared build step.
 */

:root {
    --chat-sidebar-width: 272px;
    --chat-members-width: 240px;
}

/* The chat owns the viewport: the page itself never scrolls, only the message
   list does. Without this the composer drifts off the bottom on mobile. */
body.chat-body {
    overflow: hidden;
}

body.chat-body .site-main {
    min-height: 0;
}

/* Login and the forced password change run without the site header, so the
   footer needs to be pushed down rather than following the short card. */
body.auth-body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

body.auth-body .site-main {
    flex: 1;
    display: flex;
    align-items: center;
    min-height: 0;
}

body.auth-body .site-main > .container {
    width: 100%;
}

/* The login card carries the full lockup rather than the bare mark, so it needs
   room for the wordmark instead of the shared 48px square. */
.auth-logo .auth-logo-full {
    width: 148px;
    height: auto;
    margin: 0 auto 16px;
}

.chat-shell {
    display: grid;
    grid-template-columns: var(--chat-sidebar-width) minmax(0, 1fr);
    height: calc(100vh - var(--header-height));
    background: var(--color-bg);
}

.chat-shell.with-members {
    grid-template-columns: var(--chat-sidebar-width) minmax(0, 1fr) var(--chat-members-width);
}

/* ── Sidebar ────────────────────────────────────────────── */

.chat-sidebar {
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--color-section-alt);
    border-right: 1px solid var(--color-border);
}

.chat-sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 16px 16px 10px;
}

.chat-sidebar-head h2 {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--color-text-light);
}

.chat-new-space {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    background: #fff;
    color: var(--color-text);
    text-decoration: none;
    flex-shrink: 0;
    transition: background 0.15s, border-color 0.15s;
}

.chat-new-space:hover {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: #fff;
}

.chat-space-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    padding: 0 8px 16px;
}

.chat-space-group {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--color-text-light);
    padding: 14px 8px 6px;
}

.chat-space-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    color: var(--color-text);
    text-decoration: none;
    font-size: 14px;
    line-height: 1.35;
    transition: background 0.12s;
}

.chat-space-link:hover {
    background: rgba(17, 17, 17, 0.06);
    text-decoration: none;
    color: var(--color-text);
}

.chat-space-link.active {
    background: var(--color-accent);
    color: #fff;
    font-weight: 600;
}

.chat-space-link.active .chat-space-icon,
.chat-space-link.active .chat-space-lock {
    color: rgba(255, 255, 255, 0.75);
}

.chat-space-icon {
    flex-shrink: 0;
    color: var(--color-text-light);
    display: inline-flex;
}

.chat-space-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-space-lock {
    flex-shrink: 0;
    color: var(--color-text-light);
    display: inline-flex;
}

/* Unread count doubles as the "something happened" cue, so it keeps the one
   brand yellow rather than inventing another accent. */
.chat-unread {
    flex-shrink: 0;
    min-width: 20px;
    padding: 0 6px;
    height: 19px;
    border-radius: 10px;
    background: var(--color-hero-accent);
    color: #111;
    font-size: 11px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.chat-space-link.active .chat-unread {
    background: #fff;
    color: #111;
}

.chat-sidebar-foot {
    border-top: 1px solid var(--color-border);
    padding: 10px 12px;
}

.chat-sidebar-foot a {
    display: block;
    font-size: 13px;
    color: var(--color-text-light);
    text-decoration: none;
    padding: 5px 6px;
    border-radius: var(--radius-sm);
}

.chat-sidebar-foot a:hover {
    background: rgba(17, 17, 17, 0.06);
    color: var(--color-text);
    text-decoration: none;
}

/* ── Room ───────────────────────────────────────────────── */

.chat-room {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

.chat-room-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg);
    flex-shrink: 0;
}

.chat-room-title {
    min-width: 0;
    flex: 1;
}

.chat-room-title h1 {
    font-size: 17px;
    font-weight: 700;
    line-height: 1.3;
    display: flex;
    align-items: center;
    gap: 7px;
}

.chat-room-title p {
    font-size: 12.5px;
    color: var(--color-text-light);
    line-height: 1.4;
    margin-top: 1px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-room-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.chat-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.02em;
    background: var(--color-section-alt);
    border: 1px solid var(--color-border);
    color: var(--color-text-light);
    white-space: nowrap;
}

.chat-tag-private {
    background: var(--color-warning-bg);
    border-color: var(--color-warning-border);
    color: var(--color-warning);
}

.chat-tag-readonly {
    background: var(--color-error-bg);
    border-color: var(--color-error-border);
    color: var(--color-error);
}

/* ── Messages ───────────────────────────────────────────── */

.chat-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-anchor: none;
    padding: 20px 20px 8px;
}

.chat-stream {
    max-width: 820px;
    margin: 0 auto;
}

.day-sep {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 18px 0 12px;
}

.day-sep::before,
.day-sep::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--color-border);
}

.day-sep span {
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--color-text-light);
    text-transform: lowercase;
}

.msg {
    display: flex;
    gap: 11px;
    padding: 5px 8px;
    border-radius: var(--radius-sm);
    position: relative;
}

.msg:hover {
    background: rgba(17, 17, 17, 0.025);
}

.msg + .msg {
    margin-top: 2px;
}

.msg-avatar {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.02em;
    user-select: none;
}

.msg-main {
    flex: 1;
    min-width: 0;
}

.msg-head {
    display: flex;
    align-items: baseline;
    gap: 8px;
    line-height: 1.3;
    margin-bottom: 1px;
}

.msg-author {
    font-size: 14px;
    font-weight: 700;
}

.msg-role {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--color-text-light);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 0 4px;
}

.msg-time {
    font-size: 11.5px;
    color: var(--color-text-light);
}

.msg-text {
    font-size: 14.5px;
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.msg-text a {
    text-decoration: underline;
    text-underline-offset: 2px;
}

.msg-deleted {
    font-style: italic;
    color: var(--color-text-light);
    font-size: 13.5px;
}

/* A run of messages from one person reads as one thought, so repeats of the
   avatar and name are dropped and the timestamp only appears on hover. */
.msg.msg-cont {
    margin-top: 0;
}

.msg.msg-cont .msg-avatar {
    background: none !important;
    color: transparent;
}

.msg.msg-cont .msg-hovertime {
    position: absolute;
    left: 8px;
    top: 7px;
    width: 36px;
    text-align: center;
    font-size: 10.5px;
    color: var(--color-text-light);
    opacity: 0;
    transition: opacity 0.1s;
}

.msg.msg-cont:hover .msg-hovertime {
    opacity: 1;
}

.msg-delete {
    position: absolute;
    right: 8px;
    top: 5px;
    border: 1px solid var(--color-border);
    background: #fff;
    color: var(--color-text-light);
    border-radius: var(--radius-sm);
    padding: 2px 7px;
    font-size: 11px;
    font-family: var(--font-family);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.1s, color 0.15s, border-color 0.15s;
}

.msg:hover .msg-delete {
    opacity: 1;
}

.msg-delete:hover {
    color: var(--color-error);
    border-color: var(--color-error);
}

.chat-empty {
    text-align: center;
    padding: 56px 20px;
    color: var(--color-text-light);
}

.chat-empty h3 {
    font-size: 16px;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 6px;
}

.chat-empty p {
    font-size: 14px;
}

/* ── Composer ───────────────────────────────────────────── */

.chat-composer {
    flex-shrink: 0;
    padding: 10px 20px 18px;
    background: var(--color-bg);
}

.chat-composer-inner {
    max-width: 820px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 8px 8px 8px 14px;
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.chat-composer-inner:focus-within {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.08);
}

.chat-composer textarea {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-family: var(--font-family);
    font-size: 14.5px;
    line-height: 1.55;
    max-height: 180px;
    padding: 5px 0;
    background: transparent;
    color: var(--color-text);
}

.chat-send {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 34px;
    padding: 0 15px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--color-accent);
    color: #fff;
    font-family: var(--font-family);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s;
}

.chat-send:hover:not(:disabled) {
    background: var(--color-accent-hover);
}

.chat-send:disabled {
    opacity: 0.4;
    cursor: default;
}

.chat-composer-hint {
    max-width: 820px;
    margin: 5px auto 0;
    font-size: 11.5px;
    color: var(--color-text-light);
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.chat-composer-error {
    color: var(--color-error);
    font-weight: 600;
}

.chat-locked {
    max-width: 820px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 13px 16px;
    border: 1px dashed var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-section-alt);
    font-size: 13.5px;
    color: var(--color-text-light);
}

.chat-locked strong {
    color: var(--color-text);
    font-weight: 600;
}

/* ── Members panel ──────────────────────────────────────── */

.chat-members {
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-left: 1px solid var(--color-border);
    background: var(--color-section-alt);
}

.chat-members-head {
    padding: 16px 16px 8px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--color-text-light);
}

.chat-members-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    padding: 0 10px 16px;
}

.chat-member {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 6px;
    border-radius: var(--radius-sm);
}

.chat-member-avatar {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: #fff;
}

.chat-member-name {
    flex: 1;
    min-width: 0;
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-member-role {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--color-text-light);
}

/* ── Space directory ────────────────────────────────────── */

.space-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.space-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 18px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: #fff;
    text-decoration: none;
    color: var(--color-text);
    transition: border-color 0.15s, box-shadow 0.15s;
}

a.space-card:hover {
    border-color: var(--color-accent);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    text-decoration: none;
    color: var(--color-text);
}

.space-card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.space-card h3 {
    font-size: 15.5px;
    font-weight: 700;
    line-height: 1.35;
}

.space-card p {
    font-size: 13.5px;
    color: var(--color-text-light);
    line-height: 1.55;
    flex: 1;
}

.space-card-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 12px;
    color: var(--color-text-light);
    padding-top: 4px;
    border-top: 1px solid var(--color-border);
}

.space-card-meta span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

/* ── Member picker (space settings) ─────────────────────── */

.member-picker {
    position: relative;
}

.member-results {
    position: absolute;
    z-index: 30;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    max-height: 240px;
    overflow-y: auto;
    display: none;
}

.member-results.open {
    display: block;
}

.member-result {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: none;
    font-family: var(--font-family);
    font-size: 13.5px;
    text-align: left;
    cursor: pointer;
}

.member-result:hover {
    background: var(--color-section-alt);
}

.member-result-empty {
    padding: 10px 12px;
    font-size: 13px;
    color: var(--color-text-light);
}

.member-rows {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.member-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    font-size: 13.5px;
}

.member-row + .member-row {
    border-top: 1px solid var(--color-border);
}

.member-row-name {
    flex: 1;
    min-width: 0;
}

.member-row-name small {
    display: block;
    font-size: 11.5px;
    color: var(--color-text-light);
}

/* ── Off-canvas sidebar on small screens ────────────────── */

.chat-drawer-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--color-text);
    cursor: pointer;
}

.chat-scrim {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 40;
}

.chat-scrim.open {
    display: block;
}

@media (max-width: 900px) {
    .chat-shell.with-members {
        grid-template-columns: var(--chat-sidebar-width) minmax(0, 1fr);
    }

    .chat-members {
        display: none;
    }
}

@media (max-width: 768px) {
    .chat-shell,
    .chat-shell.with-members {
        grid-template-columns: minmax(0, 1fr);
    }

    .chat-drawer-toggle {
        display: inline-flex;
    }

    .chat-sidebar {
        position: fixed;
        z-index: 50;
        top: var(--header-height);
        bottom: 0;
        left: 0;
        width: var(--chat-sidebar-width);
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }

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

    .chat-scroll {
        padding: 14px 12px 6px;
    }

    .chat-composer {
        padding: 8px 12px 14px;
    }

    .chat-room-title p {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .chat-sidebar {
        transition: none;
    }
}
