/* ذكاء الهجدة — ليل داكن مرجعي، نهار ورقي محفوظ */

:root {
  --bg: #fffef9;
  --bg-2: #ffffff;
  --bg-3: #f4f2ec;
  --gold: #b8a57a;
  --gold-dim: #8e7344;
  --cream: #161616;
  --muted: #5a5a56;
  --subtle: #6e6a62;
  --accent: #e8e2d4;
  --accent-fg: #0c0c0e;
  --local: #5a6b58;
  --line: rgba(22, 22, 20, 0.08);
  --line-strong: rgba(22, 22, 20, 0.14);
  --danger: #b4232a;
  --ok: #2d7a52;
  --font: 'IBM Plex Sans Arabic', system-ui, sans-serif;
  --display: 'Fraunces', 'Noto Naskh Arabic', serif;
  --sidebar-w: 260px;
  --top-h: 56px;
  --composer-min: 52px;
  --radius: 10px;
  --radius-pill: 999px;
  --app-h: 100dvh;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --scroll-thumb: #b8a57a;
  --scroll-thumb-hover: #8e7344;
  --scroll-track: #eeebe4;
  --shadow: 0 8px 24px rgba(16, 16, 16, 0.05);
  --glow: rgba(184, 165, 122, 0.08);
  color-scheme: light;
}

[data-theme="night"] {
  --bg: #0c0c0e;
  --bg-2: #151518;
  --bg-3: #1c1c20;
  --gold: #b8a57a;
  --gold-dim: #9a8a62;
  --cream: #f3efe6;
  --muted: #9c978c;
  --subtle: #6e6a62;
  --accent: #e8e2d4;
  --accent-fg: #0c0c0e;
  --local: #8a9a86;
  --line: rgba(243, 239, 230, 0.12);
  --line-strong: rgba(243, 239, 230, 0.22);
  --danger: #c27b6e;
  --ok: #8a9a86;
  --scroll-thumb: #b8a57a;
  --scroll-thumb-hover: #f3efe6;
  --scroll-track: #151518;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --glow: rgba(184, 165, 122, 0.07);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html, body {
  margin: 0;
  height: 100%;
  max-width: 100%;
  font-family: var(--font);
  font-variant-numeric: lining-nums;
  background: var(--bg);
  color: var(--cream);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) var(--scroll-track);
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--scroll-track);
}

::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 999px;
  border: 2px solid var(--scroll-track);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--scroll-thumb-hover);
}

body.chat-app {
  overflow: hidden;
  position: fixed;
  inset: 0;
  width: 100%;
  overscroll-behavior: none;
}

.skip-link {
  position: absolute;
  top: -100px;
  right: 1rem;
  z-index: 10000;
  background: var(--gold);
  color: #1a140c;
  padding: 0.65rem 1rem;
  border-radius: 8px;
  font-weight: 700;
  text-decoration: none;
}
.skip-link:focus { top: 1rem; }

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  height: var(--app-h, 100dvh);
  max-width: 100%;
  overflow: hidden;
}

/* ===== Sidebar (RTL: يمين) ===== */
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-2);
  border-inline-start: 1px solid var(--line);
  min-height: 0;
}

.sidebar__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 1rem 1rem 0.35rem;
  border-bottom: 0;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  text-decoration: none;
  color: var(--cream);
  min-width: 0;
}

.sidebar__mark {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  color: var(--gold);
}

.sidebar__brand strong {
  display: block;
  font-family: var(--display);
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.sidebar__brand small {
  display: block;
  font-size: 0.68rem;
  color: var(--muted);
}

.sidebar__toggle {
  display: none;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--cream);
  border-radius: 8px;
  width: 44px;
  height: 44px;
  cursor: pointer;
  touch-action: manipulation;
}

.sidebar__settings {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--cream);
  border-radius: 8px;
  min-width: 44px;
  height: 44px;
  padding: 0 0.55rem;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  touch-action: manipulation;
}

.sidebar__section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.sidebar__label {
  margin: 0.35rem 1rem 0.15rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--gold);
}

.btn-new {
  margin: 0.75rem 1rem 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  width: calc(100% - 2rem);
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--cream);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.btn-new:hover {
  border-color: rgba(184, 165, 122, 0.4);
  background: var(--bg-3);
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.35rem 0.65rem 0.75rem;
  list-style: none;
  margin: 0;
}

.chat-list__empty {
  padding: 1.25rem 0.75rem;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
  line-height: 1.6;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.25rem;
}

.chat-item__btn {
  flex: 1;
  min-width: 0;
  text-align: start;
  padding: 0.55rem 0.75rem;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--cream);
  font-family: inherit;
  font-size: 0.84rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.12rem;
  transition: background 0.12s, border-color 0.12s;
  touch-action: manipulation;
}

.chat-item__title {
  display: block;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item__time {
  font-size: 0.68rem;
  color: var(--muted);
  font-weight: 500;
}
.chat-item__btn:hover {
  background: var(--bg-3);
}
.chat-item.is-active .chat-item__btn {
  background: var(--bg-3);
  border-color: var(--line);
}

.chat-item__del {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s, color 0.12s;
  touch-action: manipulation;
}
.chat-item:hover .chat-item__del,
.chat-item__del:focus-visible { opacity: 1; }
.chat-item__del:hover { color: var(--danger); }

@media (hover: none) {
  .chat-item__del { opacity: 0.85; }
}

.sidebar__foot {
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.sidebar__foot a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.78rem;
  padding: 0.35rem 0;
}
.sidebar__foot a:hover { color: var(--gold); }

.sidebar__account {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--gold);
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.sidebar__account.is-in { color: var(--cream); background: var(--bg-3); }

.model-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  color: var(--muted);
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
  background: var(--bg-3);
}
.model-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
}
.model-pill.is-ok .dot { background: var(--ok); }
.model-pill.is-bad .dot { background: var(--danger); }

/* ===== Main ===== */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  flex: 1;
  background: var(--bg);
  position: relative;
}

.chat-pause-gate {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 30;
  place-items: center;
  padding: 1.5rem;
  background: var(--bg);
}
.chat-pause-gate.is-on { display: grid; }
.chat-pause-gate[hidden] { display: none !important; }
.main:has(.chat-pause-gate.is-on) .composer-dock,
.main:has(.chat-pause-gate.is-on) .thread-wrap { display: none; }
.chat-pause-gate__card {
  max-width: 22rem;
  width: 100%;
  padding: 1.6rem 1.4rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-2);
  box-shadow: var(--shadow);
  text-align: center;
}
.chat-pause-gate__card h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.28rem;
  font-weight: 600;
  color: var(--cream);
  line-height: 1.55;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  height: var(--top-h);
  padding: 0 1rem;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  position: relative;
  background: transparent;
}

.topbar__left {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
  flex: 1;
}

.topbar__menu {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--cream);
  border-radius: 8px;
  min-width: 44px;
  height: 44px;
  padding: 0 0.65rem;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  touch-action: manipulation;
  display: none;
}

.topbar__menu { display: none; }
.topbar__new { display: grid; place-items: center; flex-shrink: 0; }

.topbar__new {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--cream);
  border-radius: 8px;
  min-width: 44px;
  height: 44px;
  padding: 0 0.75rem;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  touch-action: manipulation;
}

.sidebar__private {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--cream);
  cursor: pointer;
}
.sidebar__private input { accent-color: var(--gold); }

.sidebar__theme {
  display: grid;
  place-items: center;
  align-self: flex-start;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--cream);
  border-radius: 8px;
  min-width: 44px;
  height: 44px;
  padding: 0 0.85rem;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  touch-action: manipulation;
}

.brain-bar[hidden] { display: none !important; }

.topbar__auth {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  min-width: 44px;
  height: 44px;
  padding: 0 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--gold);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.topbar__auth.is-in {
  color: var(--cream);
  background: var(--bg-3);
}

.topbar__title {
  margin: 0;
  font-family: var(--display);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brain-bar {
  display: none;
}

.mode-bar {
  display: none;
}

.brain-btn {
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
}
.brain-btn.is-active {
  color: var(--accent-fg);
  background: var(--accent);
  border-color: rgba(184, 165, 122, 0.35);
  box-shadow: 0 0 0 1px rgba(184, 165, 122, 0.3);
}

.mode-btn {
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s;
  touch-action: manipulation;
}
.mode-btn:hover { color: var(--cream); border-color: var(--gold-dim); }
.mode-btn.is-active {
  color: var(--accent-fg);
  background: var(--accent);
  border-color: rgba(184, 165, 122, 0.35);
  box-shadow: 0 0 0 1px rgba(184, 165, 122, 0.3);
}

[data-theme="day"] .brain-btn.is-active,
[data-theme="day"] .mode-btn.is-active {
  color: #1a140c;
  background: var(--gold);
  border-color: var(--gold);
  box-shadow: none;
}

/* ===== Thread ===== */
.thread-wrap {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.thread {
  max-width: 780px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 2rem;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem 1rem 5rem;
  gap: 0;
}

.hero__mark {
  display: grid;
  place-items: center;
  width: 3.1rem;
  height: 3.1rem;
  margin-bottom: 1.15rem;
  border-radius: 50%;
  border: 1px solid rgba(184, 165, 122, 0.35);
  background: var(--bg-3);
  color: var(--gold);
  font-family: var(--display);
  font-size: 1.55rem;
  font-weight: 600;
  line-height: 1;
}

.hero__title {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.85rem, 5vw, 2.35rem);
  font-weight: 600;
  color: var(--cream);
  line-height: 1.35;
  letter-spacing: -0.02em;
}

.hero__sub {
  margin: 0.7rem 0 0;
  max-width: 26rem;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.7;
}

.hero__chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  max-width: 28rem;
  margin-top: 1.6rem;
}

.hero-chip {
  padding: 0.5rem 0.95rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--muted);
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}
.hero-chip:hover {
  color: var(--cream);
  border-color: rgba(184, 165, 122, 0.4);
  background: var(--bg-3);
}
.hero-chip--history {
  color: var(--gold);
  border-color: rgba(184, 165, 122, 0.35);
}

.msg {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  animation: fadeUp 0.25s ease;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.msg__avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 0.72rem;
  font-weight: 700;
  border: 1px solid var(--line);
}
.msg--user .msg__avatar {
  background: var(--bg-3);
  color: var(--gold);
}
.msg--assistant .msg__avatar {
  background: var(--bg-3);
  color: var(--local);
  border-color: rgba(138, 154, 134, 0.35);
}

.msg__body { flex: 1; min-width: 0; }

.msg__role {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.msg__speak {
  margin-top: 0.45rem;
  padding: 0.3rem 0.7rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.msg__speak:hover { color: var(--cream); border-color: var(--gold-dim); }

.msg__text {
  font-size: 1rem;
  line-height: 1.8;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.msg__text.is-streaming::after {
  content: '▍';
  animation: blink 0.9s step-end infinite;
  color: var(--gold);
}
@keyframes blink { 50% { opacity: 0; } }

.msg__attach {
  margin-top: 0.5rem;
  max-width: 280px;
  border-radius: 10px;
  border: 1px solid var(--line);
  overflow: hidden;
}
.msg__attach img {
  display: block;
  width: 100%;
  height: auto;
}
.msg__attach-name {
  padding: 0.35rem 0.5rem;
  font-size: 0.72rem;
  color: var(--muted);
  background: var(--bg-3);
}

.msg--error .msg__text { color: var(--danger); }

.msg__text a,
.msg__refs-panel a {
  color: var(--gold);
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

.msg__refs { margin-top: 0.55rem; }

.msg__refs-btn {
  appearance: none;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 8px;
  padding: 0.2rem 0.65rem;
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}

.msg__refs-btn[aria-expanded='true'] {
  color: var(--gold);
  border-color: rgba(179, 147, 89, 0.45);
}

.msg__refs-panel {
  margin-top: 0.4rem;
  font-size: 0.82rem;
  line-height: 1.7;
  color: var(--muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ===== Composer ===== */
.composer-dock {
  flex-shrink: 0;
  padding: 0 1rem 1.15rem;
  background: linear-gradient(transparent, var(--bg) 28%);
}

.composer {
  max-width: 720px;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-2);
  box-shadow: none;
  overflow: hidden;
}
.composer:has(.composer__attach-preview.is-visible) {
  border-radius: 22px;
}

.composer__attach-preview {
  display: none;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.85rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.78rem;
  color: var(--muted);
}
.composer__attach-preview.is-visible { display: flex; }

.composer__attach-preview button {
  margin-inline-start: auto;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
}

.composer__row {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.35rem 0.4rem 0.35rem 0.7rem;
}

.composer__tools {
  display: flex;
  gap: 0.15rem;
  flex-shrink: 0;
}

.tool-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: color 0.12s, background 0.12s;
  touch-action: manipulation;
}
.tool-btn:hover { color: var(--cream); background: var(--bg-3); }
.tool-btn.is-recording { color: var(--danger); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

.composer__input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  max-height: 160px;
  resize: none;
  border: none;
  background: transparent;
  color: var(--cream);
  font-family: inherit;
  font-size: 16px;
  line-height: 1.5;
  padding: 0.55rem 0.15rem;
}
.composer__input::placeholder { color: var(--muted); }
.composer__input:focus { outline: none; }

.composer__send {
  width: 42px;
  height: 42px;
  border: 1px solid rgba(184, 165, 122, 0.35);
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: opacity 0.12s, transform 0.12s;
  touch-action: manipulation;
}

[data-theme="day"] .composer__send {
  background: var(--gold);
  color: #1a140c;
  border-color: var(--gold);
}
[dir="rtl"] .composer__send svg { transform: scaleX(-1); }
.composer__send:hover { transform: scale(1.04); }
.composer__send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.composer__hint {
  padding: 0 0.85rem 0.55rem;
  font-size: 0.68rem;
  color: var(--muted);
  text-align: center;
}

.hidden-input { display: none; }

/* ===== Auth sheet ===== */
.auth-sheet {
  border: none;
  padding: 0;
  background: transparent;
  max-width: calc(100vw - 2rem);
  width: 22rem;
}
.auth-sheet::backdrop {
  background: rgba(8, 7, 12, 0.72);
}
.auth-sheet__card {
  margin: 0;
  padding: 1.15rem 1.1rem 1rem;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  background: var(--bg-2);
  box-shadow: var(--shadow);
  color: var(--cream);
}
.auth-sheet__card h2 {
  margin: 0 0 0.35rem;
  font-size: 1.1rem;
}
.auth-sheet__lead {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.65;
}
.auth-sheet__field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gold);
}
.auth-sheet__field input {
  width: 100%;
  min-height: 48px;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--cream);
  font-family: inherit;
  font-size: 16px;
}
.auth-sheet__err {
  margin: 0 0 0.65rem;
  color: var(--danger);
  font-size: 0.8rem;
}
.auth-sheet__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}
.auth-sheet__primary,
.auth-sheet__ghost {
  min-height: 44px;
  padding: 0.5rem 0.9rem;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.auth-sheet__primary {
  border: 1px solid rgba(184, 165, 122, 0.35);
  background: var(--accent);
  color: var(--accent-fg);
}
[data-theme="day"] .auth-sheet__primary {
  background: var(--gold);
  color: #1a140c;
  border-color: var(--gold);
}
.auth-sheet__ghost {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--cream);
}
.auth-sheet__google {
  width: 100%;
  min-height: 44px;
  margin-bottom: 0.85rem;
  padding: 0.5rem 0.9rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--cream);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.auth-sheet__google:disabled {
  opacity: 0.55;
  cursor: wait;
}

/* ===== Mobile ===== */
@media (max-width: 820px) {
  :root { --top-h: 48px; }

  .app-shell {
    display: flex;
    flex-direction: column;
    grid-template-columns: none;
    padding-top: var(--sat);
    padding-left: var(--sal);
    padding-right: var(--sar);
  }

  .sidebar {
    position: relative;
    inset: auto;
    width: 100%;
    max-height: 0;
    overflow: hidden;
    z-index: 5;
    transform: none;
    transition: max-height 0.2s ease;
    box-shadow: none;
    pointer-events: none;
    flex-shrink: 0;
    border-inline-start: none;
    border-bottom: 1px solid var(--line);
    padding: 0;
  }
  [dir="rtl"] .sidebar {
    left: auto;
    right: auto;
    transform: none;
    box-shadow: none;
  }

  .sidebar.is-open,
  [dir="rtl"] .sidebar.is-open {
    max-height: min(42vh, 22rem);
    overflow-y: auto;
    pointer-events: auto;
    transform: none;
  }

  .sidebar__foot { display: none; }

  .topbar {
    height: auto;
    min-height: var(--top-h);
    padding: 0.35rem 0.65rem;
    gap: 0.35rem;
    flex-wrap: wrap;
  }

  .topbar__menu,
  .topbar__new,
  .topbar__auth,
  .sidebar__toggle { display: grid; place-items: center; }

  .sidebar__foot { display: flex; flex-direction: column; gap: 0.35rem; padding: 0.5rem 1rem 0.75rem; }

  .topbar__title {
    font-size: 0.86rem;
  }

  .brain-bar { display: none; }
  .mode-bar { display: none; }

  .thread,
  .composer {
    max-width: none;
  }

  .thread {
    padding: 1rem 0.9rem 1.25rem;
  }

  .hero {
    padding: 1.25rem 0.25rem 2.5rem;
  }
  .hero__title {
    font-size: clamp(1.45rem, 6.5vw, 2rem);
  }

  .msg {
    gap: 0.5rem;
    margin-bottom: 1rem;
  }
  .msg__avatar {
    width: 28px;
    height: 28px;
    font-size: 0.68rem;
  }
  .msg__text {
    font-size: 16px;
    line-height: 1.75;
  }
  .msg__attach { max-width: min(280px, 100%); }

  .composer-dock {
    padding: 0 0.65rem max(0.45rem, var(--sab));
  }

  .composer {
    border-radius: 22px;
  }
  .composer__row {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "input send"
      "tools send";
    gap: 0.2rem 0.45rem;
    align-items: end;
    padding: 0.4rem 0.5rem 0.45rem;
  }
  .composer__input {
    grid-area: input;
    min-height: 48px;
    max-height: 120px;
    padding: 0.55rem 0.2rem;
  }
  .composer__send {
    grid-area: send;
    width: 52px;
    min-height: 52px;
    height: 100%;
    align-self: stretch;
    border-radius: 999px;
  }
  .composer__tools { grid-area: tools; }
  .tool-btn { width: 44px; height: 44px; }
  .composer__hint { display: none; }

  .btn-new,
  .chat-item__btn {
    min-height: 44px;
  }
  .chat-item__del {
    width: 44px;
    height: 44px;
    opacity: 0.9;
  }

  .auth-sheet {
    margin: auto;
    width: min(22rem, calc(100vw - 1.2rem));
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* قسم «عن محسن» — محتوى زاحف مرئي أسفل التطبيق */
body.chat-app:has(.about-mohsen) { overflow: auto; }
.about-mohsen {
  background: var(--panel, #141416); color: var(--text, #eceae4);
  padding: 2.2rem clamp(1rem, 5vw, 3rem) 3.2rem;
  max-width: 760px; margin: 0 auto; line-height: 1.95;
  border-top: 1px solid var(--line, #2a2a2e);
}
.about-mohsen h2 { font-size: 1.1rem; margin: 1.5rem 0 .5rem; color: var(--gold, #d4b87a); }
.about-mohsen h2:first-child { margin-top: 0; }
.about-mohsen p, .about-mohsen li, .about-mohsen dd { color: var(--muted, #9a978f); }
.about-mohsen ul { padding-inline-start: 1.2rem; display: grid; gap: .35rem; list-style: disc; }
.about-mohsen dl { display: grid; gap: .5rem; }
.about-mohsen dt { font-weight: 700; color: var(--text, #eceae4); }
.about-mohsen dd { margin: 0 0 .4rem; }
.about-mohsen a { color: inherit; text-decoration: underline; }

/* ===== وضع المكالمة الصوتية ===== */
.topbar__call {
  border: 1px solid var(--gold, #c8a24a);
  background: transparent;
  color: var(--gold, #c8a24a);
  border-radius: 999px;
  padding: .3rem .7rem;
  font: inherit;
  font-size: .8rem;
  cursor: pointer;
}
.topbar__call:hover { background: color-mix(in srgb, var(--gold, #c8a24a) 16%, transparent); }

.call-mode {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  background: rgba(8, 10, 14, .82);
  backdrop-filter: blur(6px);
}
.call-mode[hidden] { display: none; }
.call-card {
  width: min(92vw, 380px);
  background: var(--panel, #141821);
  border: 1px solid color-mix(in srgb, var(--gold, #c8a24a) 40%, transparent);
  border-radius: 24px;
  padding: 1.6rem 1.4rem 1.2rem;
  display: grid;
  justify-items: center;
  gap: .55rem;
  box-shadow: 0 24px 70px rgba(0,0,0,.5);
  text-align: center;
}
.call-avatar {
  position: relative;
  width: 96px;
  height: 96px;
  display: grid;
  place-items: center;
}
.call-avatar__face {
  width: 84px; height: 84px; border-radius: 50%;
  background: linear-gradient(145deg, var(--gold, #c8a24a), #8a6d2b);
  color: #14161c; font-size: 2.4rem; font-weight: 700;
  display: grid; place-items: center;
}
.call-avatar__ring {
  position: absolute; inset: -6px; border-radius: 50%;
  border: 2px solid var(--gold, #c8a24a);
  opacity: .35;
}
.call-mode.is-listening .call-avatar__ring { animation: callPulse 1.4s ease-out infinite; opacity: .8; }
.call-mode.is-speaking .call-avatar__face { animation: callSpeak .9s ease-in-out infinite; }
@keyframes callPulse { 0% { transform: scale(.9); opacity: .8; } 100% { transform: scale(1.35); opacity: 0; } }
@keyframes callSpeak { 0%,100% { transform: scale(1); } 50% { transform: scale(1.06); } }

.call-name { margin: .2rem 0 0; font-size: 1.3rem; }
.call-status { margin: 0; color: var(--muted, #9aa3b2); font-size: .9rem; min-height: 1.2em; }
.call-transcript {
  width: 100%; max-height: 34vh; overflow-y: auto;
  display: grid; gap: .45rem; margin: .4rem 0 .2rem;
  text-align: start;
}
.call-bubble { padding: .5rem .7rem; border-radius: 12px; font-size: .9rem; line-height: 1.5; }
.call-bubble--me { background: color-mix(in srgb, var(--gold, #c8a24a) 18%, transparent); justify-self: end; }
.call-bubble--mohsen { background: color-mix(in srgb, #fff 8%, transparent); justify-self: start; }
.call-actions { display: flex; gap: 1rem; margin-top: .4rem; }
.call-btn {
  width: 54px; height: 54px; border-radius: 50%; border: none; cursor: pointer;
  display: grid; place-items: center; color: #fff; font-size: 1.1rem;
}
.call-btn--mute { background: #2a3342; }
.call-btn--mute.is-on { background: var(--gold, #c8a24a); color: #14161c; }
.call-btn--end { background: #d64545; }
.call-btn--type { background: #2a3342; }
.call-close { background: none; border: none; color: var(--muted, #9aa3b2); cursor: pointer; font: inherit; font-size: .85rem; margin-top: .3rem; }
