:root {
  --bg: #fafaf7; --panel: #ffffff; --text: #1d2125; --muted: #6a727b; --line: #e3e3dc;
  --accent: #c1272d; --accent-2: #006233; --accent-text: #fff; --user: #f0efe8; --danger: #b3261e;
  --notice-bg: #fff7e0; --notice-text: #6b5200; --radius: 14px; --side: 280px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Naskh Arabic", "Noto Sans Arabic", Tahoma, sans-serif;
}
:root[data-theme="dark"] {
  --bg: #15171a; --panel: #1d2024; --text: #e8e8e4; --muted: #9aa1a9; --line: #2d3136;
  --accent: #e0484d; --user: #262a2f; --notice-bg: #3a3118; --notice-text: #f0d98a; --danger: #ff8a80;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.5; -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
a { color: var(--accent-2); }
:root[data-theme="dark"] a { color: #6fd29a; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: .55rem .9rem; min-height: 44px; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.danger { color: var(--danger); border-color: var(--danger); }
button.ghost { background: transparent; }
button.icon { min-width: 44px; padding: .4rem; background: transparent; border-color: transparent; font-size: 1.15rem; }
button.link { background: none; border: 0; color: var(--accent-2); text-decoration: underline; min-height: 36px; padding: .2rem; }
.wide { width: 100%; }
.small { font-size: .82rem; } .muted { color: var(--muted); } .spacer { flex: 1; }
a.button, a.google { display: block; text-align: center; text-decoration: none; padding: .7rem .9rem; border: 1px solid var(--line); border-radius: 10px; min-height: 44px; }
.row { display: flex; gap: .6rem; align-items: center; } .col { display: flex; flex-direction: column; gap: .6rem; }
input[type=text], input[type=email], input[type=password], input:not([type]), select, textarea {
  width: 100%; padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); min-height: 44px;
}
select { width: auto; }
label { display: block; margin: .7rem 0; }
label > span:first-child { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .2rem; }
label.check { display: flex; gap: .6rem; align-items: flex-start; }
label.check input { width: 22px; height: 22px; margin-top: .15rem; flex: none; }
label.check span { margin: 0; color: var(--text); font-size: .92rem; }

#app { display: flex; height: 100dvh; }
#sidebar { width: var(--side); background: var(--panel); border-inline-end: 1px solid var(--line); display: flex; flex-direction: column; padding: .8rem; gap: .6rem; }
.side-bottom { display: flex; flex-direction: column; gap: .4rem; }
.side-bottom p { margin: .2rem 0; }
#lnk-admin::before { content: " · "; }
#chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
#chat-list li { display: flex; align-items: center; border-radius: 10px; }
#chat-list li.active, #chat-list li:hover { background: var(--user); }
#chat-list .title { flex: 1; text-align: start; background: none; border: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: .5rem .6rem; }
#chat-list .mini { min-width: 36px; min-height: 36px; padding: 0; border: 0; background: none; opacity: .6; }
#chat-list .empty { padding: .8rem; color: var(--muted); }
#scrim { display: none; }
main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
header { display: flex; align-items: center; gap: .4rem; padding: .4rem .8rem; border-bottom: 1px solid var(--line); background: var(--panel); }
header h1 { font-size: 1.05rem; margin: 0; }
#btn-menu { display: none; }
.tag { font-size: .7rem; background: var(--user); border-radius: 6px; padding: .1rem .4rem; font-weight: 500; color: var(--muted); vertical-align: middle; }
.notice { background: var(--notice-bg); color: var(--notice-text); font-size: .8rem; padding: .35rem .9rem; text-align: center; }
#messages { flex: 1; overflow-y: auto; padding: 1rem .8rem 0; scroll-behavior: smooth; }
.msg { max-width: 760px; margin: 0 auto 1rem; display: flex; flex-direction: column; }
.msg .bubble { padding: .65rem .9rem; border-radius: var(--radius); overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--user); align-self: flex-end; max-width: 92%; white-space: pre-wrap; }
.msg.assistant .bubble { background: transparent; padding-inline: 0; }
.bubble p, .bubble ul, .bubble ol, .bubble pre { margin: .4rem 0; }
.bubble pre { background: var(--user); padding: .6rem; border-radius: 8px; overflow-x: auto; direction: ltr; text-align: left; }
.bubble code { background: var(--user); padding: .05rem .3rem; border-radius: 4px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9em; }
.bubble pre code { background: none; padding: 0; }
.actions { display: flex; gap: .1rem; flex-wrap: wrap; margin-top: .1rem; }
.actions button { min-height: 36px; min-width: 36px; padding: .1rem .45rem; border: 0; background: none; opacity: .65; font-size: 1rem; }
.actions button:hover, .actions button.on { opacity: 1; background: var(--user); }
.actions .info { align-self: center; font-size: .75rem; color: var(--muted); padding-inline: .4rem; }
.typing::after { content: "▍"; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
#starters { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; padding: .5rem .8rem; max-width: 760px; margin: 0 auto; }
#starters button { border-radius: 999px; font-size: .9rem; }
.status { text-align: center; min-height: 1.3rem; padding: 0 .8rem; }
#composer { display: flex; gap: .5rem; align-items: flex-end; padding: .5rem .8rem calc(.6rem + env(safe-area-inset-bottom)); max-width: 800px; width: 100%; margin: 0 auto; position: relative; }
#composer textarea { resize: none; max-height: 9rem; border-radius: 14px; }
.counter { position: absolute; inset-inline-end: 7.5rem; bottom: 1rem; pointer-events: none; }
.empty-hero { text-align: center; margin: 12vh auto 1rem; color: var(--muted); }
.empty-hero b { display: block; font-size: 1.6rem; color: var(--text); }

dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--panel); color: var(--text); width: min(440px, 94vw); max-height: 92dvh; padding: 1rem 1.2rem; overflow-y: auto; }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; }
.dlg-head h2 { margin: 0; font-size: 1.1rem; }
.tabs { display: flex; gap: .3rem; margin: .5rem 0; }
.tab { flex: 1; border: 0; border-bottom: 2px solid var(--line); border-radius: 0; background: none; font-size: .9rem; padding: .4rem; }
.tab.active { border-color: var(--accent); font-weight: 600; }
.msg-line { min-height: 1.2rem; margin: .4rem 0; font-size: .88rem; color: var(--danger); }
.msg-line.ok { color: var(--accent-2); }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .6rem 0; }
.chips button { border-radius: 999px; font-size: .88rem; min-height: 38px; }
.chips button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
#toast { position: fixed; bottom: 5rem; inset-inline: 0; margin: 0 auto; width: max-content; max-width: 90vw; background: #222; color: #fff; padding: .55rem .9rem; border-radius: 10px; font-size: .9rem; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; }
#toast.show { opacity: .95; }

@media (max-width: 780px) {
  #btn-menu { display: inline-block; }
  #sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 20; transform: translateX(-102%); transition: transform .2s; width: min(300px, 86vw); }
  [dir="rtl"] #sidebar { transform: translateX(102%); }
  body.menu-open #sidebar { transform: none; }
  body.menu-open #scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 10; }
  .counter { inset-inline-end: 6.5rem; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
