/* FinjanHost chat — WhatsApp-style layout (RTL). */
:root {
  --bar: #008069; --bar-fg: #fff; --accent: #00a884; --accent-fg: #fff;
  --bg: #fff; --fg: #111b21; --muted: #667781; --line: #e9edef;
  --chat-bg: #efeae2; --dot: rgba(0, 0, 0, .045);
  --in: #fff; --out: #d9fdd3; --tick: #53bdeb; --chip: #fff; --note: #ffeecd; --note-fg: #54656f;
  --danger: #ea0038; --sheet: #fff; --field: #fff; --code: rgba(0, 0, 0, .06);
  --shadow: 0 1px .5px rgba(11, 20, 26, .13);
  font-family: "Segoe UI", system-ui, "Noto Sans Arabic", Tahoma, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bar: #202c33; --bar-fg: #e9edef; --accent: #00a884; --accent-fg: #111b21;
    --bg: #111b21; --fg: #e9edef; --muted: #8696a0; --line: #222d34;
    --chat-bg: #0b141a; --dot: rgba(255, 255, 255, .035);
    --in: #202c33; --out: #005c4b; --chip: #182229; --note: #182229; --note-fg: #ffd279;
    --sheet: #233138; --field: #2a3942; --code: rgba(255, 255, 255, .08);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); overscroll-behavior: none; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
svg { width: 24px; height: 24px; fill: currentColor; flex: none; }
.muted { color: var(--muted); }

/* ---------- auth ---------- */
.auth { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; padding: 2rem; text-align: center; }
.auth h1 { margin: 0; font-weight: 500; }
.logo { width: 96px; height: 96px; }
.primary { background: var(--accent); color: var(--accent-fg); font-weight: 600; border-radius: 24px; padding: .75em 1.4em; }
.ghost { color: var(--accent); font-weight: 600; padding: .75em 1.2em; }
.big { width: 100%; max-width: 320px; padding: 1em; font-size: 1.05rem; }
.error { color: var(--danger); min-height: 1.4em; }

/* ---------- screens ---------- */
.screen { height: 100dvh; display: flex; flex-direction: column; position: relative; overflow: hidden; }
.topbar { display: flex; align-items: center; gap: .35rem; min-height: 56px; padding: 0 .5rem; padding-top: env(safe-area-inset-top); background: var(--bar); color: var(--bar-fg); flex: none; }
.brand { flex: 1; margin: 0 .5rem; font-size: 1.3rem; font-weight: 600; }
.icon { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; color: inherit; }
.icon:active { background: rgba(255, 255, 255, .15); }

/* ---------- avatars ---------- */
.avatar { width: 49px; height: 49px; border-radius: 50%; display: grid; place-items: center; flex: none; overflow: hidden; background: #dfe5e7; color: #fff; }
.avatar.claude { background: #6b4430; }
.avatar.claude img { width: 100%; height: 100%; }
.avatar.group { background: #9fb4bd; }
.avatar.group svg { width: 28px; height: 28px; }
.avatar.sm { width: 40px; height: 40px; }
.chat-top .avatar { width: 38px; height: 38px; }
.chat-top .avatar.group svg { width: 22px; height: 22px; }

/* ---------- chats list ---------- */
.chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.chat-item { width: 100%; display: flex; align-items: center; gap: .8rem; padding: .55rem .9rem; text-align: start; }
.chat-item:active { background: var(--line); }
.ci-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .2rem; padding: .35rem 0 .5rem; border-bottom: 1px solid var(--line); }
.ci-top { display: flex; align-items: baseline; gap: .4rem; }
.ci-title { flex: 1; font-size: 1.05rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-time { font-size: .75rem; color: var(--muted); flex: none; }
.ci-tag { font-size: .65rem; color: var(--accent); border: 1px solid var(--accent); border-radius: 8px; padding: 0 .35em; flex: none; }
.ci-prev { color: var(--muted); font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: .2rem; }
.ci-prev svg { width: 16px; height: 16px; }
.ci-prev.typing { color: var(--accent); font-weight: 500; }
.ci-sender { flex: none; }
.ci-prev .tick { color: var(--tick); font-size: .8rem; letter-spacing: -3px; margin-inline-end: .3rem; flex: none; }
.list-empty { text-align: center; color: var(--muted); padding: 3rem 1.5rem; line-height: 1.8; }
.fab { position: absolute; inset-inline-start: auto; inset-inline-end: 16px; bottom: calc(18px + env(safe-area-inset-bottom)); width: 56px; height: 56px; border-radius: 16px; background: var(--accent); color: var(--accent-fg); display: grid; place-items: center; box-shadow: 0 2px 8px rgba(0, 0, 0, .25); }

/* ---------- bottom sheet ---------- */
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .4); display: flex; align-items: flex-end; z-index: 20; }
.sheet { width: 100%; background: var(--sheet); border-radius: 16px 16px 0 0; padding: .75rem .5rem calc(1rem + env(safe-area-inset-bottom)); }
.sheet-item { width: 100%; display: flex; align-items: center; gap: .9rem; padding: .7rem .8rem; border-radius: 10px; text-align: start; }
.sheet-item:active { background: var(--line); }
.sheet-item span:last-child { display: flex; flex-direction: column; }
.sheet-item small { color: var(--muted); }
#group-form { display: flex; flex-direction: column; gap: .6rem; padding: .5rem .8rem; }
#group-form input { font: inherit; font-size: 16px; padding: .7em .2em; border: 0; border-bottom: 2px solid var(--accent); background: transparent; color: var(--fg); outline: none; }
#group-form .row { display: flex; justify-content: flex-end; gap: .5rem; }

/* ---------- chat ---------- */
.chat-top { gap: .25rem; padding-inline-start: .15rem; }
.chat-top .who { flex: 1; min-width: 0; display: flex; flex-direction: column; margin-inline-start: .4rem; }
.chat-top .who strong { font-weight: 500; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-top .who small { font-size: .78rem; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.messages {
  flex: 1; overflow-y: auto; padding: .5rem 4% 1rem; display: flex; flex-direction: column; gap: 2px;
  background-color: var(--chat-bg);
  background-image: radial-gradient(var(--dot) 1.2px, transparent 1.4px), radial-gradient(var(--dot) 1.2px, transparent 1.4px);
  background-size: 26px 26px; background-position: 0 0, 13px 13px;
}
.enc-note { align-self: center; max-width: 88%; background: var(--note); color: var(--note-fg); font-size: .76rem; text-align: center; padding: .45rem .7rem; border-radius: 8px; margin: .4rem 0 .6rem; box-shadow: var(--shadow); line-height: 1.5; }
.day-chip { align-self: center; background: var(--chip); color: var(--muted); font-size: .75rem; padding: .3rem .7rem; border-radius: 8px; margin: .6rem 0 .4rem; box-shadow: var(--shadow); }

.msg { position: relative; max-width: 82%; padding: .35rem .5rem .3rem; border-radius: 8px; box-shadow: var(--shadow); line-height: 1.45; overflow-wrap: anywhere; margin-top: 4px; font-size: .95rem; }
.msg.in { align-self: flex-start; background: var(--in); border-start-start-radius: 0; }
.msg.out { align-self: flex-end; background: var(--out); border-start-end-radius: 0; }
.msg.in::before, .msg.out::before { content: ""; position: absolute; top: 0; width: 8px; height: 13px; }
.msg.in::before { inset-inline-start: -8px; background: linear-gradient(to bottom left, var(--in) 50%, transparent 50%); }
.msg.out::before { inset-inline-end: -8px; background: linear-gradient(to bottom right, var(--out) 50%, transparent 50%); }
[dir="rtl"] .msg.in::before { background: linear-gradient(to bottom right, var(--in) 50%, transparent 50%); }
[dir="rtl"] .msg.out::before { background: linear-gradient(to bottom left, var(--out) 50%, transparent 50%); }
.msg.err { outline: 1px solid var(--danger); }
.msg .sender { font-size: .8rem; font-weight: 600; margin-bottom: .1rem; }
.msg .body { white-space: pre-wrap; }
.msg .body.md { white-space: normal; }
.msg .body p, .msg .body ul, .msg .body h4 { margin: .2em 0; }
.msg .body ul { padding-inline-start: 1.2em; }
.msg pre { background: var(--code); padding: .5em; border-radius: 6px; overflow-x: auto; font-size: .8rem; text-align: left; white-space: pre; }
.msg code { background: var(--code); padding: 0 .25em; border-radius: 3px; font-size: .88em; }
.msg .meta { float: inline-end; display: inline-flex; align-items: center; gap: .2rem; font-size: .68rem; color: var(--muted); margin: .45rem .5rem 0 0; margin-inline-start: .6rem; position: relative; top: .25rem; }
.msg .tick { font-size: .75rem; letter-spacing: -3px; color: var(--muted); }
.msg .tick.read { color: var(--tick); }
.msg .tools { font-size: .75rem; color: var(--muted); margin-top: .3rem; }
.msg .tool { font-family: ui-monospace, Consolas, monospace; font-size: .7rem; text-align: left; padding: .1em 0; }
.msg .status { font-size: .75rem; color: var(--muted); margin-top: .25rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dots { display: flex; gap: 4px; padding: .45rem .3rem; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* voice notes */
.voice { min-width: 230px; }
.vrow { display: flex; align-items: center; gap: .6rem; padding-top: .2rem; }
.vplay { width: 34px; height: 34px; font-size: 1rem; color: var(--muted); flex: none; }
.vtrack { position: relative; flex: 1; height: 4px; background: rgba(134, 150, 160, .45); border-radius: 2px; }
.vfill { position: absolute; inset-block: 0; inset-inline-start: 0; width: 0; background: var(--accent); border-radius: 2px; }
.vknob { position: absolute; top: -5px; inset-inline-start: -6px; width: 13px; height: 13px; border-radius: 50%; background: var(--accent); }
.vmic { color: var(--accent); display: grid; place-items: center; }
.vmic svg { width: 22px; height: 22px; }
.vdur { font-size: .7rem; color: var(--muted); padding-inline-start: 44px; }
.transcript { font-size: .85rem; margin-top: .35rem; padding-top: .3rem; border-top: 1px solid rgba(134, 150, 160, .25); white-space: pre-wrap; }

/* ---------- composer ---------- */
.composer { display: flex; align-items: flex-end; gap: .35rem; padding: .35rem .4rem calc(.4rem + env(safe-area-inset-bottom)); background: var(--chat-bg); flex: none; }
.field, .recbar { flex: 1; min-height: 48px; background: var(--field); border-radius: 24px; display: flex; align-items: center; padding: 0 1rem; box-shadow: var(--shadow); }
.field textarea { flex: 1; resize: none; border: 0; outline: none; background: transparent; color: var(--fg); font: inherit; font-size: 17px; line-height: 1.35; padding: .7rem 0; max-height: 140px; }
.recbar { gap: .6rem; padding: 0 .4rem 0 1rem; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1.2s infinite; }
#rec-time { font-variant-numeric: tabular-nums; }
.rec-label { color: var(--muted); font-size: .9rem; flex: 1; }
.danger-ic { color: var(--danger); }
.round { width: 48px; height: 48px; border-radius: 50%; background: var(--accent); color: var(--accent-fg); display: grid; place-items: center; flex: none; box-shadow: var(--shadow); }
.round:active { filter: brightness(.92); }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px); background: rgba(17, 27, 33, .92); color: #fff; padding: .6rem 1rem; border-radius: 20px; font-size: .9rem; opacity: 0; transition: .25s; pointer-events: none; z-index: 50; max-width: 90%; text-align: center; }
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }
