:root {
  --bg: #0e1116;
  --grid: #1a1f27;
  --panel: #161b22;
  --panel-2: #1d232c;
  --line: #2a313c;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #4c8dff;
  --working: #3fb950;
  --needs: #f0883e;
  --done: #8b949e;
  --starting: #d29922;
  --exited: #f85149;
  --radius: 6px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { height: 100dvh; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); display: flex; flex-direction: column; overflow: hidden; }
h2 { font-size: 16px; margin: 0 0 12px; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 12px; cursor: pointer; white-space: nowrap; min-height: 32px; }
.btn:hover { border-color: #3a4350; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.icon { padding: 4px 10px; }
.btn.small { padding: 2px 8px; min-height: 28px; font-size: 13px; }
.btn[aria-pressed="true"] { border-color: var(--accent); }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; margin-top: 16px; }

.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.spaces { display: flex; gap: 4px; overflow-x: auto; min-width: 0; }
.space { background: none; border: 1px solid transparent; border-radius: var(--radius); padding: 5px 10px; cursor: pointer; color: var(--muted); white-space: nowrap; }
.space.active { color: var(--text); border-color: var(--line); background: var(--panel-2); }
.space .count { font-size: 12px; margin-left: 6px; color: var(--muted); }
.space .alert { color: var(--needs); margin-left: 4px; }
.space-tool { padding: 5px 6px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.zoom { display: flex; }
.zoom .btn { border-radius: 0; }
.zoom .btn:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.zoom .btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.zoom-value { min-width: 60px; }

.main { flex: 1; display: flex; min-height: 0; position: relative; }
.canvas { flex: 1; position: relative; overflow: hidden; cursor: grab; background-color: var(--bg);
  background-image: radial-gradient(var(--grid) 1px, transparent 1px); background-size: 24px 24px; }
.canvas.panning { cursor: grabbing; }
.world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }

.tile { position: absolute; display: flex; flex-direction: column; background: #0b0d11; border: 1px solid var(--line); border-radius: var(--radius); cursor: default; min-width: 360px; min-height: 200px; }
.tile.focused { border-color: var(--accent); }
.tile.status-needs { border-color: var(--needs); box-shadow: 0 0 0 1px var(--needs); }
.tile[hidden] { display: none; }
.tile-head { display: flex; align-items: center; gap: 8px; padding: 4px 6px 4px 10px; background: var(--panel); border-bottom: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0; cursor: move; user-select: none; }
.tile-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-meta { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.tile-tools { display: flex; gap: 2px; }
.tool { background: none; border: 0; color: var(--muted); padding: 4px 8px; border-radius: 4px; cursor: pointer; font-size: 12px; }
.tool:hover { background: var(--panel-2); color: var(--text); }
.tool.has { color: var(--accent); }
.tile-body { flex: 1; min-height: 0; padding: 4px 0 0 6px; }
.tile-body .xterm { height: 100%; }
.resize { position: absolute; right: 0; bottom: 0; width: 16px; height: 16px; cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 50%, var(--line) 50%); border-radius: 0 0 var(--radius) 0; }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--done); flex: none; }
.dot.working { background: var(--working); animation: pulse 1.4s ease-in-out infinite; }
.dot.needs { background: var(--needs); }
.dot.starting { background: var(--starting); }
.dot.exited { background: var(--exited); }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .dot.working { animation: none; } }

.map { width: 260px; flex: none; border-left: 1px solid var(--line); background: var(--panel); padding: 12px; overflow-y: auto; }
.map[hidden] { display: none; }
.legend { display: flex; gap: 10px; color: var(--muted); font-size: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
#map-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.map-item { display: grid; grid-template-columns: 8px 1fr; gap: 2px 8px; align-items: center; width: 100%; text-align: left; background: none; border: 1px solid transparent; border-radius: var(--radius); padding: 6px 8px; cursor: pointer; }
.map-item:hover { background: var(--panel-2); }
.map-item.needs { border-color: var(--needs); }
.map-item .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.map-item .sub { grid-column: 2; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.map-group { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; margin: 10px 0 2px; }

.empty { position: absolute; inset: 0; margin: auto; width: min(420px, calc(100% - 32px)); height: fit-content; padding: 24px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.empty p { color: var(--muted); margin: 0 0 16px; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; width: min(440px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .55); }
.form.wide { width: auto; }
dialog:has(.wide) { width: min(640px, calc(100vw - 32px)); }
.form label { display: grid; gap: 4px; margin-bottom: 12px; color: var(--muted); font-size: 13px; }
.form input, .form select, .form textarea { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 7px 9px; color: var(--text); width: 100%; }
.form textarea { resize: vertical; }
.form [hidden] { display: none; }
.form fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin: 12px 0 0; }
.form legend { color: var(--muted); padding: 0 4px; }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.team-row { display: grid; grid-template-columns: 160px 1fr 32px; gap: 8px; margin-bottom: 8px; align-items: start; }
.loops { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.loops li { display: flex; gap: 8px; align-items: center; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; }
.loops li .what { flex: 1; min-width: 0; }
.loops li .what small { display: block; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.loops .none { color: var(--muted); justify-content: center; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 10; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--panel-2); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: var(--radius); padding: 10px 12px; }
.offline { position: fixed; left: 50%; top: 56px; transform: translateX(-50%); background: var(--exited); color: #fff; padding: 6px 12px; border-radius: var(--radius); z-index: 10; }

.agent-tabs, .composer { display: none; }

/* Phone: one agent fills the screen, tabs switch between them, keys + a message box replace the keyboard shortcuts. */
@media (max-width: 760px) {
  .map { position: absolute; right: 0; top: 0; bottom: 0; z-index: 5; width: min(300px, 85vw); }
  .team-row { grid-template-columns: 1fr; }
  .bar { padding: 6px 8px; gap: 6px; flex-wrap: nowrap; }
  .spaces { flex: 1; }
  .actions { flex-wrap: nowrap; gap: 6px; }
  .zoom, #btn-team { display: none; }
  .btn, .space { min-height: 44px; }
  .main { flex-direction: column; }
  .agent-tabs { display: flex; gap: 4px; overflow-x: auto; padding: 6px 8px; border-bottom: 1px solid var(--line); background: var(--panel); flex: none; scrollbar-width: none; }
  .agent-tabs:empty { display: none; }
  .agent-tab { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 20px; background: none; color: var(--muted); white-space: nowrap; max-width: 60vw; flex: none; cursor: pointer; }
  .agent-tab span { overflow: hidden; text-overflow: ellipsis; }
  .agent-tab.active { color: var(--text); border-color: var(--accent); background: var(--panel-2); }
  .canvas { background-image: none; cursor: default; }
  .world { inset: 0; transform: none !important; }
  .tile { left: 0 !important; top: 0 !important; width: 100% !important; height: 100% !important; min-width: 0; min-height: 0; border: 0; border-radius: 0; }
  .tile.status-needs { box-shadow: inset 0 2px 0 var(--needs); }
  .tile-head { cursor: default; border-radius: 0; padding: 0 2px 0 10px; }
  .tile-name { display: none; } /* the tab above already names it */
  .tool { min-height: 40px; padding: 4px 8px; font-size: 13px; }
  .resize { display: none; }
  .tile-body { padding: 2px 0 0 4px; }
  .composer { display: grid; gap: 6px; padding: 6px 8px max(8px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--panel); flex: none; }
  .keys { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
  .key { flex: 1 0 auto; min-width: 40px; min-height: 40px; padding: 0 6px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); font-size: 14px; cursor: pointer; }
  .key:active { border-color: var(--accent); }
  .compose-row { display: flex; gap: 6px; align-items: flex-end; }
  #compose-text { flex: 1; min-width: 0; resize: none; font-size: 16px; /* under 16px iOS zooms in on focus */ background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); padding: 9px 10px; max-height: 120px; }
  #compose-send { min-height: 44px; }
  .empty { position: absolute; }
  .toasts { top: 112px; bottom: auto; left: 8px; right: 8px; max-width: none; }
}
