:root {
  --brand: #323234;
  --accent: #e22e34;
  --bg: #f2f2f4;
  --surface: #ffffff;
  --text: #1c1c1e;
  --muted: #6b6b70;
  --line: #e1e1e6;
  --mine: #323234;
  --mine-text: #ffffff;
  --theirs: #ffffff;
  --theirs-text: #1c1c1e;
  --advisor: #fff5f5;
  --chip: #ffffff;
  --focus: #e22e34;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161618;
    --surface: #222225;
    --text: #f2f2f4;
    --muted: #a0a0a8;
    --line: #333338;
    --mine: #4a4a50;
    --theirs: #262629;
    --theirs-text: #f2f2f4;
    --advisor: #2e2224;
    --chip: #262629;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans Arabic", sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

[hidden] { display: none !important; }

button { font: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* --- Header ------------------------------------------------------------ */

.bar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--brand);
  color: #fff;
  flex: none;
}

.logo {
  width: 36px;
  height: 36px;
  flex: none;
}

.titles { flex: 1; min-width: 0; }
.title { font-weight: 650; font-size: 17px; letter-spacing: 0.2px; }
.subtitle { font-size: 13px; opacity: 0.75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.menu-button {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 20px;
  background: transparent;
  color: #fff;
  display: grid;
  place-items: center;
}
.menu-button svg { width: 22px; height: 22px; fill: currentColor; }
.menu-button:hover { background: rgba(255, 255, 255, 0.12); }

.menu {
  position: absolute;
  top: calc(100% - 4px);
  inset-inline-end: 12px;
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
  padding: 6px;
  min-width: 220px;
  z-index: 10;
}
.menu button {
  display: block;
  width: 100%;
  text-align: start;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 10px 12px;
  border-radius: 8px;
}
.menu button:hover { background: var(--bg); }

/* --- Screens ----------------------------------------------------------- */

main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.screen { flex: 1; min-height: 0; }
.center { display: grid; place-items: center; padding: 24px 16px; overflow-y: auto; }

.card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: 18px;
  padding: 28px 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}
.card h1 { font-size: 22px; margin: 0 0 8px; line-height: 1.25; }
.card p { margin: 0 0 18px; color: var(--muted); }
.card .note { font-size: 14px; margin: 16px 0 0; }
.card .sent { margin: 16px 0 0; color: var(--text); font-weight: 550; }
.card label { display: block; font-size: 14px; margin-bottom: 6px; color: var(--muted); }
.card input {
  width: 100%;
  font: inherit;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  margin-bottom: 12px;
}

.primary {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 14px 18px;
  background: var(--accent);
  color: #fff;
  font-weight: 650;
}
.primary:disabled { opacity: 0.6; cursor: default; }

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Chat -------------------------------------------------------------- */

.chat { display: flex; flex-direction: column; }

.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  flex: none;
}
.banner span { flex: 1; }
.banner-action {
  border: 0;
  border-radius: 10px;
  padding: 8px 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  white-space: nowrap;
}
.banner-close {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  width: 32px;
  height: 32px;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overscroll-behavior: contain;
}

.day {
  align-self: center;
  font-size: 12px;
  color: var(--muted);
  background: var(--surface);
  padding: 3px 10px;
  border-radius: 10px;
  margin: 10px 0 6px;
}

.msg {
  max-width: min(82%, 560px);
  padding: 8px 12px 6px;
  border-radius: 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
}
.msg + .msg.same { margin-top: -1px; }
.msg.mine {
  align-self: flex-end;
  background: var(--mine);
  color: var(--mine-text);
  border-end-end-radius: 6px;
}
.msg.theirs {
  align-self: flex-start;
  background: var(--theirs);
  color: var(--theirs-text);
  border-end-start-radius: 6px;
}
.msg.advisor { background: var(--advisor); }
.msg .who {
  display: block;
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
  margin-bottom: 2px;
}
.msg.advisor .who { color: var(--accent); }
.msg .time {
  display: block;
  font-size: 11px;
  opacity: 0.6;
  text-align: end;
  margin-top: 2px;
}
.msg a { color: inherit; text-decoration: underline; }
.msg.mine a { color: #fff; }
.msg img {
  display: block;
  max-width: 100%;
  max-height: 60vh;
  border-radius: 10px;
  margin: 2px 0 6px;
  background: var(--bg);
}
.msg.pending { opacity: 0.6; }

.typing {
  align-self: flex-start;
  background: var(--theirs);
  border-radius: 16px;
  padding: 12px 14px;
  display: flex;
  gap: 4px;
}
.typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: 0.2s; }
.typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

.quick {
  display: flex;
  gap: 8px;
  padding: 6px 12px;
  overflow-x: auto;
  flex: none;
  scrollbar-width: none;
}
.quick::-webkit-scrollbar { display: none; }
.quick button {
  flex: none;
  border: 1px solid var(--line);
  background: var(--chip);
  color: var(--text);
  border-radius: 18px;
  padding: 8px 14px;
  font-size: 15px;
}
.quick button:hover { border-color: var(--accent); }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
  flex: none;
}
.composer textarea {
  flex: 1;
  resize: none;
  font: inherit;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--bg);
  color: var(--text);
  max-height: 140px;
  min-height: 44px;
}
.send {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 22px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  flex: none;
}
.send svg { width: 22px; height: 22px; fill: currentColor; }
[dir="rtl"] .send svg { transform: scaleX(-1); }
.send:disabled { opacity: 0.45; cursor: default; }

@media (min-width: 720px) {
  .messages { padding: 20px max(16px, calc((100% - 760px) / 2)) 8px; }
  .quick, .composer { padding-inline: max(12px, calc((100% - 760px) / 2)); }
}
