/* iVega Agent Operations — design system.
 *
 * Written mobile-first: the base rules describe the phone, and the media
 * queries progressively add space rather than trying to squeeze a desktop
 * layout down. Navigation genuinely changes shape (bottom tab bar on a phone,
 * a persistent sidebar from 880px), because a shrunk sidebar is not a mobile
 * interface.
 *
 * The visual language is deliberately quiet. Colour is reserved almost
 * entirely for agent status, so that a red or amber badge is the only thing
 * competing for attention on a screen the operator may be scanning in seconds.
 */

/* ── Tokens ──────────────────────────────────────────────────────────────── */
:root {
  --bg:            #0d1117;
  --surface:       #151b23;
  --surface-2:     #1c232c;
  --surface-3:     #232b36;
  --border:        #2a323d;
  --border-strong: #3d4654;

  --text:      #e6edf3;
  --text-dim:  #9aa7b4;
  --text-mute: #6e7d8c;

  --accent:      #4a9eff;
  --accent-dim:  #1f6feb;
  --accent-soft: rgba(74, 158, 255, 0.12);

  --ok:      #3fb950;
  --warn:    #d29922;
  --danger:  #f85149;
  --info:    #39c5cf;
  --think:   #a371f7;

  --status-WORKING:   #3fb950;
  --status-THINKING:  #a371f7;
  --status-IDLE:      #7d8b99;
  --status-BLOCKED:   #d29922;
  --status-FAILED:    #f85149;
  --status-DEAD:      #b62324;
  --status-REVIEW:    #39c5cf;
  --status-COMPLETED: #2ea043;
  --status-UNKNOWN:   #6e7d8c;

  --radius:    10px;
  --radius-sm: 7px;
  --radius-lg: 14px;

  --shadow:    0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.25);
  --shadow-lg: 0 8px 40px rgba(0,0,0,.55);

  --sidebar-w: 236px;
  --topbar-h:  56px;
  --tabbar-h:  60px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top:    env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg:            #f4f6f8;
    --surface:       #ffffff;
    --surface-2:     #f7f9fb;
    --surface-3:     #eef1f5;
    --border:        #dde3ea;
    --border-strong: #c4cdd8;

    --text:      #1b2530;
    --text-dim:  #556270;
    --text-mute: #7a8794;

    --accent:      #0b64d6;
    --accent-dim:  #0a58bd;
    --accent-soft: rgba(11, 100, 214, 0.09);

    --ok:     #1a7f37;
    --warn:   #9a6700;
    --danger: #cf222e;
    --info:   #0f7c8a;
    --think:  #7c3aed;

    --status-WORKING:   #1a7f37;
    --status-THINKING:  #7c3aed;
    --status-IDLE:      #6b7885;
    --status-BLOCKED:   #9a6700;
    --status-FAILED:    #cf222e;
    --status-DEAD:      #a40e26;
    --status-REVIEW:    #0f7c8a;
    --status-COMPLETED: #1a7f37;
    --status-UNKNOWN:   #7a8794;

    --shadow:    0 1px 2px rgba(16,24,40,.06), 0 4px 14px rgba(16,24,40,.06);
    --shadow-lg: 0 12px 40px rgba(16,24,40,.16);
  }
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  /* 16px base on phones: never require pinch-zoom to read a status. */
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

body { overflow-x: hidden; }

h1, h2, h3, h4 { margin: 0; font-weight: 650; line-height: 1.25; letter-spacing: -0.01em; }
p { margin: 0; }
button { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

::selection { background: var(--accent-soft); }

/* ── Boot ────────────────────────────────────────────────────────────────── */
.boot {
  position: fixed; inset: 0; z-index: 200;
  display: grid; place-content: center; justify-items: center; gap: 16px;
  background: var(--bg); color: var(--text-dim);
}
.boot__spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Login ───────────────────────────────────────────────────────────────── */
.login {
  min-height: 100dvh;
  display: grid; place-items: center;
  padding: 24px 20px calc(24px + var(--safe-bottom));
  background:
    radial-gradient(1000px 500px at 50% -10%, rgba(74,158,255,.10), transparent 70%),
    var(--bg);
}
.login__card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  box-shadow: var(--shadow-lg);
  display: grid; gap: 18px;
}
.login__brand { display: flex; align-items: center; gap: 13px; margin-bottom: 4px; }
.login__mark, .sidebar__mark {
  width: 34px; height: 34px; flex: none; border-radius: 9px;
  background: linear-gradient(140deg, var(--accent), var(--think));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.16);
}
.login__title { font-size: 1.06rem; }
.login__sub { font-size: .8rem; color: var(--text-mute); margin-top: 2px; }

.field { display: grid; gap: 6px; }
.field__label { font-size: .8rem; font-weight: 600; color: var(--text-dim); }
.field__input, .input, .textarea, .select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  /* 16px minimum stops iOS Safari zooming the page on focus. */
  font-size: 16px;
  padding: 11px 13px;
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}
.textarea { resize: vertical; min-height: 96px; line-height: 1.5; }
.field__input:focus, .input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.login__error {
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 42%, transparent);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 12px; font-size: .875rem;
}
.login__note { font-size: .79rem; color: var(--text-mute); text-align: center; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  /* 44px tall: a comfortable touch target on a phone. */
  min-height: 44px;
  padding: 0 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: .9rem; font-weight: 600;
  cursor: pointer;
  transition: background .14s, border-color .14s, opacity .14s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-3); border-color: var(--border-strong); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--primary { background: var(--accent-dim); border-color: var(--accent-dim); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); }
.btn--danger { background: transparent; border-color: color-mix(in srgb, var(--danger) 50%, transparent); color: var(--danger); }
.btn--danger:hover:not(:disabled) { background: color-mix(in srgb, var(--danger) 14%, transparent); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn--ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn--full { width: 100%; }
.btn--sm { min-height: 36px; padding: 0 11px; font-size: .82rem; }
.btn svg { width: 16px; height: 16px; }

/* ── App shell ───────────────────────────────────────────────────────────── */
.app { min-height: 100dvh; }

.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 60;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) 12px 0;
  display: flex; align-items: center; gap: 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar__title {
  font-size: 1.05rem; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar__back, .topbar__menu {
  width: 40px; height: 40px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface-2); cursor: pointer;
}
.topbar__menu { font-size: .8rem; font-weight: 700; letter-spacing: .02em; }
.topbar__back { border-color: transparent; background: transparent; }
.topbar__right { display: flex; align-items: center; gap: 8px; }

.conn { display: flex; align-items: center; gap: 7px; font-size: .8rem; color: var(--text-mute); }
.conn__dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-mute); flex: none;
  transition: background .3s;
}
.conn.is-live .conn__dot { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
.conn.is-lost .conn__dot { background: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 22%, transparent); }
.conn.is-wait .conn__dot { background: var(--warn); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.accountmenu {
  position: fixed; z-index: 80;
  top: calc(var(--topbar-h) + var(--safe-top) + 6px); right: 12px;
  width: 210px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.accountmenu__who { padding: 10px 12px; border-bottom: 1px solid var(--border); display: grid; gap: 2px; }
.accountmenu__who strong { font-size: .9rem; }
.accountmenu__who span { font-size: .79rem; color: var(--text-mute); text-transform: capitalize; }
.accountmenu__item {
  width: 100%; text-align: left; min-height: 42px; padding: 0 12px;
  background: none; border: 0; border-radius: var(--radius-sm);
  cursor: pointer; font-size: .88rem; color: var(--text);
}
.accountmenu__item:hover { background: var(--surface-2); }

.sidebar { display: none; }

.main {
  padding: calc(var(--topbar-h) + var(--safe-top) + 14px) 14px
           calc(var(--tabbar-h) + var(--safe-bottom) + 22px);
  max-width: 1600px; margin: 0 auto;
  outline: none;
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  border-top: 1px solid var(--border);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  background: none; border: 0; cursor: pointer;
  color: var(--text-mute); font-size: .75rem; font-weight: 600;
  position: relative; padding: 0 2px;
  -webkit-tap-highlight-color: transparent;
}
.tab svg { width: 21px; height: 21px; }
.tab.is-active { color: var(--accent); }
.tab__badge {
  position: absolute; top: 6px; left: 50%; margin-left: 6px;
  min-width: 19px; height: 19px; padding: 0 5px;
  border-radius: 10px; background: var(--danger); color: #fff;
  font-size: 12px; font-weight: 700;
  display: grid; place-items: center;
  border: 2px solid var(--bg);
}

/* ── Layout primitives ───────────────────────────────────────────────────── */
.stack  { display: grid; gap: 14px; }
.stack--lg { gap: 22px; }
.row    { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }

.section { display: grid; gap: 11px; }
.section__head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.section__title { font-size: .78rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--text-mute); }
.section__count { font-size: .78rem; color: var(--text-mute); }
.section__link {
  margin-left: auto; font-size: .82rem; color: var(--accent);
  background: none; border: 0; cursor: pointer;
  /* A real touch target; the visual weight stays the same. */
  min-height: 44px; padding: 0 6px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.grid { display: grid; gap: 12px; grid-template-columns: 1fr; }

/* ── Status vocabulary ───────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px;
  font-size: .7rem; font-weight: 700; letter-spacing: .045em;
  text-transform: uppercase; white-space: nowrap;
  background: color-mix(in srgb, var(--sc, var(--text-mute)) 16%, transparent);
  color: var(--sc, var(--text-mute));
  border: 1px solid color-mix(in srgb, var(--sc, var(--text-mute)) 34%, transparent);
}
.badge__dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge--live .badge__dot { animation: pulse 1.6s ease-in-out infinite; }

.s-WORKING   { --sc: var(--status-WORKING); }
.s-THINKING  { --sc: var(--status-THINKING); }
.s-IDLE      { --sc: var(--status-IDLE); }
.s-BLOCKED   { --sc: var(--status-BLOCKED); }
.s-FAILED    { --sc: var(--status-FAILED); }
.s-DEAD      { --sc: var(--status-DEAD); }
.s-REVIEW    { --sc: var(--status-REVIEW); }
.s-COMPLETED { --sc: var(--status-COMPLETED); }
.s-UNKNOWN   { --sc: var(--status-UNKNOWN); }

/* ── Overview counters ───────────────────────────────────────────────────── */
/* Three across on a phone. At two across the six status counters filled three
 * rows and pushed "Needs your attention" below the fold, which inverts the
 * priority this dashboard exists to express. */
.counters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.counter {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 10px;
  display: grid; gap: 2px; text-align: left;
  cursor: pointer; position: relative; overflow: hidden;
  border-left: 3px solid var(--sc, var(--border));
  min-height: 62px;
}
.counter:hover { background: var(--surface-2); }
.counter__n { font-size: 1.4rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; color: var(--sc, var(--text)); }
.counter__l { font-size: 12px; font-weight: 650; letter-spacing: .03em; text-transform: uppercase; color: var(--text-dim); }

.headline {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 18px;
  display: grid; gap: 4px;
}
.headline__n { font-size: 2.4rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.headline__l { font-size: .8rem; color: var(--text-dim); }
.headline__meta { font-size: .78rem; color: var(--text-mute); margin-top: 6px; }

/* ── Agent card ──────────────────────────────────────────────────────────── */
.agent {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--sc, var(--border));
  border-radius: var(--radius);
  padding: 13px 14px;
  display: grid; gap: 9px;
  cursor: pointer;
  transition: background .14s, border-color .14s;
  -webkit-tap-highlight-color: transparent;
}
.agent:hover { background: var(--surface-2); }
.agent--attention { border-color: color-mix(in srgb, var(--sc) 55%, var(--border)); }

.agent__top { display: flex; align-items: flex-start; gap: 10px; }
.agent__id { min-width: 0; flex: 1; display: grid; gap: 3px; }
.agent__name {
  font-size: 1rem; font-weight: 650;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.agent__where { font-size: .78rem; color: var(--text-mute); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.agent__provider { font-weight: 650; color: var(--text-dim); }
.agent__sep { opacity: .45; }

.agent__activity {
  font-size: .84rem; color: var(--text-dim); line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; word-break: break-word;
}
.agent__attention {
  font-size: .82rem; font-weight: 600; color: var(--sc);
  background: color-mix(in srgb, var(--sc) 11%, transparent);
  border-radius: var(--radius-sm); padding: 8px 10px;
  border: 1px solid color-mix(in srgb, var(--sc) 28%, transparent);
}
.agent__foot { display: flex; align-items: center; gap: 8px; font-size: .78rem; color: var(--text-mute); }
.agent__actions { display: flex; gap: 6px; margin-left: auto; }

.mono { font-family: var(--mono); font-size: .82em; }
.dim  { color: var(--text-mute); }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Project group ───────────────────────────────────────────────────────── */
.project { display: grid; gap: 11px; }
.project__head {
  display: flex; align-items: center; gap: 10px;
  padding-bottom: 9px; border-bottom: 1px solid var(--border);
  cursor: pointer; flex-wrap: wrap;
}
.project__name { font-size: .96rem; font-weight: 680; }
.project__pills { display: flex; gap: 5px; margin-left: auto; flex-wrap: wrap; }
.pill {
  font-size: .75rem; font-weight: 700; letter-spacing: .04em;
  padding: 2px 7px; border-radius: 999px;
  background: color-mix(in srgb, var(--sc, var(--text-mute)) 15%, transparent);
  color: var(--sc, var(--text-mute)); white-space: nowrap;
}
.project__chevron { transition: transform .18s; color: var(--text-mute); }
.project.is-collapsed .project__chevron { transform: rotate(-90deg); }
.project.is-collapsed .project__body { display: none; }

/* ── Filters ─────────────────────────────────────────────────────────────── */
.filters { display: grid; gap: 10px; }
.search {
  position: relative; display: flex; align-items: center;
}
.search svg { position: absolute; left: 12px; color: var(--text-mute); width: 17px; height: 17px; pointer-events: none; }
.search .input { padding-left: 38px; }
.chips {
  display: flex; gap: 7px; overflow-x: auto; padding-bottom: 3px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 36px; padding: 0 13px;
  border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-dim);
  font-size: .82rem; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.chip.is-active {
  background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  color: var(--accent);
}

/* ── Terminal ────────────────────────────────────────────────────────────── */
.terminal {
  background: #07090c; border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  display: grid; grid-template-rows: auto 1fr;
}
@media (prefers-color-scheme: light) { .terminal { background: #0d1117; } }

.terminal__bar {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 11px; border-bottom: 1px solid #222c38;
  background: #0d1117; font-size: .78rem; color: #8b949e;
}
.terminal__body {
  /* Horizontal scrolling inside the terminal only: the page itself must never
   * scroll sideways on a phone. */
  overflow: auto; -webkit-overflow-scrolling: touch;
  max-height: 46vh; padding: 11px 13px;
}
.terminal__pre {
  margin: 0; font-family: var(--mono);
  font-size: 11.5px; line-height: 1.5;
  color: #c9d5e1; white-space: pre;
  tab-size: 2;
}
.terminal.is-wrapped .terminal__pre { white-space: pre-wrap; word-break: break-word; }
.terminal.is-full {
  position: fixed; inset: 0; z-index: 120; border-radius: 0; border: 0;
  grid-template-rows: auto 1fr;
}
.terminal.is-full .terminal__body { max-height: none; height: 100%; padding-bottom: calc(16px + var(--safe-bottom)); }
.terminal.is-full .terminal__bar { padding-top: calc(8px + var(--safe-top)); }

/* ── Detail view ─────────────────────────────────────────────────────────── */
.detail__hero {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--sc, var(--border));
  border-radius: var(--radius-lg); padding: 16px;
  display: grid; gap: 11px;
}
.detail__name { font-size: 1.25rem; font-weight: 690; }
.detail__reason { font-size: .86rem; color: var(--text-dim); line-height: 1.5; }

.kv { display: grid; grid-template-columns: minmax(88px, auto) 1fr; gap: 7px 14px; font-size: .84rem; }
.kv__k { color: var(--text-mute); }
.kv__v { color: var(--text); min-width: 0; overflow-wrap: anywhere; }

.tabs {
  display: flex; gap: 3px; overflow-x: auto; scrollbar-width: none;
  border-bottom: 1px solid var(--border); margin-bottom: 2px;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs__btn {
  flex: none; min-height: 42px; padding: 0 13px;
  background: none; border: 0; border-bottom: 2px solid transparent;
  color: var(--text-mute); font-size: .87rem; font-weight: 600; cursor: pointer;
  white-space: nowrap;
}
.tabs__btn.is-active { color: var(--text); border-bottom-color: var(--accent); }

.composer { display: grid; gap: 10px; }
.composer__hint { font-size: .79rem; color: var(--text-mute); line-height: 1.45; }
.composer__target {
  font-size: .8rem; color: var(--text-dim);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 11px;
  display: grid; gap: 3px;
}

/* ── Feed ────────────────────────────────────────────────────────────────── */
.feed { display: grid; gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.feed__item { background: var(--surface); padding: 11px 13px; display: grid; gap: 4px; }
.feed__top { display: flex; gap: 9px; align-items: baseline; }
.feed__summary { font-size: .86rem; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.feed__time { font-size: .76rem; color: var(--text-mute); flex: none; font-variant-numeric: tabular-nums; }
.feed__meta { font-size: .77rem; color: var(--text-mute); }
.feed__item--warn  { border-left: 3px solid var(--warn); }
.feed__item--error { border-left: 3px solid var(--danger); }

/* ── States ──────────────────────────────────────────────────────────────── */
.empty {
  text-align: center; padding: 40px 20px;
  color: var(--text-mute); display: grid; gap: 8px; justify-items: center;
}
.empty svg { width: 30px; height: 30px; opacity: .5; }
.empty__title { font-size: .95rem; font-weight: 620; color: var(--text-dim); }
.empty__body { font-size: .84rem; max-width: 340px; line-height: 1.5; }

.notice {
  border-radius: var(--radius); padding: 11px 13px;
  font-size: .84rem; line-height: 1.5;
  border: 1px solid color-mix(in srgb, var(--nc, var(--warn)) 38%, transparent);
  background: color-mix(in srgb, var(--nc, var(--warn)) 11%, transparent);
  color: var(--text);
  display: flex; gap: 9px; align-items: flex-start;
}
.notice svg { flex: none; width: 17px; height: 17px; margin-top: 2px; color: var(--nc, var(--warn)); }
.notice--error { --nc: var(--danger); }
.notice--info  { --nc: var(--accent); }

.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-3) 37%, var(--surface) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
  border-radius: var(--radius); height: 88px;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 150; display: grid; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.65); backdrop-filter: blur(2px); }
.modal__panel {
  position: relative; z-index: 1;
  background: var(--surface); border: 1px solid var(--border);
  width: 100%; max-width: 520px;
  display: grid; grid-template-rows: auto 1fr auto;
  /* Bottom sheet on a phone. */
  align-self: end; justify-self: stretch;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  max-height: 92dvh;
  box-shadow: var(--shadow-lg);
  animation: sheet .2s ease-out;
}
@keyframes sheet { from { transform: translateY(14px); opacity: .6; } }
.modal__head { display: flex; align-items: center; gap: 10px; padding: 15px 16px; border-bottom: 1px solid var(--border); }
.modal__head h2 { font-size: 1rem; flex: 1; min-width: 0; }
.modal__close { width: 34px; height: 34px; flex: none; display: grid; place-items: center; border-radius: 50%; border: 0; background: var(--surface-2); cursor: pointer; }
.modal__body { padding: 16px; overflow-y: auto; display: grid; gap: 13px; }
.modal__foot { padding: 13px 16px calc(13px + var(--safe-bottom)); border-top: 1px solid var(--border); display: flex; gap: 9px; justify-content: flex-end; flex-wrap: wrap; }
.modal__foot .btn { flex: 1; min-width: 120px; }

.targetlist { max-height: 190px; overflow-y: auto; display: grid; gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.targetlist__item { background: var(--surface-2); padding: 10px 11px; font-size: .84rem; display: flex; gap: 8px; align-items: center; }

/* ── Toasts ──────────────────────────────────────────────────────────────── */
.toasts {
  position: fixed; z-index: 300; left: 12px; right: 12px;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px);
  display: grid; gap: 8px; pointer-events: none;
}
.toast {
  background: var(--surface-3); border: 1px solid var(--border-strong);
  border-left: 3px solid var(--tc, var(--accent));
  border-radius: var(--radius); padding: 11px 13px;
  font-size: .86rem; box-shadow: var(--shadow-lg);
  animation: toastIn .22s ease-out; pointer-events: auto;
  display: flex; gap: 9px; align-items: flex-start;
}
@keyframes toastIn { from { transform: translateY(10px); opacity: 0; } }
.toast--ok    { --tc: var(--ok); }
.toast--error { --tc: var(--danger); }
.toast--warn  { --tc: var(--warn); }
.toast__body { flex: 1; overflow-wrap: anywhere; }

/* ── Tablet ──────────────────────────────────────────────────────────────── */
@media (min-width: 600px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .counters { grid-template-columns: repeat(4, 1fr); gap: 10px; }
  .counter { padding: 13px 14px; gap: 3px; }
  .counter__n { font-size: 1.65rem; }
  .main { padding-left: 20px; padding-right: 20px; }
  .modal__panel {
    align-self: center; justify-self: center;
    border-radius: var(--radius-lg);
    max-height: 84dvh;
  }
  .toasts { left: auto; right: 20px; width: 380px; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px); }
}

/* ── Sidebar layout: laptop and desktop ──────────────────────────────────── */
@media (min-width: 880px) {
  .topbar, .tabbar { display: none; }

  .sidebar {
    display: flex; flex-direction: column;
    position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-w);
    background: var(--surface); border-right: 1px solid var(--border);
    padding: 18px 12px; gap: 8px; z-index: 50;
  }
  .sidebar__brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 16px; }
  .sidebar__brandtext { display: grid; line-height: 1.25; }
  .sidebar__brandtext strong { font-size: .95rem; }
  .sidebar__brandtext span { font-size: .76rem; color: var(--text-mute); }
  .sidebar__nav { display: grid; gap: 2px; }
  .sidebar__foot { margin-top: auto; display: grid; gap: 10px; padding: 12px 8px 0; border-top: 1px solid var(--border); }

  .navitem {
    display: flex; align-items: center; gap: 11px;
    min-height: 42px; padding: 0 11px; border-radius: var(--radius-sm);
    background: none; border: 0; cursor: pointer;
    color: var(--text-dim); font-size: .9rem; font-weight: 600; text-align: left;
    width: 100%;
  }
  .navitem:hover { background: var(--surface-2); color: var(--text); }
  .navitem.is-active { background: var(--accent-soft); color: var(--accent); }
  .navitem svg { width: 18px; height: 18px; flex: none; }
  .navitem__badge {
    margin-left: auto; min-width: 21px; height: 21px; padding: 0 6px;
    border-radius: 11px; background: var(--danger); color: #fff;
    font-size: 12px; font-weight: 700; display: grid; place-items: center;
  }

  .main {
    margin-left: var(--sidebar-w);
    padding: 26px 26px 40px;
  }
  .toasts { bottom: 20px; }
  .terminal__body { max-height: 56vh; }
  .terminal__pre { font-size: 12.5px; }
}

@media (min-width: 1180px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .counters { grid-template-columns: repeat(6, 1fr); }
  .main { padding: 30px 34px 46px; }
}

@media (min-width: 1600px) {
  .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* Two-column detail on wide screens: terminal beside the metadata. */
@media (min-width: 1180px) {
  .detail--split { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(320px, .65fr); gap: 20px; align-items: start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}


/* ── Mobile legibility floor ─────────────────────────────────────────────────
 * Nothing on a phone may render below 12px. This is a backstop: the individual
 * rules above already sit at or over the floor, and this keeps them there if
 * one is ever nudged down. */
@media (max-width: 879px) {
  .pill, .counter__l, .feed__time, .feed__meta, .agent__foot,
  .agent__where, .badge, .tab, .conn, .terminal__bar {
    font-size: max(12px, 0.78rem);
  }
  .badge { font-size: max(12px, 0.72rem); }
  /* Comfortable thumb targets throughout. */
  .section__link, .chip, .tabs__btn { min-height: 44px; }
}
