/* Anwaar AI — deep green + brass. Layout is LTR; every text block uses dir="auto"
   so Urdu, Roman Urdu and English each read naturally. */

:root {
  --font-ur: "Noto Naskh Arabic", "Noto Nastaliq Urdu", "Segoe UI", Tahoma, serif;
  --font-nq: "Noto Nastaliq Urdu", "Noto Naskh Arabic", serif;
  --font-en: "Sora", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 18px;
  --sb-w: 292px;
}

:root[data-theme="dark"] {
  --bg: #0b2016;
  --bg-2: #0f2a1d;
  --surface: #143524;
  --surface-2: #19402b;
  --line: #234d38;
  --text: #ecf2ea;
  --muted: #9db8a6;
  --accent: #d9b45a;
  --accent-ink: #231a05;
  --user-bg: #d9b45a;
  --user-ink: #231a05;
  --danger: #ff8a7a;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

:root[data-theme="light"] {
  --bg: #eef3ef;
  --bg-2: #e4ece6;
  --surface: #ffffff;
  --surface-2: #f3f7f4;
  --line: #cfdcd3;
  --text: #12261b;
  --muted: #587064;
  --accent: #0f6b43;
  --accent-ink: #ffffff;
  --user-bg: #0f6b43;
  --user-ink: #ffffff;
  --danger: #b3321f;
  --shadow: 0 10px 26px rgba(18, 38, 27, .12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ur), var(--font-en);
  font-size: 17px;
  line-height: 1.8;
  overflow: hidden;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app { display: flex; height: 100dvh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sb-w);
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 16px 14px calc(14px + env(safe-area-inset-bottom));
  gap: 12px;
  z-index: 30;
}
.sb-head { display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--accent); }
.logo { width: 38px; height: 38px; flex: none; }
.brand-ur { font-family: var(--font-nq); font-weight: 700; font-size: 20px; line-height: 1.7; color: var(--text); }
.brand-en { font-family: var(--font-en); font-size: 12px; letter-spacing: .06em; color: var(--muted); margin-top: -4px; }

.btn-new {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 14px; border-radius: 14px; border: 1px dashed var(--accent);
  background: transparent; color: var(--accent); font-weight: 600;
}
.btn-new svg { width: 18px; height: 18px; }
.btn-new:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }

.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; margin: 0 -4px; padding: 0 4px; }
.chat-item {
  display: flex; align-items: center; gap: 6px;
  border-radius: 12px; padding: 2px 4px 2px 12px;
}
.chat-item:hover { background: var(--surface); }
.chat-item.active { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); }
.chat-item .t {
  flex: 1; text-align: start; background: none; border: 0; padding: 9px 0;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 15px; line-height: 1.5;
}
.chat-item .del { background: none; border: 0; color: var(--muted); width: 32px; height: 32px; border-radius: 8px; opacity: .0; }
.chat-item:hover .del, .chat-item.active .del { opacity: 1; }
.chat-item .del:hover { color: var(--danger); }
.chat-empty { color: var(--muted); font-size: 14px; padding: 8px 12px; }

.sb-foot { display: flex; flex-direction: column; gap: 6px; font-family: var(--font-en); font-size: 12.5px; }
.sb-foot a { color: var(--muted); text-decoration: none; }
.sb-foot a:hover { color: var(--accent); }
.link-btn { background: none; border: 0; padding: 0; text-align: start; color: var(--muted); font-size: 12.5px; text-decoration: underline; text-underline-offset: 3px; }
.link-btn:hover { color: var(--danger); }

.scrim { display: none; }

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

.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
}
.top-title { flex: 1; min-width: 0; text-align: center; font-weight: 600; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.icon-btn {
  width: 42px; height: 42px; flex: none; border-radius: 14px; border: 0;
  background: transparent; color: var(--muted); display: grid; place-items: center;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:hover { background: var(--surface); color: var(--text); }
.icon-btn.on { background: var(--accent); color: var(--accent-ink); animation: pulse 1.3s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--accent) 25%, transparent); } }

.pill-btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  border-radius: 999px; padding: 4px 12px; font-size: 14px; line-height: 1.6;
}
.pill-btn:hover { color: var(--text); border-color: var(--accent); }

/* ---------- Messages ---------- */
.messages {
  flex: 1; overflow-y: auto; scroll-behavior: smooth;
  padding: 18px 14px 8px; display: flex; flex-direction: column; gap: 16px;
}
.messages > * { width: 100%; max-width: 780px; margin-inline: auto; }

.msg { display: flex; flex-direction: column; gap: 4px; }
.msg.user { align-items: flex-end; }
.msg.ai { align-items: flex-start; }

.bubble {
  max-width: min(100%, 680px); padding: 10px 16px; border-radius: var(--radius);
  overflow-wrap: anywhere; word-break: break-word;
}
.msg.user .bubble { background: var(--user-bg); color: var(--user-ink); border-end-end-radius: 6px; white-space: pre-wrap; }
.msg.ai .bubble { background: var(--surface); border: 1px solid var(--line); border-end-start-radius: 6px; }
.msg .attached { max-width: 220px; border-radius: 14px; border: 1px solid var(--line); display: block; margin-bottom: 4px; }
.msg.err .bubble { border-color: var(--danger); color: var(--danger); }

.bubble > :first-child { margin-top: 0; }
.bubble > :last-child { margin-bottom: 0; }
.bubble p { margin: .55em 0; }
.bubble h2, .bubble h3, .bubble h4, .bubble h5 { margin: 1em 0 .3em; line-height: 1.5; font-weight: 600; }
.bubble h2 { font-size: 1.2em; } .bubble h3 { font-size: 1.1em; } .bubble h4, .bubble h5 { font-size: 1em; }
.bubble ul, .bubble ol { margin: .5em 0; padding-inline-start: 1.5em; }
.bubble li { margin: .15em 0; }
.bubble a { color: var(--accent); text-underline-offset: 3px; }
.bubble blockquote { margin: .6em 0; padding: .1em .9em; border-inline-start: 3px solid var(--accent); color: var(--muted); }
.bubble hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.bubble code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .86em; background: var(--surface-2); padding: .1em .4em; border-radius: 6px; direction: ltr; unicode-bidi: embed; }
.code { position: relative; margin: .7em 0; border-radius: 14px; background: #08150e; border: 1px solid var(--line); direction: ltr; }
:root[data-theme="light"] .code { background: #0e2a1c; }
.code pre { margin: 0; padding: 34px 14px 12px; overflow-x: auto; color: #e6efe4; line-height: 1.55; }
.code pre code { background: none; padding: 0; font-size: 13.5px; color: inherit; }
.code .lang { position: absolute; top: 6px; left: 12px; font: 11.5px var(--font-en); color: #8fb09a; }
.copy-code { position: absolute; top: 4px; right: 6px; background: none; border: 0; color: #8fb09a; font: 12px var(--font-en); padding: 4px 8px; border-radius: 8px; }
.copy-code:hover { background: #17352550; color: #fff; }
.tbl { overflow-x: auto; margin: .7em 0; }
.tbl table { border-collapse: collapse; min-width: 100%; font-size: .92em; }
.tbl th, .tbl td { border: 1px solid var(--line); padding: 6px 10px; text-align: start; }
.tbl th { background: var(--surface-2); }

.typing { display: inline-flex; gap: 5px; padding: 6px 2px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); opacity: .35; animation: blink 1.1s infinite; }
.typing i:nth-child(2) { animation-delay: .18s; } .typing i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 40% { opacity: 1; transform: translateY(-2px); } }

.actions { display: flex; gap: 2px; margin-inline-start: 6px; }
.actions button {
  background: none; border: 0; color: var(--muted); font: 12.5px var(--font-en);
  padding: 2px 8px; border-radius: 8px; display: inline-flex; align-items: center; gap: 5px;
}
.actions button:hover { background: var(--surface); color: var(--text); }
.actions svg { width: 15px; height: 15px; }
.actions button.on { color: var(--accent); }

/* ---------- Welcome ---------- */
.welcome { padding: 24px 0 8px; text-align: center; }
.welcome .hello { font-family: var(--font-nq); font-weight: 700; font-size: clamp(26px, 6vw, 38px); line-height: 2; margin: 0; color: var(--accent); }
.welcome .sub { margin: 0 auto 22px; max-width: 520px; color: var(--muted); font-size: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.card {
  border: 1px solid var(--line); background: var(--surface); border-radius: 16px; padding: 12px 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; text-align: center; line-height: 1.6;
  transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card b { font-size: 16.5px; font-weight: 600; }
.card span { font-size: 13.5px; color: var(--muted); font-family: var(--font-en); }

/* ---------- Composer ---------- */
.composer { padding: 6px 12px calc(10px + env(safe-area-inset-bottom)); max-width: 804px; width: 100%; margin-inline: auto; }
.modes { display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 8px; scrollbar-width: none; }
.modes::-webkit-scrollbar { display: none; }
.mode {
  flex: none; border: 1px solid var(--line); background: transparent; color: var(--muted);
  border-radius: 999px; padding: 2px 14px; font-size: 15px; line-height: 1.8; white-space: nowrap;
}
.mode:hover { color: var(--text); border-color: var(--accent); }
.mode.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }

.img-preview { position: relative; width: 76px; margin: 0 0 8px 6px; }
.img-preview img { width: 76px; height: 76px; object-fit: cover; border-radius: 14px; border: 1px solid var(--line); display: block; }
.img-preview .x { position: absolute; top: -7px; right: -7px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: var(--danger); color: #fff; line-height: 1; font-size: 16px; }

.input-row {
  display: flex; align-items: flex-end; gap: 2px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 24px; padding: 5px 6px;
  transition: border-color .15s;
}
.input-row:focus-within { border-color: var(--accent); }
textarea {
  flex: 1; min-width: 0; resize: none; border: 0; background: transparent; outline: none;
  max-height: 170px; padding: 9px 6px; line-height: 1.7; font-size: 17px;
}
textarea:focus-visible { outline: none; }
textarea::placeholder { color: var(--muted); }
.send-btn {
  width: 42px; height: 42px; flex: none; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
}
.send-btn svg { width: 20px; height: 20px; fill: currentColor; stroke: none; }
.send-btn.stop svg { display: none; }
.send-btn.stop::before { content: ""; width: 14px; height: 14px; border-radius: 3px; background: currentColor; }
.send-btn:disabled { opacity: .4; cursor: default; }
.hint { text-align: center; color: var(--muted); font-size: 12.5px; line-height: 1.7; padding-top: 6px; }

/* ---------- Responsive ---------- */
@media (max-width: 899px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; transform: translateX(-102%); transition: transform .22s ease; box-shadow: var(--shadow); }
  .app.menu-open .sidebar { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .5); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20; }
  .app.menu-open .scrim { opacity: 1; pointer-events: auto; }
}
@media (min-width: 900px) {
  #menuBtn, .sb-close { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
