:root {
    --ink: #17231f;
    --muted: #71807a;
    --paper: #f5f7f2;
    --white: #fff;
    --line: #dfe7df;
    --green: #176b4c;
    --lime: #c9ef6b;
    --navy: #203d58;
    --shadow: 0 24px 70px rgba(30, 56, 42, .10);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    color: var(--ink);
    background: var(--paper);
    font-family: "IBM Plex Sans Arabic", sans-serif;
    direction: rtl;
}
body:before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    opacity: .38;
    background-image: radial-gradient(#d7e1d9 .7px, transparent .7px);
    background-size: 16px 16px;
}
.chat-top, .chat-shell, .gate { position: relative; z-index: 1; }
.chat-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 24px;
    border-bottom: 1px solid var(--line);
    background: rgba(255,255,255,.82);
}
.brand { display: flex; gap: 11px; align-items: center; text-decoration: none; color: inherit; }
.brand-mark {
    display: grid; place-items: center; width: 37px; height: 37px; border-radius: 11px;
    background: var(--lime); font: 800 20px Cairo, sans-serif; transform: rotate(-7deg);
}
.brand strong { display: block; font: 800 18px Cairo, sans-serif; }
.brand small { display: block; color: var(--muted); font-size: 10px; }
.chat-nav { display: flex; align-items: center; gap: 18px; font-size: 13px; font-weight: 600; }
.chat-nav a { color: inherit; text-decoration: none; }
.chat-nav a:hover { color: var(--green); }
.live-dot { color: var(--green); font: 700 11px Cairo, sans-serif; }
.live-dot:before {
    content: ""; display: inline-block; width: 7px; height: 7px; margin-left: 7px;
    border-radius: 50%; background: #71c26f; box-shadow: 0 0 0 4px #dcefd6;
}
.live-dot.off { color: var(--muted); }
.live-dot.off:before { background: #c4cfc6; box-shadow: none; }
.chat-shell {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr) 220px;
    height: calc(100vh - 74px);
}
.rooms-pane, .people-pane {
    background: rgba(255,255,255,.72);
    border-left: 1px solid var(--line);
    padding: 18px 14px;
    overflow: auto;
}
.people-pane { border-left: 0; border-right: 1px solid var(--line); }
.pane-kicker { margin: 0 8px 12px; color: var(--muted); font: 700 11px Cairo, sans-serif; letter-spacing: .4px; }
.room-btn, .person {
    display: grid; gap: 3px; width: 100%; margin: 0 0 8px; padding: 12px 12px;
    border: 1px solid transparent; border-radius: 8px; background: transparent;
    text-align: right; cursor: pointer; color: inherit; font: inherit;
}
.room-btn small, .person small { color: var(--muted); font-size: 11px; }
.room-btn.active, .room-btn:hover { background: #fff; border-color: var(--line); box-shadow: var(--shadow); }
.room-btn strong { font: 700 14px Cairo, sans-serif; }
.me-card {
    display: flex; gap: 10px; align-items: center; margin-top: 18px; padding: 12px;
    border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
.avatar, .bubble-avatar {
    display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
    background: var(--lime); color: var(--ink); font: 800 14px Cairo, sans-serif; flex: 0 0 auto;
}
.me-card strong, .person strong { display: block; font-size: 13px; }
.me-card small { color: var(--muted); font-size: 11px; }
.thread-pane { display: flex; flex-direction: column; min-width: 0; background: rgba(255,255,255,.45); }
.thread-head {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.thread-head h1 { margin: 0; font: 800 22px Cairo, sans-serif; }
.thread-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.ghost-btn {
    display: none; border: 1px solid var(--line); background: #fff; border-radius: 8px;
    padding: 8px 12px; font: 700 12px Cairo, sans-serif; cursor: pointer;
}
.messages { flex: 1; overflow: auto; padding: 18px 20px 8px; display: flex; flex-direction: column; gap: 12px; }
.msg { display: flex; gap: 10px; max-width: min(680px, 100%); }
.msg.mine { align-self: flex-start; flex-direction: row-reverse; }
.msg-body { padding: 10px 12px; border-radius: 12px; background: #fff; border: 1px solid var(--line); }
.msg.mine .msg-body { background: #e8f4ea; border-color: #cfe6d4; }
.msg-meta { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; font-size: 11px; color: var(--muted); }
.msg-meta b { color: var(--ink); font: 700 12px Cairo, sans-serif; }
.badge { padding: 2px 7px; border-radius: 999px; font: 700 9px Cairo, sans-serif; }
.badge.admin { background: var(--navy); color: #fff; }
.badge.subscriber { background: var(--lime); color: var(--ink); }
.badge.member { background: #e0f1e4; color: var(--green); }
.msg p { margin: 0; white-space: pre-wrap; line-height: 1.8; font-size: 14px; }
.msg .del {
    border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 11px;
}
.typing { min-height: 18px; margin: 0 20px 6px; color: var(--green); font-size: 12px; }
.composer {
    display: flex; gap: 8px; padding: 14px 18px 18px; border-top: 1px solid var(--line); background: rgba(255,255,255,.9);
}
.composer input {
    flex: 1; padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px;
    font: 14px "IBM Plex Sans Arabic", sans-serif; background: #fbfcfa; outline: none;
}
.composer input:focus { border-color: var(--green); box-shadow: 0 0 0 3px #e0f0e8; }
.send-btn {
    border: 0; border-radius: 10px; padding: 0 18px; color: #fff; background: var(--green);
    font: 700 13px Cairo, sans-serif; cursor: pointer;
}
.send-btn:disabled { opacity: .55; cursor: not-allowed; }
.gate {
    position: fixed; inset: 0; display: grid; place-items: center;
    background: rgba(23, 35, 31, .28); backdrop-filter: blur(8px);
}
.gate-card {
    width: min(420px, 92vw); display: grid; gap: 10px; padding: 28px;
    background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
}
.gate-card h2 { margin: 8px 0 0; font: 800 24px Cairo, sans-serif; }
.gate-card p, .quiet { color: var(--muted); font-size: 13px; line-height: 1.9; }
.gate-card label { font-size: 12px; font-weight: 700; }
.gate-card input { padding: 13px 14px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.telegram-login { display: grid; place-items: center; min-height: 48px; direction: ltr; margin: 8px 0 4px; }
.gate-error { margin: 0; padding: 10px 12px; border-right: 3px solid #cf8d42; color: #79521c; background: #fff5df; font-size: 12px; }
.guest-form { display: grid; gap: 10px; margin-top: 8px; }
.guest-toggle { display: inline-flex; width: 100%; justify-content: center; }
.field-help { color: var(--muted); font-size: 12px; line-height: 1.8; margin: 0; }
.field-help b { color: var(--green); direction: ltr; display: inline-block; }
.empty {
    margin: auto; text-align: center; color: var(--muted); padding: 40px 12px;
}
.people { display: grid; gap: 4px; }
@media (max-width: 980px) {
    .chat-shell { grid-template-columns: 1fr; }
    .rooms-pane { display: flex; gap: 8px; overflow-x: auto; border-left: 0; border-bottom: 1px solid var(--line); }
    .rooms { display: flex; gap: 8px; }
    .room-btn { min-width: 150px; margin: 0; }
    .me-card { display: none; }
    .people-pane { display: none; position: absolute; inset: 74px 0 auto auto; width: min(260px, 80vw); height: calc(100vh - 74px); z-index: 3; }
    .people-pane.open { display: block; }
    .ghost-btn { display: inline-flex; }
    .chat-nav a:nth-child(2) { display: none; }
}
