:root {
    --bg: #020617;
    --bg-alt: #030712;
    --bg-card: #020617;
    --bg-light: #ffffff;
    --text: #e5e7eb;
    --text-muted: #9ca3af;
    --accent: #38bdf8;
    --accent-soft: rgba(56,189,248,0.1);
    --border: rgba(148,163,184,0.3);
    --danger: #f97373;
    --male-bg: #0ea5e9;
    --female-bg: #f472b6;
    --shadow-soft: 0 18px 45px rgba(15,23,42,0.7);
}

.theme-light {
    --bg: #f3f4f6;
    --bg-alt: #ffffff;
    --bg-card: #ffffff;
    --text: #111827;
    --text-muted: #6b7280;
    --accent-soft: rgba(56,189,248,0.08);
}

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

/* IMPORTANT: full-height document so chat can use 100vh */
html,
body {
    height: 100%;
}

/* On chat page, only the chat pane scrolls, not the body */
body[data-page="chat"] {
    overflow: hidden;
    height: 100vh;   /* lock viewport height for the chat page */
}

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: radial-gradient(circle at top, #0f172a 0, #020617 50%, #000 100%);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

.theme-light body {
    background: linear-gradient(to bottom, #e5f4ff, #f9fafb);
}

/* Layout */

.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 0.75rem;
    max-width: 1200px;
    margin: 0 auto;
}

.app-header {
    padding: 1rem 0.5rem 0.75rem;
}

.app-header-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.app-footer {
    padding: 0.75rem 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
}

/* Logo */

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.logo span {
    color: var(--accent);
}

.logo.small {
    font-size: 1.1rem;
}

.tagline {
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* Cards */

.card {
    background: linear-gradient(145deg, rgba(15,23,42,0.98), rgba(15,23,42,0.85));
    border-radius: 1.25rem;
    border: 1px solid rgba(148,163,184,0.35);
    box-shadow: var(--shadow-soft);
    padding: 1.5rem;
}

.theme-light .card {
    background: #ffffff;
    border-color: #e5e7eb;
    box-shadow: 0 10px 30px rgba(15,23,42,0.1);
}

.card-center {
    margin: auto;
    width: 100%;
    max-width: 480px;
}

.card-auth h2 {
    margin-bottom: 0.5rem;
}

.card-auth .muted {
    margin-bottom: 1rem;
}

/* Forms */

.form-grid {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    margin-top: 0.5rem;
}

label {
    font-size: 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

input[type="text"],
select,
textarea {
    border-radius: 999px;
    border: 1px solid var(--border);
    padding: 0.6rem 0.9rem;
    background: rgba(15,23,42,0.9);
    color: var(--text);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.theme-light input[type="text"],
.theme-light select,
.theme-light textarea {
    background: #f9fafb;
}

input[type="text"]:focus,
select:focus,
textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px rgba(56,189,248,0.4);
}

textarea {
    border-radius: 1.25rem;
    resize: none;
}

/* Buttons */

button,
.btn-primary,
.btn-ghost {
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    border-radius: 999px;
    padding: 0.6rem 1.05rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    transition: background 0.15s, transform 0.06s, box-shadow 0.15s;
}

.btn-primary {
    background: linear-gradient(135deg, #38bdf8, #0ea5e9);
    color: #0b1120;
    font-weight: 600;
    box-shadow: 0 10px 30px rgba(56,189,248,0.4);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 18px 40px rgba(56,189,248,0.5);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border-radius: 999px;
    border: 1px solid rgba(148,163,184,0.35);
    padding-inline: 0.9rem;
}

.btn-ghost:hover {
    background: rgba(148,163,184,0.08);
    color: var(--text);
}

/* Icons / Pills / Badges */

.icon-btn {
    background: rgba(15,23,42,0.7);
    border-radius: 999px;
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(148,163,184,0.4);
}

.theme-light .icon-btn {
    background: #f3f4f6;
}

.icon-btn .icon-mail::before {
    content: "✉";
    font-size: 1rem;
}
.icon-btn .icon-moon::before {
    content: "☾";
    font-size: 1rem;
}
.icon-btn .icon-block::before {
    content: "⛔";
    font-size: 1rem;
}

.badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    border-radius: 999px;
    background: #f97373;
    color: white;
    font-size: 0.7rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.icon-btn {
    position: relative;
}

/* Checkboxes */

.checkbox-row {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
}

.checkbox-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
}

/* Alerts */

.alert {
    border-radius: 0.9rem;
    padding: 0.7rem 0.9rem;
    font-size: 0.85rem;
}

.alert-danger {
    background: rgba(239,68,68,0.09);
    border: 1px solid rgba(239,68,68,0.5);
}

/* Pool layout */

.pool-layout {
    flex: 1;
    padding: 0.75rem 0.25rem 0.25rem;
}

.pool-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 0.75rem;
}

/* User cards */

.user-card {
    border-radius: 1rem;
    padding: 0.8rem 0.9rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    color: #0b1120;
}

.user-card.male {
    background: linear-gradient(135deg, rgba(14,165,233,0.96), rgba(56,189,248,0.94));
}
.user-card.female {
    background: linear-gradient(135deg, rgba(244,114,182,0.96), rgba(236,72,153,0.94));
}

.user-main {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.user-row {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.user-nick {
    font-weight: 700;
}

.user-meta {
    font-size: 0.8rem;
    opacity: 0.9;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
}

.dot-online {
    background: #22c55e;
}

.dot-offline {
    background: rgba(15,23,42,0.4);
}

.btn-chat {
    background: rgba(15,23,42,0.92);
    color: #e5e7eb;
    border-radius: 999px;
    padding: 0.5rem 0.85rem;
    font-size: 0.8rem;
}

/* Header right */

.header-left {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: nowrap;
}

.user-pill {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.15rem;
    font-size: 0.8rem;
}

.online-counter {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Modal */

.modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 40;
}

.modal.active {
    display: flex;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15,23,42,0.75);
    backdrop-filter: blur(6px);
}

.modal-content {
    position: relative;
    z-index: 41;
    width: 100%;
    max-width: 420px;
    border-radius: 1.1rem;
    padding: 1rem 1rem 1rem;
    background: linear-gradient(145deg, rgba(15,23,42,0.98), rgba(15,23,42,0.9));
    border: 1px solid rgba(148,163,184,0.5);
    box-shadow: var(--shadow-soft);
}

.theme-light .modal-content {
    background: #ffffff;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.6rem;
}

.modal-body {
    max-height: 60vh;
    overflow-y: auto;
    padding-right: 0.25rem;
}

/* Mailbox items */

.mail-item {
    padding: 0.55rem 0.1rem;
    border-bottom: 1px solid rgba(148,163,184,0.25);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: 0.85rem;
}

.mail-item:last-child {
    border-bottom: none;
}

.mail-main {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.mail-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.mail-unread {
    font-weight: 600;
}

/* Blocked list */

.block-item {
    padding: 0.45rem 0.1rem;
    border-bottom: 1px solid rgba(148,163,184,0.25);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.85rem;
}

/* =========================
   Chat
   ========================= */

/* Reactions summary under messages */
.chat-reactions-summary {
    margin-top: 0.2rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    font-size: 0.8rem;
    opacity: 0.95;
}

.reaction-pill {
    padding: 0.05rem 0.45rem;
    border-radius: 999px;
    background: rgba(15,23,42,0.8);
    color: #e5e7eb;
}

.chat-bubble.me .reaction-pill {
    background: rgba(15,23,42,0.15);
    color: #0b1120;
}

/* Reactions picker inside bubbles */
.chat-bubble {
    position: relative; /* ensures menu sits nicely inside */
}

[data-role="reaction-menu"] {
    display: flex !important;
    flex-wrap: nowrap;
    gap: 0.35rem;
    margin-top: 0.25rem;
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.85);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
    z-index: 5;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
}

[data-role="reaction-menu"] button {
    background: transparent !important;
    border: none !important;
    color: #ffffff !important;
    font-size: 20px;
    line-height: 1;
    padding: 0 4px;
    cursor: pointer;
}

.chat-main {
    overflow-y: auto;
    padding: 0.25rem 0.1rem;
    flex: none;              /* JS will control height */
}

.typing-indicator {
    padding: 0.15rem 0.4rem;
    font-size: 0.78rem;
    opacity: 0.8;
}

.chat-header {
    padding: 0.4rem 0.2rem 0.3rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.chat-header-right {
    display: flex;
    align-items: center;
}

.chat-main {
    flex: 1;
    min-height: 0;
    max-height: calc(100vh - 150px); /* FORCE it to stay inside window */
    overflow-y: auto;
    padding: 0.25rem 0.1rem;
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.chat-bubble-row {
    display: flex;
}

.chat-bubble {
    max-width: 78%;
    padding: 0.45rem 0.7rem;
    border-radius: 1rem;
    font-size: 0.9rem;
    line-height: 1.3;
    word-wrap: break-word;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}

.chat-bubble.me {
    margin-left: auto;
    border-bottom-right-radius: 0.2rem;
    background: linear-gradient(135deg, #38bdf8, #0ea5e9);
    color: #0b1120;
}

.chat-bubble.other {
    margin-right: auto;
    border-bottom-left-radius: 0.2rem;
    background: rgba(15,23,42,0.96);
    border: 1px solid rgba(148,163,184,0.4);
}

.chat-time {
    margin-top: 0.2rem;
    font-size: 0.7rem;
    opacity: 0.7;
}

.chat-attachment {
    margin-top: 0.3rem;
    border-radius: 0.75rem;
    overflow: hidden;
}

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

.chat-attachment video {
    max-width: 100%;
    display: block;
}

/* Chat footer */

.chat-footer {
    padding-top: 0.25rem;
}

.chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 0.4rem;
    background: rgba(15,23,42,0.9);
    border-radius: 999px;
    padding: 0.25rem 0.25rem 0.25rem 0.5rem;
    border: 1px solid rgba(148,163,184,0.6);
}

.theme-light .chat-input-row {
    background: #f3f4f6;
}

.chat-input-row textarea {
    flex: 1;
    border: none;
    background: transparent;
    padding-left: 0;
    padding-right: 0;
}

.file-btn {
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0.2rem 0.45rem;
    border-radius: 999px;
    background: rgba(15,23,42,0.85);
    color: #e5e7eb;
}

.theme-light .file-btn {
    background: #e5e7eb;
    color: #111827;
}

.file-btn input[type="file"] {
    display: none;
}

/* Utility */

.muted {
    color: var(--text-muted);
}

.small {
    font-size: 0.8rem;
}

.center {
    text-align: center;
}

/* Responsive tweaks */

@media (max-width: 720px) {
    .app-shell {
        padding-inline: 0.4rem;
    }

    .app-header-bar {
        flex-direction: column;
        align-items: flex-start;
    }

    .header-right {
        width: 100%;
        justify-content: space-between;
    }

    .user-pill {
        display: none;
    }

    .pool-list {
        grid-template-columns: 1fr;
    }

    .chat-shell {
        padding-inline: 0.3rem;
    }

    .chat-header {
        padding-inline: 0.1rem;
    }

    .chat-bubble {
        max-width: 86%;
    }
}
