/* Jarvis 2.0. Mobile first. Lessons carried from jarvis-stream (server.py CSS notes):
   - svh, not dvh: dvh follows the Safari address bar, so every scroll resized the app and dragged
     the composer ("the chat area also moves up").
   - black-translucent status bar puts the page UNDER the Dynamic Island: every fixed edge adds the
     safe-area inset, or taps there go to iOS ("cannot click on left tab", 2026-09-12).
   - bottom inset only in the installed app: a browser tab already reserves the gesture strip, and
     adding it again left a dead band under the composer (2026-08-05).
   - inputs at 16px: smaller makes iOS zoom on focus, with no way back when body cannot scroll. */
:root {
  color-scheme: dark;
  --bg: #181818; --panel: #202123; --panel2: #26272a; --line: #2f2f2f; --text: #ececec; --muted: #9aa0a6;
  --accent: #10a37f; --warn: #e0a24a; --bad: #e5484d; --push: #d9730d; --demo: #7c3aed;
  --sa-top: env(safe-area-inset-top, 0px); --sa-bottom: env(safe-area-inset-bottom, 0px);
  --sa-left: env(safe-area-inset-left, 0px); --sa-right: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; }
html, body { height: 100vh; height: 100svh; margin: 0; overflow: hidden; max-width: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.demo-banner {
  background: var(--demo); color: #fff; font-size: 12.5px; font-weight: 650; text-align: center;
  padding: calc(4px + var(--sa-top)) calc(10px + var(--sa-right)) 4px calc(10px + var(--sa-left));
}
body.demo #top { padding-top: 6px; }

#top {
  flex: 0 0 auto; background: var(--panel); border-bottom: 1px solid var(--line);
  padding: calc(6px + var(--sa-top)) calc(10px + var(--sa-right)) 4px calc(10px + var(--sa-left));
}
.top-row { display: flex; align-items: center; gap: 8px; }
.brand { font-weight: 700; letter-spacing: .2px; white-space: nowrap; }
#tabs { display: flex; gap: 4px; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
#tabs::-webkit-scrollbar { display: none; }
.tab {
  background: none; border: 1px solid transparent; border-radius: 8px; padding: 6px 10px; color: var(--muted);
  white-space: nowrap; font-size: 14px;
}
.tab.active { color: var(--text); background: var(--panel2); border-color: var(--line); }
.badge { background: var(--push); color: #fff; border-radius: 9px; padding: 0 6px; font-size: 11px; font-weight: 700; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); vertical-align: middle; }
.dot.ok { background: var(--accent); } .dot.bad { background: var(--bad); }
.icon-btn { background: none; border: none; font-size: 20px; padding: 2px 6px; display: none; }

.activity { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 2px; min-height: 26px; scrollbar-width: none; }
.activity::-webkit-scrollbar { display: none; }
.agent-chip {
  flex: 0 0 auto; font-size: 12px; border: 1px solid var(--line); border-radius: 12px; padding: 1px 9px;
  color: var(--muted); background: var(--bg); white-space: nowrap;
}
.agent-chip b { color: var(--text); font-weight: 600; }
.agent-chip.working, .agent-chip.checking { border-color: var(--accent); }
.agent-chip.waiting, .agent-chip.blocked, .agent-chip.queued { border-color: var(--warn); }
.agent-chip.failed { border-color: var(--bad); color: var(--bad); }
.agent-chip .demo-tag, .demo-tag { color: #c4b5fd; font-weight: 700; font-size: 10px; margin-left: 4px; }
.muted { color: var(--muted); }

main { flex: 1 1 auto; position: relative; min-height: 0; }
.view { position: absolute; inset: 0; display: none; }
.view.active { display: flex; }
.view.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.wrap { width: 100%; max-width: 760px; margin: 0 auto; padding: 12px calc(14px + var(--sa-right)) calc(24px + var(--sa-bottom)) calc(14px + var(--sa-left)); }
h2 { font-size: 16px; margin: 22px 0 10px; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: .6px; }
h2:first-child { margin-top: 6px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0 10px; }

/* ---------------- chat ---------------- */
#view-chat { flex-direction: row; }
#threadPanel {
  width: 250px; flex: 0 0 250px; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 8px; overflow-y: auto;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 8px; color: var(--muted); font-size: 13px; }
.small-btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; font-size: 13px; }
.new-thread { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 4px 8px; }
.new-thread input, .new-thread select {
  flex: 1 1 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; color: var(--text);
  padding: 7px 9px; font-size: 16px;
}
#threadList { list-style: none; margin: 0; padding: 0; }
#threadList li { padding: 8px 9px; border-radius: 8px; cursor: pointer; margin-bottom: 2px; }
#threadList li.active { background: var(--panel2); }
#threadList .t-name { font-size: 14px; font-weight: 600; }
#threadList .t-last { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sens { font-size: 10.5px; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 0 5px; margin-left: 4px; }
#scrim { display: none; }

#chatPane { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; }
.thread-head { padding: 8px 14px; border-bottom: 1px solid var(--line); font-size: 13.5px; color: var(--muted); }
.thread-head b { color: var(--text); }
#messages { flex: 1 1 auto; overflow-y: auto; padding: 12px calc(14px + var(--sa-right)) 12px calc(14px + var(--sa-left)); -webkit-overflow-scrolling: touch; }
.msg { max-width: 760px; margin: 0 auto 12px; display: flex; flex-direction: column; }
.msg .bubble { padding: 9px 13px; border-radius: 14px; overflow-wrap: anywhere; }
.msg.user { align-items: flex-end; }
.msg.user .bubble { background: #2f3b36; border-top-right-radius: 4px; white-space: pre-wrap; max-width: 88%; }
.msg.assistant .bubble { background: var(--panel); border: 1px solid var(--line); border-top-left-radius: 4px; }
.msg.system .bubble { color: var(--muted); font-size: 13px; }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 3px; }
.msg .meta.bad { color: var(--bad); }
.pasted { background: rgba(224, 162, 74, .14); border-bottom: 1px dashed var(--warn); }
.bubble p { margin: 0 0 8px; } .bubble p:last-child { margin-bottom: 0; }
.bubble pre { background: #111; padding: 9px; border-radius: 8px; overflow-x: auto; font-size: 13px; }
.bubble code { font-family: ui-monospace, Menlo, monospace; font-size: 13px; background: #111; padding: 1px 4px; border-radius: 4px; }
.bubble pre code { background: none; padding: 0; }
.bubble a { color: #6cc4a9; }
.streaming .bubble::after { content: " ▍"; color: var(--accent); }
.att { display: inline-block; font-size: 12px; border: 1px solid var(--line); border-radius: 8px; padding: 1px 7px; margin: 4px 4px 0 0; color: var(--muted); }
.empty-thread { color: var(--muted); text-align: center; margin-top: 18vh; font-size: 14px; }

#composerWrap { flex: 0 0 auto; border-top: 1px solid var(--line); padding: 8px calc(10px + var(--sa-right)) 8px calc(10px + var(--sa-left)); background: var(--bg); }
.composer { max-width: 760px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
#input {
  flex: 1; resize: none; background: #2b2b2b; color: var(--text); border: 1px solid #444; border-radius: 20px;
  padding: 10px 15px; font: inherit; font-size: 16px; max-height: 160px; overflow-y: hidden;
}
#input:focus { outline: none; border-color: var(--accent); }
.round-btn { width: 42px; height: 42px; flex: 0 0 auto; border-radius: 50%; border: 1px solid #444; background: #2b2b2b; font-size: 20px; }
.round-btn.send { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 800; }
.round-btn:disabled { opacity: .5; }
.attach-row { max-width: 760px; margin: 0 auto; display: flex; flex-wrap: wrap; gap: 6px; }
.attach-row .att { margin: 0 0 6px; }
.attach-row .att button { background: none; border: none; color: var(--muted); padding: 0 0 0 4px; }

/* ---------------- inbox cards ---------------- */
.group-title { display: flex; align-items: center; gap: 8px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; }
.card.push { border-left: 4px solid var(--push); }
.card .head { font-size: 12px; font-weight: 700; letter-spacing: .4px; color: var(--muted); margin-bottom: 6px; }
.card .line { margin: 2px 0; }
.card .default { color: var(--muted); font-size: 13px; margin-top: 6px; }
.card .evidence { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.btns button {
  background: var(--panel2); border: 1px solid #444; border-radius: 10px; padding: 8px 14px; font-size: 14px; min-height: 40px;
}
.btns button.star { border-color: var(--accent); }
.btns button.star::before { content: "★ "; color: var(--accent); }
.btns button:disabled { opacity: .45; }
.card .pending { margin-top: 8px; color: var(--accent); font-size: 13px; }
.card textarea {
  width: 100%; margin-top: 8px; background: var(--bg); color: var(--text); border: 1px solid #444; border-radius: 10px;
  padding: 8px 10px; font: inherit; font-size: 16px; min-height: 64px;
}
.none { color: var(--muted); font-size: 14px; padding: 4px 0 8px; }
.digest { margin: 0 0 12px; padding-left: 18px; font-size: 14px; }
.digest-line { padding: 3px 0; }
.digest-for { color: var(--muted); font-size: 12px; }

/* ---------------- goals and bars ---------------- */
.row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); }
.row .title { font-weight: 600; }
.row .sub { grid-column: 1 / -1; color: var(--muted); font-size: 12.5px; }
.chip { font-size: 11px; border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; color: var(--muted); margin-left: 6px; white-space: nowrap; }
.chip.warn { color: var(--warn); border-color: var(--warn); }
.bar10 { display: grid; grid-template-columns: repeat(10, 1fr); gap: 2px; width: 120px; }
.bar10 span { height: 9px; border-radius: 2px; background: #333; }
.bar10 span.on { background: var(--accent); }
.bar10.unset span { background: repeating-linear-gradient(45deg, #2a2a2a, #2a2a2a 3px, #333 3px, #333 6px); }
.meter { height: 12px; background: #2a2a2a; border-radius: 6px; overflow: hidden; position: relative; }
.meter .fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); }
.meter .fill.over { background: var(--bad); }
.meter-row { margin: 8px 0 12px; }
.meter-row .lbl { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.strat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin-bottom: 12px; }
.strat .bet { color: var(--muted); font-size: 13px; margin: 4px 0 8px; }
.menu-item { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 8px 0; border-top: 1px solid var(--line); }
.menu-item .txt { flex: 1; min-width: 0; }

/* ---------------- system ---------------- */
.kv { display: grid; grid-template-columns: minmax(120px, 40%) 1fr; gap: 6px 12px; font-size: 14px; }
.kv .k { color: var(--muted); }
.problems { margin: 0 0 12px; padding-left: 18px; color: var(--warn); }
.ok-line { color: var(--accent); margin-bottom: 12px; }
.danger-btn { margin-top: 16px; background: none; border: 1px solid var(--bad); color: var(--bad); border-radius: 10px; padding: 8px 16px; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + var(--sa-bottom)); z-index: 50;
  background: #333; color: #fff; padding: 8px 14px; border-radius: 10px; font-size: 14px; max-width: 90vw;
}

/* ---------------- login ---------------- */
body.login { align-items: center; justify-content: center; padding: calc(24px + var(--sa-top)) 24px calc(24px + var(--sa-bottom)); }
.auth-box { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.auth-logo { color: var(--accent); font-weight: 800; font-size: 28px; }
.auth-box h1 { margin: 0; font-size: 22px; }
.auth-box p { color: var(--muted); font-size: 13.5px; margin: 0 0 6px; }
.auth-box input { background: #2b2b2b; color: var(--text); border: 1px solid #444; border-radius: 12px; padding: 13px 15px; font: inherit; font-size: 16px; }
.auth-box input:focus { outline: none; border-color: var(--accent); }
#loginBtn { background: var(--accent); color: #fff; border: none; border-radius: 12px; padding: 13px; font-weight: 650; }
#loginBtn:disabled { opacity: .6; }
#loginNote { color: var(--warn); font-size: 13px; min-height: 18px; }

/* ---------------- phone ---------------- */
@media (max-width: 700px) {
  .icon-btn { display: inline-block; }
  body:not(.chat-view) #threadsBtn { visibility: hidden; }
  .brand { font-size: 14px; }
  .tab { padding: 5px 7px; font-size: 13.5px; }
  #tabs { gap: 2px; }
  #threadPanel {
    position: fixed; z-index: 20; top: 0; bottom: 0; left: 0; width: calc(270px + var(--sa-left));
    padding: calc(10px + var(--sa-top)) 8px calc(10px + var(--sa-bottom)) calc(8px + var(--sa-left));
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: 2px 0 20px rgba(0,0,0,.5);
  }
  body.drawer-open #threadPanel { transform: translateX(0); }
  body.drawer-open #scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 15; }
  .msg.user .bubble { max-width: 92%; }
  .bar10 { width: 90px; }
}
@media (max-width: 420px) {
  .brand { display: none; }
}
@media (display-mode: standalone) {
  #composerWrap { padding-bottom: calc(8px + var(--sa-bottom)); }
}
