:root {
  --accent: #0061ff; --accent-dark: #004fe0; --accent-tint: #eaf1ff; --accent-tint2: #f3f7ff;
  --accent-ring: rgba(0,97,255,.15); --accent-border: #b7cdfb;
  --bg: #f7f8fa; --surface: #ffffff; --surface2: #f3f4f7; --line: #e8eaef; --line2: #dfe2e8;
  --ink: #1a1d26; --body: #3d4354; --muted: #8b91a1; --faint: #b4bac8;
  --coral: #e85d3a; --teal: #2aabb8; --purple: #6b5ce0; --green: #22a06b; --red: #e5484d;
  --sans: "Plus Jakarta Sans", system-ui, -apple-system, "PingFang HK", sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
  --shadow: 0 1px 2px rgba(26,29,38,.04), 0 4px 16px rgba(26,29,38,.05);
  --radius: 6px;
  --top-h: 52px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.5 var(--sans); background: var(--bg); color: var(--body);
       -webkit-font-smoothing: antialiased; overflow: hidden;
       overscroll-behavior: none; text-size-adjust: 100%; }

/* app shell — dvh for iOS dynamic toolbar, fallback vh */
.app { display: grid; height: 100vh; height: 100dvh;
       grid-template-columns: 280px 1fr; grid-template-rows: var(--top-h) auto auto 1fr; }

/* slim topbar */
.topbar { grid-column: 1 / -1; grid-row: 1; display: flex; align-items: center;
          justify-content: space-between; gap: 10px; padding: 0 max(16px, env(safe-area-inset-left)) 0 max(16px, env(safe-area-inset-left));
          padding-top: env(safe-area-inset-top); background: rgba(255,255,255,.88);
          backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
          border-bottom: 1px solid var(--line); z-index: 5; min-height: var(--top-h); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { width: 28px; height: 28px; border-radius: 6px; background: var(--ink); color: #fff;
        display: grid; place-items: center; flex-shrink: 0; overflow: hidden; }
.logo svg { width: 100%; height: 100%; display: block; }
.brand h1 { font-size: 15px; margin: 0; font-weight: 700; color: var(--ink); letter-spacing: -.03em;
            white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.accent { color: var(--accent); }
  .topright { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }


.runtime-badge {
  font-size: 10.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  padding: 4px 9px; border-radius: 999px; border: 1px solid var(--line2);
  background: var(--surface2); color: var(--muted); line-height: 1; white-space: nowrap;
}
.runtime-badge.local { color: var(--teal); border-color: rgba(42,171,184,.35); background: rgba(42,171,184,.08); }
.runtime-badge.remote { color: var(--accent-dark); border-color: var(--accent-border); background: var(--accent-tint); }

.warm-banner {
  position: absolute; top: 0; left: 0; right: 0; z-index: 6;
  display: flex; align-items: center; gap: 8px; padding: 8px 12px 8px 14px;
  background: rgba(255,255,255,.92); border-bottom: 1px solid rgba(42,171,184,.25);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  color: var(--ink); font-size: 12.5px; font-weight: 600;
  /* tint via inset so overlay stays opaque enough over tabs/messages */
  box-shadow: 0 4px 14px rgba(26,29,38,.08), inset 0 0 0 999px rgba(42,171,184,.1);
}
.warm-banner.hidden { display: none; }
.warm-banner.failed {
  border-bottom-color: rgba(232,93,58,.28);
  box-shadow: 0 4px 14px rgba(26,29,38,.08), inset 0 0 0 999px rgba(232,93,58,.1);
}
.warm-banner.failed .warm-spin { display: none; }
.warm-banner .warm-retry.hidden { display: none; }
.warm-copy { display: flex; flex-direction: row; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.warm-copy #warmText { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.warm-steps { display: none !important; } /* compact overlay: hide step row */
.warm-dismiss {
  flex-shrink: 0; border: none; background: transparent; color: var(--muted);
  cursor: pointer; width: 28px; height: 28px; border-radius: 5px;
  font-size: 18px; line-height: 1; padding: 0; display: grid; place-items: center;
}
.warm-dismiss:hover { color: var(--ink); background: rgba(26,29,38,.06); }
.sleep-banner {
  display: flex; align-items: center; gap: 10px; padding: 10px 20px;
  background: rgba(232,93,58,.1); border-bottom: 1px solid rgba(232,93,58,.28);
  color: var(--ink); font-size: 12.5px; font-weight: 600; flex-shrink: 0;
}
.sleep-banner.hidden { display: none; }
.sleep-banner .sleep-copy { flex: 1; min-width: 0; line-height: 1.35; }
.sleep-banner .sleep-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  background: var(--coral); box-shadow: 0 0 0 3px rgba(232,93,58,.22);
  animation: warm-pulse 1.2s ease-in-out infinite;
}
.notif-wrap { position: relative; flex-shrink: 0; }
.notif-bell { position: relative; }
.notif-bell .notif-badge {
  position: absolute; top: 4px; right: 4px; min-width: 16px; height: 16px;
  padding: 0 4px; border-radius: 999px; background: var(--coral); color: #fff;
  font-size: 9.5px; font-weight: 700; line-height: 16px; text-align: center;
  pointer-events: none; box-shadow: 0 0 0 1.5px var(--surface);
}
.notif-bell .notif-badge.hidden { display: none; }
.notif-panel {
  position: absolute; top: calc(100% + 6px); right: 0; width: min(340px, calc(100vw - 24px));
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow); z-index: 40; overflow: hidden;
}
.notif-panel.hidden { display: none; }
.notif-panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface2);
}
.notif-panel-head .t { font-size: 12px; font-weight: 700; color: var(--ink); }
.notif-panel-head button {
  border: none; background: transparent; color: var(--accent); font-size: 11.5px;
  font-weight: 600; cursor: pointer; padding: 4px 6px; border-radius: 4px;
}
.notif-panel-head button:hover { background: var(--accent-tint); }
.notif-section-label {
  padding: 8px 12px 4px; font-size: 10.5px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
}
.user-menu-wrap { position: relative; flex-shrink: 0; }
.user-menu-panel {
  position: absolute; top: calc(100% + 6px); right: 0; width: min(260px, calc(100vw - 24px));
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow); z-index: 40; overflow: hidden; padding: 4px;
}
.user-menu-panel.hidden { display: none; }
.user-menu-profile {
  padding: 10px 12px 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px;
}
.user-menu-profile-label {
  font-size: 10.5px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px;
}
.user-menu-email {
  font-size: 13px; font-weight: 600; color: var(--ink);
  word-break: break-all; line-height: 1.35;
}
.user-menu-pack {
  margin-top: 4px; font-size: 11.5px; color: var(--muted); font-weight: 500;
}
.user-menu-pack:empty { display: none; }
.user-menu-item {
  display: flex; align-items: center; width: 100%; border: none; background: transparent;
  color: var(--ink); font-size: 12.5px; font-weight: 600; text-align: left;
  padding: 8px 10px; border-radius: 6px; cursor: pointer; min-height: 36px;
}
.user-menu-item:hover { background: var(--accent-tint2); color: var(--accent-dark); }
.usage-list { list-style: none; margin: 0; padding: 0 0 6px; max-height: 160px; overflow: auto;
              border-bottom: 1px solid var(--line); }
.usage-list li {
  display: grid; grid-template-columns: 8px 1fr auto; gap: 8px; align-items: center;
  padding: 8px 12px; font-size: 12.5px; color: var(--body);
}
.usage-list li .udot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--faint);
}
.usage-list li.live .udot { background: var(--green); box-shadow: 0 0 0 3px rgba(34,160,107,.2); }
.usage-list li .uname {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-weight: 600; color: var(--ink);
}
.usage-list li .utimes { text-align: right; font-size: 11px; color: var(--muted); line-height: 1.3; }
.usage-list li .utimes b { color: var(--ink); font-weight: 700; font-variant-numeric: tabular-nums; }
.usage-empty, .notif-empty {
  padding: 14px 12px; text-align: center; color: var(--muted); font-size: 12px; font-weight: 550;
}
.notif-list { list-style: none; margin: 0; padding: 0; max-height: 200px; overflow: auto; }
.notif-list li {
  display: flex; flex-direction: column; gap: 2px; padding: 10px 12px;
  border-bottom: 1px solid var(--line); font-size: 12.5px; color: var(--body);
  cursor: default;
}
.notif-list li:last-child { border-bottom: none; }
.notif-list li.unread { background: var(--accent-tint2); }
.notif-list li .ntitle { font-weight: 600; color: var(--ink); }
.notif-list li .nmeta { font-size: 11px; color: var(--muted); }
.warm-spin {
  width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid rgba(42,171,184,.3); border-top-color: var(--teal);
  animation: warm-spin .7s linear infinite;
}
@keyframes warm-spin { to { transform: rotate(360deg); } }
.ws-dot.warming { background: var(--teal); box-shadow: 0 0 0 3px rgba(42,171,184,.25); animation: warm-pulse 1.2s ease-in-out infinite; }
@keyframes warm-pulse { 50% { opacity: .45; } }

body.ui-locked #workspaces { pointer-events: none; opacity: .55; }
body.ui-locked #newWsControls { pointer-events: none; opacity: .55; }
body.ui-locked #dropzone { pointer-events: none; opacity: .55; }
body.ui-locked #opStatus { opacity: 1; }
body.ui-locked #files .rowbtn.del { pointer-events: none; opacity: .4; }
body.ui-locked #manageChatsList .sess-actions { pointer-events: none; opacity: .45; }
body.ui-locked #manageChatsList .sess-main { pointer-events: none; }
body.ui-locked #stopBtn { pointer-events: auto; opacity: 1; }
/* Agent runs do not lock navigation — tabs/workspaces stay interactive. */

.chat-tab .tab-spin {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
  border: 1.5px solid rgba(0,97,255,.25); border-top-color: var(--accent);
  animation: warm-spin .7s linear infinite;
}
.chat-tab .tab-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent);
}
.ws-dot.running {
  background: transparent; border: 2px solid rgba(0,97,255,.28);
  border-top-color: var(--accent); box-shadow: none;
  animation: warm-spin .7s linear infinite;
}
.ws-dot.unread { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }

.composer-col { display: flex; flex-direction: column; gap: 0; border-top: 1px solid var(--line); background: var(--surface); }
.composer-tip {
  padding: 6px 16px 0; font-size: 11.5px; font-weight: 550; color: var(--muted); line-height: 1.35;
}
.composer-tip.hidden { display: none; }

.mode-toggle { display: inline-flex; align-items: stretch; border: 1px solid var(--line2);
               border-radius: 8px; overflow: hidden; flex-shrink: 0; background: var(--surface); }
.mode-btn { border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 12px;
            font-weight: 600; padding: 7px 12px; cursor: pointer; letter-spacing: .02em; }
.mode-btn:hover:not(:disabled) { color: var(--ink); background: var(--bg); }
.mode-btn.on { background: var(--accent-tint); color: var(--accent-dark); }
.mode-btn:disabled { opacity: .35; cursor: not-allowed; }
.modebar {
  grid-row: 2; grid-column: 2;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px; min-height: 48px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  z-index: 2;
}
.modebar .mode-hint { font-size: 11px; color: var(--muted); min-width: 0; flex: 1;
                      white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modebar #queryCustomizeBtn {
  flex-shrink: 0;
  font-size: 22px;
  line-height: 1;
  min-width: 40px;
  min-height: 40px;
  padding: 0 8px;
  display: grid;
  place-items: center;
}

.op-status {
  display: flex; align-items: center; gap: 8px; margin: 0 12px 10px;
  padding: 8px 10px; border-radius: 6px;
  background: rgba(42,171,184,.12); border: 1px solid rgba(42,171,184,.3);
  color: var(--ink); font-size: 12px; font-weight: 600; line-height: 1.35;
}
.op-status.hidden { display: none; }
.btn-spin {
  display: inline-block; width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid rgba(26,29,38,.2); border-top-color: var(--accent);
  animation: warm-spin .7s linear infinite; vertical-align: -1px;
}
.newws-input-wrap .btn-embed.busy { min-width: 72px; color: var(--accent-dark); }

/* Chat / Files — mobile only, above the composer */
.segbar { display: none; }

/* sidebar (file manager) */
.sidebar { grid-row: 2 / -1; grid-column: 1; background: var(--surface2); border-right: 1px solid var(--line);
           display: flex; flex-direction: column; min-height: 0; overflow: hidden; z-index: 1; }
.sb-section { display: flex; flex-direction: column; min-height: 0; }
.sb-section + .sb-section { border-top: 1px solid var(--line); }
.sb-fill { flex: 1; min-height: 0; }
.sb-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 8px; flex-shrink: 0; }
.sb-head .t { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.sb-head .active { color: var(--ink); font-weight: 700; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

ul.list { list-style: none; margin: 0; padding: 0 8px 10px; overflow: auto; min-height: 0; -webkit-overflow-scrolling: touch; }
ul.list li { display: flex; align-items: center; gap: 9px; padding: 9px 10px; border-radius: var(--radius);
             cursor: pointer; font-size: 13px; color: var(--ink); min-height: 40px; font-weight: 500;
             transition: background .12s; }
ul.list li:hover { background: rgba(255,255,255,.7); }
li.ws.active { background: var(--accent-tint); color: var(--accent-dark); font-weight: 600; }
li .ico { width: 18px; text-align: center; flex-shrink: 0; }
li .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
li .meta { font-size: 11px; color: var(--muted); flex-shrink: 0; }
li .rowbtns { display: flex; gap: 2px; flex-shrink: 0; }
/* desktop: reveal actions on hover; touch keeps them always visible (no sticky :hover trap) */
@media (hover: hover) and (pointer: fine) {
  li .rowbtns { display: none; }
  li:hover .rowbtns { display: flex; }
  li:hover .meta { display: none; }
}
.rowbtn { border: none; background: transparent; color: var(--muted); cursor: pointer; padding: 5px 6px; border-radius: 5px; font-size: 14px; min-width: 32px; min-height: 32px; }
.rowbtn:hover { background: rgba(26,29,38,.06); color: var(--ink); }
.rowbtn.dl:hover { color: var(--accent); }
.rowbtn.del:hover { color: var(--red); }
.rowbtn.ws-more { font-size: 16px; line-height: 1; letter-spacing: .02em; }
.ws-menu {
  position: fixed; min-width: 168px; padding: 4px; z-index: 50;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow);
}
.ws-menu.hidden { display: none; }
.ws-menu button {
  display: flex; align-items: center; gap: 8px; width: 100%; border: none; background: transparent;
  color: var(--ink); font-size: 12.5px; font-weight: 600; text-align: left;
  padding: 8px 10px; border-radius: 6px; cursor: pointer; min-height: 36px;
}
.ws-menu button:hover { background: var(--accent-tint2); color: var(--accent-dark); }
.ws-menu button:disabled { opacity: .4; cursor: not-allowed; }
.ws-menu button.hidden { display: none; }
.badge-s { background: var(--accent); color: #fff; border-radius: 999px; font-size: 9.5px; padding: 1px 6px; font-weight: 700; }
.ws-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); flex-shrink: 0; }
.ws-dot.on { background: var(--green); }
/* workspace controls: name input with embedded New, then Open + Import */
.newws-controls { display: flex; flex-direction: column; gap: 6px; padding: 0 12px 12px; flex-shrink: 0; }
.pack-switch {
  display: flex; flex-direction: column; gap: 4px;
  padding: 0 12px 10px; flex-shrink: 0;
}
.pack-switch-label {
  font-size: 11px; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--muted);
}
.pack-switch-select { width: 100%; }
.newws-input-wrap { display: flex; align-items: stretch; width: 100%;
                    border: 1.5px solid var(--line2); border-radius: 6px; background: var(--surface);
                    overflow: hidden; min-height: 40px; transition: border-color .12s, box-shadow .12s; }
.newws-input-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.newws-controls.highlight .newws-input-wrap { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.newws-input-wrap input { flex: 1; min-width: 0; border: none !important; box-shadow: none !important;
                          border-radius: 0; background: transparent; font-size: 12.5px;
                          padding: 8px 10px; min-height: 38px; }
.newws-input-wrap input:focus { outline: none; }
.newws-input-wrap .btn-embed { flex-shrink: 0; border: none; border-left: 1.5px solid var(--line2);
                               border-radius: 0; background: var(--surface2); color: var(--ink);
                               padding: 0 12px; font-size: 12px; font-weight: 600; min-height: 0;
                               min-width: 64px; white-space: nowrap; }
.newws-input-wrap .btn-embed:hover { background: var(--accent-tint2); color: var(--accent-dark); }
.ws-hint { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.4; }
.newws-actions { display: flex; gap: 6px; }
.newws-actions button { flex: 1 1 0; min-width: 0; justify-content: center; }

.import-choices { display: flex; flex-direction: column; gap: 8px; }
.import-choices .btn-soft { justify-content: center; min-height: 44px; font-weight: 600; }
.import-git-panel.hidden { display: none; }

/* server folder browser */
.browse-path { font-family: var(--mono); font-size: 11.5px; color: var(--muted); word-break: break-all;
               padding: 8px 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; margin-bottom: 10px; }
.browse-list { list-style: none; margin: 0; padding: 0; max-height: min(48vh, 360px); overflow: auto;
               border: 1px solid var(--line); border-radius: 6px; }
.browse-list li { display: flex; align-items: center; gap: 8px; padding: 9px 12px; cursor: pointer;
                  border-bottom: 1px solid var(--line); font-size: 13px; min-height: 40px; }
.browse-list li:last-child { border-bottom: none; }
.browse-list li:hover { background: var(--accent-tint2); }
.browse-list li .ico { flex-shrink: 0; opacity: .7; }
.browse-list li .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.browse-empty { color: var(--muted); padding: 16px; text-align: center; font-size: 13px; }

/* dropzone */
.dropzone { margin: 4px 12px 8px; border: 1.5px dashed var(--line2); border-radius: var(--radius); padding: 14px;
            text-align: center; color: var(--muted); font-size: 12px; cursor: pointer; transition: .15s;
            background: var(--surface); }
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-tint2); color: var(--accent-dark); }
.dropzone b { color: var(--accent); }

/* chat */
.chat-head { grid-row: 3; grid-column: 2; display: flex; align-items: center; justify-content: space-between; padding: 10px 20px;
             border-bottom: 1px solid var(--line); background: var(--surface); flex-shrink: 0; min-height: 48px; z-index: 2; }
.chat-head .ct { display: flex; align-items: center; gap: 9px; min-width: 0; flex: 1; }
.chat-head .fname { font-weight: 700; color: var(--ink); font-size: 14px; letter-spacing: -.02em;
                    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .chat-ws-more { display: none; flex-shrink: 0; }
body.query-mode .chat-head .chat-ws-more { display: none !important; }
body.query-mode .sb-agent-only { display: none !important; }
body.query-mode .sb-query-only { display: flex !important; flex-direction: column; min-height: 0; }
body:not(.query-mode) .sb-query-only { display: none !important; }
.sb-query-only.sb-fill { flex: 1; min-height: 0; }
.chat-head-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; align-items: center; flex-shrink: 0; }
.chat { grid-row: 4; grid-column: 2; display: flex; flex-direction: column; min-height: 0; background: var(--bg); overflow: hidden; position: relative; }
.pill { font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--accent-tint); color: var(--accent-dark); flex-shrink: 0; }
.pill.idle { background: var(--surface2); color: var(--muted); }

/* browser-style chat session tabs */
.chat-tabs { display: flex; align-items: stretch; gap: 0; background: var(--surface2);
             border-bottom: 1px solid var(--line); flex-shrink: 0; min-height: 38px; }
.chat-tabs-scroll { display: flex; align-items: stretch; gap: 2px; flex: 1; min-width: 0;
                    overflow-x: auto; overflow-y: hidden; padding: 4px 4px 0;
                    -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
.chat-tab { display: flex; align-items: center; gap: 6px; max-width: 180px; min-width: 72px;
            padding: 6px 8px 6px 12px; border: 1px solid transparent; border-bottom: none;
            border-radius: 6px 6px 0 0; background: transparent; color: var(--muted);
            font-size: 12px; font-weight: 600; cursor: pointer; flex-shrink: 0; min-height: 32px; }
.chat-tab:hover { background: var(--surface); color: var(--ink); }
.chat-tab.active { background: var(--surface); color: var(--ink); border-color: var(--line);
                   box-shadow: 0 -1px 0 var(--surface); position: relative; z-index: 1; }
.chat-tab .tt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0;
                text-align: left; pointer-events: none; }
.chat-tab .tx { border: none; background: transparent; color: var(--muted); cursor: pointer;
                padding: 0; margin: 0; width: 22px; min-width: 22px; height: 22px; min-height: 22px;
                border-radius: 4px; font-size: 14px; line-height: 1; display: grid; place-items: center;
                flex-shrink: 0; opacity: .55; }
.chat-tab .tx:hover { background: rgba(26,29,38,.08); color: var(--ink); opacity: 1; }
.chat-tab-add { flex-shrink: 0; border: none; background: transparent; color: var(--muted);
                width: 36px; min-width: 36px; min-height: 36px; padding: 0; margin: 1px 2px 0 2px;
                border-radius: 5px; font-size: 18px; line-height: 1; cursor: pointer;
                display: grid; place-items: center; }
.chat-tab-add:hover { background: var(--accent-tint2); color: var(--accent-dark); }
.chat-tab-add:disabled { opacity: .35; cursor: not-allowed; }
.chat-tab-manage { font-size: 15px; }
.chat.disabled .chat-tabs { pointer-events: none; opacity: .55; }

.sess-list { list-style: none; margin: 0; padding: 0; max-height: min(52vh, 420px); overflow: auto;
             border: 1px solid var(--line); border-radius: 6px; }
.sess-list li { display: flex; align-items: center; gap: 10px; padding: 10px 12px;
                border-bottom: 1px solid var(--line); min-height: 48px; }
.sess-list li:last-child { border-bottom: none; }
.sess-list li.closed { opacity: .72; background: var(--bg); }
.sess-list .sess-main { flex: 1; min-width: 0; cursor: pointer; }
.sess-list .sess-title { font-weight: 600; font-size: 13px; color: var(--ink);
                         white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sess-list .sess-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.sess-list .sess-actions { display: flex; gap: 6px; flex-shrink: 0; }
.sess-empty { color: var(--muted); padding: 20px; text-align: center; font-size: 13px; }

.messages { flex: 1; overflow: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; min-height: 0;
            -webkit-overflow-scrolling: touch; }
.msg { max-width: 80%; display: flex; flex-direction: column; gap: 5px; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.agent { align-self: flex-start; }
.bubble { padding: 10px 13px; border-radius: 10px; font-size: 14px; line-height: 1.55; word-break: break-word; }
.msg.user .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 3px; white-space: pre-wrap; }
.msg.agent .bubble { background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-bottom-left-radius: 3px; box-shadow: var(--shadow); }
.msg .who { font-size: 10.5px; color: var(--muted); font-weight: 600; padding: 0 4px; }
.toolchip { font-family: var(--mono); font-size: 11.5px; background: var(--accent-tint2); border: 1px solid var(--accent-border);
            border-radius: 5px; padding: 5px 9px; color: var(--accent-dark); margin: 4px 0; }
.toolchip > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 6px;
                      user-select: none; color: var(--muted); font-weight: 600; }
.toolchip > summary::-webkit-details-marker { display: none; }
.toolchip > summary::before { content: '▸'; font-size: 10px; color: var(--muted); transition: transform .12s ease; }
.toolchip[open] > summary::before { transform: rotate(90deg); }
.toolchip .tn { color: var(--coral); font-weight: 700; }
.toolchip.is-error .tn { color: var(--red); }
.toolchip-body { margin: 6px 0 2px; padding: 6px 8px; border-radius: 4px; background: var(--surface);
                 border: 1px solid var(--line); font-family: var(--mono); font-size: 11px; line-height: 1.45;
                 white-space: pre-wrap; word-break: break-word; color: var(--ink); overflow-x: auto; max-height: 220px; overflow-y: auto; }
.md { white-space: normal; color: var(--ink); }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0.55em 0; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 {
  margin: 0.85em 0 0.35em; line-height: 1.3; font-weight: 800; color: var(--ink);
  letter-spacing: -0.02em;
}
.md h1 { font-size: 1.45em; }
.md h2 { font-size: 1.28em; }
.md h3 { font-size: 1.14em; }
.md h4, .md h5, .md h6 { font-size: 1.05em; font-weight: 700; }
.md ul, .md ol { margin: 0.45em 0; padding-left: 1.45em; }
.md ul { list-style: disc; }
.md ol { list-style: decimal; }
.md li { margin: 0.25em 0; }
.md li > p { margin: 0.2em 0; }
.md a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.md blockquote { margin: 0.5em 0; padding: 0.15em 0 0.15em 0.75em; border-left: 3px solid var(--accent-border); color: var(--muted); }
.md hr { border: none; border-top: 1px solid var(--line); margin: 0.75em 0; }
.md code { font-family: var(--mono); font-size: 0.88em; background: var(--accent-tint2); border: 1px solid var(--accent-border);
           border-radius: 4px; padding: 0.1em 0.35em; }
.md pre { margin: 0.55em 0; padding: 8px 10px; border-radius: 6px; background: var(--accent-tint2);
          border: 1px solid var(--accent-border); overflow-x: auto; }
.md pre code { background: none; border: none; padding: 0; font-size: 12px; white-space: pre; }
.md table { border-collapse: collapse; margin: 0.55em 0; font-size: 0.92em; width: 100%; }
.md th, .md td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; }
.md th { background: var(--accent-tint2); font-weight: 600; }
.md strong { font-weight: 700; }
.agentmeta { font-size: 11px; color: var(--green); font-weight: 600; }
.typing { color: var(--muted); font-style: italic; }
.empty { margin: auto; text-align: center; color: var(--muted); padding: 28px 24px; max-width: 360px; }
.welcome-wrap { width: 100%; padding: 12px 16px 20px; }
.welcome-wrap .msg { max-width: 720px; }
.empty .big { width: 48px; height: 48px; margin: 0 auto 14px; border-radius: 8px;
              background: var(--accent-tint); border: 1px solid var(--accent-border);
              display: grid; place-items: center; font-size: 22px; line-height: 1; color: var(--accent); }
.empty b { color: var(--ink); font-weight: 600; }
.chat.disabled { opacity: .55; }
.chat-head.disabled { pointer-events: none; opacity: .55; }
.chat.disabled .composer { pointer-events: none; opacity: .5; }
.segbtn:disabled { opacity: .4; cursor: not-allowed; }

/* composer — sits above iOS home indicator */
.composer { background: transparent; padding: 12px 16px;
            padding-bottom: max(12px, env(safe-area-inset-bottom));
            display: flex; gap: 8px; align-items: flex-end; flex-shrink: 0; border-top: none; }
.composer textarea { flex: 1; resize: none; min-height: 44px; max-height: 120px; font-family: var(--sans);
                     font-size: 15px; padding: 10px 12px; border: 1.5px solid var(--line2); border-radius: 8px;
                     line-height: 1.4; background: var(--bg); }
.composer textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); background: var(--surface); }
#sendBtn { width: 44px; min-width: 44px; padding: 0; display: grid; place-items: center; flex-shrink: 0; }
#sendBtn svg { width: 18px; height: 18px; display: block; }
#langBtn { min-width: 52px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }

button { font: inherit; cursor: pointer; border: 1.5px solid transparent; border-radius: 6px;
         padding: 10px 16px; font-weight: 600; transition: .12s; min-height: 42px; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
button:disabled { opacity: .4; cursor: not-allowed; }
button.btn-soft { background: var(--surface); border-color: var(--line2); color: var(--ink); }
button.btn-soft:hover { background: var(--surface2); border-color: var(--line); }
button.sm { padding: 7px 12px; font-size: 12px; min-height: 36px; border-radius: 5px; }
button.icon { padding: 8px; background: transparent; color: var(--muted); border: none; min-width: 38px; min-height: 38px; border-radius: 5px; }
button.icon:hover { color: var(--accent); background: var(--accent-tint2); }

.hint { color: var(--muted); font-size: 12px; margin: 0; }
.modal-bg { position: fixed; inset: 0; background: rgba(26,29,38,.4); display: none; place-items: center;
            z-index: 20; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.modal-bg.open { display: grid; }
.modal { background: var(--surface); border-radius: 10px; width: min(720px, 94vw); max-height: 84vh;
         display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 24px 64px rgba(26,29,38,.18);
         border: 1px solid var(--line); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-head .mn { font-weight: 700; color: var(--ink); font-family: var(--mono); font-size: 13px; }
.modal-body { padding: 16px; overflow: auto; -webkit-overflow-scrolling: touch; }
.modal-body pre { margin: 0; font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; word-break: break-word; color: var(--ink); }

/* customize modal */
.cust-field { display: flex; flex-direction: column; }
.cust-field label { font-weight: 700; color: var(--ink); font-size: 13px; margin-bottom: 5px; }
.cust-field .hint { color: var(--muted); font-weight: 400; font-size: 11.5px; }
.cust-ta { width: 100%; min-height: 110px; font-family: var(--mono); font-size: 12.5px; padding: 10px;
           border: 1.5px solid var(--line2); border-radius: 6px; resize: vertical; line-height: 1.5; background: var(--bg); }
.cust-ta:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); background: var(--surface); }

select, input.inp { font: inherit; color: var(--ink); background: var(--surface); border: 1.5px solid var(--line2);
                    border-radius: 6px; padding: 8px 10px; min-height: 38px; }
select:focus, input.inp:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.hidden { display: none !important; }

/* ── responsive: iPad portrait & mobile (≤ 860px) ── */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: var(--top-h) auto auto 1fr auto; }
  .topbar { grid-row: 1; }
  .modebar { grid-row: 2; grid-column: 1; padding: 8px 12px; }
  .chat-head { grid-row: 3; grid-column: 1; padding: 8px 12px; min-height: 44px; background: var(--surface2);
               border-bottom: 1px solid var(--line); }
  .chat-head .fname { font-size: 15px; }
  .chat-head .chat-ws-more { display: grid; place-items: center; width: 36px; min-width: 36px;
                             height: 36px; min-height: 36px; font-size: 18px;
                             border: 1px solid var(--line2); border-radius: 6px; background: var(--surface); }
  .chat-head .chat-ws-more:hover { background: var(--accent-tint2); color: var(--accent-dark); }
  .sidebar { grid-row: 4; grid-column: 1; border-right: none; background: var(--bg); }
  .chat { grid-row: 4; grid-column: 1; }
  body:not(.view-files) .sidebar { display: none; }
  body.view-files .chat { display: none; }
  body.view-files #resumePill { display: none; }
  /* Keep modebar visible on Files so Agent-without-workspace can switch to Query. */
  .segbar { display: flex; grid-row: 5; grid-column: 1; justify-content: center; align-items: center;
            padding: 6px 12px; padding-bottom: max(6px, env(safe-area-inset-bottom));
            background: var(--surface); border-top: 1px solid var(--line); z-index: 3; }
  .segbar-track { display: flex; gap: 2px; width: fit-content; max-width: calc(100% - 24px);
                  margin: 0 auto; padding: 3px; background: var(--bg); border: 1px solid var(--line2);
                  border-radius: 8px; }
  .segbtn { flex: 0 0 auto; min-width: 96px; border: none; background: transparent; color: var(--muted);
            padding: 7px 14px; border-radius: 6px; font-weight: 600; font-size: 13px; min-height: 34px; cursor: pointer; }
  .segbtn.on { background: var(--surface); color: var(--accent-dark); box-shadow: var(--shadow); }
  .messages { padding: 14px; }
  .msg { max-width: 88%; }
  li .meta { display: none; }              /* hide size so action buttons always fit */
  .chat-tabs { background: var(--surface); }
}

/* phones */
@media (max-width: 480px) {
  .brand h1 { font-size: 14px; }
  .segbtn { font-size: 12.5px; padding: 6px 12px; min-width: 88px; min-height: 32px; }
  .composer { padding: 8px 10px; }
  .messages { padding: 12px 10px; }
  .bubble { font-size: 13.5px; padding: 9px 12px; }
}

/* landscape phones — keep segmented, give chat priority */
@media (max-width: 860px) and (orientation: landscape) and (max-height: 500px) {
  .app { grid-template-rows: var(--top-h) auto auto 1fr auto; }
  .messages { padding-top: 8px; padding-bottom: 8px; }
}
