/* URC operator workspace — desktop-first tri-pane shell with a compact TMA mode. */

:root {
  --bg: #070a0d;
  --surface: #0d1116;
  --surface-2: #131920;
  --surface-3: #19212a;
  --text: #eef4f8;
  --hint: #7f8b96;
  --accent: #39d9c1;
  --accent-ink: #04110f;
  --link: #61e6d2;
  --danger: #ff665c;
  --line: rgba(161, 181, 197, .15);
  --line-strong: rgba(97, 230, 210, .32);
  --shadow: 0 20px 60px rgba(0, 0, 0, .45);
  --radius: 16px;
  --topbar-height: 64px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; width: 100%; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px; line-height: 1.45;
  overscroll-behavior: none;
}
button, textarea, select { font: inherit; }
button { -webkit-user-select: none; user-select: none; }

#app { height: 100dvh; min-height: 100dvh; display: flex; flex-direction: column; }

/* ── Global top bar ───────────────────────────────────────────────── */
.topbar {
  flex: 0 0 var(--topbar-height); height: var(--topbar-height);
  display: flex; align-items: center; gap: 11px; padding: 0 18px;
  border-bottom: 1px solid var(--line); background: #090d11;
}
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  color: var(--accent-ink); background: var(--accent); font-weight: 900; font-size: 17px;
  box-shadow: 0 0 0 1px rgba(255,255,255,.12), 0 0 24px rgba(57,217,193,.14);
}
.brand-copy { display: grid; line-height: 1.1; }
.topbar .title { font-weight: 760; font-size: 15px; letter-spacing: .02em; }
.topbar .subtitle { margin-top: 4px; color: var(--hint); font-size: 11px; }
.topbar .spacer { flex: 1; }
.icon-btn {
  appearance: none; border: 0; background: transparent; color: var(--text);
  width: 38px; height: 38px; border-radius: 10px; font-size: 19px;
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn:hover, .icon-btn:active { background: var(--surface-2); }
#menu-btn { display: none; }
.system-state {
  display: inline-flex; align-items: center; gap: 7px; color: #a8b4bd;
  font-size: 12px; padding-right: 5px;
}
.state-dot, .live-dot, .chat-online {
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 0 4px rgba(57,217,193,.1);
}
.new-session-btn {
  display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 13px;
  color: var(--text); background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 9px; font-weight: 650; font-size: 12px; cursor: pointer;
}
.new-session-btn:hover { border-color: var(--line-strong); background: var(--surface-3); }
.new-session-btn span { color: var(--accent); font-size: 18px; line-height: 1; }

/* ── Three-pane workspace ─────────────────────────────────────────── */
.workspace-grid {
  min-height: 0; flex: 1 1 auto; display: grid;
  grid-template-columns: clamp(220px, 13.25vw, 260px) minmax(560px, 1fr) clamp(320px, 19.5vw, 380px);
  background: var(--bg); transition: grid-template-columns .24s ease;
}
.workspace-grid.rail-collapsed { grid-template-columns: 0 minmax(560px, 1fr) clamp(320px, 19.5vw, 380px); }
#report-rail, #chat-panel, #agent-stage { min-width: 0; min-height: 0; }
#report-rail {
  display: flex; flex-direction: column; border-right: 1px solid var(--line);
  background: #090d11; padding: 20px 13px 14px;
  opacity: 1; overflow: hidden; transition: opacity .16s ease, padding .24s ease;
}
.workspace-grid.rail-collapsed #report-rail {
  padding-left: 0; padding-right: 0; border-right-color: transparent;
  opacity: 0; pointer-events: none;
}
.pane-heading, .chat-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.eyebrow {
  display: block; color: var(--accent); font-size: 10px; font-weight: 750;
  letter-spacing: .14em; text-transform: uppercase; margin-bottom: 2px;
}
.pane-heading h2, .chat-heading h2 { margin: 0; font-size: 17px; line-height: 1.2; letter-spacing: -.02em; }
.pane-intro { margin: 10px 2px 15px; color: var(--hint); font-size: 11px; line-height: 1.45; }
.rail-action {
  width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 8px;
  color: var(--hint); background: transparent; cursor: pointer;
}
.rail-action:hover { color: var(--accent); border-color: var(--line-strong); }
.report-list { list-style: none; padding: 0; margin: 0; overflow-y: auto; min-height: 0; }
.report-list .link-row {
  display: grid; grid-template-columns: 26px minmax(0, 1fr); align-items: start; gap: 8px;
  margin-bottom: 5px; padding: 10px 8px; border: 1px solid transparent;
  border-radius: 10px; color: var(--text); text-decoration: none; cursor: pointer;
}
.report-list .link-row:hover { background: var(--surface-2); border-color: var(--line); }
.report-list .doc { color: var(--accent); font-size: 15px; text-align: center; }
.report-list .report-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 620; }
.report-list .rmeta { display: block; margin-top: 3px; color: var(--hint); font-size: 10px; }
.report-list .empty { color: var(--hint); font-size: 11px; padding: 12px 8px; }
.rail-footer {
  display: flex; gap: 8px; align-items: center; margin-top: auto; padding: 12px 8px 2px;
  border-top: 1px solid var(--line); color: var(--hint); font-size: 10px; line-height: 1.35;
}
.rail-footer-icon { color: var(--accent); font-size: 14px; }

#agent-stage { position: relative; display: flex; flex-direction: column; background: #202428; }
.stage-toolbar {
  flex: 0 0 56px; height: 56px; padding: 0 16px; display: flex; align-items: center;
  justify-content: space-between; border-bottom: 1px solid var(--line); background: var(--surface);
}
.stage-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.rail-toggle {
  width: 28px; height: 28px; flex: 0 0 auto; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 8px; color: var(--hint);
  background: var(--surface-2); cursor: pointer;
}
.rail-toggle:hover { color: var(--accent); border-color: var(--line-strong); }
.rail-toggle-icon { display: block; font-size: 22px; line-height: 1; transition: transform .24s ease; }
.workspace-grid.rail-collapsed .rail-toggle-icon { transform: rotate(180deg); }
.stage-title { display: flex; align-items: center; gap: 10px; }
.stage-title > div { display: grid; }
.stage-title strong { font-size: 13px; }
.stage-title span:not(.live-dot) { color: var(--hint); font-size: 10px; margin-top: 2px; }
.stage-badge {
  padding: 5px 9px; border: 1px solid var(--line-strong); border-radius: 999px;
  color: var(--accent); background: rgba(57,217,193,.06); font-size: 10px; font-weight: 700;
  letter-spacing: .04em;
}

/* ── Co-browser ───────────────────────────────────────────────────── */
#cobrowser { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; background: #202428; }
#cobrowser .cb-head { display: none; }
#cobrowser .cb-body { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; background: #202428; display: flex; flex-direction: column; }
.cb-tools {
  position: relative; z-index: 4; flex: 0 0 42px; display: flex; align-items: center; gap: 6px;
  padding: 5px 8px; background: #101419; border-bottom: 1px solid var(--line); overflow-x: auto;
}
.cb-tools button {
  flex: 0 0 auto; min-height: 32px; padding: 0 11px; border: 1px solid rgba(255,255,255,.16);
  border-radius: 8px; background: #20262d; color: #f5f7f9; font: 650 11px/1 sans-serif; cursor: pointer;
}
.cb-tools button:hover, .cb-tools button.active { color: var(--accent); border-color: var(--line-strong); }
#screen { position: relative; z-index: 2; flex: 1 1 auto; min-height: 0; width: 100%; }
#screen canvas { background: #fff; }
#novnc-keyboard {
  position: absolute; left: 0; bottom: 0; width: 1px; height: 1px;
  padding: 0; border: 0; opacity: .01; z-index: -1;
}
#cobrowser.fullscreen {
  position: fixed; inset: 0; z-index: 80; display: flex; flex-direction: column; background: #030405;
}
#cobrowser.fullscreen .cb-head { display: flex; flex: 0 0 auto; }
#cobrowser.fullscreen .cb-body { height: auto; flex: 1 1 auto; }
.browser-empty {
  position: absolute; z-index: 1; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 8px; color: var(--hint); text-align: center;
  background: #202428;
}
.browser-empty-icon { color: var(--accent); font-size: 32px; opacity: .7; }
.browser-empty strong { color: #c4cdd4; font-size: 13px; }
.browser-empty span { font-size: 11px; }
#agent-stage.driving .live-dot { animation: agentPulse 1.1s ease-in-out infinite; }
#agent-stage.driving .stage-badge { background: rgba(57,217,193,.14); }
@keyframes agentPulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(57,217,193,.1); }
  50% { box-shadow: 0 0 0 8px rgba(57,217,193,.03); }
}

/* ── Chat panel and stream ────────────────────────────────────────── */
#chat-panel {
  display: flex; flex-direction: column; border-left: 1px solid var(--line); background: #090d11;
}
.chat-heading { flex: 0 0 56px; height: 56px; padding: 0 16px; border-bottom: 1px solid var(--line); }
.chat-online { margin-right: 3px; }
#chat {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 18px 13px 10px; display: flex; flex-direction: column; gap: 8px;
}
.model-source { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .06em; margin-bottom: 6px; text-transform: uppercase; }
.drive-control { display: inline-flex; align-items: center; gap: 4px; color: var(--hint); font-size: 11px; cursor: pointer; user-select: none; }
.drive-control input { accent-color: var(--accent); margin: 0; }
.bubble {
  max-width: 92%; padding: 10px 12px; border-radius: 14px;
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere;
  font-size: 12px; line-height: 1.5; animation: pop .18s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.bubble.you {
  align-self: flex-end; background: #1c544f; color: #f1fffc; border: 1px solid rgba(97,230,210,.14);
  border-bottom-right-radius: 4px;
}
.bubble.urc {
  align-self: flex-start; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-bottom-left-radius: 4px;
}
.bubble.err { background: rgba(255,102,92,.12); border-color: rgba(255,102,92,.25); }
.bubble .actions { display: flex; gap: 5px; margin-top: 7px; }
.act {
  display: inline-flex; align-items: center; justify-content: center; width: 27px; height: 27px;
  padding: 0; border: 1px solid var(--line); cursor: pointer; border-radius: 999px;
  background: var(--surface-3); color: var(--hint); font-size: 11px; line-height: 1;
}
.act:hover { color: var(--text); }
.act.play .i-stop { display: none; }
.act.play.playing { color: var(--accent); border-color: var(--line-strong); }
.act.play.playing .i-play { display: none; }
.act.play.playing .i-stop { display: inline; }
.act.play.loading { color: var(--accent); }
.act.play.loading .i-play { animation: pulse .8s ease-in-out infinite; }
.act.copy.done { color: var(--accent); border-color: var(--line-strong); }
@keyframes pulse { 0%,100% { opacity: .35; } 50% { opacity: 1; } }
.step {
  align-self: flex-start; max-width: 90%; font-size: 10px; color: var(--hint);
  padding: 0 6px; display: flex; gap: 6px;
}
.step .tick { color: var(--accent); }
.thinking { display: inline-flex; align-items: center; gap: 5px; color: var(--hint); }
.thinking .dots { letter-spacing: 2px; animation: blink 1.1s steps(4) infinite; }
@keyframes blink { 50% { opacity: .35; } }
.thinking .t { font-variant-numeric: tabular-nums; opacity: .7; }
.report-chip {
  align-self: flex-start; display: inline-flex; align-items: center; gap: 7px;
  background: rgba(57,217,193,.07); color: var(--link); padding: 8px 10px;
  border-radius: 10px; text-decoration: none; font-size: 11px; font-weight: 600;
  border: 1px solid var(--line-strong); cursor: pointer;
}

/* ── Composer ─────────────────────────────────────────────────────── */
#composer {
  flex: 0 0 auto; display: flex; flex-direction: column; gap: 7px;
  margin: 0 10px calc(10px + env(safe-area-inset-bottom)); padding: 9px;
  border: 1px solid var(--line); border-radius: 13px; background: #0f151b;
  transition: border-color .18s, box-shadow .18s;
}
#composer:focus-within { border-color: var(--line-strong); box-shadow: 0 0 0 3px rgba(57,217,193,.05); }
#composer textarea {
  width: 100%; min-height: 42px; max-height: 120px; resize: none; border: 0; outline: 0;
  background: transparent; color: var(--text); padding: 3px 4px; font-size: 12px; line-height: 1.45;
}
#composer textarea::placeholder { color: var(--hint); }
.composer-tools { display: flex; align-items: center; gap: 7px; }
.composer-hint { margin-left: auto; color: var(--hint); font-size: 9px; }
.send-btn, .stop-btn {
  flex: 0 0 auto; width: 32px; height: 32px; border-radius: 9px; border: 0;
  display: grid; place-items: center; font-size: 15px; cursor: pointer;
}
.send-btn { background: var(--accent); color: var(--accent-ink); }
.send-btn:disabled { opacity: .4; }
.stop-btn { background: var(--danger); color: #fff; display: none; }
#composer.busy .send-btn { display: none; }
#composer.busy .stop-btn { display: grid; }
.depth-control { flex: 0 0 auto; }
.depth-control select {
  max-width: 86px; height: 30px; padding: 0 22px 0 8px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--surface-3); color: var(--text); font-size: 10px;
  font-weight: 650; cursor: pointer;
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ── Bottom sheet (compact layout) ────────────────────────────────── */
#scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,.58); opacity: 0;
  pointer-events: none; transition: opacity .25s; z-index: 40;
}
#scrim.show { opacity: 1; pointer-events: auto; }
#sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; background: var(--surface);
  border: 1px solid var(--line); border-radius: 18px 18px 0 0; box-shadow: var(--shadow);
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom)); transform: translateY(100%);
  transition: transform .28s cubic-bezier(.32,.72,0,1); max-height: 80dvh; overflow-y: auto;
}
#sheet.show { transform: translateY(0); }
#sheet .grip { width: 40px; height: 4px; border-radius: 3px; background: var(--line); margin: 6px auto 12px; }
#sheet .menu-item {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 13px 8px;
  border: 0; background: transparent; color: var(--text); text-align: left; cursor: pointer; border-radius: 10px;
}
#sheet .menu-item:active { background: var(--surface-2); }
#sheet .menu-item .ic { font-size: 18px; width: 24px; text-align: center; }
#sheet .sec { font-size: 11px; color: var(--hint); font-weight: 700; padding: 15px 8px 6px; text-transform: uppercase; letter-spacing: .08em; }
#sheet ul { list-style: none; margin: 0; padding: 0; }
#sheet .link-row { display: flex; align-items: center; gap: 12px; padding: 11px 8px; border-radius: 10px; text-decoration: none; color: var(--text); }
#sheet .link-row:active { background: var(--surface-2); }
#sheet .link-row .doc { font-size: 17px; color: var(--link); }
#sheet .link-row .rmeta { display: block; font-size: 10px; color: var(--hint); }
#sheet .empty { color: var(--hint); font-size: 12px; padding: 10px 8px; }

/* ── Report reader ────────────────────────────────────────────────── */
#reader {
  position: absolute; inset: 0; z-index: 10; background: var(--surface); display: none; flex-direction: column;
}
#reader.show { display: flex; }
#reader .rhead { flex: 0 0 56px; display: flex; align-items: center; gap: 10px; padding: 0 14px; border-bottom: 1px solid var(--line); }
#reader .rhead .rtitle { font-weight: 650; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#reader .pill { border: 1px solid var(--line-strong); background: rgba(57,217,193,.08); color: var(--accent); padding: 7px 12px; border-radius: 8px; font-size: 11px; cursor: pointer; }
#reader .rbody { flex: 1; overflow-y: auto; padding: 24px clamp(20px, 7vw, 90px); }
#reader .rbody h1 { font-size: 26px; margin: .4em 0 .3em; }
#reader .rbody h2 { font-size: 19px; margin: 1.2em 0 .3em; }
#reader .rbody h3 { font-size: 15px; margin: 1em 0 .3em; }
#reader .rbody p { margin: .6em 0; color: #c6d0d7; }
#reader .rbody ul, #reader .rbody ol { margin: .4em 0; padding-left: 1.3em; }
#reader .rbody a { color: var(--link); }
#reader .rbody code { background: var(--surface-3); padding: 1px 5px; border-radius: 5px; font-size: .92em; }

/* ── Toast ────────────────────────────────────────────────────────── */
#status {
  position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 12px);
  background: #202932; color: #fff; border: 1px solid var(--line); padding: 8px 14px;
  border-radius: 999px; font-size: 11px; opacity: 0; pointer-events: none;
  transition: all .2s; z-index: 70; max-width: 90vw; box-shadow: var(--shadow);
}
#status.show { opacity: 1; transform: translate(-50%, 0); }
#status.err { background: var(--danger); }

/* ── Compact Telegram / phone layout ─────────────────────────────── */
@media (max-width: 820px) {
  :root { --topbar-height: 56px; }
  .topbar { padding: 0 10px; gap: 9px; }
  #menu-btn { display: grid; }
  .brand-mark { width: 30px; height: 30px; border-radius: 9px; font-size: 15px; }
  .topbar .subtitle, .system-state, .new-session-btn { display: none; }
  /* Morning Roundup is a primary phone action, not a desktop-only control. */
  .topbar .spacer { display: none; }
  #roundup-btn { display: inline-flex; margin-left: auto; padding: 0 10px; }
  .workspace-grid { display: flex; flex-direction: column; min-height: 0; }
  #report-rail, .stage-toolbar, .chat-heading { display: none; }
  #agent-stage { flex: 0 0 auto; display: block; }
  #cobrowser { display: block; border-bottom: 1px solid var(--line); background: var(--surface); }
  #cobrowser .cb-head {
    display: flex; align-items: center; gap: 10px; padding: 9px 14px; cursor: pointer;
    user-select: none; font-size: 12px; color: var(--text);
  }
  #cobrowser .chev { transition: transform .22s ease; font-size: 10px; color: var(--hint); }
  #cobrowser.open .chev { transform: rotate(90deg); }
  #cobrowser .cb-label { font-weight: 600; }
  #cobrowser .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--hint); margin-left: auto; }
  #cobrowser.driving .dot { background: var(--accent); box-shadow: 0 0 0 4px rgba(57,217,193,.12); }
  #cobrowser .cb-body { height: 0; overflow: hidden; transition: height .25s ease; }
  #cobrowser.open .cb-body { height: min(56vh, 520px); }
  #cobrowser.fullscreen .cb-body { height: auto; }
  #chat-panel { flex: 1 1 auto; min-height: 0; border: 0; }
  #chat { padding: 14px 11px 8px; }
  .bubble { max-width: 84%; font-size: 14px; padding: 9px 12px; }
  .step { max-width: 84%; font-size: 12px; }
  #composer { margin: 0 9px calc(9px + env(safe-area-inset-bottom)); }
  #composer textarea { font-size: 14px; }
  .composer-hint { display: none; }
  #reader { position: fixed; }
  #reader .rbody { padding: 16px 18px calc(24px + env(safe-area-inset-bottom)); }
  #status { bottom: 84px; }
}

@media (min-width: 821px) and (max-width: 1180px) {
  .workspace-grid { grid-template-columns: 190px minmax(390px, 1fr) 310px; }
  .topbar .subtitle { display: none; }
}
