:root {
  --bg: #ffffff;
  --surface: #f6f6f4;
  --surface-2: #efefec;
  --ink: #0a0a0a;
  --ink-soft: #5b5b58;
  --line: #e6e6e2;
  --accent: #1f6f5c;       /* restrained Saudi-green */
  --accent-ink: #ffffff;
  --bot-bubble: #f3f3f0;
  --user-bubble: #1f6f5c;
  --radius: 16px;
  --maxw: 760px;
  --font: -apple-system, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-ar: "SF Arabic", "Geeza Pro", "Noto Naskh Arabic", "Segoe UI", Tahoma, sans-serif;
}

* { box-sizing: border-box; }
/* `.gate`/`.chat` set display:grid/flex, which would otherwise override the
   `hidden` attribute — force hidden to win so the login pane disappears. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}
html[dir="rtl"] body, html[dir="rtl"] textarea, html[dir="rtl"] input { font-family: var(--font-ar); }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: rgba(255,255,255,.85);
  backdrop-filter: saturate(180%) blur(14px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 50%;
  object-fit: cover; background: var(--surface);
}
.gate-avatar {
  width: 96px; height: 96px; border-radius: 50%; object-fit: cover;
  display: block; margin: 0 auto 18px;
  box-shadow: 0 6px 24px rgba(31, 111, 92, .18); background: var(--surface);
}
.brand-name { font-weight: 600; letter-spacing: -.01em; font-size: 15px; }
.lang-toggle {
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  border-radius: 999px; padding: 7px 14px; font-size: 13px; font-weight: 500;
  cursor: pointer; transition: background .15s, border-color .15s;
}
.lang-toggle:hover { background: var(--surface); border-color: #d8d8d3; }

/* Gate */
.gate { flex: 1; display: grid; place-items: center; padding: 24px; }
.gate-card {
  width: 100%; max-width: 420px; text-align: center;
}
.gate-card h1 { font-size: 28px; letter-spacing: -.02em; margin: 0 0 8px; }
.muted { color: var(--ink-soft); margin: 0 0 22px; font-size: 15px; }
.key-form { display: flex; gap: 8px; }
.key-form input {
  flex: 1; padding: 13px 15px; font-size: 15px; color: var(--ink);
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg); outline: none;
}
.key-form input:focus { border-color: var(--accent); }
.key-form button, .composer button {
  padding: 0 18px; font-size: 15px; font-weight: 600; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 12px;
  transition: filter .15s; min-height: 46px;
}
.key-form button:hover, .composer button:hover { filter: brightness(1.06); }
.error { color: #b3261e; font-size: 14px; margin-top: 14px; }

/* Chat */
.chat { flex: 1; display: flex; flex-direction: column; width: 100%; max-width: var(--maxw); margin: 0 auto; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 24px 20px 8px; display: flex; flex-direction: column; gap: 14px; }
.bubble {
  max-width: 80%; padding: 12px 15px; border-radius: var(--radius); font-size: 15.5px;
  line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; animation: rise .18s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.bubble.bot { align-self: flex-start; background: var(--bot-bubble); color: var(--ink); border-bottom-left-radius: 5px; }
.bubble.user { align-self: flex-end; background: var(--user-bubble); color: #fff; border-bottom-right-radius: 5px; }
html[dir="rtl"] .bubble.bot { border-bottom-left-radius: var(--radius); border-bottom-right-radius: 5px; }
html[dir="rtl"] .bubble.user { border-bottom-right-radius: var(--radius); border-bottom-left-radius: 5px; }

.typing { align-self: flex-start; display: inline-flex; gap: 4px; padding: 14px 16px; background: var(--bot-bubble); border-radius: var(--radius); }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: #b9b9b3; animation: blink 1.2s infinite both; }
.typing span:nth-child(2) { animation-delay: .2s; } .typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

.done-banner {
  margin: 8px 20px; padding: 14px 16px; border: 1px solid var(--line);
  background: var(--surface); border-radius: 12px; font-size: 14.5px;
}
.done-banner a { color: var(--accent); font-weight: 600; }

.composer { display: flex; gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.composer textarea {
  flex: 1; resize: none; max-height: 160px; padding: 12px 15px; font: inherit; font-size: 15.5px;
  color: var(--ink); border: 1px solid var(--line); border-radius: 14px; outline: none; line-height: 1.45;
}
.composer textarea:focus { border-color: var(--accent); }
.composer button:disabled { opacity: .5; cursor: default; filter: none; }

.top-actions { display: flex; align-items: center; gap: 8px; }
.done-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

.btn-accent-sm, .btn-ghost-sm, .btn-danger-sm {
  border-radius: 999px; padding: 8px 14px; font-size: 13px; font-weight: 600;
  cursor: pointer; border: 1px solid transparent; transition: filter .15s, background .15s;
}
.btn-accent-sm { background: var(--accent); color: #fff; }
.btn-accent-sm:hover { filter: brightness(1.06); }
.btn-ghost-sm { background: var(--bg); color: var(--ink); border-color: var(--line); }
.btn-ghost-sm:hover { background: var(--surface); }
.btn-danger-sm { background: var(--bg); color: #b3261e; border-color: #eccfcd; }
.btn-danger-sm:hover { background: #fbeceb; }

/* My requests */
.requests { flex: 1; width: 100%; max-width: var(--maxw); margin: 0 auto; display: flex; flex-direction: column; min-height: 0; }
.req-head { display: flex; align-items: center; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.req-title { font-weight: 600; font-size: 15px; flex: 1; }
.req-list { flex: 1; overflow-y: auto; padding: 16px 20px 24px; display: flex; flex-direction: column; gap: 14px; }
.req-empty { color: var(--ink-soft); text-align: center; padding: 40px 0; font-size: 14.5px; }
.req-card { border: 1px solid var(--line); border-radius: 14px; padding: 14px; background: var(--bg); display: flex; flex-direction: column; gap: 10px; }
.req-meta { color: var(--ink-soft); font-size: 12.5px; }
.req-title-input {
  font: inherit; font-size: 15px; font-weight: 600; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: none;
}
.req-title-input:focus, .req-body-input:focus { border-color: var(--accent); }
.req-body-input {
  font: inherit; font-size: 13.5px; line-height: 1.5; color: var(--ink-soft);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: none;
  min-height: 120px; resize: vertical; white-space: pre-wrap;
}
.req-actions { display: flex; align-items: center; gap: 8px; }
.req-card-status { color: var(--ink-soft); font-size: 12.5px; }

@media (max-width: 520px) {
  .gate-card h1 { font-size: 24px; }
  .bubble { max-width: 88%; }
}
