/* Ra — white-label theme via CSS variables (solar amber on ink + the night pole). */
:root {
  --ink: #0d0b08;
  --ink-2: #16130d;
  --panel: #1d1810;
  --line: #2c2517;
  --text: #f3ead8;
  --muted: #9b8e74;
  --amber: #f6b53c;
  --amber-2: #c8631b;
  --night: #0a1128;   /* deep pre-dawn indigo (gradient pole) */
  --night-2: #1b2a52; /* rising night blue */
  --gold: #ffd27a;    /* dawn gold */
  --ok: #6fbf73;
  --warn: #e0a83c;
  --danger: #ff9b9b;
  --radius: 14px;
  --safe: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--ink);
  color: var(--text);
  font: 16px/1.5 -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  display: flex; flex-direction: row; height: 100dvh; overflow: hidden;
}

/* ── sidebar (nav) ─────────────────────────────────────────────────────── */
#sidebar {
  width: 230px; flex-shrink: 0; display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--ink-2), var(--ink));
  border-right: 1px solid var(--line);
}
#sidebar .brand {
  display: flex; align-items: center; gap: 10px;
  padding: 16px; border-bottom: 1px solid var(--line);
  /* Duat — the static night wash behind the brand (one gradient, zero runtime cost) */
  background: linear-gradient(160deg, var(--night) 0%, var(--night-2) 55%, rgba(200, 99, 27, .35) 100%);
}
#sidebar .brand .logo { width: 26px; height: 26px; }
#sidebar .brand .title { font-weight: 700; letter-spacing: .5px; }
.side-foot { padding: 8px; border-top: 1px solid var(--line); }

#tabs { display: flex; flex-direction: column; gap: 4px; padding: 8px; flex: 1; overflow-y: auto; }
#tabs button, .navitem {
  display: flex; align-items: center; gap: 12px; width: 100%;
  background: transparent; border: 1px solid transparent; border-radius: 10px;
  color: var(--muted); font-size: 14px; font-weight: 600; min-height: 44px;
  padding: 0 12px; text-align: left;
}
#tabs button svg, .navitem svg { width: 18px; height: 18px; flex-shrink: 0; }
#tabs button:hover, .navitem:hover { color: var(--text); }
#tabs button.active, .navitem.active {
  color: var(--amber); background: var(--ink-2); border-color: var(--line);
}

/* ── main column + slim topbar ─────────────────────────────────────────── */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100dvh; }
.topbar {
  display: flex; align-items: center; gap: 10px; min-height: 52px;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--ink-2), var(--ink));
  position: relative;
}
/* Solar Noon — the 3px sun-line under the topbar, animated ONLY while Horus thinks
   (replaces a spinner; costs one compositor layer, nothing when idle). */
.topbar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 3px;
  background: linear-gradient(90deg, transparent, var(--night-2), var(--amber), var(--gold), var(--amber-2), transparent);
  background-size: 220% 100%;
  opacity: 0; transition: opacity .4s;
}
body.thinking .topbar::after { opacity: 1; animation: sunline 2.6s linear infinite; }
@keyframes sunline { from { background-position: 120% 0; } to { background-position: -120% 0; } }
@media (prefers-reduced-motion: reduce) {
  body.thinking .topbar::after { animation: none; background-position: 50% 0; }
}
.topbar .title { font-weight: 700; letter-spacing: .5px; }
.topbar .sub { color: var(--muted); font-size: 12px; margin-left: auto; }
.iconbtn {
  min-height: 40px; min-width: 40px; padding: 0 10px;
  background: transparent; border: 1px solid var(--line); border-radius: 10px;
  color: var(--muted); font-size: 20px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
#navToggle { display: none; }
.only-mobile { display: none; }
#scrim { display: none; }

/* mobile: the sidebar becomes an off-canvas drawer */
@media (max-width: 720px) {
  #sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 40;
    width: 268px; max-width: 82vw; transform: translateX(-100%);
    transition: transform .22s ease;
  }
  body.nav-open #sidebar { transform: translateX(0); }
  #scrim {
    display: block; position: fixed; inset: 0; z-index: 30;
    background: rgba(0, 0, 0, .5); opacity: 0; pointer-events: none; transition: opacity .2s;
  }
  body.nav-open #scrim { opacity: 1; pointer-events: auto; }
  #navToggle { display: inline-flex; }
  .only-mobile { display: inline-flex; }
}

/* login hides the app chrome */
body.login-mode #sidebar, body.login-mode .topbar, body.login-mode #scrim { display: none; }

/* ── view + surfaces ───────────────────────────────────────────────────── */
#view { flex: 1; min-height: 0; display: flex; }
.surface { flex: 1; min-height: 0; display: none; flex-direction: column; overflow-y: auto; }
.surface.active { display: flex; }
#v-chat { overflow: hidden; }            /* chat scrolls its own log, not the surface */
#v-chat.active { display: flex; }

.head {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--ink); z-index: 2;
}
.head h2 { font-size: 15px; margin: 0; flex: 1; font-weight: 700; letter-spacing: .3px; }

.list { display: flex; flex-direction: column; gap: 10px; padding: 16px; }
.item {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px;
}
.item .grow { flex: 1; min-width: 0; }
.item .t { font-weight: 600; word-wrap: break-word; }
.item .t.done { color: var(--muted); text-decoration: line-through; }
.item .m { color: var(--muted); font-size: 12px; margin-top: 2px; }
.item .body { color: var(--text); font-size: 14px; margin-top: 8px; white-space: pre-wrap; word-wrap: break-word; }
.item.tappable { cursor: pointer; }

.addbar { display: flex; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.addbar input, .addbar textarea {
  flex: 1; background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 12px; padding: 11px 13px; font: inherit; min-height: 44px;
}
.addbar textarea { resize: none; max-height: 120px; }
.addbar input:focus, .addbar textarea:focus { outline: none; border-color: var(--amber-2); }
.addcol { display: flex; flex-direction: column; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.addcol .row { display: flex; gap: 8px; }

.empty { color: var(--muted); text-align: center; padding: 44px 24px; font-size: 14px; }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 0; }

.risk { font-size: 11px; color: var(--ink); background: var(--warn); padding: 1px 7px; border-radius: 999px; margin-left: 6px; vertical-align: middle; }

/* ── Sessions — context-fill sun-disc ring + row chrome ─────────────────── */
.sessbar { display: flex; gap: 8px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.sessbar .threadsearch {
  flex: 1; min-width: 0; background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; padding: 9px 13px; font: inherit;
}
.sessbar .threadsearch:focus { outline: none; border-color: var(--amber-2); }
.archtoggle { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.fillring {
  --hole: 70%;
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  position: relative; background: var(--line);
}
.fillring::before {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle, var(--panel) var(--hole), transparent calc(var(--hole) + 1%));
}
.fillring .pct {
  position: relative; z-index: 1; font-size: 10px; font-weight: 700;
  font-variant-numeric: tabular-nums; color: var(--text);
}
.fillring.na .pct { color: var(--muted); }
.fillring.hot .pct { color: var(--danger); }
.item.sess .t { display: flex; align-items: center; gap: 6px; }
.pulse {
  width: 8px; height: 8px; border-radius: 50%; background: var(--amber);
  display: inline-block; animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }
button.mini.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }

/* admin */
.kv { padding: 16px; display: flex; flex-direction: column; gap: 2px; }
.kv .pair { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.kv .k { color: var(--muted); width: 42%; flex-shrink: 0; }
.kv .v { color: var(--text); word-wrap: break-word; }
.kv .v.ok { color: var(--ok); }
.kv .v.stale { color: var(--danger); font-weight: 700; }

/* ── chat ──────────────────────────────────────────────────────────────── */
#log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 88%; padding: 10px 13px; border-radius: var(--radius); white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: linear-gradient(135deg, var(--amber), var(--amber-2)); color: #1a1206; border-bottom-right-radius: 4px; }
.msg.horus { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.thinking { align-self: flex-start; color: var(--muted); font-style: italic; font-size: 14px; background: transparent; padding: 2px 4px; }
.tool { align-self: flex-start; font-size: 13px; color: var(--muted); border-left: 2px solid var(--amber-2); padding: 4px 10px; background: var(--ink-2); border-radius: 6px; }
.err { align-self: center; color: var(--danger); font-size: 14px; }

/* approval card (Inbox + inline in chat) */
.approval { align-self: stretch; background: var(--ink-2); border: 1px solid var(--warn); border-radius: var(--radius); padding: 12px; }
.approval h4 { margin: 0 0 6px; color: var(--warn); font-size: 14px; }
.approval pre { margin: 6px 0; font-size: 12px; color: var(--muted); white-space: pre-wrap; max-height: 140px; overflow: auto; }
.approval textarea.json {
  width: 100%; min-height: 84px; max-height: 220px; resize: vertical;
  background: var(--ink); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.approval .meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.approval .row { display: flex; gap: 8px; margin-top: 10px; }
.approval .row button { flex: 1; }

/* buttons + composer */
button {
  font: inherit; font-weight: 600; border: 0; border-radius: 10px; padding: 11px 14px;
  background: var(--panel); color: var(--text); border: 1px solid var(--line); min-height: 44px;
}
button.primary { background: linear-gradient(135deg, var(--amber), var(--amber-2)); color: #1a1206; border: 0; }
button.ghost { background: transparent; color: var(--muted); }
button.mini { min-height: 36px; padding: 6px 12px; font-size: 13px; }
button:active { transform: translateY(1px); }
button:disabled { opacity: .55; }

.composer {
  display: flex; gap: 8px; padding: 10px 12px calc(10px + var(--safe));
  border-top: 1px solid var(--line); background: var(--ink-2);
}
#input {
  flex: 1; resize: none; max-height: 120px; min-height: 44px;
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 12px; padding: 11px 13px; font: inherit;
}
#input:focus { outline: none; border-color: var(--amber-2); }

/* ── nav badge (Inbox) ─────────────────────────────────────────────────── */
.badge {
  margin-left: auto; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--amber-2); color: #fff; font-size: 10px; font-weight: 700; font-style: normal;
  display: inline-flex; align-items: center; justify-content: center;
}

/* ── login ─────────────────────────────────────────────────────────────── */
.login { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; position: relative; overflow: hidden; }
.login .gradient-canvas { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; }
.login form {
  width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px;
  background: rgba(29, 24, 16, .88); backdrop-filter: blur(6px);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 22px;
  position: relative; z-index: 1;
}
.login h2 { margin: 0 0 4px; font-size: 18px; }
.login input {
  background: var(--ink); color: var(--text); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; font: inherit; min-height: 44px;
}
.login input:focus { outline: none; border-color: var(--amber-2); }
.login .err { color: var(--danger); font-size: 13px; min-height: 18px; }

/* ── chat header: model picker + agent/chat toggle + thread switcher ─────── */
.chathead {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 10px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.chathead .chatswitch { max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chathead select.mini {
  background: var(--ink); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 5px 8px; font-size: 12px; margin-left: auto;
}
.chathead button.mini { white-space: nowrap; }

/* thread list panel (find / continue / pin / archive) */
.threadpanel {
  border-bottom: 1px solid var(--line); background: var(--ink);
  max-height: 50vh; overflow: auto; padding: 8px;
}
.threadpanel .threadsearch {
  width: 100%; box-sizing: border-box; background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; font: inherit; margin-bottom: 8px;
}
.threadpanel .item.current { border-color: var(--amber-2); }

/* ── chat attachments (images / video / voice notes / documents) ─────────── */
.composer .iconbtn {
  flex: 0 0 auto; width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--ink); color: var(--text); border: 1px solid var(--line); border-radius: 12px; cursor: pointer;
}
.composer .iconbtn svg { width: 20px; height: 20px; }
.composer .iconbtn:hover { border-color: var(--amber-2); }
.composer .iconbtn.recording { background: var(--danger); color: #fff; border-color: var(--danger); animation: ra-pulse 1s infinite; }
@keyframes ra-pulse { 0%,100% { opacity: 1; } 50% { opacity: .55; } }

.attachtray { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 10px 0; }
.attchip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 220px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 6px 5px 11px; font-size: 12px; color: var(--text);
}
.attchip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attchip.pending { opacity: .7; }
.attchip.err { border-color: var(--danger); color: var(--danger); }
.attchip .attx { width: 20px; height: 20px; border-radius: 999px; border: none; background: var(--ink); color: var(--text); cursor: pointer; line-height: 1; }

.attbox { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.attimg, .attvid { max-width: min(260px, 70vw); max-height: 240px; border-radius: 12px; border: 1px solid var(--line); cursor: pointer; }
.attaudio { display: flex; flex-direction: column; gap: 4px; max-width: min(280px, 80vw); }
.attaudio audio { width: 100%; }
.atttranscript { font-size: 12px; opacity: .8; font-style: italic; }
.attdoc {
  display: inline-flex; align-items: center; gap: 6px; background: var(--ink); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 11px; color: var(--text); text-decoration: none; font-size: 13px; max-width: 260px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.attdoc:hover { border-color: var(--amber-2); }
.msg .msgtext { white-space: pre-wrap; }

/* ── Home dashboard ────────────────────────────────────────────────────── */
.dashgrid {
  display: grid; gap: 12px; padding: 16px;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
}
.widget {
  background: linear-gradient(175deg, var(--panel), var(--ink-2));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; min-width: 0;
}
.widget.whidden { opacity: .4; }
.wtitle {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase;
  color: var(--muted); margin-bottom: 8px;
}
.wctl { margin-left: auto; display: flex; gap: 4px; }
.wctl button { min-height: 28px; padding: 2px 8px; }
.wbody { display: flex; flex-direction: column; gap: 8px; }
.wrow { display: flex; align-items: center; gap: 10px; min-width: 0; }
.wrow .t { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wrow .m { font-size: 12px; color: var(--muted); }
.wrow.tappable { cursor: pointer; }
.wrow .fillring { width: 36px; height: 36px; }
.wempty { color: var(--muted); font-size: 13px; padding: 4px 0; }
.wactions { display: flex; flex-wrap: wrap; gap: 8px; }
.hb-ok { color: var(--ok); font-weight: 700; }
.hb-stale { color: var(--danger); font-weight: 700; }

/* ── Tasks (Khonsu scheduler) ──────────────────────────────────────────── */
.schedpick { display: flex; flex-wrap: wrap; gap: 8px; }
.schedpick select, .schedpick input {
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 11px; font: inherit; min-height: 44px;
}
.schedpick input[type="time"] { width: 110px; }
.schedpick input:not([hidden]):not([type="time"]) { flex: 1; min-width: 150px; }
.listlabel {
  color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .8px;
  text-transform: uppercase; margin: 8px 2px 0;
}
.runlist { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.runrow { font-size: 12px; color: var(--muted); padding: 3px 0; border-top: 1px solid var(--line); }
.runrow.tappable:hover { color: var(--text); cursor: pointer; }

/* ── Memory graph ──────────────────────────────────────────────────────── */
.memsurface { overflow: hidden !important; }
.membar { flex-wrap: wrap; }
.memstats { color: var(--muted); font-size: 12px; }
.membadge {
  display: inline-block; font-size: 10px; font-weight: 700; padding: 1px 7px;
  border-radius: 999px; background: var(--panel); border: 1px solid var(--line);
  color: var(--amber);
}
.membadge.stale { color: var(--danger); border-color: var(--danger); }
.graphwrap { position: relative; flex: 1; min-height: 0; background: radial-gradient(120% 100% at 50% 0%, var(--ink-2), var(--ink)); }
.graph-canvas { position: absolute; inset: 0; cursor: grab; }
.memsheet {
  position: absolute; left: 10px; right: 10px; bottom: calc(10px + var(--safe)); z-index: 5;
  background: rgba(29, 24, 16, .94); backdrop-filter: blur(6px);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 40px 12px 14px;
  max-height: 38%; overflow-y: auto;
}
.memsheet .t { font-size: 14px; white-space: pre-wrap; }
.memsheet .m { margin-top: 6px; }
.memsheet-x { position: absolute; top: 8px; right: 8px; }
.mempanel {
  position: absolute; top: 0; left: 0; right: 0; z-index: 6;
  background: rgba(13, 11, 8, .97); border-bottom: 1px solid var(--line);
  max-height: 70%; overflow-y: auto;
}
