:root {
    --bg: #0f172a;
    --panel: #111827;
    --panel-soft: #1f2937;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --accent: #22c55e;
    --danger: #ef4444;
    --border: #334155;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: Segoe UI, Tahoma, sans-serif;
    background: radial-gradient(circle at top, #1e293b 0%, var(--bg) 55%);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.app {
    width: 100%;
    max-width: 1080px;
    border: 1px solid var(--border);
    background: rgba(17, 24, 39, 0.96);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.35);
}

.header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: rgba(15, 23, 42, 0.8);
}

.title { font-size: 18px; font-weight: 600; }

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-info {
    color: var(--muted);
    font-size: 14px;
}

.content {
    display: grid;
    grid-template-columns: 320px 1fr;
    min-height: 76vh;
}

.content.logged-in {
    grid-template-columns: 1fr;
}

.auth-panel {
    border-right: 1px solid var(--border);
    padding: 18px;
    background: rgba(15, 23, 42, 0.42);
}

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

.rooms-panel {
    border-bottom: 1px solid var(--border);
    padding: 10px 12px;
    background: rgba(15, 23, 42, 0.6);
    display: grid;
    gap: 8px;
}

.room-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.room-row input,
.room-row select,
.room-row button {
    width: auto;
}

.room-row input,
.room-row select {
    min-width: 160px;
}

.room-badge {
    padding: 4px 8px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: rgba(30, 41, 59, 0.7);
    font-size: 12px;
}

.rooms-lobby {
    flex: 1;
    padding: 12px;
    overflow: auto;
}

.rooms-list {
    display: grid;
    gap: 10px;
    align-content: start;
}

.room-card {
    border: 1px solid var(--border);
    background: rgba(17, 24, 39, 0.8);
    border-radius: 12px;
    padding: 10px;
    display: grid;
    gap: 8px;
}

.room-card-title {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.room-tag {
    font-size: 11px;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 2px 8px;
}

.room-tag.owner {
    border-color: #0ea5e9;
    color: #7dd3fc;
}

.room-tag.system {
    border-color: #16a34a;
    color: #86efac;
}

.room-card-meta {
    color: var(--muted);
    font-size: 13px;
}

.room-pm-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    color: #111827;
    background: #fbbf24;
    border: 1px solid #f59e0b;
}

.room-card-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.chat-view {
    display: grid;
    grid-template-rows: auto 1fr;
    min-height: 0;
}

.chat-layout {
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 280px;
    gap: 10px;
    padding: 10px;
}

.chat-main-col {
    min-height: 0;
    display: grid;
    grid-template-rows: auto 1fr auto auto;
    gap: 10px;
}

.room-header {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.6);
}

.room-activity {
    min-height: 18px;
    padding: 4px 12px 0;
    color: var(--muted);
    font-size: 12px;
    opacity: 0.85;
}

.room-users-wrap {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 12px;
    background: rgba(15, 23, 42, 0.45);
    display: grid;
    gap: 8px;
}

.room-users-col {
    align-content: start;
    max-height: 100%;
    overflow: auto;
}

.room-users-list {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.room-user-chip {
    width: auto;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.room-user-menu {
    position: fixed;
    z-index: 90;
    min-width: 210px;
    max-width: calc(100vw - 16px);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 6px;
    background: rgba(15, 23, 42, 0.98);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    display: grid;
    gap: 6px;
}

.room-user-menu-item {
    width: 100%;
    text-align: left;
    background: rgba(30, 41, 59, 0.85);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
}

.block-title {
    margin: 0 0 12px;
    font-size: 15px;
    color: var(--muted);
    font-weight: 600;
}

form {
    display: grid;
    gap: 10px;
    margin-bottom: 16px;
}

input, button {
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--panel-soft);
    color: var(--text);
    font: inherit;
}

button {
    cursor: pointer;
    font-weight: 600;
    transition: 0.16s ease;
    background: #166534;
    border-color: #15803d;
}

button:hover { filter: brightness(1.1); }
button:disabled { opacity: 0.65; cursor: not-allowed; }

.secondary {
    background: transparent;
    border-color: var(--border);
    color: var(--muted);
}

.header-btn {
    width: auto;
    padding: 8px 14px;
    font-size: 13px;
}

.admin-panel {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    background: rgba(15, 23, 42, 0.52);
    display: grid;
    gap: 10px;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(2, 6, 23, 0.65);
}

.modal-content {
    position: relative;
    width: min(1100px, 100%);
    max-height: 90vh;
    overflow: auto;
    background: rgba(17, 24, 39, 0.98);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px;
    display: grid;
    gap: 12px;
    z-index: 1;
}

.modal-small {
    width: min(560px, 100%);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
}

.admin-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

.admin-table th, .admin-table td {
    border-bottom: 1px solid var(--border);
    padding: 8px;
    text-align: left;
    font-size: 13px;
}

.admin-inline {
    display: flex;
    align-items: center;
    gap: 6px;
}

.admin-inline input[type="text"],
.admin-inline input[type="password"] {
    min-width: 140px;
    width: auto;
    padding: 7px 8px;
}

.admin-inline button {
    width: auto;
    padding: 7px 10px;
    font-size: 12px;
}

.danger {
    background: #7f1d1d;
    border-color: #991b1b;
}

.messages {
    flex: 1;
    overflow: auto;
    padding: 16px;
    display: grid;
    gap: 10px;
    align-content: start;
    background: rgba(15, 23, 42, 0.22);
}

.msg {
    border: 1px solid var(--border);
    background: rgba(31, 41, 55, 0.75);
    border-radius: 10px;
    padding: 10px;
}

.msg-system {
    border-style: dashed;
    background: rgba(30, 64, 175, 0.15);
}

.msg-presence {
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    padding: 2px 4px;
    opacity: 0.8;
}

.msg-private-out {
    border-color: #fb7185;
    background: rgba(190, 24, 93, 0.14);
}

.msg-private-in {
    border-color: #60a5fa;
    background: rgba(37, 99, 235, 0.16);
}

.user-chip {
    width: auto;
    padding: 2px 8px;
    font-size: 12px;
    border-radius: 999px;
    background: rgba(30, 41, 59, 0.85);
    border: 1px solid var(--border);
    color: var(--text);
}

.private-bar {
    border-top: 1px solid var(--border);
    padding: 8px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: rgba(30, 58, 138, 0.2);
    font-size: 13px;
}

.msg-meta {
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 6px;
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.composer {
    border-top: 1px solid var(--border);
    padding: 12px;
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 10px;
    background: rgba(15, 23, 42, 0.85);
    position: relative;
    align-items: center;
}

.emoji-toggle {
    width: auto;
    min-width: 44px;
    padding: 8px 10px;
    font-size: 18px;
    line-height: 1;
}

.emoji-panel {
    position: absolute;
    left: 12px;
    bottom: calc(100% + 8px);
    width: min(340px, 90vw);
    max-height: 180px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.98);
    display: grid;
    grid-template-columns: repeat(8, minmax(30px, 1fr));
    gap: 6px;
    padding: 8px;
    z-index: 5;
}

.emoji-btn {
    width: 100%;
    padding: 6px;
    border-radius: 8px;
    background: rgba(30, 41, 59, 0.8);
    border: 1px solid var(--border);
    font-size: 18px;
    line-height: 1;
}

.notice {
    min-height: 20px;
    padding: 8px 12px;
    color: var(--muted);
    font-size: 13px;
}

.notice.error { color: #fda4af; }
.hidden { display: none !important; }

@media (max-width: 860px) {
    body {
        padding: 10px;
    }
    .app {
        border-radius: 10px;
    }
    .content { grid-template-columns: 1fr; }
    .auth-panel { border-right: 0; border-bottom: 1px solid var(--border); }
    .admin-inline { flex-wrap: wrap; }
    .header {
        flex-wrap: wrap;
        align-items: flex-start;
        gap: 8px;
    }
    .header-right {
        width: 100%;
        flex-wrap: wrap;
        gap: 8px;
    }
    .user-info {
        width: 100%;
    }
    .header-btn {
        width: auto;
        flex: 1 1 120px;
    }
    .room-row input,
    .room-row select {
        min-width: 0;
        width: 100%;
    }
    .room-row button {
        width: 100%;
    }
    .room-card-actions button {
        flex: 1 1 140px;
        width: auto;
    }
    .chat-layout {
        grid-template-columns: 1fr;
    }
    .room-users-col {
        max-height: none;
    }
    .messages {
        padding: 10px;
    }
    .private-bar {
        flex-direction: column;
        align-items: stretch;
    }
    .composer {
        grid-template-columns: auto 1fr;
        grid-template-areas:
            "emoji input"
            "send send";
    }
    .composer .emoji-toggle {
        grid-area: emoji;
    }
    .composer #messageInput {
        grid-area: input;
        min-width: 0;
    }
    .composer #sendBtn {
        grid-area: send;
    }
    .emoji-panel {
        left: 8px;
        right: 8px;
        width: auto;
    }
    .modal {
        padding: 8px;
    }
    .modal-content {
        width: 100%;
        max-height: 92vh;
    }
}

@media (max-width: 480px) {
    .title {
        font-size: 16px;
    }
    .chat-layout {
        padding: 8px;
        gap: 8px;
    }
    .room-header {
        padding: 8px;
    }
    .messages {
        gap: 8px;
    }
    .msg {
        padding: 8px;
    }
    .room-card {
        padding: 8px;
    }
}
