@font-face {
  font-family: "Vazirmatn";
  src: url("../fonts/Vazirmatn-wght.woff2") format("woff2-variations"),
       url("../fonts/Vazirmatn-wght.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --text: #1b2421;
  --muted: #5d6b66;
  --accent: #1f6f5c;
  --accent-text: #ffffff;
  --own: #d7f0e6;
  --other: #ffffff;
  --bad: #b3261e;
  --border: #dde3e0;
  --status-bg: #fff4d6;
  --status-text: #6b4e00;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111715;
    --surface: #1a2220;
    --text: #e6ece9;
    --muted: #9aa8a3;
    --accent: #5cc3a5;
    --accent-text: #0d1a16;
    --own: #1e4a3d;
    --other: #222c29;
    --bad: #ff8a80;
    --border: #2b3532;
    --status-bg: #3d3214;
    --status-text: #ffe08a;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Vazirmatn", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
a { color: var(--accent); }

#app { height: 100%; }

/* ---------- screens ---------- */
.screen {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  background: var(--bg);
}
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.empty { text-align: center; padding: 32px 16px; }

/* ---------- top bar ---------- */
.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(8px + var(--safe-top)) 12px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  min-height: 56px;
}
.bar-title {
  flex: 1;
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bar-titles { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.bar-subtitle { color: var(--muted); font-size: 13px; }
.bar-subtitle:empty { display: none; }
.text-button { background: none; border: 0; color: var(--accent); padding: 8px; font-weight: 600; }
.icon-button {
  background: none;
  border: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 22px;
  line-height: 1;
  color: var(--accent);
}
.icon-button:active { background: var(--bg); }

/* ---------- connection status ---------- */
.status {
  position: fixed;
  top: var(--safe-top);
  inset-inline: 0;
  z-index: 10;
  text-align: center;
  font-size: 14px;
  padding: 4px 8px;
  background: var(--status-bg);
  color: var(--status-text);
}

/* ---------- login ---------- */
.login { justify-content: center; padding: 24px 20px calc(24px + var(--safe-bottom)); max-width: 420px; }
.app-title { margin: 0; color: var(--accent); font-weight: 800; font-size: 28px; text-align: center; }
.login > .muted { text-align: center; margin: 4px 0 24px; }
.login-form { display: flex; flex-direction: column; gap: 6px; }
.login-form label { font-weight: 600; margin-top: 8px; }
.login-form input {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  font-size: 16px; /* 16px stops iPhone from zooming in */
}
.login-form input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.form-error { color: var(--bad); min-height: 1.6em; margin: 8px 0 0; }
.primary {
  margin-top: 8px;
  padding: 12px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
}
.primary:disabled { opacity: 0.6; }

/* ---------- chat list ---------- */
.room-list { list-style: none; margin: 0; padding: 0 0 var(--safe-bottom); }
.room-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 14px;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--border);
  text-align: start;
}
.room-item:active { background: var(--surface); }
.room-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.room-name, .room-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: start; }
.room-name { font-weight: 700; }
.room-preview { color: var(--muted); font-size: 14px; }
.room-time { color: var(--muted); font-size: 12px; align-self: flex-start; padding-top: 4px; white-space: nowrap; }

.avatar {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  font-size: 19px;
}
.c0 { background: #1f6f5c; } .c1 { background: #3f5fb0; } .c2 { background: #a2462f; } .c3 { background: #7b4fa6; }
.c4 { background: #8a6d12; } .c5 { background: #2f7f99; } .c6 { background: #b03f6b; } .c7 { background: #4f6b3a; }

/* ---------- chat ---------- */
.back { transform: none; }
.timeline { list-style: none; margin: 0; padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; }
.msg { display: flex; align-items: center; gap: 6px; max-width: 85%; }
/* RTL: the other person's messages start on the right, our own on the left */
.msg.other { align-self: flex-start; }
.msg.own { align-self: flex-end; flex-direction: row-reverse; }
.bubble {
  padding: 6px 10px 4px;
  border-radius: 16px;
  background: var(--other);
  border: 1px solid var(--border);
  min-width: 64px;
  overflow-wrap: anywhere;
}
.own .bubble { background: var(--own); border-color: transparent; }
.bubble .sender { display: block; font-size: 13px; font-weight: 700; color: var(--accent); }
.bubble .text { white-space: pre-wrap; }
.bubble .meta { display: block; font-size: 11px; color: var(--muted); text-align: end; margin-top: 2px; }
.bubble.deleted .text { font-style: italic; color: var(--muted); }
.bubble.failed { border: 1px solid var(--bad); }
.retry {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 0;
  background: var(--bad);
  color: #fff;
  font-weight: 800;
}
.system {
  align-self: center;
  font-size: 12px;
  color: var(--muted);
  background: var(--surface);
  border-radius: 10px;
  padding: 2px 10px;
  margin: 4px 0;
  text-align: center;
  max-width: 90%;
}

/* ---------- composer ---------- */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px calc(8px + var(--safe-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 9px 14px;
  background: var(--bg);
  font-size: 16px; /* 16px stops iPhone from zooming in */
  line-height: 1.4;
  max-height: 140px;
}
.composer textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
.send-button {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 20px;
  font-weight: 800;
}
.send-button:disabled { opacity: 0.4; }
