/* Bản đồ Agent: bảng tổng quan project + agent (tông tối, không cần kéo/zoom). */
.agent-map-dialog {
  width: min(1180px, 97vw); height: min(88vh, 880px); max-width: none; max-height: none; padding: 0; overflow: hidden;
  border-radius: 16px; background: var(--bg); position: relative;
}
.agent-map-dialog[open] { display: flex; flex-direction: column; }
/* Dạng trang trên điện thoại: nằm trên nội dung nhưng chừa footer để chuyển tab. */
.agent-map-dialog.is-inline {
  position: fixed; inset: 0 0 calc(60px + env(safe-area-inset-bottom)) 0; z-index: 31; margin: 0; width: 100%; height: auto;
  border: 0; border-radius: 0; padding-top: env(safe-area-inset-top);
}
.agent-map-dialog.is-inline .am-close { display: none; }

.am-head { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px 6px; }
.am-title { min-width: 0; }
.am-title h2 { margin: 0; font-size: 19px; }
.am-title p { margin: 2px 0 0; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.am-head-actions { display: flex; gap: 6px; flex-shrink: 0; }
.am-head-actions .btn { width: 40px; height: 40px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }

.am-stats { flex: none; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 6px 16px; }
.am-stats button {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px; padding: 8px 12px; border-radius: 12px; cursor: pointer;
  background: var(--panel); border: 1px solid var(--border); color: var(--muted); font: inherit; font-size: 12px; text-align: left; min-height: 56px;
}
.am-stats b { font-size: 22px; line-height: 1.1; color: var(--text); font-variant-numeric: tabular-nums; }
.am-stats button[aria-pressed='true'] { border-color: var(--accent); background: #1b2a47; color: var(--text); }
.am-stats .is-running b { color: #7fb0ff; } .am-stats .is-waiting b { color: var(--warn); } .am-stats .is-ready b { color: var(--codex); }
.am-searchbar { flex: none; display: flex; gap: 6px; align-items: center; padding: 6px 16px 8px; }
.am-searchbar input { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel); color: var(--text); font: inherit; font-size: 14px; }

.am-body { flex: 1; min-height: 0; display: flex; position: relative; }
.am-board { flex: 1; min-width: 0; overflow-y: auto; padding: 4px 16px 16px; overscroll-behavior: contain; }
.am-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; align-items: start; }
.am-project { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 10px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.am-project.needs-attention { border-color: rgba(227, 179, 65, 0.6); }
.am-project-head { display: flex; align-items: center; gap: 10px; }
.am-project-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; background: var(--panel-2); color: var(--accent); font-size: 17px; flex: none; }
.am-project-name { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.am-project-name strong { font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.am-project-name small { font-size: 11.5px; color: var(--muted); }
.am-add { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel-2); color: var(--text); font-size: 18px; cursor: pointer; flex: none; }
.am-add:hover { border-color: var(--accent); }
.am-agents { display: flex; flex-direction: column; gap: 6px; }
.am-agent {
  display: flex; gap: 10px; align-items: center; text-align: left; width: 100%; padding: 8px 10px; border-radius: 12px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--border); border-left: 4px solid #4a5368; color: var(--text); font: inherit;
}
.am-agent:hover { border-color: #3b4660; }
.am-agent.is-selected { border-color: var(--accent); background: #1b2a47; }
.am-agent.is-running, .am-agent.is-queued { border-left-color: var(--accent); }
.am-agent.is-waiting { border-left-color: var(--warn); }
.am-agent.is-error { border-left-color: var(--danger); }
.am-agent.is-done { border-left-color: var(--codex); }
.am-fig { width: 44px; height: 54px; flex: none; display: grid; place-items: center; }
.am-fig .agent-minifigure { width: 100%; height: 100%; }
.am-fig-sm { width: 32px; height: 40px; }
.am-fig-lg { width: 84px; height: 108px; }
.am-agent-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.am-agent-top { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.am-agent-top strong { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.am-agent-task { font-size: 12.5px; color: #c7d0e0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.am-agent-meta { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.am-chip { flex: none; font-style: normal; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: #2a3142; color: var(--muted); }
.am-chip.is-running, .am-chip.is-queued { background: rgba(79, 140, 255, 0.22); color: #9ec0ff; }
.am-chip.is-waiting { background: rgba(227, 179, 65, 0.22); color: var(--warn); }
.am-chip.is-error { background: rgba(229, 83, 83, 0.22); color: #ff9b9b; }
.am-chip.is-ready, .am-chip.is-done { background: rgba(63, 185, 80, 0.2); color: #7ee08c; }
.am-empty { margin: 2px 4px; font-size: 12.5px; color: var(--muted); }
.am-more { align-self: flex-start; background: transparent; border: 0; color: var(--accent); font: inherit; font-size: 12.5px; padding: 8px 4px; cursor: pointer; min-height: 36px; }
.am-lounge { grid-column: 1 / -1; }
.am-idles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; }
.am-idles .am-empty, .am-idles .am-more { grid-column: 1 / -1; }
.am-idle { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--border); color: var(--text); font: inherit; cursor: pointer; text-align: left; min-width: 0; }
.am-idle strong { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.am-idle.is-selected { border-color: var(--accent); }
.am-idle.is-offline, .am-idle.is-unknown { opacity: 0.6; }
.am-first { padding: 28px 16px; text-align: center; color: var(--muted); }
.am-first strong { color: var(--text); font-size: 16px; }

/* Chi tiết: cột phải trên máy tính, tấm trượt từ dưới trên điện thoại */
.am-detail { width: 340px; flex: none; overflow-y: auto; padding: 16px; border-left: 1px solid var(--border); background: var(--panel); position: relative; }
.am-detail[hidden] { display: none; }
.am-detail-close { position: absolute; top: 8px; right: 8px; width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel-2); color: var(--text); cursor: pointer; }
.am-detail h3 { margin: 0 0 6px; font-size: 17px; overflow-wrap: anywhere; }
.am-detail h4 { margin: 16px 0 6px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.am-kicker { font-size: 11px; letter-spacing: 0.08em; color: var(--accent); }
.am-profile { display: flex; align-items: center; gap: 12px; margin: 8px 28px 10px 0; }
.am-facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 12px; margin: 0 0 12px; font-size: 13px; }
.am-facts dt { color: var(--muted); } .am-facts dd { margin: 0; overflow-wrap: anywhere; }
.am-note { font-size: 12px; color: var(--muted); line-height: 1.5; }
.am-primary, .am-secondary { width: 100%; min-height: 44px; margin-top: 6px; display: inline-flex; align-items: center; justify-content: center; }
.am-row { width: 100%; display: flex; gap: 10px; align-items: center; text-align: left; padding: 9px 10px; margin-top: 6px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel-2); color: var(--text); font: inherit; cursor: pointer; min-height: 44px; }
.am-row small { display: block; color: var(--muted); font-size: 11.5px; }
.am-dot { width: 9px; height: 9px; border-radius: 50%; background: #4a5368; flex: none; }
.am-row.is-running .am-dot, .am-row.is-queued .am-dot { background: var(--accent); }
.am-row.is-waiting .am-dot { background: var(--warn); } .am-row.is-error .am-dot { background: var(--danger); }
.am-history { display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left; padding: 8px 10px; margin-top: 6px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel-2); color: var(--text); font: inherit; cursor: pointer; }
.am-history span { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.am-foot { flex: none; padding: 6px 16px 10px; font-size: 11.5px; color: var(--muted); border-top: 1px solid var(--border); }

.is-running .minifigure-body { animation: am-working 2s ease-in-out infinite; transform-origin: 50px 120px; }
@keyframes am-working { 50% { transform: rotate(-3deg) translateY(-2px); } }
@media (prefers-reduced-motion: reduce) { .is-running .minifigure-body { animation: none; } }

@media (max-width: 1000px) {
  .am-detail { position: absolute; left: 0; right: 0; bottom: 0; width: auto; max-height: 62%; border: 1px solid var(--border); border-bottom: 0; border-radius: 18px 18px 0 0; box-shadow: 0 -12px 32px #000a; z-index: 3; }
}
@media (max-width: 820px), (pointer: coarse) and (max-height: 550px) {
  .agent-map-dialog:not(.is-inline) { width: 100vw; height: 100dvh; border-radius: 0; }
  .am-head { padding: 10px 12px 4px; }
  .am-stats { padding: 6px 12px; gap: 6px; }
  .am-stats button { padding: 6px 8px; min-height: 52px; }
  .am-stats b { font-size: 19px; }
  .am-searchbar { padding: 4px 12px 6px; }
  .am-searchbar input { font-size: 16px; }
  .am-board { padding: 2px 12px 16px; }
  .am-grid { grid-template-columns: 1fr; }
  .am-add { width: 44px; height: 44px; }
  .am-agent { min-height: 64px; }
}
