:root {
    color-scheme: light;
    --ink: #18202a;
    --muted: #627084;
    --line: #dde4ed;
    --paper: #ffffff;
    --soft: #f4f7fb;
    --blue: #2457d6;
    --blue-dark: #173d98;
    --green: #168a5a;
    --red: #be3a34;
    --dark-bg: #0e141d;
    --dark-panel: #151d29;
    --dark-panel-2: #1b2533;
    --dark-line: #2d3a4d;
    --dark-ink: #eef4ff;
    --dark-muted: #9daabe;
    --dark-accent: #6ea8ff;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background: var(--soft);
    font-family: Arial, Helvetica, sans-serif;
}

body.app-dark {
    color-scheme: dark;
    color: var(--dark-ink);
    background:
        linear-gradient(180deg, rgba(25, 38, 58, 0.72), rgba(14, 20, 29, 0) 320px),
        var(--dark-bg);
}

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

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 18px clamp(18px, 5vw, 64px);
    background: rgba(255, 255, 255, 0.94);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
}

.app-dark .topbar {
    background: rgba(16, 24, 36, 0.92);
    border-bottom-color: var(--dark-line);
}

.app-dark nav a {
    color: var(--dark-muted);
}

.app-dark nav a:hover,
.app-dark .brand {
    color: var(--dark-ink);
}

.brand {
    font-weight: 800;
    font-size: 1.1rem;
}

nav {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

main {
    min-height: calc(100vh - 139px);
}

.hero {
    min-height: 68vh;
    display: flex;
    align-items: center;
    padding: clamp(32px, 7vw, 92px);
    color: #fff;
    background:
        linear-gradient(90deg, rgba(12, 24, 38, 0.9), rgba(12, 24, 38, 0.68), rgba(12, 24, 38, 0.2)),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1200' height='760' viewBox='0 0 1200 760'%3E%3Crect width='1200' height='760' fill='%23244e73'/%3E%3Cpath d='M0 521c171-117 331-139 480-66 163 80 291 68 455-37 99-63 187-92 265-87v429H0z' fill='%231a805c'/%3E%3Cpath d='M773 0h427v760H773z' fill='%23d8e1ef' opacity='.24'/%3E%3Cpath d='M850 132h234v410H850z' fill='%23ffffff' opacity='.26'/%3E%3Cpath d='M905 189h124v18H905zm0 62h124v18H905zm0 62h124v18H905zm0 62h124v18H905z' fill='%23ffffff' opacity='.52'/%3E%3Ccircle cx='258' cy='238' r='74' fill='%23f6c84c' opacity='.95'/%3E%3C/svg%3E") center/cover;
}

.hero-copy {
    max-width: 650px;
}

.eyebrow {
    margin: 0 0 10px;
    color: var(--blue);
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
    font-size: 0.78rem;
}

.hero .eyebrow {
    color: #9ed9ff;
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 18px;
    font-size: clamp(2.6rem, 7vw, 5.5rem);
    line-height: 0.96;
    letter-spacing: 0;
}

h2 {
    font-size: 1.25rem;
}

.hero p {
    max-width: 560px;
    font-size: 1.18rem;
    line-height: 1.6;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 28px;
}

.button,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0 18px;
    border: 0;
    border-radius: 8px;
    background: var(--blue);
    color: #fff;
    font-weight: 800;
    cursor: pointer;
}

.nav-button {
    min-height: auto;
    padding: 0;
    border-radius: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    font-weight: 700;
}

.nav-button:hover {
    background: transparent;
    color: var(--blue);
}

.app-dark .nav-button {
    color: var(--dark-muted);
}

.app-dark .nav-button:hover {
    color: var(--dark-ink);
}

.button:hover,
button:hover {
    background: var(--blue-dark);
}

.button.small {
    min-height: 36px;
    padding: 0 14px;
}

.button.ghost {
    background: #fff;
    color: var(--ink);
}

.button.danger {
    background: var(--red);
}

.button.danger:hover {
    background: #8f2722;
}

.button.danger.subtle {
    background: transparent;
    border: 1px solid var(--red);
    color: var(--red);
}

.button.danger.subtle:hover {
    background: #fff0ef;
}

.band {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 28px;
    padding: 42px clamp(18px, 5vw, 64px);
    background: var(--paper);
    border-top: 1px solid var(--line);
}

.band p,
.muted,
.empty-state p {
    color: var(--muted);
    line-height: 1.6;
}

.app-dark .muted,
.app-dark .empty-state p,
.app-dark .chat-head span,
.app-dark .contact-list span,
.app-dark .contact-list small,
.app-dark time,
.app-dark label {
    color: var(--dark-muted);
}

.auth-panel {
    width: min(480px, calc(100% - 32px));
    margin: 58px auto;
    padding: 28px;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.app-dark .auth-panel,
.app-dark .chat-layout,
.app-dark .contact-list,
.app-dark .empty-state,
.app-dark .profile-card,
.app-dark .profile-form {
    background: var(--dark-panel);
    border-color: var(--dark-line);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.22);
}

.auth-panel h1 {
    font-size: 2rem;
}

form {
    display: grid;
    gap: 16px;
}

label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-weight: 700;
}

input,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 13px 14px;
    color: var(--ink);
    background: #fff;
    font: inherit;
}

.app-dark input,
.app-dark textarea {
    color: var(--dark-ink);
    background: #101722;
    border-color: var(--dark-line);
}

.app-dark input::placeholder,
.app-dark textarea::placeholder {
    color: #718096;
}

textarea {
    resize: vertical;
}

.check {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
}

.check input {
    width: auto;
}

.form-link {
    margin: 18px 0 0;
    color: var(--blue);
    font-weight: 700;
}

.form-link a:hover {
    color: var(--blue-dark);
}

.flash {
    margin: 18px auto 0;
    width: min(960px, calc(100% - 32px));
    padding: 14px 16px;
    border-radius: 8px;
    background: #eaf1ff;
    border: 1px solid #bdd0ff;
}

.app-dark .flash {
    background: #15243d;
    border-color: #2f4a77;
    color: var(--dark-ink);
}

.app-dark .flash.success {
    background: #102d24;
    border-color: #1d6b51;
    color: #75e0b3;
}

.app-dark .flash.error {
    background: #351a1c;
    border-color: #743238;
    color: #ff9b9b;
}

.flash.success {
    background: #e9f8f1;
    border-color: #bce7d2;
    color: var(--green);
}

.flash.error {
    background: #fff0ef;
    border-color: #ffc9c4;
    color: var(--red);
}

.chat-layout {
    width: min(920px, calc(100% - 32px));
    margin: 32px auto;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

.chat-layout.single {
    margin-top: 32px;
}

.chat-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    padding: 24px;
    border-bottom: 1px solid var(--line);
}

.chat-head h1 {
    margin-bottom: 0;
    font-size: 1.7rem;
    line-height: 1.15;
}

.chat-head span {
    color: var(--muted);
    overflow-wrap: anywhere;
}

.messages {
    display: grid;
    gap: 14px;
    min-height: 260px;
    max-height: 52vh;
    overflow-y: auto;
    padding: 24px;
    background: #f8fafc;
}

.app-dark .messages {
    background: #0f1722;
}

.message {
    display: flex;
}

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

.bubble {
    max-width: min(620px, 88%);
    padding: 14px 16px;
    border-radius: 8px;
    background: #fff;
    border: 1px solid var(--line);
}

.app-dark .bubble {
    background: var(--dark-panel-2);
    border-color: var(--dark-line);
}

.mine .bubble {
    background: #eaf1ff;
    border-color: #c6d6ff;
}

.app-dark .mine .bubble {
    background: #17345d;
    border-color: #2b63a8;
}

.bubble p {
    margin-bottom: 8px;
    line-height: 1.55;
    overflow-wrap: anywhere;
}

time {
    display: block;
    color: var(--muted);
    font-size: 0.82rem;
}

.reply-form {
    padding: 20px 24px 24px;
    background: var(--paper);
}

.app-dark .reply-form {
    background: var(--dark-panel);
}

.admin-layout {
    display: grid;
    grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
    gap: 24px;
    padding: 24px clamp(16px, 4vw, 42px);
}

.contact-list {
    align-self: start;
    display: grid;
    gap: 10px;
    padding: 18px;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.contact-list h1 {
    font-size: 1.8rem;
}

.contact-list a {
    display: grid;
    gap: 4px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.app-dark .contact-list a {
    background: var(--dark-panel-2);
    border-color: var(--dark-line);
}

.contact-list a.active {
    border-color: var(--blue);
    box-shadow: inset 4px 0 0 var(--blue);
}

.app-dark .contact-list a.active {
    border-color: var(--dark-accent);
    box-shadow: inset 4px 0 0 var(--dark-accent);
}

.contact-list span,
.contact-list small {
    color: var(--muted);
    overflow-wrap: anywhere;
}

.contact-list small.online {
    color: var(--green);
    font-weight: 800;
}

.contact-list small.offline {
    color: var(--muted);
}

.app-dark .contact-list small.online {
    color: #75e0b3;
}

.admin-thread .chat-layout {
    width: 100%;
    margin: 0;
}

.admin-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px;
    margin-bottom: 12px;
}

.admin-actions form {
    display: block;
}

.app-dark .button.danger.subtle:hover {
    background: #351a1c;
}

.empty-state {
    padding: 28px;
    background: var(--paper);
    border: 1px dashed var(--line);
    border-radius: 8px;
}

footer {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 24px clamp(18px, 5vw, 64px);
    color: var(--muted);
    border-top: 1px solid var(--line);
    background: var(--paper);
}

.app-dark footer {
    color: var(--dark-muted);
    background: #0f1722;
    border-top-color: var(--dark-line);
}

.app-dark .eyebrow,
.app-dark .form-link,
.app-dark .profile-facts a {
    color: var(--dark-accent);
}

.profile-layout {
    display: grid;
    grid-template-columns: minmax(260px, 360px) minmax(0, 680px);
    gap: 24px;
    align-items: start;
    width: min(1120px, calc(100% - 32px));
    margin: 32px auto;
}

.profile-card,
.profile-form {
    padding: 24px;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.profile-preview {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 16px;
    align-items: center;
}

.profile-preview h1 {
    margin-bottom: 6px;
    font-size: 1.8rem;
    line-height: 1.1;
}

.profile-preview p:last-child {
    margin-bottom: 0;
    color: var(--muted);
    overflow-wrap: anywhere;
}

.app-dark .profile-preview p:last-child {
    color: var(--dark-muted);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--blue);
    color: #fff;
    font-weight: 800;
}

.avatar-large {
    width: 84px;
    height: 84px;
    flex-basis: 84px;
    font-size: 2rem;
}

.avatar-tiny {
    width: 28px;
    height: 28px;
    flex-basis: 28px;
    margin-right: 8px;
    font-size: 0.8rem;
    vertical-align: middle;
}

.contact-list strong {
    display: flex;
    align-items: center;
    min-width: 0;
}

.profile-facts {
    display: grid;
    gap: 12px;
    margin: 24px 0 0;
}

.profile-facts div {
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.app-dark .profile-facts div {
    border-top-color: var(--dark-line);
}

.profile-facts dt {
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 800;
    text-transform: uppercase;
}

.app-dark .profile-facts dt {
    color: var(--dark-muted);
}

.profile-facts dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.notification-options {
    display: grid;
    gap: 12px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
}

.notification-options h2 {
    margin-bottom: 0;
}

.app-dark .notification-options {
    background: #101722;
    border-color: var(--dark-line);
}

.toast-wrap {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 50;
    display: grid;
    gap: 10px;
    width: min(360px, calc(100vw - 36px));
}

.toast-message {
    display: grid;
    gap: 6px;
    width: 100%;
    min-height: auto;
    padding: 14px 16px;
    border: 1px solid var(--dark-line);
    border-radius: 8px;
    background: var(--dark-panel-2);
    color: var(--dark-ink);
    text-align: left;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.34);
}

.toast-message:hover {
    background: #223047;
}

.toast-message span {
    color: var(--dark-muted);
    font-weight: 600;
    line-height: 1.45;
}

@media (max-width: 820px) {
    .topbar,
    footer,
    .chat-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .band,
    .admin-layout,
    .profile-layout,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .hero {
        min-height: 62vh;
    }

    .messages {
        max-height: none;
    }
}
