/* Agent Mode — start page, session view, workspace panel, leaderboard. Uses the app theme variables. */
.main.ag-view { display: flex; flex-direction: column; overflow: hidden; min-width: 0; min-height: 0; }
.ag-view > .topbar-m { flex: none; }
.ag-icon { display: inline-flex; flex: none; }
.ag-dim { color: var(--fg3); }
.ag-mono { font-family: var(--mono); }

/* ---------- start page ---------- */
.ag-home { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px 64px; }
.ag-home-in { width: 100%; max-width: 672px; display: flex; flex-direction: column; gap: 24px; position: relative; }
.ag-title { margin: 0; text-align: center; text-wrap: balance; color: var(--fg); font-family: var(--serif); font-weight: 400; font-size: clamp(34px, 5vw, 50px); letter-spacing: -.03em; line-height: 1.1; }
.ag-box { background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; padding: 8px; transition: border-color .15s, box-shadow .15s; }
.ag-box:focus-within { border-color: var(--fg3); }
.ag-box textarea { display: block; width: 100%; resize: none; border: 0; outline: 0; background: transparent; padding: 8px 8px 4px; min-height: 80px; max-height: 40vh; line-height: 1.5; }
.ag-box textarea::placeholder { color: var(--fg3); }
.ag-box-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 2px 0 0; }
.ag-box-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.ag-plus { width: 32px; height: 32px; border-radius: 8px; border: 0; background: transparent; color: var(--fg2); display: grid; place-items: center; }
.ag-plus:hover { background: var(--bg3); color: var(--fg); }
.ag-box .mode-picker { margin-right: 0; }
.ag-box .mode-trigger { background: transparent; border-color: transparent; padding: 6px 8px; font-size: 14px; }
.ag-box .mode-trigger:hover { color: var(--fg); background: var(--bg3); }
.ag-box .mode-menu { bottom: auto; top: calc(100% + 6px); }
.ag-dock .ag-box .mode-menu { top: auto; bottom: calc(100% + 6px); }
.ag-send { width: 32px; height: 32px; border-radius: 6px; border: 0; background: var(--accent); color: var(--accent-fg); display: grid; place-items: center; flex: none; }
.ag-send:disabled { opacity: .35; cursor: default; }
.ag-send.stop { background: var(--fg2); }
.ag-attached { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 6px 0; }
.ag-attached:empty { display: none; }
.ag-file-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 220px; border: 1px solid var(--line); background: var(--bg); border-radius: 6px; padding: 2px 4px 2px 8px; font: 12px var(--mono); }
.ag-file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-file-chip button { border: 0; background: none; color: var(--fg3); padding: 0 4px; line-height: 1; }

/* ---------- session ---------- */
.ag-session { flex: 1; min-height: 0; min-width: 0; display: flex; position: relative; overflow: hidden; }
.ag-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ag-top { flex: none; min-height: 52px; display: flex; align-items: center; gap: 8px; padding: 6px 14px; }
.ag-session-title { font-size: 14px; color: var(--fg2); padding: 8px; border-radius: 8px; max-width: min(60vw, 520px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-top .grow { flex: 1; }
.ag-log { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 8px 0 24px; scroll-behavior: auto; }
.ag-log-in { max-width: 768px; margin: 0 auto; padding: 0 16px; display: flex; flex-direction: column; gap: 16px; }
.ag-turn { display: flex; flex-direction: column; gap: 16px; }
.ag-user { align-self: flex-end; max-width: min(70%, 768px); background: var(--bg3); border-radius: 10px; padding: 8px 12px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; }
.ag-user .ag-file-chip { margin: 6px 4px 0 0; }
.ag-asst { display: flex; flex-direction: column; gap: 10px; min-width: 0; padding: 0 2px; }
.ag-thought-head { display: flex; align-items: center; gap: 6px; border: 0; background: none; padding: 0; font-size: 14px; color: var(--fg2); }
.ag-thought-head:hover { color: var(--fg3); }
.ag-chev { display: inline-flex; transition: transform .15s; }
.ag-open > .ag-thought-head .ag-chev, .ag-open > .ag-row .ag-chev { transform: rotate(90deg); }
.ag-thought-body { position: relative; margin: 10px 8px 2px 24px; padding-left: 0; font: 12px/1.6 var(--mono); color: var(--fg2); white-space: pre-wrap; overflow-wrap: anywhere; }
.ag-thought-body::before { content: ""; position: absolute; left: -18px; top: 0; bottom: 0; width: 2px; border-radius: 2px; background: var(--line); }
.ag-row { display: flex; align-items: center; gap: 6px; font-size: 13.5px; cursor: pointer; min-width: 0; border: 0; background: none; padding: 0; text-align: left; width: 100%; }
.ag-row .ag-tn { color: var(--fg2); }
.ag-row.bad .ag-tn { color: var(--danger); }
.ag-row .ag-chip { background: var(--bg3); color: var(--fg3); border-radius: 4px; padding: 1px 5px; font: 10px/1.2 var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.ag-row small { color: var(--fg3); font-size: 10px; white-space: nowrap; }
.ag-row .ag-act { margin-left: 2px; color: var(--fg3); font-size: 10px; text-decoration: none; background: none; border: 0; padding: 2px; }
.ag-row .ag-act:hover { color: var(--fg2); }
.ag-tool-body { margin: 8px 0 0 0; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); overflow: hidden; }
.ag-tool-body pre { margin: 0; padding: 10px 12px; font: 12px/1.5 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 320px; overflow: auto; color: var(--fg2); }
.ag-tool-body .cmd { color: var(--fg); border-bottom: 1px solid var(--line); background: var(--bg2); }
.ag-tool-body .res a { color: var(--fg); }
.ag-tool-body .hit { padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
.ag-tool-body .hit:last-child { border-bottom: 0; }
.ag-tool-body .hit small { display: block; color: var(--fg3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-art { display: block; width: 100%; text-align: left; margin-top: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg2); overflow: hidden; padding: 0; position: relative; box-shadow: 0 0 8px rgba(0,0,0,.04); }
.ag-art:hover { border-color: var(--fg3); background: var(--bg3); box-shadow: none; }
.ag-art-head { display: flex; align-items: center; gap: 6px; padding: 8px 12px; }
.ag-art-head b { flex: 1; min-width: 0; font-weight: 400; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-lang { border: 1px solid var(--line); border-radius: 4px; padding: 3px 6px; font-size: 11px; font-weight: 500; line-height: 1; text-transform: uppercase; color: var(--fg3); background: var(--bg2); }
.ag-art pre { margin: 0 12px 12px; border: 1px solid var(--line); border-radius: 4px; background: var(--bg); padding: 12px; height: 260px; overflow: hidden; font: 12px/1.5 var(--mono); color: var(--fg2); white-space: pre-wrap; }
.ag-art .ag-open-hint { position: absolute; inset: 0; display: grid; place-items: center; opacity: 0; transition: opacity .15s; background: rgba(0,0,0,.45); color: #fff; font-size: 15px; }
.ag-art:hover .ag-open-hint { opacity: 1; }
.ag-text { overflow-wrap: anywhere; line-height: 1.65; }
.ag-text p { margin: 0 0 12px; }
.ag-text p:last-child { margin-bottom: 0; }
.ag-text pre { background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; overflow: auto; font: 13px/1.5 var(--mono); }
.ag-text code { background: var(--bg3); border-radius: 4px; padding: 1px 5px; font-family: var(--mono); font-size: .9em; }
.ag-text pre code { background: none; padding: 0; }
.ag-text a { color: #5b9bd5; }
.ag-fchip { display: inline-flex; align-items: center; vertical-align: middle; margin: 2px 0; border: 1px solid var(--line); background: var(--bg2); border-radius: 4px; padding: 0 5px; font: 12px/1.6 var(--mono); color: var(--fg2); max-width: 100%; }
.ag-fchip:hover { background: var(--bg3); color: var(--fg); }
.ag-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 2px; flex-wrap: wrap; }
.ag-foot .l { display: flex; align-items: center; gap: 4px; }
.ag-foot .icon-btn { width: 28px; height: 28px; }
.ag-verdict { font-size: 12px; color: var(--fg3); padding: 0 6px; }
.ag-verdict.yes { color: var(--good); }
.ag-verdict.no { color: var(--danger); }
.ag-time { font-size: 12px; color: var(--fg3); font-variant-numeric: tabular-nums; cursor: default; }
.ag-err { border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--line)); background: color-mix(in srgb, var(--danger) 8%, var(--bg)); border-radius: 8px; padding: 10px 12px; font-size: 14px; }
.ag-note { color: var(--fg3); font-size: 13px; font-style: italic; }
.ag-dots { display: inline-flex; gap: 4px; padding: 6px 0; }
.ag-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--fg3); animation: ag-pulse 1.2s infinite ease-in-out; }
.ag-dots i:nth-child(2) { animation-delay: .15s; }
.ag-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes ag-pulse { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .ag-dots i { animation: none; opacity: .6; } }

.ag-dock { flex: none; padding: 0 16px max(16px, env(safe-area-inset-bottom)); }
.ag-dock-in { max-width: 800px; margin: 0 auto; }
.ag-dock .ag-box textarea { min-height: 48px; }
.ag-fb { max-width: 768px; margin: 0 auto 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg2); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.ag-fb-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; font-size: 14px; }
.ag-fb-head .x { display: flex; align-items: center; gap: 4px; color: var(--fg3); }
.ag-fb-head kbd { font: 11px var(--mono); }
.ag-fb-head button { border: 0; background: none; color: var(--fg3); width: 24px; height: 24px; border-radius: 4px; }
.ag-fb-head button:hover { background: var(--bg3); color: var(--fg); }
.ag-fb-list { margin: 0 12px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); overflow: hidden; }
.ag-fb-list button { display: flex; width: 100%; align-items: center; gap: 8px; border: 0; background: none; padding: 12px 16px; font-size: 14px; color: var(--fg3); text-align: left; }
.ag-fb-list button + button { border-top: 1px solid var(--line); }
.ag-fb-list button:hover, .ag-fb-list button:focus-visible { background: var(--bg3); color: var(--fg); outline: 0; }
.ag-fb-dot { width: 14px; height: 14px; border: 1.5px solid currentColor; border-radius: 50%; flex: none; }

/* ---------- workspace side panel ---------- */
.ag-side { width: 320px; flex: none; border-left: 1px solid var(--line); overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; background: var(--bg); }
.ag-session.nosidebar .ag-side { display: none; }
.ag-card { border: 1px solid var(--line); border-radius: 6px; background: var(--bg); overflow: hidden; display: flex; flex-direction: column; }
.ag-card-head { padding: 12px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.ag-card-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--fg3); }
.ag-card-title a, .ag-card-title button { color: var(--fg3); background: none; border: 0; padding: 0; display: inline-flex; }
.ag-card-title a:hover, .ag-card-title button:hover { color: var(--fg); }
.ag-stats { display: flex; justify-content: space-between; gap: 8px; font: 11px var(--mono); color: var(--fg3); }
.ag-bar { height: 3px; border-radius: 2px; background: var(--bg3); overflow: hidden; }
.ag-bar i { display: block; height: 100%; background: var(--fg3); }
.ag-files { padding: 8px; max-height: 360px; overflow-y: auto; }
.ag-frow { display: flex; align-items: center; gap: 6px; padding: 8px; border: 1px solid transparent; border-radius: 4px; cursor: pointer; font-size: 14px; }
.ag-frow:hover { background: var(--bg3); border-color: var(--line); }
.ag-frow .n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-frow .acts { display: none; align-items: center; gap: 8px; }
.ag-frow:hover .acts, .ag-frow:focus-within .acts { display: flex; }
.ag-frow .acts a, .ag-frow .acts button { color: var(--fg3); background: none; border: 0; padding: 0; display: inline-flex; }
.ag-frow .acts a:hover, .ag-frow .acts button:hover { color: var(--fg); }
.ag-empty-files { color: var(--fg3); font-size: 13px; padding: 10px 8px; }

/* ---------- viewer ---------- */
.ag-viewer-bg { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.55); display: grid; place-items: center; padding: 16px; }
.ag-viewer { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; width: min(980px, 100%); max-height: min(86dvh, 860px); display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow); }
.ag-viewer-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.ag-viewer-head b { flex: 1; min-width: 0; font: 500 14px var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-viewer-body { margin: 0; padding: 14px; overflow: auto; font: 12.5px/1.55 var(--mono); white-space: pre; tab-size: 4; min-height: 80px; }
.ag-viewer-body img { max-width: 100%; display: block; }

/* ---------- leaderboard ---------- */
.ag-lb .lb-main { padding-top: 32px; }
.ag-lb h1 { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.ag-seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--bg2); border-radius: 8px; padding: 3px; gap: 2px; }
.ag-seg button { border: 0; background: transparent; border-radius: 6px; padding: 5px 10px; font-size: 13px; color: var(--fg2); }
.ag-seg button.on { background: var(--bg); color: var(--fg); box-shadow: 0 1px 2px rgba(0,0,0,.14); }
.ag-fgroup { border-top: 1px solid var(--line); padding: 14px 0 6px; }
.ag-fgroup:first-child { border-top: 0; padding-top: 4px; }
.ag-fgroup .f-head { font-size: 15px; margin-bottom: 10px; }
.ag-fgroup .f-head span { color: var(--fg3); margin-left: 4px; }
.ag-radio { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; font-size: 14px; color: var(--fg2); cursor: pointer; }
.ag-radio:hover { background: var(--bg2); }
.ag-radio i { width: 16px; height: 16px; border: 1px solid var(--fg3); border-radius: 50%; display: grid; place-items: center; flex: none; }
.ag-radio.on i::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--fg); }
.ag-radio.on { color: var(--fg); }
.ag-strip { display: flex; align-items: center; gap: 12px; border-top: 1px solid var(--line); padding: 10px 0; flex-wrap: wrap; }
.ag-strip .link { background: none; border: 0; display: flex; gap: 8px; align-items: center; font-size: 14px; padding: 4px 6px; border-radius: 6px; }
.ag-strip .link:hover { background: var(--bg2); }
.ag-strip .grow { flex: 1; }
.ag-strip input { background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; outline: 0; width: 220px; }
.ag-cols-pop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 25; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 6px; min-width: 230px; }
.ag-cols-pop label { display: flex; gap: 10px; align-items: center; padding: 7px 10px; border-radius: 6px; font-size: 14px; cursor: pointer; }
.ag-cols-pop label:hover { background: var(--bg2); }
.ag-table-wrap { border: 1px solid var(--line); border-radius: 10px; background: var(--bg2); overflow: auto; max-height: calc(100dvh - 240px); }
.ag-table { width: 100%; border-collapse: separate; border-spacing: 0; table-layout: auto; font-size: 14px; }
.ag-table th { text-transform: none; letter-spacing: 0; position: sticky; top: 0; z-index: 3; background: var(--bg2); font-size: 12px; font-weight: 500; text-align: left; padding: 12px 14px; white-space: nowrap; box-shadow: inset 0 -1px 0 var(--line); color: var(--fg); }
.ag-table th .th { display: inline-flex; align-items: center; gap: 4px; }
.ag-table th .th button { border: 0; background: none; padding: 0; color: var(--fg3); display: inline-flex; }
.ag-table td { padding: 8px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
.ag-table tbody tr:last-child td { border-bottom: 0; }
.ag-table tbody tr:hover td { background: var(--bg3); }
.ag-table td.s1, .ag-table th.s1 { position: sticky; left: 0; z-index: 2; background: var(--bg2); text-align: center; min-width: 72px; }
.ag-table td.s2, .ag-table th.s2 { position: sticky; left: 72px; z-index: 2; background: var(--bg2); min-width: 240px; box-shadow: inset 1px 0 0 var(--line); }
.ag-table th.s1, .ag-table th.s2 { z-index: 4; }
.ag-table tbody tr:hover td.s1, .ag-table tbody tr:hover td.s2 { background: var(--bg3); }
.ag-rank { display: flex; flex-direction: column; align-items: center; line-height: 1.25; }
.ag-rank small { color: var(--fg3); font-size: 12px; display: flex; gap: 4px; }
.ag-mcell { display: flex; align-items: center; gap: 10px; min-height: 36px; }
.ag-logo { width: 24px; height: 24px; border-radius: 50%; background: var(--bg3); display: grid; place-items: center; font-size: 12px; color: var(--fg2); flex: none; }
.ag-mname { font: 14px var(--mono); }
.ag-mlab { font-size: 12px; color: var(--fg2); }
.ag-net { display: flex; align-items: center; gap: 12px; min-width: 210px; }
.ag-net .v { width: 80px; flex: none; display: flex; flex-direction: column; align-items: flex-end; font-variant-numeric: tabular-nums; }
.ag-net svg { flex: 1; min-width: 80px; height: 16px; display: block; }
.ag-val { display: inline-flex; flex-direction: column; align-items: center; font-variant-numeric: tabular-nums; }
.ag-val b { font-weight: 400; display: inline-flex; align-items: center; gap: 2px; }
.ag-val small, .ag-net small { color: var(--fg3); font-size: 12px; }
.pos { color: var(--good); }
.neg { color: var(--danger); }
.ag-na { color: var(--fg3); }
.ag-pareto { border: 1px solid var(--line); border-radius: 10px; background: var(--bg2); padding: 12px; }
.ag-pareto svg { width: 100%; height: auto; display: block; }
.ag-pareto text { fill: var(--fg2); font-size: 11px; }
.ag-tip { position: fixed; z-index: 80; max-width: 320px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 10px 12px; font-size: 13px; line-height: 1.45; color: var(--fg2); }
.ag-lb-loading, .ag-lb-empty { padding: 36px 16px; text-align: center; color: var(--fg2); }

@media (max-width: 1100px) {
  .ag-side { position: absolute; right: 0; top: 0; bottom: 0; z-index: 15; width: min(340px, 92vw); box-shadow: var(--shadow); }
  .ag-session:not(.sideopen) .ag-side { display: none; }
}
@media (max-width: 860px) {
  .ag-user { max-width: 88%; }
  .ag-home { justify-content: flex-start; padding-top: 12vh; }
  .ag-table td.s2, .ag-table th.s2 { left: 56px; min-width: 190px; }
  .ag-table td.s1, .ag-table th.s1 { min-width: 56px; }
  .ag-strip input { width: 140px; }
}
.ag-creator { color: var(--fg3); font-size: 12.5px; margin-bottom: 2px; }
.ag-creator b { color: var(--fg2); font-weight: 600; }

/* Direct agent: model choice next to the mode picker, name chip in the session header */
.ag-model-pick { padding: 0; flex: 0 1 230px; min-width: 0; flex-wrap: nowrap; }
.ag-model-pick .model-select { padding: 5px 8px; font-size: 13px; }
.ag-top .ag-direct { background: var(--bg3); color: var(--fg2); border-radius: 6px; padding: 2px 8px; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45%; }
