:root {
    --bg: #fff5eb;
    --panel: rgba(255, 251, 246, 0.9);
    --panel-strong: #fffdf9;
    --line: rgba(128, 78, 24, 0.12);
    --line-strong: rgba(128, 78, 24, 0.2);
    --text: #4e2d14;
    --muted: #8e6d51;
    --accent: #f38b1d;
    --accent-soft: rgba(243, 139, 29, 0.14);
    --danger: #de5d5d;
    --success: #2b9c71;
    --shadow: 0 24px 60px rgba(163, 91, 21, 0.12);
    --radius-xl: 30px;
    --radius-lg: 22px;
    --radius-md: 16px;
    --radius-sm: 12px;
    --font: "Segoe UI", "Trebuchet MS", "Helvetica Neue", sans-serif;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    min-height: 100%;
    font-family: var(--font);
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(243, 139, 29, 0.22), transparent 30%),
        radial-gradient(circle at bottom right, rgba(255, 181, 86, 0.18), transparent 26%),
        linear-gradient(180deg, #fffaf3 0%, #fff1e4 100%);
}

body {
    min-height: 100vh;
}

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

button, input, textarea, select {
    font: inherit;
}

.clean-body {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    min-height: 100vh;
}

.auth-shell {
    width: min(100%, 520px);
    margin: 0 auto;
}

.auth-card {
    background: var(--panel);
    backdrop-filter: blur(22px);
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow);
    padding: 36px;
}

.auth-card--wide {
    max-width: 680px;
}

.brand-mark {
    width: 64px;
    height: 64px;
    display: grid;
    place-items: center;
    font-weight: 800;
    letter-spacing: 0.08em;
    border-radius: 20px;
    color: white;
    background: linear-gradient(135deg, #ef7d12, #ffae42);
    margin-bottom: 22px;
}

.auth-kicker,
.sidebar__eyebrow,
.section-title,
.details-card__label {
    margin: 0 0 8px;
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: 0.16em;
    color: var(--muted);
}

.auth-card h1,
.sidebar__top h1,
.admin-page__header h1 {
    margin: 0 0 10px;
    font-size: clamp(28px, 4vw, 36px);
    line-height: 1.05;
}

.auth-note,
.details-card__text,
.muted {
    margin: 0;
    color: var(--muted);
    line-height: 1.5;
}

.auth-form,
.stack-form,
.inline-form {
    display: grid;
    gap: 16px;
}

.field {
    display: grid;
    gap: 8px;
}

.field span {
    font-size: 14px;
    color: var(--muted);
}

.field input,
.field textarea,
.field select,
.field--compact input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.9);
    color: var(--text);
    padding: 14px 16px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.field textarea {
    resize: none;
    min-height: 52px;
    max-height: 180px;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
    border-color: rgba(243, 139, 29, 0.6);
    box-shadow: 0 0 0 4px rgba(243, 139, 29, 0.12);
}

.button {
    border: 0;
    border-radius: 16px;
    padding: 12px 16px;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.button:hover {
    transform: translateY(-1px);
}

.button--primary {
    color: white;
    background: linear-gradient(135deg, #ef7d12, #ffab38);
    box-shadow: 0 16px 34px rgba(243, 139, 29, 0.24);
}

.button--ghost {
    background: rgba(255, 253, 249, 0.84);
    border: 1px solid var(--line);
    color: var(--text);
}

.button--full {
    width: 100%;
}

.flash {
    padding: 14px 16px;
    border-radius: 16px;
    margin: 16px 0;
    font-size: 14px;
}

.flash--success {
    background: rgba(43, 156, 113, 0.12);
    color: var(--success);
}

.flash--error {
    background: rgba(222, 93, 93, 0.12);
    color: var(--danger);
}

.flash--info {
    background: rgba(243, 139, 29, 0.12);
    color: var(--accent);
}

.saved-logins {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.saved-login {
    display: inline-flex;
    gap: 8px;
    align-items: center;
    background: rgba(243, 139, 29, 0.08);
    padding: 8px 12px;
    border-radius: 999px;
    font-size: 13px;
}

.saved-login button {
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    padding: 0;
}

.chat-app {
    min-height: 100vh;
    position: relative;
    padding: 18px;
}

.sidebar,
.chat-main,
.details-panel,
.admin-card {
    background: var(--panel);
    backdrop-filter: blur(22px);
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow);
}

.sidebar {
    position: fixed;
    top: 18px;
    left: 18px;
    bottom: 18px;
    width: min(340px, calc(100vw - 36px));
    display: flex;
    flex-direction: column;
    padding: 20px;
    gap: 18px;
    overflow: auto;
    transform: translateX(calc(-100% - 24px));
    transition: transform 0.24s ease;
    z-index: 30;
}

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

.chat-app__overlay {
    position: fixed;
    inset: 0;
    background: rgba(66, 34, 10, 0.18);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 20;
}

.chat-app--sidebar-open .chat-app__overlay,
.chat-app--details-open .chat-app__overlay {
    opacity: 1;
    pointer-events: auto;
}

.sidebar__toolbar,
.details-panel__toolbar {
    display: flex;
    justify-content: flex-end;
}

.sidebar__top,
.chat-header,
.admin-page__header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
}

.sidebar__actions,
.inline-form {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.sidebar__section {
    display: grid;
    gap: 12px;
}

.chat-list,
.people-list,
.search-results {
    display: grid;
    gap: 8px;
}

.chat-link,
.person-link,
.search-card {
    display: grid;
    gap: 6px;
    padding: 14px;
    border: 1px solid transparent;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.68);
    transition: border-color 0.18s ease, background 0.18s ease;
}

.chat-link:hover,
.person-link:hover,
.search-card:hover {
    border-color: var(--line-strong);
}

.chat-link--active {
    background: linear-gradient(135deg, rgba(243, 139, 29, 0.18), rgba(255, 179, 84, 0.1));
    border-color: rgba(243, 139, 29, 0.24);
}

.chat-link__title,
.person-link__title {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    font-weight: 600;
}

.chat-link__meta,
.person-link__meta {
    font-size: 13px;
    color: var(--muted);
}

.badge {
    min-width: 24px;
    padding: 4px 8px;
    border-radius: 999px;
    background: var(--accent);
    color: white;
    font-size: 12px;
    text-align: center;
}

.presence {
    color: var(--muted);
    font-size: 13px;
}

.presence--online {
    color: var(--success);
}

.chat-main {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    min-height: calc(100vh - 36px);
    padding: 18px;
    gap: 16px;
}

.chat-header {
    padding: 8px 4px 0;
    align-items: flex-start;
}

.chat-header__controls {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

.chat-header__content {
    flex: 1;
}

.chat-header__title h2 {
    margin: 0;
    font-size: 28px;
}

.chat-header__title p {
    margin: 6px 0 0;
    color: var(--muted);
}

.messages {
    min-height: 50vh;
    max-height: calc(100vh - 240px);
    overflow: auto;
    padding-right: 6px;
    display: grid;
    gap: 12px;
    scroll-behavior: smooth;
}

.message {
    max-width: min(78%, 760px);
    display: grid;
    gap: 8px;
    padding: 14px 16px;
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.9);
}

.message--first-unread {
    box-shadow: 0 0 0 2px rgba(243, 139, 29, 0.16);
}

.message-unread-marker {
    display: flex;
    align-items: center;
    gap: 14px;
    color: var(--accent);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-weight: 700;
}

.message-unread-marker::before,
.message-unread-marker::after {
    content: "";
    height: 1px;
    flex: 1;
    background: linear-gradient(90deg, rgba(243, 139, 29, 0), rgba(243, 139, 29, 0.45), rgba(243, 139, 29, 0));
}

.message-unread-marker span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 14px;
    border-radius: 999px;
    background: rgba(243, 139, 29, 0.08);
    border: 1px solid rgba(243, 139, 29, 0.16);
}

.message--mine {
    margin-left: auto;
    background: linear-gradient(135deg, rgba(243, 139, 29, 0.16), rgba(255, 186, 101, 0.12));
    border-color: rgba(243, 139, 29, 0.22);
}

.message--deleted {
    opacity: 0.72;
    font-style: italic;
}

.message__top,
.message__bottom {
    display: flex;
    gap: 12px;
    justify-content: space-between;
    align-items: center;
}

.message__author {
    font-weight: 700;
}

.message__time,
.message__edited {
    font-size: 12px;
    color: var(--muted);
}

.message__body {
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.55;
}

.message__attachments,
.composer__files {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.message__attachments {
    gap: 12px;
}

.attachment-card {
    display: grid;
    gap: 8px;
}

.attachment-card--image {
    max-width: min(320px, 100%);
}

.attachment-preview {
    display: block;
    border-radius: 18px;
    overflow: hidden;
    background: rgba(243, 139, 29, 0.08);
    border: 1px solid rgba(243, 139, 29, 0.14);
}

.attachment-preview img {
    display: block;
    width: 100%;
    max-width: 320px;
    max-height: 260px;
    object-fit: cover;
    background: rgba(255, 255, 255, 0.8);
}

.attachment-pill,
.file-chip {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(23, 50, 78, 0.06);
    font-size: 13px;
}

.message-actions {
    display: flex;
    gap: 8px;
}

.message-action {
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    padding: 0;
}

.typing-indicator {
    min-height: 22px;
    color: var(--muted);
    font-size: 14px;
}

.composer {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 12px;
    align-items: end;
}

.composer__body {
    display: grid;
    gap: 10px;
}

.composer__hint {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
}

.composer__submit,
.composer__file {
    min-height: 52px;
}

.details-panel {
    position: fixed;
    left: 18px;
    right: 18px;
    bottom: 18px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    padding: 18px;
    align-content: start;
    transform: translateY(calc(100% + 24px));
    transition: transform 0.24s ease;
    z-index: 28;
    overflow: auto;
    max-height: min(44vh, 360px);
}

.chat-app--details-open .details-panel {
    transform: translateY(0);
}

.details-card {
    padding: 18px;
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.9);
}

.details-card__label {
    margin-bottom: 10px;
}

.details-card__help {
    margin-top: 10px;
}

.details-card__actions {
    display: grid;
    gap: 10px;
    margin-top: 14px;
}

.notification-status,
.notification-logs {
    margin-top: 14px;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.78);
}

.notification-status {
    padding: 12px 14px;
    display: grid;
    gap: 6px;
    font-size: 13px;
    color: var(--muted);
}

.notification-status strong {
    color: var(--text);
}

.notification-logs {
    padding: 14px;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 260px;
    overflow: auto;
    font-size: 12px;
    line-height: 1.45;
    color: var(--text);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

.admin-page {
    display: grid;
    gap: 18px;
    padding: 18px;
}

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

.admin-card {
    padding: 20px;
}

.admin-card h2 {
    margin: 0 0 16px;
}

.table-wrap {
    overflow: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    text-align: left;
    padding: 14px 12px;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}

.data-table th {
    font-size: 13px;
    color: var(--muted);
    font-weight: 600;
}

.empty-state {
    padding: 36px 20px;
    text-align: center;
    color: var(--muted);
}

@media (max-width: 1180px) {
    .details-panel {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

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

@media (max-width: 900px) {
    .sidebar,
    .details-panel,
    .chat-main {
        min-width: 0;
    }

    .messages {
        max-height: 45vh;
    }

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

    .details-panel {
        grid-template-columns: 1fr;
        max-height: 60vh;
    }

    .message {
        max-width: 100%;
    }

    .attachment-card--image,
    .attachment-preview img {
        max-width: 100%;
    }

    .chat-header {
        flex-direction: column;
        align-items: stretch;
    }
}
