:root {
  --bg: #0e1320;
  --surface: #161d2e;
  --surface-2: #1e2740;
  --line: #2a3452;
  --text: #eef1f8;
  --muted: #9aa5c0;
  --accent: #f4b860;
  --accent-ink: #2a1b02;
  --user: #24304f;
  --bad: #ff8f8f;
  --ok: #8fe0b0;
  --radius: 18px;
  --font: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #faf7f1;
    --surface: #ffffff;
    --surface-2: #f1ece2;
    --line: #e2dbcd;
    --text: #1c2233;
    --muted: #6a7187;
    --accent: #d98a1c;
    --accent-ink: #ffffff;
    --user: #efe6d4;
    --bad: #b3261e;
    --ok: #1c7a45;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
h1, h2, p { margin: 0; }
h1 { font-size: 1.5rem; font-weight: 600; line-height: 1.3; }
h2 { font-size: 1.05rem; font-weight: 600; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
.muted { color: var(--muted); }
.pad { padding: 8px 12px; font-size: .92rem; }

/* brand mark: a small sun, "nour" means light */
.mark {
  width: 64px; height: 64px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe2a8, var(--accent) 55%, #c9781a 100%);
  box-shadow: 0 0 0 10px color-mix(in srgb, var(--accent) 14%, transparent);
}
.mark.small { width: 28px; height: 28px; box-shadow: none; }
.mark.glow { box-shadow: 0 0 0 12px color-mix(in srgb, var(--accent) 12%, transparent), 0 0 60px color-mix(in srgb, var(--accent) 35%, transparent); }
.mark.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(.88); opacity: .7; } }

/* centered screens */
.center {
  min-height: 100dvh; display: grid; place-items: center;
  padding: 24px; padding-top: max(24px, env(safe-area-inset-top));
}
.auth-card {
  width: min(380px, 100%); display: grid; gap: 14px; justify-items: center; text-align: center;
}
.brand span { color: var(--accent); margin-inline-start: 6px; }
#auth-form { width: 100%; display: grid; gap: 12px; margin-top: 10px; text-align: start; }
label { display: grid; gap: 6px; font-size: .9rem; color: var(--muted); }
input, textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 13px 14px; outline: none; color: var(--text);
}
input:focus, textarea:focus { border-color: var(--accent); }
.primary {
  background: var(--accent); color: var(--accent-ink); font-weight: 600;
  border-radius: 14px; padding: 13px 18px; min-height: 48px;
}
.primary:disabled { opacity: .6; }
.primary.block { width: 100%; }
.link-btn { color: var(--muted); padding: 8px; text-decoration: underline; text-underline-offset: 3px; }
.auth-msg { font-size: .92rem; min-height: 1.2em; }
.auth-msg.bad { color: var(--bad); }
.auth-msg.ok { color: var(--ok); }

/* app shell */
#view-app { height: 100dvh; display: flex; overflow: hidden; }
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100%; }
#topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
}
.top-title { font-weight: 600; letter-spacing: .02em; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; color: var(--text);
}
.icon-btn.small { width: 36px; height: 36px; color: var(--muted); flex: none; }
.icon-btn:active { background: var(--surface-2); }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.small svg { width: 16px; height: 16px; }

/* drawer */
#drawer {
  position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 30;
  width: min(320px, 86vw); background: var(--surface);
  border-inline-end: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 10px;
  padding: 16px 12px; padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateX(-102%); transition: transform .22s ease;
}
[dir="rtl"] #drawer { transform: translateX(102%); }
.drawer-open #drawer { transform: none; }
#scrim {
  position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.5);
  opacity: 0; pointer-events: none; transition: opacity .22s;
}
.drawer-open #scrim { opacity: 1; pointer-events: auto; }
.drawer-head { display: flex; align-items: center; gap: 10px; padding: 0 6px 6px; }
.drawer-head span { color: var(--accent); }
.drawer-title { font-size: .8rem; color: var(--muted); font-weight: 500; padding: 8px 8px 0; }
#conv-list { flex: 1; overflow-y: auto; display: grid; gap: 2px; align-content: start; }
.conv { display: flex; align-items: center; border-radius: 12px; }
.conv.active { background: var(--surface-2); }
.conv-open {
  flex: 1; min-width: 0; text-align: start; padding: 11px 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.drawer-foot { display: grid; gap: 2px; border-top: 1px solid var(--line); padding-top: 8px; }
.row-btn { text-align: start; padding: 12px; border-radius: 12px; }
.row-btn:active { background: var(--surface-2); }

@media (min-width: 900px) {
  #drawer { position: static; transform: none !important; flex: none; }
  #scrim, #menu-btn { display: none; }
  #topbar { justify-content: space-between; }
  .top-title { margin-inline-start: 8px; }
}

/* conversation */
#scroll { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
#messages, #empty { width: min(760px, 100%); margin-inline: auto; padding: 16px 14px; }
#empty { display: grid; gap: 12px; justify-items: center; text-align: center; padding-top: 12dvh; }
.chips { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; margin-top: 14px; }
.chip {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 14px; text-align: start; font-size: .94rem; line-height: 1.45; min-height: 64px;
}
.chip:active { border-color: var(--accent); }

#messages { display: grid; gap: 16px; }
.msg { display: grid; gap: 6px; }
.msg.user { justify-items: end; }
.bubble { max-width: 100%; overflow-wrap: anywhere; }
.msg.user .bubble {
  background: var(--user); border-radius: var(--radius); border-end-end-radius: 6px;
  padding: 10px 14px; max-width: 86%; white-space: pre-wrap;
}
.msg.assistant .bubble > :first-child { margin-top: 0; }
.msg.assistant .bubble > :last-child { margin-bottom: 0; }
.bubble p, .bubble ul, .bubble ol { margin: 0 0 .7em; }
.bubble ul, .bubble ol { padding-inline-start: 1.3em; }
.bubble li { margin-bottom: .25em; }
.bubble h1, .bubble h2, .bubble h3 { font-size: 1.05rem; margin: .9em 0 .4em; }
.bubble a { color: var(--accent); }
.bubble code { background: var(--surface-2); padding: .1em .35em; border-radius: 6px; font-size: .9em; direction: ltr; unicode-bidi: embed; }
.bubble pre { background: var(--surface-2); padding: 12px; border-radius: 12px; overflow-x: auto; direction: ltr; text-align: left; }
.bubble pre code { background: none; padding: 0; }
.bubble table { border-collapse: collapse; display: block; overflow-x: auto; margin-bottom: .7em; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: 6px 10px; text-align: start; }
.bubble blockquote { margin: 0 0 .7em; padding-inline-start: 12px; border-inline-start: 3px solid var(--line); color: var(--muted); }

.msg-foot { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.ghost-btn { color: var(--muted); font-size: .85rem; padding: 6px 8px; border-radius: 8px; margin-inline-start: auto; }
.sources { font-size: .88rem; color: var(--muted); min-width: 0; }
.sources summary { cursor: pointer; padding: 6px 0; }
.sources a {
  display: block; color: var(--text); padding: 6px 0; text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 70vw;
}
.msg-error { color: var(--bad); font-size: .92rem; }

.dots { display: inline-flex; gap: 5px; padding: 8px 0; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: dot 1.1s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* composer */
#composer {
  width: min(760px, 100%); margin-inline: auto; display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 12px; padding-bottom: max(12px, env(safe-area-inset-bottom));
}
#input { resize: none; border-radius: 22px; padding: 12px 16px; max-height: 160px; line-height: 1.5; }
#send {
  flex: none; width: 48px; height: 48px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
}
#send:disabled { opacity: .4; }
#send .i-stop { display: none; fill: currentColor; stroke: none; }
#send.stop .i-send { display: none; }
#send.stop .i-stop { display: block; }

/* memory sheet */
.sheet-wrap { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.55); display: grid; align-items: end; justify-items: center; }
.sheet {
  width: min(560px, 100%); max-height: 86dvh; overflow-y: auto; background: var(--surface);
  border-radius: 22px 22px 0 0; padding: 16px; padding-bottom: max(16px, env(safe-area-inset-bottom));
  display: grid; gap: 12px;
}
@media (min-width: 700px) { .sheet-wrap { align-items: center; } .sheet { border-radius: 22px; } }
.sheet header { display: flex; align-items: center; justify-content: space-between; }
#memory-list { display: grid; gap: 8px; }
.note { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border-radius: 12px; padding: 8px 8px 8px 12px; padding-inline: 12px 4px; }
.note span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
#memory-form { display: flex; gap: 8px; }
#memory-form input { background: var(--bg); }

#toast {
  position: fixed; inset-inline: 0; bottom: 96px; margin-inline: auto; width: fit-content; max-width: 86vw;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: .92rem;
  opacity: 0; transform: translateY(8px); transition: .2s; pointer-events: none; z-index: 50; text-align: center;
}
#toast.on { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

/* ---------- stage 2: tabs, feed, ideas, goals, approvals ---------- */
.tabview { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.page { overflow-y: auto; padding: 18px 14px 28px; }
.page > * { width: min(760px, 100%); margin-inline: auto; }
.page h1 { font-size: 1.35rem; margin-bottom: 4px; }
.page h2 { font-size: .8rem; font-weight: 500; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; margin: 22px auto 8px; }
.page .lead { color: var(--muted); margin-bottom: 6px; }
#composer { padding-bottom: 8px; }
#tabs {
  display: grid; grid-template-columns: repeat(5, 1fr);
  border-top: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
  background: var(--bg); padding: 4px 4px max(6px, env(safe-area-inset-bottom));
}
#tabs button {
  display: grid; justify-items: center; gap: 2px; padding: 8px 2px 4px;
  color: var(--muted); font-size: .72rem; border-radius: 12px; min-height: 52px;
}
#tabs button svg { width: 22px; height: 22px; }
#tabs button[aria-current="page"] { color: var(--accent); }
#toast { bottom: 150px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 14px; display: grid; gap: 6px; margin-bottom: 10px;
}
.card .row { display: flex; align-items: center; gap: 10px; }
.card .grow { flex: 1; min-width: 0; }
.card strong { font-weight: 600; overflow-wrap: anywhere; }
.card .meta { color: var(--muted); font-size: .86rem; }
.card .detail { color: var(--muted); font-size: .92rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card.tap { cursor: pointer; text-align: start; width: 100%; }
.card.tap:active { border-color: var(--accent); }
.tag {
  display: inline-block; font-size: .72rem; font-weight: 600; letter-spacing: .03em;
  color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent);
  padding: 2px 8px; border-radius: 999px; width: fit-content;
}
.tag.done { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.btn { border: 1px solid var(--line); border-radius: 12px; padding: 9px 14px; font-size: .92rem; min-height: 40px; }
.btn.go { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn:active { opacity: .8; }
.empty-note { color: var(--muted); padding: 18px 4px; text-align: center; }
.inline-form { display: flex; gap: 8px; margin: 12px auto 4px; }
.idea-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.idea-grid .card { margin: 0; min-height: 92px; align-content: start; }
.idea-grid .card .detail { -webkit-line-clamp: 3; }
.cards { display: grid; gap: 8px; margin-top: 4px; }
.cards .card { margin: 0; border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.cards .card.settled { border-color: var(--line); opacity: .75; }
.hero-empty { display: grid; justify-items: center; gap: 10px; text-align: center; padding-top: 14dvh; color: var(--muted); }
@media (min-width: 700px) { .idea-grid { grid-template-columns: repeat(3, 1fr); } }

/* ---------- stage 3: connected apps, email and event cards ---------- */
.body-preview { white-space: pre-wrap; -webkit-line-clamp: 6 !important; color: var(--text) !important; background: var(--bg); border-radius: 10px; padding: 8px 10px; }
a.link-btn { font-size: .85rem; }

/* ---------- stage 4: library, documents, attachments ---------- */
#attach-btn { flex: none; color: var(--muted); width: 44px; height: 48px; }
#attach-chip {
  width: min(736px, calc(100% - 24px)); margin: 0 auto; display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 6px 6px 6px 12px; font-size: .9rem;
}
#attach-chip span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-view { position: fixed; inset: 0; z-index: 45; background: var(--bg); display: flex; flex-direction: column; }
.doc-bar {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
}
.doc-actions { display: flex; gap: 6px; margin-inline-start: auto; overflow-x: auto; }
.doc-actions .btn { white-space: nowrap; padding: 7px 12px; min-height: 36px; font-size: .86rem; }
.doc-body { flex: 1; overflow-y: auto; width: min(760px, 100%); margin-inline: auto; padding: 22px 18px 60px; }
.doc-body h1 { font-size: 1.5rem; margin: 0 0 .6em; }
.doc-body h2 { font-size: 1.2rem; margin: 1.2em 0 .5em; }
.doc-body h3 { font-size: 1.05rem; }
.doc-body table { display: table; width: 100%; }
@media print {
  body > *:not(#doc) { display: none !important; }
  .doc-view { position: static; display: block; background: #fff; color: #000; }
  .doc-bar { display: none; }
  .doc-body { overflow: visible; width: 100%; padding: 0; color: #000; }
  .doc-body a { color: #000; }
  .doc-body code, .doc-body pre { background: #f2f2f2; }
}
