/* Mission Control - Agents V1 concept. Light mode only. */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e4e7ec;
  --border-strong: #cfd4dc;
  --text: #101828;
  --muted: #566074;
  --accent: #2459d6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-hover: 0 8px 22px rgba(16, 24, 40, 0.08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; color-scheme: light; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p, ul, ol, dl, dd, blockquote { margin: 0; }
ul, ol { padding: 0; list-style: none; }
a { color: inherit; text-decoration: none; }
button, select { font: inherit; color: inherit; }
img { max-width: 100%; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip {
  position: absolute; left: 8px; top: -60px; z-index: 100; background: #fff; padding: 10px 14px;
  border: 1px solid var(--border-strong); border-radius: 8px;
}
.skip:focus { top: 8px; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
#view:focus, h1:focus, h2:focus { outline: none; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh; background: var(--surface);
  border-right: 1px solid var(--border); padding: 22px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; }
.brand__mark { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, #2459d6, #5b8def); }
.brand__name { font-weight: 700; letter-spacing: -0.01em; }
.nav { display: grid; gap: 4px; }
.nav__item {
  display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 8px 12px;
  border-radius: 10px; color: var(--muted); font-weight: 600; transition: background 0.15s ease, color 0.15s ease;
}
.nav__item svg { flex: none; }
.nav__item[href]:hover { background: #f2f4f7; color: var(--text); }
.nav__item[aria-current="page"] { background: #eaf0ff; color: var(--accent); }
.nav__item.is-disabled { color: #98a2b3; cursor: not-allowed; }
.soon {
  margin-left: auto; font-size: 12px; font-weight: 600; color: #667085; background: #f2f4f7;
  border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; white-space: nowrap;
}

.main { min-width: 0; padding: 0 32px 56px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 18px 0 8px; max-width: 1480px;
}
.simchip { font-size: 13px; color: var(--muted); }
.simchip #source-label {
  display: inline-block; font-weight: 700; letter-spacing: 0.04em; color: #7a2e0e; background: #fef0c7;
  border: 1px solid #fedf89; border-radius: 6px; padding: 1px 8px;
}
.clock { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.clock--fake { color: #7a2e0e; font-weight: 600; }

.page { max-width: 1480px; padding-top: 8px; }
.page-head { margin: 8px 0 24px; }
.page-head h1, .detail__name, .taskdetail__title { font-size: 28px; line-height: 1.2; letter-spacing: -0.02em; }
.page-sub { margin-top: 6px; color: var(--muted); max-width: 70ch; }

/* ---------- Agent cards ---------- */
.cards {
  display: grid; gap: 20px;
  grid-template-columns: repeat(auto-fill, minmax(min(310px, 100%), 1fr));
}
.card-item { min-width: 0; }
.agent-card {
  position: relative;
  display: flex; flex-direction: column; gap: 16px; height: 100%; padding: 20px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
@media (hover: hover) {
  .agent-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); border-color: var(--border-strong); }
}
/* card link stretches over the whole card; count badge links sit above it (siblings, not nested) */
.agent-card__link { display: block; color: inherit; text-decoration: none; }
.agent-card__link::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
.agent-card__link:focus-visible { outline: none; }
.agent-card__link:focus-visible::after { outline: 3px solid #2e90fa; outline-offset: 2px; }
.counts__item { list-style: none; display: flex; position: relative; z-index: 1; }
.count { text-decoration: none; min-height: 32px; }
.count:focus-visible { outline: 3px solid #2e90fa; outline-offset: 2px; }
@media (hover: hover) { .count:hover { box-shadow: var(--shadow-hover); } }
@media (pointer: coarse) { .count { min-height: 44px; } }
.card__head { display: flex; align-items: center; gap: 14px; min-width: 0; }
.card__ident { min-width: 0; }
.card__name { font-size: 18px; line-height: 1.25; font-weight: 700; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.card__role { color: var(--muted); font-size: 14px; }

.avatar {
  flex: none; border-radius: 50%; object-fit: cover; background: #eef0f3;
  border: 1px solid var(--border);
}
.avatar--md { width: 96px; height: 96px; }
.avatar--lg { width: 120px; height: 120px; }
/* name with the status chip + dot always directly beside it: the chip never wraps below;
   when space is tight the full name wraps onto more lines inside its own box instead */
.namerow { display: flex; flex-wrap: nowrap; align-items: center; gap: 10px; min-width: 0; }
.namerow > :first-child { flex: 0 1 auto; min-width: 0; overflow-wrap: anywhere; }
.namerow .status { align-self: center; flex: none; white-space: nowrap; }
.detail__ident .namerow { gap: 12px; }

.model { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 4px; font-size: 13px; color: var(--muted); }
.model__k { color: var(--muted); }
.model__v { color: var(--text); font-weight: 600; }
.tag {
  font-size: 11px; font-weight: 700; letter-spacing: 0.05em; color: #7a2e0e; background: #fef0c7;
  border: 1px solid #fedf89; border-radius: 4px; padding: 0 5px; line-height: 16px;
}

/* status: small box, dot at the left, text label */
.status {
  align-self: flex-start; display: inline-flex; align-items: center; gap: 8px; padding: 5px 12px;
  border-radius: 8px; border: 1px solid transparent; font-size: 13px; font-weight: 600; line-height: 20px;
  transition: background 0.25s ease, color 0.25s ease, border-color 0.25s ease;
}
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: currentColor; }
.status--active { background: #ecfdf3; color: #067647; border-color: #abefc6; }
.status--active .dot { background: #12b76a; animation: pulse 2.6s ease-in-out infinite; }
.status--idle { background: #fff4e5; color: #b54708; border-color: #fedf89; }
.status--idle .dot { background: #f79009; }
.status--offline { background: #eceff3; color: #344054; border-color: #d0d5dd; }
.status--offline .dot { background: #475467; }
.status--error { background: #fef3f2; color: #b42318; border-color: #fecdca; }
.status--error .dot { background: #f04438; }

/* the four count badges */
/* compact chips, same scale as the status chip (13px / 20px line / 8px radius) */
.counts { display: flex; flex-wrap: wrap; gap: 6px; }
.count {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 8px; min-width: 0;
}
.count__n { font-size: 13px; line-height: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.count__l { font-size: 13px; font-weight: 600; line-height: 20px; }
.count--working, .groupnav__btn--working { background: #dcfae6; color: #085d3a; }
.count--queued, .groupnav__btn--queued { background: #fee4e2; color: #912018; }
.count--waiting, .groupnav__btn--waiting { background: #fef0c7; color: #7a2e0e; }
.count--completed, .groupnav__btn--completed { background: #d1e9ff; color: #194185; }

/* ---------- Agent detail ---------- */
.back {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px 0 12px; margin: 4px 0 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; font-weight: 600;
  transition: background 0.15s ease, border-color 0.15s ease;
}
@media (hover: hover) { .back:hover { background: #f2f4f7; border-color: var(--border-strong); } }

.detail__head { display: flex; align-items: center; gap: 18px; margin-bottom: 20px; min-width: 0; }
.detail__ident { display: grid; gap: 4px; justify-items: start; min-width: 0; }
.detail__name { overflow-wrap: anywhere; }
.detail__role { color: var(--muted); }

.groupnav {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px;
  position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 8px 0 12px;
}
.groupnav__btn {
  display: flex; flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: flex-start; gap: 2px 6px; min-height: 44px; padding: 6px 10px;
  border: 1px solid rgba(16, 24, 40, 0.06); border-radius: 10px; cursor: pointer; text-align: left;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
@media (hover: hover) { .groupnav__btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-hover); } }

.group { margin-top: 26px; scroll-margin-top: 84px; }
.group__title { font-size: 19px; display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.group--working .group__title { border-left: 4px solid #12b76a; padding-left: 10px; }
.group--queued .group__title { border-left: 4px solid #f04438; padding-left: 10px; }
.group--waiting .group__title { border-left: 4px solid #eaaa08; padding-left: 10px; }
.group--completed .group__title { border-left: 4px solid #2e90fa; padding-left: 10px; }
.group__count {
  font-size: 13px; font-weight: 700; background: #eef0f3; border-radius: 999px; padding: 0 9px; min-width: 24px;
  text-align: center; line-height: 22px; color: var(--muted);
}
.empty { color: var(--muted); font-size: 14px; padding: 4px 2px; }
.tasks:not(:empty) + .empty { display: none; }

.tasks { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(430px, 100%), 1fr)); }
.task-item { min-width: 0; }
.task {
  display: block; height: 100%; padding: 16px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); min-height: 44px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
@media (hover: hover) { .task:hover { border-color: var(--border-strong); box-shadow: var(--shadow-hover); } }
.task__top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.task__title { font-size: 16px; line-height: 1.3; font-weight: 700; overflow-wrap: anywhere; min-width: 0; }
.task__meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.task__id { font: 12.5px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); }
.task__chip { font-size: 12.5px; font-weight: 600; color: #3730a3; background: #eef2ff; border-radius: 999px; padding: 0 9px; }
.task__line { font-size: 14px; overflow-wrap: anywhere; }
.task__waiting { color: #7a2e0e; font-weight: 600; }
.lbl { color: var(--muted); font-weight: 600; }
.task__waiting .lbl { color: #7a2e0e; }
.times {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 6px 14px;
  margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border);
}
.times__row { min-width: 0; }
.times dt { font-size: 12px; font-weight: 600; color: var(--muted); }
.times dd { font-size: 13px; font-variant-numeric: tabular-nums; }

.history { margin-top: 30px; }
.history summary {
  display: flex; align-items: center; gap: 8px; min-height: 44px; cursor: pointer; font-weight: 600; color: var(--muted);
}
.history .tasks { margin-top: 10px; }

/* ---------- Task detail ---------- */
.taskdetail { display: grid; gap: 16px; margin-top: 16px; max-width: 980px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.panel__title { font-size: 15px; margin-bottom: 12px; }
.kv { display: grid; gap: 10px; }
.kv__row { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 12px; align-items: baseline; }
.kv dt { color: var(--muted); font-size: 14px; font-weight: 600; }
.kv dd { overflow-wrap: anywhere; }
.chip { display: inline-block; font-size: 13px; font-weight: 700; border-radius: 999px; padding: 1px 10px; }
.chip--working { background: #dcfae6; color: #085d3a; }
.chip--queued { background: #fee4e2; color: #912018; }
.chip--waiting { background: #fef0c7; color: #7a2e0e; }
.chip--completed { background: #d1e9ff; color: #194185; }
.sub { font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
.sub:first-child { margin-top: 0; }
.linklist { display: grid; gap: 8px; }
.link-task {
  display: flex; align-items: center; gap: 4px 12px; flex-wrap: wrap; min-height: 44px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: #fcfcfd;
}
@media (hover: hover) { .link-task:hover { border-color: var(--border-strong); background: #f6f7f9; } }
.link-task__id { font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); }
.link-task__title { font-weight: 600; overflow-wrap: anywhere; min-width: 0; }
.link-task__agent { color: var(--muted); font-size: 14px; margin-left: auto; }
.quote { border-left: 3px solid var(--border-strong); padding: 4px 0 4px 14px; color: #344054; overflow-wrap: anywhere; }
.timeline { display: grid; gap: 12px; }
.timeline__item { display: grid; gap: 2px; padding-left: 14px; border-left: 2px solid var(--border); }
.timeline__time { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.timeline__change { font-weight: 600; }
.timeline__note { font-size: 14px; color: #344054; overflow-wrap: anywhere; }

/* ---------- Mobile bottom navigation ---------- */
.bottomnav {
  display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: rgba(255, 255, 255, 0.97); border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}
.bn__item {
  flex: 1; min-width: 0; min-height: 60px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px; color: var(--muted); font-size: 12px; font-weight: 600; padding: 6px 4px;
}
.bn__item[aria-current="page"] { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }
.bn__item.is-disabled { color: #98a2b3; }
.bn__soon { font-size: 12px; font-weight: 500; color: #667085; }

/* ---------- DEMO controls (separate from the owner UI) ---------- */
.demo-fab {
  position: fixed; right: 16px; bottom: 16px; z-index: 45; min-height: 44px; padding: 0 18px;
  border: 0; border-radius: 999px; background: #101828; color: #fff; font-size: 13px; font-weight: 700;
  letter-spacing: 0.02em; cursor: pointer; box-shadow: 0 6px 18px rgba(16, 24, 40, 0.25);
}
.demo {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 60; width: min(420px, 100vw);
  display: flex; flex-direction: column; background: #fff; border-left: 1px solid var(--border-strong);
  box-shadow: -12px 0 32px rgba(16, 24, 40, 0.12); animation: slide-in 0.22s ease-out;
}
.demo__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.demo__title { font-size: 17px; }
.demo__sub { font-size: 12px; font-weight: 700; letter-spacing: 0.05em; color: #7a2e0e; }
.demo__close { flex: none; width: 44px; height: 44px; border: 1px solid var(--border); border-radius: 10px; background: #fff; font-size: 24px; line-height: 1; cursor: pointer; }
.demo__body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 14px 16px 28px; display: grid; gap: 14px; align-content: start; }
.demo__warn { font-size: 13px; background: #fffaeb; border: 1px solid #fedf89; border-radius: 10px; padding: 10px 12px; color: #7a2e0e; }
.demo__sec { display: grid; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.demo__sec h3 { font-size: 14px; }
.demo__approval { border: 2px dashed #b54708; border-radius: 12px; background: #fffaf0; padding: 12px; }
.tag--demo { font-size: 11px; }
.dlabel { font-size: 13px; font-weight: 600; color: var(--muted); }
.dnote { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.derror { font-size: 13px; font-weight: 600; color: #b42318; background: #fef3f2; border: 1px solid #fecdca; border-radius: 10px; padding: 8px 12px; }
.demo select {
  width: 100%; min-height: 44px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: 10px; background: #fff;
}
.drow { display: flex; gap: 8px; }
.drow--wrap { flex-wrap: wrap; }
.dbtn {
  flex: 1 1 auto; min-height: 44px; padding: 8px 14px; border: 1px solid var(--border-strong); border-radius: 10px;
  background: #fff; font-size: 14px; font-weight: 600; cursor: pointer; text-align: center;
}
.dbtn--primary { background: #101828; color: #fff; border-color: #101828; }
.dbtn[aria-pressed="true"] { background: #eaf0ff; border-color: var(--accent); color: var(--accent); }
.dbtn:disabled { opacity: 0.45; cursor: not-allowed; }
.dbtn-col { display: grid; gap: 8px; }
.dbtn-wrap { display: grid; gap: 2px; }
.dbtn-wrap .dbtn { width: 100%; }
.dphase { font-size: 14px; font-weight: 600; }
.dphase__k { color: var(--muted); font-weight: 600; }
.dsteps { display: grid; gap: 6px; }
.dstep { display: flex; gap: 8px; font-size: 13px; color: var(--muted); }
.dstep.is-current { color: var(--text); font-weight: 600; }
.dstep.is-done { color: #067647; }
.dstep__mark { width: 16px; flex: none; }
.dstep__txt { display: grid; gap: 2px; min-width: 0; overflow-wrap: anywhere; }
.dstep__expect { font-weight: 400; color: var(--muted); }
.dclock { font-size: 14px; font-variant-numeric: tabular-nums; font-weight: 600; }
.dhealth { display: grid; gap: 8px; }
.dhealth__row { display: grid; grid-template-columns: minmax(0, 1fr) 140px; gap: 8px; align-items: center; font-size: 14px; }
.dlog { display: grid; gap: 4px; font-size: 12.5px; color: #344054; }
.dlog li { overflow-wrap: anywhere; }
.dlog__t { font-variant-numeric: tabular-nums; color: var(--muted); }

/* ---------- Motion ---------- */
.enter { animation: enter 0.24s ease-out; }
.bump { animation: bump 0.45s ease; }
@keyframes enter { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes bump { 0% { transform: scale(1); } 35% { transform: scale(1.18); } 100% { transform: scale(1); } }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(18, 183, 106, 0.45); }
  70% { box-shadow: 0 0 0 7px rgba(18, 183, 106, 0); }
  100% { box-shadow: 0 0 0 0 rgba(18, 183, 106, 0); }
}
@keyframes slide-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important; animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important; scroll-behavior: auto !important;
  }
  .status--active .dot { animation: none; }
}

/* ---------- Narrow / iPhone ---------- */
@media (max-width: 899px) {
  .shell { display: block; }
  .sidebar { display: none; }
  .bottomnav { display: flex; }
  .main { padding: 0 16px calc(150px + var(--safe-bottom)); }
  .topbar { padding-top: max(14px, env(safe-area-inset-top, 0px)); }
  .page-head h1, .detail__name, .taskdetail__title { font-size: 24px; }
  .cards { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .tasks { grid-template-columns: minmax(0, 1fr); }
  .detail__head { gap: 14px; }
  .avatar--md { width: 88px; height: 88px; }
  .avatar--lg { width: 104px; height: 104px; }
  .groupnav { position: static; grid-template-columns: 1fr 1fr; padding: 4px 0 8px; }
  .group { scroll-margin-top: 12px; }
  .kv__row { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .demo-fab { bottom: calc(72px + var(--safe-bottom)); right: 12px; }
  .demo {
    top: auto; left: 0; right: 0; width: auto; max-height: 86vh; max-height: 86dvh;
    border-left: 0; border-top: 1px solid var(--border-strong); border-radius: 18px 18px 0 0;
    box-shadow: 0 -12px 32px rgba(16, 24, 40, 0.16); animation-name: sheet-in;
  }
  .dhealth__row { grid-template-columns: minmax(0, 1fr) 128px; }
}
@keyframes sheet-in { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
