:root {
    --ink: #17211f;
    --muted: #697571;
    --line: #dfe5e2;
    --surface: #ffffff;
    --surface-soft: #f5f7f6;
    --canvas: #edf1ef;
    --green: #166b57;
    --green-dark: #0d5544;
    --green-soft: #dff2e9;
    --amber-soft: #fff0c7;
    --danger: #a83a3a;
    --shadow: 0 18px 55px rgba(20, 43, 36, .13);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--canvas);
    font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { min-height: 100vh; }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .65; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.login-page {
    display: grid;
    place-items: center;
    padding: 24px;
    background-color: #e6ede9;
    background-image: url("chat-pattern.svg");
}

.login-shell { width: min(100%, 430px); }
.login-panel {
    background: var(--surface);
    border: 1px solid rgba(15, 54, 43, .1);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 36px;
}
.brand-mark {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border-radius: 8px;
    color: white;
    background: var(--green);
    font-size: 22px;
    font-weight: 800;
}
.brand-mark-small { width: 38px; height: 38px; font-size: 17px; }
.login-heading { margin: 0 0 24px; }
.login-heading h1, .panel-header h1 { margin: 4px 0 0; font-size: 25px; line-height: 1.2; letter-spacing: 0; }
.login-heading p:not(.eyebrow) { margin: 10px 0 0; color: var(--muted); line-height: 1.55; }
.eyebrow { margin: 0; color: var(--green); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 0; }

.stack-form { display: grid; gap: 17px; }
label span, .setting-row label { display: block; margin-bottom: 7px; font-size: 13px; font-weight: 700; }
input, textarea, select {
    width: 100%;
    border: 1px solid #cbd4d0;
    border-radius: 6px;
    color: var(--ink);
    background: white;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
input, select { height: 43px; padding: 0 12px; }
textarea { padding: 11px 13px; resize: none; }
input:focus, textarea:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(22, 107, 87, .12); }

.button {
    min-height: 40px;
    border: 1px solid #cbd4d0;
    border-radius: 6px;
    padding: 8px 15px;
    color: var(--ink);
    background: white;
    font-weight: 700;
}
.button:hover { background: var(--surface-soft); }
.button-primary { border-color: var(--green); color: white; background: var(--green); }
.button-primary:hover { background: var(--green-dark); }
.button-quiet { color: var(--muted); background: transparent; }
.button-small { min-height: 32px; padding: 5px 9px; font-size: 12px; }
.stack-form .button { width: 100%; margin-top: 4px; }

.alert { margin: 0 0 18px; border: 1px solid var(--line); border-radius: 6px; padding: 11px 13px; font-size: 14px; }
.alert-error { border-color: #efcaca; color: #862d2d; background: #fff1f1; }
.alert-success { border-color: #b9dfd0; color: #145947; background: #ecf8f3; }

.app-page { overflow: hidden; }
.app-shell { display: grid; grid-template-columns: 244px minmax(0, 1fr); height: 100vh; min-height: 560px; background: var(--surface-soft); }
.sidebar { display: flex; flex-direction: column; min-width: 0; border-right: 1px solid var(--line); background: var(--surface); }
.brand { display: flex; align-items: center; gap: 11px; min-height: 76px; padding: 17px 20px; border-bottom: 1px solid var(--line); }
.brand strong, .brand span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand strong { font-size: 15px; }
.brand span { margin-top: 2px; color: var(--muted); font-size: 12px; }
.main-nav { display: grid; gap: 4px; padding: 16px 12px; }
.nav-label { margin: 10px 11px 5px; color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.nav-label:first-child { margin-top: 0; }
.room-nav { display: grid; gap: 4px; min-width: 0; }
.room-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 42px;
    border: 0;
    border-radius: 6px;
    padding: 8px 11px;
    color: #46514e;
    background: transparent;
    text-align: left;
    font-size: 14px;
    font-weight: 700;
}
.nav-item:hover { background: var(--surface-soft); }
.nav-item.is-active { color: var(--green-dark); background: var(--green-soft); }
.nav-icon { display: grid; place-items: center; width: 20px; height: 20px; font-size: 17px; font-weight: 800; }
.unread-badge { min-width: 20px; margin-left: auto; border-radius: 10px; padding: 2px 6px; color: white; background: var(--green); text-align: center; font-size: 11px; }
.account { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 9px; align-items: center; margin-top: auto; padding: 14px 16px; border-top: 1px solid var(--line); }
.avatar { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; color: var(--green-dark); background: var(--green-soft); font-size: 13px; font-weight: 800; }
.account-name { min-width: 0; }
.account-name strong, .account-name span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-name strong { font-size: 13px; }
.account-name span { color: var(--muted); font-size: 11px; }
.account form { grid-column: 1 / -1; }
.logout-button { width: 100%; min-height: 34px; border: 1px solid var(--line); border-radius: 5px; color: #596461; background: var(--surface-soft); font-size: 12px; font-weight: 700; }
.logout-button:hover { color: var(--danger); border-color: #e7c4c4; background: #fff5f5; }

.workspace { min-width: 0; min-height: 0; }
.panel { display: none; height: 100%; min-height: 0; }
.panel.is-active { display: flex; flex-direction: column; }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; flex: 0 0 76px; padding: 14px 28px; border-bottom: 1px solid var(--line); background: var(--surface); }
.panel-header h1 { font-size: 20px; }
.chat-actions { display: flex; align-items: center; gap: 16px; }
.notification-button { min-height: 34px; border: 1px solid var(--line); border-radius: 5px; padding: 6px 10px; color: #52605c; background: var(--surface-soft); font-size: 11px; font-weight: 700; }
.notification-button:hover { border-color: #b9c8c2; background: white; }
.notification-button.is-enabled { color: var(--green-dark); border-color: #b9dfd0; background: var(--green-soft); }
.connection-status { display: flex; align-items: center; color: var(--muted); font-size: 12px; font-weight: 700; }
.connection-status span { width: 8px; height: 8px; margin-right: 7px; border-radius: 50%; background: #2f966e; box-shadow: 0 0 0 3px #dff2e9; }
.connection-status.is-offline span { background: #bb4a4a; box-shadow: 0 0 0 3px #fae1e1; }

.messages {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 26px max(24px, calc((100% - 920px) / 2));
    background-color: #edf1ef;
    background-image: linear-gradient(rgba(237, 241, 239, .89), rgba(237, 241, 239, .89)), url("chat-pattern.svg");
    scroll-behavior: smooth;
}
.empty-state { position: absolute; top: 50%; left: 50%; width: min(320px, 80%); transform: translate(-50%, -50%); text-align: center; }
.empty-icon { display: grid; place-items: center; width: 46px; height: 46px; margin: 0 auto 13px; border-radius: 8px; color: var(--green); background: var(--green-soft); font-size: 22px; font-weight: 800; }
.empty-state h2 { margin: 0; font-size: 17px; }
.empty-state p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.message { width: fit-content; max-width: min(70%, 660px); margin: 0 0 10px; border: 1px solid rgba(21, 50, 42, .08); border-radius: 7px; padding: 9px 12px 8px; background: white; box-shadow: 0 2px 8px rgba(24, 48, 42, .06); }
.message-own { margin-left: auto; background: var(--amber-soft); }
.message-meta { display: flex; align-items: baseline; justify-content: space-between; gap: 18px; margin-bottom: 4px; }
.message-meta strong { color: var(--green-dark); font-size: 12px; }
.message-meta time { color: var(--muted); font-size: 10px; white-space: nowrap; }
.message p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.45; }
.composer { display: flex; align-items: flex-end; gap: 10px; flex: 0 0 auto; padding: 13px max(24px, calc((100% - 920px) / 2)); border-top: 1px solid var(--line); background: var(--surface); }
.composer textarea { min-height: 44px; max-height: 132px; }
.send-button { flex: 0 0 auto; min-width: 88px; height: 44px; border: 0; border-radius: 6px; color: white; background: var(--green); font-size: 13px; font-weight: 800; }
.send-button:hover { background: var(--green-dark); }

.admin-panel { background: var(--surface-soft); }
.admin-content { flex: 1; min-height: 0; overflow-y: auto; padding: 28px; }
.admin-content.narrow { max-width: 920px; width: 100%; }
.inline-editor, .settings-form, .table-wrap { border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.inline-editor { display: grid; grid-template-columns: 1.25fr 1fr 1fr auto; gap: 18px; align-items: end; margin-bottom: 20px; padding: 20px; }
.inline-editor h2 { margin: 0 0 5px; font-size: 16px; }
.inline-editor p, .setting-row p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.form-actions { display: flex; gap: 8px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { padding: 11px 15px; color: var(--muted); background: var(--surface-soft); text-align: left; font-size: 11px; text-transform: uppercase; }
td { padding: 14px 15px; border-top: 1px solid var(--line); vertical-align: middle; }
td strong, td > span:not(.status-badge) { display: block; }
td > span:not(.status-badge) { min-height: 15px; margin-top: 2px; color: var(--muted); font-size: 11px; }
.status-badge { display: inline-block; border-radius: 12px; padding: 4px 8px; font-size: 11px; font-weight: 700; }
.status-active { color: #145947; background: var(--green-soft); }
.status-disabled { color: #7b4d27; background: #f8eadc; }
.row-actions { display: flex; justify-content: flex-end; gap: 7px; white-space: nowrap; }
.room-editor { display: grid; grid-template-columns: minmax(180px, .8fr) minmax(220px, 1fr) minmax(260px, 1.4fr) auto; gap: 18px; align-items: end; margin-bottom: 20px; padding: 20px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.room-editor h2 { margin: 0 0 5px; font-size: 16px; }
.room-editor p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.room-editor fieldset { min-width: 0; margin: 0; border: 0; padding: 0; }
.room-editor legend { margin-bottom: 7px; padding: 0; font-size: 13px; font-weight: 700; }
.member-choices { display: flex; flex-wrap: wrap; gap: 7px; max-height: 92px; overflow-y: auto; }
.member-choice { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 5px; padding: 6px 8px; background: var(--surface-soft); font-size: 12px; }
.member-choice input { width: 15px; height: 15px; margin: 0; }
.member-choice span { margin: 0; font-weight: 600; }
.settings-form { overflow: hidden; }
.setting-row { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(220px, 320px); gap: 28px; align-items: center; padding: 22px; border-bottom: 1px solid var(--line); }
.setting-row label { margin-bottom: 4px; }
.settings-footer { display: flex; justify-content: flex-end; padding: 18px 22px; background: var(--surface-soft); }

@media (max-width: 820px) {
    .app-shell { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
    .sidebar { display: grid; grid-template-columns: minmax(130px, 1fr) auto; grid-template-rows: auto auto; border-right: 0; border-bottom: 1px solid var(--line); }
    .brand { min-height: 58px; padding: 10px 14px; border-bottom: 0; }
    .brand span, .account-name, .avatar { display: none; }
    .main-nav { grid-column: 1 / -1; grid-row: 2; display: flex; overflow-x: auto; padding: 0 8px 8px; }
    .nav-label { display: none; }
    .room-nav { display: flex; gap: 4px; }
    .nav-item { justify-content: center; min-width: max-content; min-height: 36px; padding: 6px 10px; }
    .account { display: block; margin: 0; padding: 11px 12px; border: 0; }
    .account form { height: 36px; }
    .logout-button { height: 36px; }
    .panel-header { flex-basis: 64px; padding: 10px 16px; }
    .chat-actions { gap: 9px; }
    .messages { padding: 16px 12px; }
    .composer { padding: 10px; }
    .message { max-width: 88%; }
    .admin-content { padding: 16px; }
    .inline-editor { grid-template-columns: 1fr; align-items: stretch; }
    .room-editor { grid-template-columns: 1fr; align-items: stretch; }
}

@media (max-width: 560px) {
    .login-page { padding: 14px; }
    .login-panel { padding: 26px 22px; }
    .brand-mark-small { width: 34px; height: 34px; }
    .brand { min-width: 0; }
    .brand strong { max-width: 120px; }
    .nav-icon { display: none; }
    .connection-status { font-size: 0; }
    .connection-status span { margin-right: 0; }
    .send-button { min-width: 68px; }
    .setting-row { grid-template-columns: 1fr; gap: 12px; }
    .panel-header .button { min-height: 36px; padding: 7px 10px; font-size: 12px; }
    .notification-button { max-width: 116px; min-height: 32px; padding: 5px 7px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
