:root {
  --teal-900: #0b2f2e; --teal-800: #0e3b3a; --teal-700: #14524f; --teal-500: #1f7a74;
  --sand-50: #fbf8f1; --sand-100: #f4eee1; --sand-200: #e8dfcc; --sand-300: #d8ccb3;
  --ink: #1d2a29; --muted: #6b7773; --amber: #e3a63a; --amber-700: #b77d17; --red: #c2452f;
  --mine: #d9efe6; --theirs: #ffffff; --radius: 16px;
  --font: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body { font-family: var(--font); color: var(--ink); background: var(--sand-100); font-size: 15px; line-height: 1.5; -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }

.btn { border: 0; border-radius: 12px; padding: 11px 18px; font-weight: 600; background: var(--sand-200); display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; }
.btn.primary { background: var(--teal-800); color: #fff; }
.btn.primary:hover { background: var(--teal-700); }
.btn.small { padding: 6px 12px; border-radius: 999px; font-size: 13px; background: var(--amber); color: var(--teal-900); }
.btn.small svg { width: 15px; height: 15px; stroke-width: 2.4; }
.btn:disabled { opacity: .6; cursor: default; }
.link { background: none; border: 0; padding: 4px; color: var(--teal-500); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.icon-btn { border: 0; background: transparent; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none; color: inherit; }
.icon-btn:hover { background: rgba(127, 127, 127, .16); }
.icon-btn.accent { color: var(--teal-500); }
.icon-btn.solid { background: var(--teal-800); color: #fff; }
.icon-btn.solid:hover { background: var(--teal-700); }
.icon-btn.recording { background: var(--red); color: #fff; }
.lang-btn { font-weight: 700; font-size: 13px; }
[dir="rtl"] .flip, [dir="rtl"] .back svg { transform: scaleX(-1); }
.error { color: var(--red); font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; }

/* ---------- auth ---------- */
.auth { height: 100dvh; overflow-y: auto; display: grid; place-items: center; padding: 24px; position: relative;
  background: radial-gradient(1200px 600px at 80% -10%, #1b6560 0%, transparent 60%), var(--teal-800); }
.auth-lang { position: absolute; top: 16px; inset-inline-end: 16px; color: #fff; border: 1px solid rgba(255,255,255,.35); background: transparent; border-radius: 999px; padding: 6px 14px; }
.auth-card { width: min(400px, 100%); background: var(--sand-50); border-radius: 24px; padding: 32px 28px; box-shadow: 0 30px 60px rgba(0,0,0,.3); display: grid; gap: 18px; justify-items: stretch; }
.brand { text-align: center; display: grid; gap: 6px; justify-items: center; }
.brand h1 { font-size: 28px; letter-spacing: -.01em; }
.brand h1 span { color: var(--amber-700); margin-inline-start: 6px; }
.brand p { color: var(--muted); }
.brand-mark { width: 56px; height: 56px; border-radius: 18px; background: var(--teal-800); position: relative; }
.brand-mark::after { content: ""; position: absolute; inset: 15px 12px 17px; border-radius: 8px 8px 8px 2px; background: var(--amber); }
.brand-mark.big { width: 84px; height: 84px; border-radius: 26px; opacity: .9; }
.brand-mark.big::after { inset: 23px 18px 26px; border-radius: 12px 12px 12px 3px; }
#auth-form { display: grid; gap: 14px; }
#auth-form label { display: grid; gap: 6px; font-weight: 500; font-size: 14px; }
input:not([type=checkbox]), select, textarea { border: 1.5px solid var(--sand-300); background: #fff; border-radius: 12px; padding: 11px 14px; width: 100%; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--teal-500); }
.auth-card .link { justify-self: center; }

/* ---------- layout ---------- */
.app { height: 100dvh; display: grid; grid-template-columns: 340px 1fr; }
.side { background: var(--teal-800); color: #eef5f2; display: flex; flex-direction: column; min-height: 0; }
.side-head { display: flex; align-items: center; gap: 4px; padding: 14px 12px 10px 16px; padding-inline: 16px 12px; }
.me { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.me-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; flex: none; position: relative; text-transform: uppercase; background: var(--teal-500); }
.avatar.group { border-radius: 14px; }
.avatar.on::after { content: ""; position: absolute; inset-block-end: 0; inset-inline-end: 0; width: 11px; height: 11px; border-radius: 50%; background: #48c774; border: 2px solid var(--dot-ring, var(--teal-800)); }

.prayer { margin: 4px 12px 10px; padding: 10px 14px; border: 1px solid rgba(255,255,255,.14); background: rgba(255,255,255,.07); color: inherit; border-radius: 14px; display: flex; align-items: center; gap: 10px; text-align: start; }
.prayer:hover { background: rgba(255,255,255,.12); }
.prayer svg { color: var(--amber); }
.prayer-text { flex: 1; display: grid; line-height: 1.3; }
.prayer-text small { opacity: .7; font-size: 12px; }
.prayer-time { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--amber); }

.side-title { display: flex; align-items: center; justify-content: space-between; padding: 6px 16px 8px; }
.side-title h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; opacity: .65; font-weight: 600; }
.conv-list { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.conv { width: 100%; border: 0; background: transparent; color: inherit; display: flex; gap: 12px; align-items: center; padding: 10px; border-radius: 14px; text-align: start; }
.conv:hover { background: rgba(255,255,255,.07); }
.conv.active { background: rgba(255,255,255,.14); }
.conv-body { flex: 1; min-width: 0; display: grid; }
.conv-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.conv-top b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.conv-top time { font-size: 11px; opacity: .6; flex: none; }
.conv-bottom { display: flex; gap: 8px; align-items: center; }
.conv-bottom span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; opacity: .7; }
.conv-bottom span.typing { color: var(--amber); opacity: 1; }
.badge { background: var(--amber); color: var(--teal-900); font-size: 11px; font-weight: 700; border-radius: 999px; min-width: 20px; height: 20px; padding: 0 6px; display: grid; place-items: center; flex: none; }
.conn { background: var(--amber); color: var(--teal-900); text-align: center; font-size: 13px; padding: 6px; font-weight: 600; }

/* ---------- chat ---------- */
.chat { min-width: 0; min-height: 0; display: flex; flex-direction: column; background:
  radial-gradient(circle at 1px 1px, rgba(14,59,58,.07) 1px, transparent 0) 0 0 / 22px 22px, var(--sand-100); }
.empty { margin: auto; text-align: center; color: var(--muted); display: grid; gap: 16px; justify-items: center; padding: 24px; }
.chat-inner { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--sand-50); border-bottom: 1px solid var(--sand-200); --dot-ring: var(--sand-50); }
.chat-title { display: grid; line-height: 1.3; min-width: 0; }
.chat-title b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-title small { color: var(--muted); font-size: 12.5px; min-height: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-title small.typing { color: var(--teal-500); font-weight: 600; }
.back { display: none; margin-inline-start: -8px; }
.alert { position: fixed; z-index: 70; inset-block-start: 12px; inset-inline: 0; margin-inline: auto; width: fit-content; max-width: calc(100vw - 24px); border: 2px solid var(--amber); border-radius: 16px; box-shadow: 0 12px 40px rgba(0,0,0,.35); background: var(--teal-800); color: #fff; padding: 12px 20px; display: flex; gap: 10px; align-items: center; justify-content: center; font-weight: 600; text-align: center; }
.alert::before { content: "☾"; color: var(--amber); font-size: 18px; }

.messages { flex: 1; overflow-y: auto; padding: 16px max(16px, calc((100% - 820px) / 2)); display: flex; flex-direction: column; gap: 3px; overscroll-behavior: contain; }
.day { align-self: center; background: var(--sand-200); color: var(--muted); font-size: 12px; padding: 3px 12px; border-radius: 999px; margin: 10px 0 6px; }
.more { align-self: center; margin-bottom: 8px; }
.msg { max-width: min(78%, 560px); align-self: flex-start; background: var(--theirs); border-radius: 6px var(--radius) var(--radius) var(--radius); padding: 7px 12px 5px; box-shadow: 0 1px 1px rgba(0,0,0,.06); position: relative; overflow-wrap: anywhere; }
[dir="rtl"] .msg { border-radius: var(--radius) 6px var(--radius) var(--radius); }
.msg.mine { align-self: flex-end; background: var(--mine); border-radius: var(--radius) 6px var(--radius) var(--radius); }
[dir="rtl"] .msg.mine { border-radius: 6px var(--radius) var(--radius) var(--radius); }
.msg.first { margin-top: 8px; }
.msg.pending { opacity: .6; }
.msg .who { font-size: 12.5px; font-weight: 700; display: block; margin-bottom: 1px; }
.msg .meta { display: block; font-size: 10.5px; color: var(--muted); text-align: end; margin-top: 1px; direction: ltr; }
[dir="rtl"] .msg .meta { text-align: start; }
.msg.media { padding: 4px 4px 3px; }
.msg.media .who, .msg.media .meta, .msg.media .md { padding: 0 8px; }
.msg img.pic { display: block; max-width: 100%; max-height: 340px; border-radius: 13px; cursor: zoom-in; background: var(--sand-200); min-width: 80px; min-height: 60px; }
.md p { margin: 0; white-space: pre-wrap; }
.md p + p, .md ul, .md ol, .md pre, .md blockquote { margin: 6px 0 0; }
.md ul, .md ol { padding-inline-start: 22px; }
.md h4 { margin: 2px 0; font-size: 1.08em; }
.md code { font-family: "IBM Plex Mono", ui-monospace, Menlo, monospace; font-size: .88em; background: rgba(14,59,58,.09); padding: 1px 5px; border-radius: 5px; direction: ltr; unicode-bidi: embed; }
.md pre { background: var(--teal-900); color: #e6f2ee; padding: 10px 12px; border-radius: 10px; overflow-x: auto; direction: ltr; text-align: left; }
.md pre code { background: none; padding: 0; color: inherit; }
.md blockquote { border-inline-start: 3px solid var(--amber); padding-inline-start: 10px; color: var(--muted); }
.md a { color: var(--teal-500); }
.voice { display: flex; align-items: center; gap: 10px; padding: 4px 8px 2px; min-width: 190px; }
.voice audio { height: 36px; max-width: 240px; }
.voice .icon-btn { background: var(--teal-800); color: #fff; }
.voice span { font-size: 13px; color: var(--muted); }

.composer { display: flex; align-items: flex-end; gap: 6px; padding: 10px max(12px, calc((100% - 820px) / 2)); padding-bottom: max(10px, env(safe-area-inset-bottom)); background: var(--sand-50); border-top: 1px solid var(--sand-200); }
.composer textarea { flex: 1; resize: none; max-height: 140px; border-radius: 20px; padding: 9px 16px; line-height: 1.45; }
.rec { flex: 1; display: flex; align-items: center; gap: 10px; height: 40px; padding: 0 12px; font-variant-numeric: tabular-nums; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .rec-dot { animation: none; } }

/* ---------- dialogs ---------- */
.dialog { border: 0; border-radius: 20px; padding: 20px; width: min(420px, calc(100vw - 32px)); background: var(--sand-50); color: var(--ink); box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.dialog[open] { display: grid; gap: 12px; }
.dialog::backdrop { background: rgba(11,47,46,.55); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.user-list { max-height: 44vh; overflow-y: auto; display: grid; gap: 2px; }
.user-row { display: flex; align-items: center; gap: 10px; padding: 6px 4px; border-radius: 12px; --dot-ring: var(--sand-50); }
.user-row:hover { background: var(--sand-100); }
.user-row label { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; cursor: pointer; }
.user-row input { width: 18px; height: 18px; accent-color: var(--teal-800); flex: none; }
.user-row .avatar { width: 34px; height: 34px; font-size: 14px; }
.user-row b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.user-row .btn { padding: 6px 12px; font-size: 13px; }
.group-make { display: flex; gap: 8px; }
.group-make input { min-width: 0; }
.prayer-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.prayer-list li { display: flex; justify-content: space-between; padding: 8px 12px; border-radius: 10px; font-variant-numeric: tabular-nums; }
.prayer-list li.next { background: var(--teal-800); color: #fff; font-weight: 600; }
.prayer-list li.dim { color: var(--muted); }
.row { display: grid; grid-template-columns: 110px 1fr; align-items: center; gap: 10px; font-size: 14px; }
.row.check { grid-template-columns: auto 1fr; cursor: pointer; }
.row.check input { width: 18px; height: 18px; accent-color: var(--teal-800); }

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.88); display: grid; place-items: center; z-index: 50; cursor: zoom-out; padding: 16px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }
.toast { position: fixed; inset-block-end: 84px; inset-inline: 0; margin-inline: auto; width: fit-content; max-width: calc(100vw - 32px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; z-index: 60; font-size: 14px; }

/* ---------- phone ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .chat { position: fixed; inset: 0; transform: translateX(100%); transition: transform .22s ease; z-index: 10; }
  [dir="rtl"] .chat { transform: translateX(-100%); }
  .app.open .chat { transform: none; }
  .back { display: grid; }
  .empty { display: none; }
  .msg { max-width: 86%; }
  input, select, textarea { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) { .chat { transition: none; } }

/* ---------- Google sign-in ---------- */
.google-wrap { display: grid; gap: 14px; justify-items: center; }
.or { width: 100%; display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--sand-300); }
#google-btn { min-height: 44px; color-scheme: light; }
