:root {
  --bg: #f4f6f3;
  --card: #ffffff;
  --ink: #16211b;
  --muted: #64716a;
  --line: #e3e8e2;
  --soft: #eef2ed;
  --green: #1f9d55;
  --green-dark: #167a41;
  --green-pale: #e6f5ec;
  --red: #d6202d;
  --sun: #f7b500;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(22, 33, 27, .10), 0 2px 8px rgba(22, 33, 27, .05);
  --font: "Segoe UI", system-ui, -apple-system, Tahoma, "Noto Sans Arabic", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2 { margin: 0; line-height: 1.2; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid rgba(31, 157, 85, .35); outline-offset: 2px; }

/* brand */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 22px; letter-spacing: -.02em; }
.brand img { width: 38px; height: 25px; display: block; }
.brand-large { justify-content: center; font-size: 30px; margin-bottom: 18px; }
.brand-large img { width: 54px; height: 36px; }

/* forms */
.form { display: grid; gap: 8px; }
.form label { font-size: 13px; font-weight: 600; margin-top: 6px; }
input[type="text"], input[type="password"], input[type="search"] {
  width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: 12px; background: #fff; outline: none;
}
input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(31, 157, 85, .15); }
.form-error { min-height: 20px; margin: 2px 0 0; color: var(--red); font-size: 13px; }
.primary { border: 0; border-radius: 12px; padding: 11px 18px; background: var(--green); color: #fff; font-weight: 700; }
.primary:hover { background: var(--green-dark); }
.primary:disabled { opacity: .6; cursor: default; }
.ghost { border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 11px 18px; font-weight: 600; }
.link-button { border: 0; background: none; color: var(--green-dark); font-weight: 600; font-size: 13px; padding: 4px 6px; border-radius: 8px; }
.link-button:hover { background: var(--green-pale); }
.password-field { position: relative; }
.password-field input { padding-right: 62px; }
.password-field .link-button { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); }

/* auth */
.auth { min-height: 100%; display: grid; place-items: center; padding: 20px; }
.auth-card { width: min(420px, 100%); background: var(--card); border-radius: 22px; padding: 30px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 22px; text-align: center; margin-bottom: 16px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--soft); border-radius: 12px; margin-bottom: 14px; }
.tab { border: 0; background: none; padding: 9px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.tab.is-active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }
.auth-card .primary { margin-top: 4px; }

/* app layout */
.app { height: 100dvh; display: grid; grid-template-columns: 340px 1fr; background: var(--card); }
.side { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: #fbfcfa; }
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px; }
.side-top .brand { font-size: 20px; }
.side-top .brand img { width: 32px; height: 21px; }
.me { display: flex; align-items: center; gap: 2px; min-width: 0; }
.me-name { font-size: 13px; color: var(--muted); max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search { padding: 8px 16px 12px; }
.side-scroll { flex: 1; overflow-y: auto; padding: 0 10px 16px; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 14px 8px 6px; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.make-room { width: calc(100% - 12px); margin: 4px 6px 0; display: flex; align-items: center; justify-content: center; gap: 8px; border: 1.5px dashed #b9d9c6; background: var(--green-pale); color: var(--green-dark); border-radius: 12px; padding: 10px; font-weight: 700; }
.make-room:hover { border-color: var(--green); }

.row { width: 100%; display: flex; align-items: center; gap: 12px; padding: 9px 10px; border: 0; border-radius: 12px; background: none; text-align: start; }
.row:hover { background: var(--soft); }
.row.is-active { background: var(--green-pale); }
.row-body { flex: 1; min-width: 0; display: grid; }
.row-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-actions { display: flex; gap: 6px; }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--red); color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.pill { border: 0; border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 700; background: var(--green); color: #fff; }
.pill.quiet { background: var(--soft); color: var(--muted); }
.pill:disabled { cursor: default; }

.avatar { position: relative; flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 16px; text-transform: uppercase; }
.avatar.c0 { background: #1f9d55; } .avatar.c1 { background: #d6202d; } .avatar.c2 { background: #2f6fdb; }
.avatar.c3 { background: #c98a00; } .avatar.c4 { background: #7b4bd1; } .avatar.c5 { background: #0f8b8d; }
.avatar.on::after { content: ""; position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px; border-radius: 50%; background: #2bd16b; border: 2px solid #fff; }

.empty-card { margin: 10px 6px; padding: 22px 16px; text-align: center; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.empty-card strong { display: block; margin-bottom: 4px; }
.empty-card span { font-size: 13.5px; color: var(--muted); }
.note { margin: 12px 10px; font-size: 13.5px; color: var(--muted); }

/* chat */
.chat { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--bg); }
.empty-chat { flex: 1; display: grid; place-content: center; justify-items: center; gap: 8px; padding: 24px; text-align: center; color: var(--muted); }
.empty-chat img { width: 96px; height: 64px; margin-bottom: 6px; }
.empty-chat h2 { color: var(--ink); font-size: 22px; }
.empty-chat p { margin: 0; }
.convo { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.convo-top { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.convo-title { flex: 1; min-width: 0; display: grid; }
.convo-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.convo-title span { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.convo-actions { display: flex; gap: 6px; }
.icon-button { border: 0; background: var(--soft); width: 36px; height: 36px; border-radius: 50%; font-size: 24px; line-height: 1; }
.back { display: none; }

.messages { flex: 1; overflow-y: auto; padding: 18px 16px; display: flex; flex-direction: column; gap: 6px; }
.msg { display: flex; flex-direction: column; max-width: min(520px, 82%); align-self: flex-start; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg-name { font-size: 12px; font-weight: 700; color: var(--green-dark); margin: 6px 4px 2px; }
.bubble { padding: 9px 13px; border-radius: 16px 16px 16px 4px; background: #fff; border: 1px solid var(--line); overflow-wrap: anywhere; white-space: pre-wrap; }
.msg.mine .bubble { background: var(--green); border-color: var(--green); color: #fff; border-radius: 16px 16px 4px 16px; }
.msg time { font-size: 11px; color: var(--muted); margin: 2px 4px 0; }
.day-empty { margin: auto; text-align: center; color: var(--muted); font-size: 14px; }
.system { align-self: center; font-size: 12.5px; color: var(--muted); }

.status { display: flex; align-items: center; gap: 6px; padding: 4px 18px; font-size: 12px; color: var(--muted); }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: #2bd16b; }
.status.is-offline .dot { background: var(--sun); }
.composer { display: flex; gap: 10px; padding: 8px 16px 16px; }
.composer input { flex: 1; border-radius: 999px; padding: 12px 18px; }
.send { width: 46px; height: 46px; border: 0; border-radius: 50%; background: var(--green); color: #fff; display: grid; place-items: center; }
.send svg { width: 22px; height: 22px; }
.send:disabled { background: #c9d4cd; cursor: default; }

/* dialogs */
dialog { border: 0; border-radius: 20px; padding: 24px; width: min(420px, calc(100% - 32px)); box-shadow: var(--shadow); color: var(--ink); }
dialog::backdrop { background: rgba(10, 20, 14, .45); }
dialog h2 { font-size: 20px; margin-bottom: 6px; }
.check-list { max-height: 220px; overflow-y: auto; display: grid; gap: 2px; border: 1px solid var(--line); border-radius: 12px; padding: 6px; }
.check-list label { display: flex; align-items: center; gap: 10px; margin: 0; padding: 7px 8px; border-radius: 8px; font-weight: 500; cursor: pointer; }
.check-list label:hover { background: var(--soft); }
.check-list input { width: 18px; height: 18px; accent-color: var(--green); }
.check-list .note { margin: 8px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); z-index: 10; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* mobile */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .app[data-view="list"] .chat { display: none; }
  .app[data-view="chat"] .side { display: none; }
  .back { display: block; }
  .auth-card { padding: 24px 20px; }
}

@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
