/* Mobile-first, RTL. No inline styles anywhere (CSP style-src 'self'). */

:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #6b7480;
  --border: #dde2e8;
  --brand: #1f5fd1;
  --brand-text: #ffffff;
  --error-bg: #fdecec;
  --error-border: #f3c2c2;
  --error-text: #a61b1b;
  --tag-bg: #eceff3;
  --tag-text: #5b6470;
  --ok: #1a7f37;
  --radius: 16px;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}

button, input, textarea { font: inherit; }

button {
  min-height: 44px;
  padding: 10px 16px;
  border: 0;
  border-radius: 10px;
  background: var(--brand);
  color: var(--brand-text);
  font-weight: 600;
  cursor: pointer;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }

button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* ---- Login ---- */

.login {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.card {
  width: 100%;
  max-width: 360px;
  display: grid;
  gap: 12px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.card h1 { margin: 0; font-size: 1.4rem; }
.sub { margin: 0; color: var(--muted); }
label { font-weight: 600; }

input[type="password"] {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px; /* 16px stops iOS from zooming in */
}

.form-error { margin: 0; color: var(--error-text); }

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

.chat {
  height: 100vh;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 1.05rem; }
.actions { display: flex; gap: 8px; }
.actions button { min-height: 40px; padding: 8px 12px; font-size: 0.9rem; }

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

.msg { display: flex; flex-direction: column; max-width: 85%; }
/* RTL mirror: agent on the right (start), customer on the left (end). */
.msg-agent, .msg-error { align-self: flex-start; align-items: flex-start; }
.msg-user { align-self: flex-end; align-items: flex-end; }

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg-agent .bubble { background: var(--surface); border: 1px solid var(--border); border-start-start-radius: 4px; }
.msg-user .bubble { background: var(--brand); color: var(--brand-text); border-start-end-radius: 4px; }
.msg-error .bubble { background: var(--error-bg); color: var(--error-text); border: 1px solid var(--error-border); }

.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  font-size: 0.8rem;
}
.tag { padding: 2px 10px; border-radius: 999px; background: var(--tag-bg); color: var(--tag-text); }
.handoff { color: var(--ok); font-weight: 600; }

.typing .bubble { color: var(--muted); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }
@media (prefers-reduced-motion: reduce) { .typing .bubble { animation: none; } }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 16px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.composer textarea {
  flex: 1;
  min-height: 44px;
  max-height: 160px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 16px;
  line-height: 1.4;
  resize: none;
}
