:root {
    --bg: #f4f6f8;
    --panel: #ffffff;
    --panel-soft: #f8fafc;
    --border: #d7dee7;
    --border-strong: #bcc7d4;
    --text: #1f2933;
    --text-soft: #5b6875;
    --primary: #1f5f8b;
    --primary-hover: #174a6d;
    --accent: #d9a441;
    --danger-bg: #fff1f1;
    --danger-border: #e7b4b4;
    --danger-text: #8b2e2e;
    --shadow: 0 10px 30px rgba(16, 24, 40, 0.08);
    --radius: 16px;
    --radius-sm: 10px;
    --header-height: 76px;
    --sidebar-width: 320px;
    --max-login-width: 1080px;
    --content-width: 1600px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

html {
    font-size: 16px;
}

body {
    margin: 0;
    font-family: var(--font);
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
}

body.sidebar-open {
    overflow: hidden;
}

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

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

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

/* Login */

.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(circle at top left, rgba(217, 164, 65, 0.18), transparent 32%),
        radial-gradient(circle at bottom right, rgba(31, 95, 139, 0.16), transparent 34%),
        var(--bg);
}

.login-page {
    width: 100%;
    max-width: var(--max-login-width);
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 28px;
    align-items: stretch;
}

.login-brand-panel,
.login-form-panel {
    min-width: 0;
}

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.login-card {
    padding: 32px;
}

.login-brand-panel {
    padding: 24px 8px 24px 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 28px;
}

.login-intro h1 {
    margin: 0 0 12px;
    font-size: 2rem;
    line-height: 1.15;
}

.login-intro p {
    margin: 0;
    max-width: 40rem;
    color: var(--text-soft);
    font-size: 1.05rem;
}

/* Brand */

.brand-lockup {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.brand-lockup-large {
    align-items: flex-start;
    gap: 18px;
}

.brand-logo-wrap {
    width: 64px;
    height: 64px;
    border-radius: 18px;
    background: linear-gradient(180deg, #ffffff 0%, #eef3f8 100%);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    overflow: hidden;
}

.brand-logo-wrap-small {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    box-shadow: none;
}

.brand-logo {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.brand-text {
    min-width: 0;
}

.brand-name {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.brand-slogan {
    margin-top: 4px;
    color: var(--text-soft);
    font-size: 0.98rem;
}

/* Forms */

.stack-form {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.form-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-row label {
    font-weight: 600;
}

.form-row input,
.form-row textarea,
select {
    width: 100%;
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    background: #fff;
    color: var(--text);
    padding: 13px 14px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-row input:focus,
.form-row textarea:focus,
.chat-composer textarea:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(31, 95, 139, 0.12);
}

.form-actions {
    padding-top: 6px;
}

/* Buttons */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 10px 16px;
    border: 1px solid transparent;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, opacity 0.15s ease;
    white-space: nowrap;
}

.btn:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-secondary {
    background: #fff;
    color: var(--text);
    border-color: var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
    background: #f8fafc;
}

.btn-small {
    min-height: 34px;
    padding: 6px 10px;
    border-radius: 10px;
    font-size: 0.9rem;
}

/* Alerts */

.alert {
    border-radius: 12px;
    padding: 12px 14px;
    border: 1px solid transparent;
    margin-bottom: 18px;
}

.alert-error {
    background: var(--danger-bg);
    border-color: var(--danger-border);
    color: var(--danger-text);
}

.notice-banner {
    margin-bottom: 14px;
    padding: 12px 14px;
    border: 1px solid #e6c17a;
    border-radius: 12px;
    background: #fff5dd;
    color: #7a5613;
    font-weight: 600;
}

/* App Layout */

.app-body {
    min-height: 100vh;
    background: var(--bg);
}

.app-shell {
    min-height: 100vh;
    width: 100%;
    max-width: var(--content-width);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
}

.app-header {
    min-height: var(--header-height);
    padding: 14px 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 40;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.user-badge {
    color: var(--text-soft);
    font-size: 0.95rem;
}

.logout-form {
    display: inline;
    margin: 0;
}

.app-layout {
    flex: 1;
    min-height: 0;
    display: grid;
}

.app-layout.has-sidebar {
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
}

.app-layout.no-sidebar {
    grid-template-columns: minmax(0, 1fr);
}

.single-room-mode .chat-main {
    padding-left: 20px;
}

/* Sidebar */

.sidebar {
    border-right: 1px solid var(--border);
    background: #fbfcfd;
    padding: 20px 16px;
    min-width: 0;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

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

.sidebar-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-soft);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.sidebar-close {
    display: none;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: #fff;
    color: var(--text);
    cursor: pointer;
    font-size: 1.4rem;
    line-height: 1;
}

.sidebar-backdrop {
    display: none;
}

.sidebar-backdrop[hidden] {
    display: none !important;
}

.room-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.room-item {
    display: block;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #fff;
    padding: 13px 14px;
    transition: border-color 0.15s ease, background-color 0.15s ease, transform 0.15s ease;
}

.room-item:hover {
    border-color: var(--primary);
    background: #f8fbfe;
    transform: translateY(-1px);
}

.room-item.active {
    border-color: var(--primary);
    background: #eef6fb;
}

.room-item-title {
    font-weight: 700;
    margin-bottom: 4px;
}

.room-item-meta {
    color: var(--text-soft);
    font-size: 0.92rem;
}

.room-switcher-toggle {
    display: none;
}

/* Main Chat Area */

.chat-main {
    min-width: 0;
    padding: 20px;
}

.panel,
.chat-room-panel {
    min-height: calc(100vh - var(--header-height) - 40px);
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.chat-room-panel {
    display: grid;
    grid-template-rows: auto auto 1fr auto;
    overflow: hidden;
}

.chat-room-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    padding: 20px 22px;
    border-bottom: 1px solid var(--border);
    background: var(--panel-soft);
}

.chat-room-header-main {
    min-width: 0;
}

.chat-room-header h1 {
    margin: 0 0 6px;
    font-size: 1.35rem;
}

.chat-room-header p {
    margin: 0;
    color: var(--text-soft);
}

.chat-room-tools {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.current-room-badge {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: #fff;
    color: var(--text-soft);
    font-size: 0.92rem;
}

/* Polls */

.polls-panel {
    padding: 18px 20px 10px;
    border-bottom: 1px solid var(--border);
    background: #fcfdff;
}

.polls-header {
    margin-bottom: 12px;
}

.polls-header h2 {
    margin: 0;
    font-size: 1.1rem;
}

.poll-create-form {
    margin-bottom: 18px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #fff;
}

.poll-create-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.poll-options-wrap {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.poll-options-wrap input[type="text"] {
    width: 100%;
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    background: #fff;
    color: var(--text);
    padding: 13px 14px;
    outline: none;
}

.active-polls-sticky {
    position: sticky;
    top: 0;
    z-index: 5;
    margin-bottom: 16px;
}

.poll-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.poll-list-active {
    gap: 12px;
}

.poll-card {
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #fff;
    padding: 14px;
}

.poll-card-active {
    background: #fff0d9;
    border-color: #ebb35d;
}

.poll-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.poll-card-header h3 {
    margin: 0 0 6px;
    font-size: 1rem;
}

.poll-card-top-actions {
    flex: 0 0 auto;
}

.poll-meta {
    color: var(--text-soft);
    font-size: 0.9rem;
}

.poll-required-status {
    margin-top: 8px;
    padding: 8px 10px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.7);
    color: #7a5613;
    font-size: 0.92rem;
    font-weight: 600;
}


.poll-voter-status-list {
    margin-top: 12px;
    border-top: 1px dashed var(--border);
    padding-top: 10px;
}

.poll-voter-status-list summary {
    cursor: pointer;
    color: var(--text-soft);
    font-size: 0.92rem;
}

.poll-voter-status-list ul {
    margin: 10px 0 0;
    padding-left: 18px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.poll-voter-status-list li {
    color: var(--text);
    font-size: 0.94rem;
}

.poll-body[hidden] {
    display: none !important;
}

.poll-options {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.poll-option {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 10px;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    background: #fbfcfd;
}

.poll-option-input {
    display: inline-flex;
    align-items: center;
}

.poll-option-label {
    min-width: 0;
    word-break: break-word;
}

.poll-option-votes {
    color: var(--text-soft);
    font-size: 0.9rem;
    white-space: nowrap;
}

.poll-actions {
    margin-top: 12px;
    display: flex;
    justify-content: flex-start;
    gap: 8px;
    flex-wrap: wrap;
}

/* Message Toolbar */

.message-list-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    background: #f8fafc;
}

.message-list-toolbar.hidden {
    display: none;
}

.message-list-toolbar-left {
    display: flex;
    flex-direction: column;
    gap: 2px;
    color: var(--text-soft);
    font-size: 0.92rem;
}

.message-list-toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.message-list-toolbar-right input[type="number"],
.message-list-toolbar-right select {
    width: auto;
    min-width: 84px;
    padding: 8px 10px;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: #fff;
}

/* Messages */

.message-stream {
    padding: 22px;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.88) 0%, rgba(248, 250, 252, 0.92) 100%);
}

.system-note {
    align-self: center;
    max-width: 780px;
    padding: 12px 14px;
    border-radius: 12px;
    background: #fff8e8;
    border: 1px solid #ecd9a9;
    color: #6f5a1a;
    font-size: 0.95rem;
}

.message-bubble {
    max-width: min(720px, 85%);
    padding: 12px 14px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: #fff;
    box-shadow: 0 4px 16px rgba(16, 24, 40, 0.05);
}

.message-bubble.self {
    align-self: flex-end;
    background: #edf6fc;
    border-color: #c8dfee;
}

.message-bubble.other {
    align-self: flex-start;
}

.message-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
    font-size: 0.88rem;
    flex-wrap: wrap;
}

.message-author {
    font-weight: 700;
}

.message-time {
    color: var(--text-soft);
}

.message-text {
    white-space: pre-wrap;
    word-break: break-word;
}

.message-flag {
    display: inline-flex;
    align-items: center;
    margin-bottom: 8px;
    padding: 4px 9px;
    border-radius: 999px;
    background: #fff4d6;
    border: 1px solid #edd28c;
    color: #775600;
    font-size: 0.82rem;
    font-weight: 700;
}

.message-flag.alt {
    background: #eef6fb;
    border-color: #c5dcec;
    color: #194d72;
}


.message-edit-form {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.message-edit-textarea {
    width: 100%;
    min-height: 110px;
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    padding: 12px 14px;
    resize: vertical;
    background: #fff;
    color: var(--text);
    font: inherit;
}

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

.message-actions {
    margin-top: 10px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.message-edited {
    margin-top: 8px;
    color: var(--text-soft);
    font-size: 0.85rem;
    font-style: italic;
}

/* Attachments */

.attachment-list {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.attachment-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
}

.attachment-item:hover {
    border-color: var(--primary);
    background: #f8fbfe;
}

.attachment-file-link {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.attachment-name {
    font-weight: 700;
}

.attachment-meta {
    color: var(--text-soft);
    font-size: 0.88rem;
}

.attachment-preview-link {
    display: block;
    width: 100%;
}

.attachment-preview-image {
    display: block;
    width: 100%;
    max-width: 420px;
    max-height: 260px;
    object-fit: cover;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #f8fafc;
}

/* Composer */

.chat-composer {
    padding: 16px 18px 18px;
    border-top: 1px solid var(--border);
    background: #fff;
}

.composer-options {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
    margin-bottom: 12px;
    color: var(--text-soft);
    font-size: 0.94rem;
}

.composer-options label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

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

.chat-composer textarea {
    min-height: 90px;
    max-height: 240px;
    resize: vertical;
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    padding: 14px;
    background: #fff;
}

/* Empty State */

.empty-state {
    min-height: 320px;
    display: grid;
    place-items: center;
    text-align: center;
    padding: 32px;
    color: var(--text-soft);
}

.empty-state.small {
    min-height: 120px;
    padding: 16px;
    border: 1px dashed var(--border-strong);
    border-radius: 12px;
    background: #fff;
}

.empty-state h1 {
    margin: 0 0 10px;
    color: var(--text);
}

/* Tablet / Sidebar */

@media (max-width: 980px) {
    .login-page {
        grid-template-columns: 1fr;
    }

    .login-brand-panel {
        padding-right: 0;
    }

    .app-layout.has-sidebar,
    .app-layout.no-sidebar {
        grid-template-columns: 1fr;
    }

    .chat-main,
    .single-room-mode .chat-main {
        padding: 16px;
    }

    .room-switcher-toggle {
        display: inline-flex;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(86vw, 340px);
        max-width: 340px;
        z-index: 60;
        border-right: 1px solid var(--border);
        box-shadow: var(--shadow);
        transform: translateX(-105%);
        transition: transform 0.2s ease;
        padding-top: 18px;
        overflow: auto;
    }

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

    .sidebar-close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }



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

    .chat-room-tools {
        justify-content: flex-start;
    }

    .current-room-badge {
        max-width: 100%;
    }
}

/* Mobile */

@media (max-width: 720px) {
    .login-body {
        padding: 16px;
    }

    .login-card {
        padding: 24px;
    }

    .login-intro h1 {
        font-size: 1.65rem;
    }

    .app-header {
        padding: 12px 14px;
        align-items: flex-start;
        flex-direction: column;
    }

    .header-actions {
        width: 100%;
        justify-content: flex-start;
        gap: 10px;
    }

    .header-actions .user-badge {
        width: 100%;
        order: 99;
    }

    .chat-main,
    .single-room-mode .chat-main {
        padding: 12px;
    }

    .chat-room-header {
        padding: 16px;
    }

    .polls-panel {
        padding: 14px 14px 8px;
    }

    .active-polls-sticky {
        top: 0;
        z-index: 2;
    }

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

    .poll-option {
        grid-template-columns: auto 1fr;
    }

    .poll-option-votes {
        grid-column: 2;
    }

    .message-list-toolbar {
        padding: 12px;
    }

    .message-list-toolbar-right {
        width: 100%;
    }

    .message-list-toolbar-right input[type="number"],
    .message-list-toolbar-right select {
        flex: 1 1 110px;
        min-width: 0;
    }

    .message-stream {
        padding: 16px;
    }

    .chat-composer {
        padding: 14px;
    }

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

    .message-bubble {
        max-width: 100%;
    }

    .brand-name {
        font-size: 1.2rem;
    }

    .brand-slogan {
        font-size: 0.9rem;
    }

    .attachment-preview-image {
        max-width: 100%;
        max-height: 220px;
    }

    .btn {
        min-height: 42px;
    }
}


.search-attribute-filters {
    margin-top: 4px;
}

.hint-text {
    margin-top: 6px;
    color: var(--text-soft);
    font-size: 0.9rem;
}

.search-result-attributes {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin: 8px 0 0;
}

.message-edit-attributes {
    margin-top: 12px;
}

.message-edit-attributes {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px 12px;
    min-width: 0;
}

.message-edit-attributes legend {
    padding: 0 6px;
    color: var(--text-soft);
    font-size: 0.92rem;
}
