/* Fleet — v1 chosen screen set (design/README.md, screens-set1.html, screens-set2.html)
 * Look: "Thẻ sáng × Liquid Glass" (iOS 26), light by default, dark via prefers-color-scheme.
 * Supports GIAO DIỆN KÍNH: Trong (clear), Nhuộm màu (tinted), Đặc (solid).
 * Respects prefers-reduced-transparency (fallback to solid cards).
 */

:root {
  color-scheme: light dark;
  --bg-page: #eef1f8;
  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-muted: #475569;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-deep: #1e40af;
  --accent-soft: rgba(219, 234, 254, 0.95);
  --accent-border: rgba(37, 99, 235, 0.38);

  --green-dot: #16a34a;
  --green-glow: #22c55e;
  --green-text: #166534;
  --green-deep: #14532d;
  --green-bg: rgba(220, 252, 231, 0.92);
  --green-border: rgba(22, 163, 74, 0.35);

  --amber-text: #9a3412;
  --amber-strong: #7c2d12;
  --amber-accent: #c2410c;
  --amber-bg: rgba(255, 237, 213, 0.95);
  --amber-soft: rgba(255, 237, 213, 0.78);
  --amber-border: rgba(234, 88, 12, 0.38);

  --red-dot: #dc2626;
  --red-text: #991b1b;
  --red-strong: #7f1d1d;
  --red-bg: rgba(254, 226, 226, 0.92);
  --red-border: rgba(220, 38, 38, 0.38);

  --purple-dot: #9333ea;
  --purple-text: #6b21a8;
  --purple-bg: rgba(243, 232, 255, 0.95);

  --indigo-mono: #3730a3;
  --divider-color: rgba(15, 23, 42, 0.08);
  --sheet-backdrop: rgba(15, 23, 42, 0.22);
  --grabber-color: rgba(15, 23, 42, 0.25);

  --blob-1: #2563eb;
  --blob-1-op: 0.32;
  --blob-2: #fb923c;
  --blob-2-op: 0.30;
  --blob-3: #a78bfa;
  --blob-3-op: 0.34;

  --font-sans: -apple-system, "SF Pro Text", Inter, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "SF Mono", "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
}

a {
  color: var(--accent-strong);
  text-decoration: none;
}

.hidden {
  display: none !important;
}

.mono {
  font-family: var(--font-mono);
}

/* Core Liquid Glass classes from design/blend-liquid-glass.html & screens-set1/2 */
.glass {
  background: linear-gradient(140deg, rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0.52));
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: inset 0 1px 0 #ffffff, inset 0 -1px 0 rgba(15, 23, 42, 0.04), 0 10px 28px rgba(30, 41, 90, 0.10);
}

.tile {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0.38));
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.85);
  box-shadow: inset 0 1px 0 #ffffff;
}

.pill {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(255, 255, 255, 0.6));
  backdrop-filter: blur(14px) saturate(190%);
  -webkit-backdrop-filter: blur(14px) saturate(190%);
  border: 1px solid rgba(255, 255, 255, 0.95);
  box-shadow: inset 0 1px 0 #ffffff, 0 2px 8px rgba(30, 41, 90, 0.08);
}

/* Dark glass (.gd) used by floating terminal toolbar (reference screen 16) */
.gd {
  background: linear-gradient(140deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.06));
  backdrop-filter: blur(26px) saturate(170%);
  -webkit-backdrop-filter: blur(26px) saturate(170%);
  border: 1px solid rgba(255, 255, 255, 0.28);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45), 0 14px 34px rgba(0, 0, 0, 0.35);
  color: #ffffff;
}

/* Glass style variants from Cài đặt (screen 20): Trong / Nhuộm màu / Đặc */
.glass-style-tinted .glass {
  background: linear-gradient(140deg, rgba(219, 234, 254, 0.84), rgba(221, 214, 254, 0.56));
  border-color: rgba(255, 255, 255, 0.92);
}

.glass-style-tinted .tile {
  background: linear-gradient(180deg, rgba(224, 242, 254, 0.74), rgba(237, 233, 254, 0.44));
}

.glass-style-solid .glass,
.glass-style-solid .tile,
.glass-style-solid .pill {
  background: #ffffff !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  border-color: #e2e8f0 !important;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.06) !important;
}

/* Soft colour blobs behind glass */
.liquid-bg {
  position: fixed;
  inset: 0;
  max-width: 520px;
  margin: 0 auto;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.bg-blob {
  position: absolute;
  border-radius: 50%;
}

.bg-blob-blue {
  left: -100px;
  top: -90px;
  width: 320px;
  height: 320px;
  background: var(--blob-1);
  opacity: var(--blob-1-op);
  filter: blur(42px);
}

.bg-blob-orange {
  right: -120px;
  top: 300px;
  width: 320px;
  height: 320px;
  background: var(--blob-2);
  opacity: var(--blob-2-op);
  filter: blur(44px);
}

.bg-blob-violet {
  left: -40px;
  bottom: -110px;
  width: 340px;
  height: 300px;
  background: var(--blob-3);
  opacity: var(--blob-3-op);
  filter: blur(44px);
}

/* Outer mobile shell */
.app-shell {
  position: relative;
  z-index: 1;
  max-width: 460px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding-top: calc(20px + env(safe-area-inset-top, 0px));
  padding-left: calc(16px + env(safe-area-inset-left, 0px));
  padding-right: calc(16px + env(safe-area-inset-right, 0px));
  padding-bottom: calc(104px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Cleaner Header: back button + title + "cập nhật lúc HH:MM:SS" small line + ONE refresh button */
.app-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-titles {
  flex-grow: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.header-eyebrow {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-title {
  margin: 0;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.08;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-title.title-fleet {
  font-size: 28px;
}

.header-updated-line {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.btn44 {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 0;
  transition: transform 0.1s ease;
}

.btn44:active {
  transform: scale(0.95);
}

.refresh-btn.spinning svg {
  animation: spin 0.75s linear infinite;
}

/* Running badge pill */
.running-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

.running-badge.is-running {
  color: var(--green-text);
}

.running-badge.is-stopped {
  color: var(--text-muted);
}

.running-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.running-badge.is-running .running-dot {
  background: var(--green-dot);
  box-shadow: 0 0 8px var(--green-glow);
}

/* Banners */
.banners-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.banner {
  padding: 12px 14px;
  border-radius: 18px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
}

.banner-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.banner-offline {
  background: var(--amber-bg);
  border: 1px solid var(--amber-border);
  color: var(--amber-strong);
}

.banner-error {
  background: var(--red-bg);
  border: 1px solid var(--red-border);
  color: var(--red-strong);
}

/* Main container */
.app-main {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

.app-main.sheet-open-bg {
  filter: saturate(0.92);
  opacity: 0.78;
  pointer-events: none;
}

/* Section captions (CẦN CHÚ Ý, ĐANG LÀM, NGHỈ, MÁY CHỦ, GIAO DIỆN KÍNH) */
.cap {
  padding: 4px 6px 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

/* Fleet list cards (screen 9) */
.cards-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.fleet-list-card {
  border-radius: 24px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  color: var(--text-primary);
  text-decoration: none;
}

.fleet-list-card.is-stopped-card {
  opacity: 0.88;
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.fleet-card-name {
  font-size: 20px;
  font-weight: 700;
  flex-grow: 1;
  color: var(--text-primary);
}

.fleet-card-meta {
  font-size: 13px;
  color: var(--text-muted);
}

.fleet-chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.fleet-stat-chip {
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.chip-busy {
  background: rgba(219, 234, 254, 0.95);
  color: #1e40af;
}

.chip-attn {
  background: rgba(255, 237, 213, 0.95);
  color: #9a3412;
}

.chip-idle {
  background: rgba(241, 245, 249, 0.95);
  color: #334155;
}

.urgent-line {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--text-secondary);
  word-break: break-word;
}

.urgent-line.tone-danger {
  color: var(--amber-text);
  font-weight: 600;
}

.urgent-line.tone-success {
  color: var(--green-text);
}

/* 4 Stat Tiles on Fleet screen (screen 5) */
.metrics-strip {
  border-radius: 24px;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.metric-box {
  border-radius: 16px;
  padding: 10px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.metric-value {
  font-size: 21px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  color: var(--text-primary);
}

.metric-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.metric-box.metric-busy-active .metric-value {
  color: var(--accent-strong);
}

.metric-box.metric-busy-active .metric-label {
  color: var(--accent-deep);
}

.metric-box.metric-attention-active {
  background: linear-gradient(180deg, rgba(255, 237, 213, 0.9), rgba(255, 237, 213, 0.55));
}

.metric-box.metric-attention-active .metric-value {
  color: var(--amber-accent);
}

.metric-box.metric-attention-active .metric-label {
  color: var(--amber-text);
}

/* Fleet screen agent cards (screen 5) */
.agent-card-big {
  border-radius: 22px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  color: var(--text-primary);
  text-decoration: none;
}

.agent-grid-2up {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.agent-card-small {
  border-radius: 20px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--text-primary);
  text-decoration: none;
  min-height: 68px;
}

.dot-9 {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-limited {
  background: var(--purple-dot);
}

.dot-dead {
  background: var(--red-dot);
}

.small-state-limited {
  font-size: 13px;
  color: var(--purple-text);
  font-weight: 600;
}

.small-state-dead {
  font-size: 13px;
  color: var(--red-text);
  font-weight: 600;
}

/* Compact NGHỈ card listing idle agent names */
.idle-compact-card {
  border-radius: 20px;
  padding: 13px 15px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.idle-names-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.idle-name-pill {
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-decoration: none;
}

/* Chips & State badges */
.chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-secondary);
}

.chip-model {
  color: var(--indigo-mono);
  font-family: var(--font-mono);
}

.chip-backup {
  background: var(--amber-bg);
  color: var(--amber-text);
  font-weight: 600;
}

.state-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.state-busy {
  background: rgba(219, 234, 254, 0.95);
  color: #1e40af;
}

.state-waiting {
  background: rgba(255, 237, 213, 0.95);
  color: #9a3412;
}

.state-limited {
  background: rgba(243, 232, 255, 0.95);
  color: #6b21a8;
}

.state-dead {
  background: rgba(254, 226, 226, 0.95);
  color: #991b1b;
}

.state-idle {
  background: rgba(220, 252, 231, 0.92);
  color: #166534;
}

.state-starting {
  background: rgba(224, 242, 254, 0.95);
  color: #075985;
}

.state-null {
  background: rgba(226, 232, 240, 0.85);
  color: #334155;
}

/* Status paragraphs & Progress bars */
.status-callout {
  margin: 0;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.62);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-primary);
  word-break: break-word;
}

.status-callout.tone-danger {
  background: rgba(255, 237, 213, 0.82);
  color: #7c2d12;
}

.status-callout.tone-success {
  background: rgba(220, 252, 231, 0.78);
  color: #166534;
}

.status-inline {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.42;
  color: var(--text-secondary);
  word-break: break-word;
}

.status-inline.tone-success {
  color: var(--green-text);
}

.status-inline.tone-danger {
  color: var(--amber-strong);
}

.progress-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.progress-labels {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
}

.progress-track {
  height: 6px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.3);
  overflow: hidden;
  display: flex;
}

.progress-fill-done {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.25s ease;
}

/* Agent Bottom Sheet (reference screen 13 + screen 8) */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: var(--sheet-backdrop);
  z-index: 50;
}

.agent-sheet {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  max-width: 452px;
  max-height: 86vh;
  max-height: 86dvh;
  margin: 0 auto;
  border-radius: 36px;
  padding: 10px 16px 18px;
  z-index: 55;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

.sheet-grabber {
  align-self: center;
  width: 40px;
  height: 5px;
  border-radius: 99px;
  background: var(--grabber-color);
  flex-shrink: 0;
}

.sheet-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.sheet-title-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.sheet-eyebrow {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.sheet-agent-name {
  font-size: 24px;
  font-weight: 700;
  line-height: 1.15;
  color: var(--text-primary);
}

.sheet-body-scroll {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 6px;
}

.agent-summary-card {
  border-radius: 22px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.agent-counters-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  text-align: center;
}

.agent-counter-col {
  display: flex;
  flex-direction: column;
}

.agent-counter-val {
  font-size: 19px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.agent-counter-lbl {
  font-size: 12px;
  color: var(--text-muted);
}

/* Segmented Tabs inside Agent sheet (Hàng đợi / Màn hình / Sự kiện) */
.tabs-bar {
  border-radius: 999px;
  padding: 4px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  flex-shrink: 0;
}

.tab-btn {
  height: 40px;
  min-height: 40px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.tab-btn.active {
  color: var(--accent);
  font-weight: 600;
}

/* Queue cards in Agent sheet (screen 8) */
.queue-card {
  border-radius: 20px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.queue-card.queue-held {
  background: linear-gradient(140deg, rgba(254, 243, 199, 0.88), rgba(255, 255, 255, 0.58));
}

.queue-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.queue-card-title {
  font-size: 14px;
  font-weight: 700;
}

.queue-card-time {
  font-size: 12px;
  color: var(--text-muted);
}

.queue-card-text {
  font-size: 14px;
  line-height: 1.42;
  word-break: break-word;
}

.queue-card-evidence {
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(220, 252, 231, 0.82);
  color: var(--green-deep);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.4;
  word-break: break-word;
}

.queue-card-evidence.ev-failed {
  background: rgba(254, 226, 226, 0.85);
  color: var(--red-strong);
}

/* Screen 16: Dark full-bleed terminal with floating glass toolbar */
.terminal-fullbleed {
  position: relative;
  border-radius: 24px;
  background: #05070c;
  color: #cbd5e1;
  min-height: 330px;
  max-height: 54vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.terminal-top-pill {
  margin: 10px 12px 0;
  border-radius: 999px;
  padding: 7px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.terminal-scroll-box {
  flex: 1;
  overflow-x: auto;
  overflow-y: auto;
  padding: 10px 14px 76px;
  font-family: var(--font-mono);
  line-height: 1.65;
  -webkit-overflow-scrolling: touch;
}

.terminal-divider {
  color: #64748b;
  white-space: pre;
}

.terminal-row {
  white-space: pre;
  min-width: max-content;
}

.terminal-row.term-success {
  color: #4ade80;
}

.terminal-row.term-danger {
  color: #fca5a5;
}

.terminal-floating-toolbar {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 12px;
  border-radius: 999px;
  padding: 5px;
  display: flex;
  align-items: center;
  gap: 4px;
  z-index: 5;
}

.term-tool-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

.term-tool-btn.active {
  background: rgba(255, 255, 255, 0.22);
}

/* Screen 15: Global Event Timeline (#/events) */
.filter-chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.filter-chip {
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  border: 1px solid transparent;
}

.filter-chip.active {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  color: #ffffff !important;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.28);
}

.time-bucket-pill {
  align-self: flex-start;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.event-row-card {
  border-radius: 20px;
  padding: 12px 14px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 14px;
}

.event-row-card.tone-danger {
  background: linear-gradient(140deg, rgba(254, 226, 226, 0.9), rgba(255, 255, 255, 0.55));
  color: var(--red-text);
}

.event-row-card.tone-warning {
  background: linear-gradient(140deg, rgba(255, 237, 213, 0.9), rgba(255, 255, 255, 0.55));
  color: var(--amber-text);
}

.event-row-time {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-muted);
  flex-shrink: 0;
  padding-top: 1px;
  /* "Hôm qua 23:09" / "24/11 23:09" wrap onto two lines instead of squeezing the text. */
  min-width: 7.2ch;
  max-width: 10.5ch;
  line-height: 1.35;
}

.event-row-body {
  flex: 1;
  min-width: 0;
  line-height: 1.42;
  word-break: break-word;
}

.event-agent-link {
  font-weight: 700;
  color: var(--text-primary);
  margin-right: 5px;
}

/* Screen 20: Cài đặt (#/settings) */
.settings-group {
  border-radius: 22px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.settings-row {
  padding: 14px 16px;
  border-bottom: 1px solid var(--divider-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 14.5px;
}

.settings-row:last-child {
  border-bottom: none;
}

.glass-picker-grid {
  border-radius: 22px;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.glass-style-option {
  height: 92px;
  border-radius: 16px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.8);
}

.glass-style-option.opt-clear {
  background: linear-gradient(140deg, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.5));
}

.glass-style-option.opt-tinted {
  background: linear-gradient(140deg, rgba(191, 219, 254, 0.95), rgba(221, 214, 254, 0.7));
}

.glass-style-option.opt-solid {
  background: #ffffff;
  border-color: #e2e8f0;
  color: #0f172a;
}

.glass-style-option.selected {
  border: 2px solid var(--accent);
  font-weight: 700;
}

/* Screen 10: Kết nối first-run screen */
.connect-screen {
  padding: 18px 4px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.connect-app-icon {
  width: 72px;
  height: 72px;
  border-radius: 22px;
  overflow: hidden;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), 0 10px 24px rgba(37, 99, 235, 0.35);
  flex-shrink: 0;
}

.connect-app-icon img,
.connect-app-icon svg {
  width: 100%;
  height: 100%;
  display: block;
}

.connect-heading {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
}

.connect-lead {
  font-size: 15px;
  color: var(--text-muted);
  line-height: 1.45;
  margin: 0;
}

.qr-placeholder-card {
  border-radius: 26px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.qr-dashed-box {
  width: 148px;
  height: 148px;
  border-radius: 20px;
  border: 2px dashed rgba(37, 99, 235, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-strong);
  font-weight: 600;
  font-size: 14px;
}

.connect-input-card {
  border-radius: 20px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.token-input {
  width: 100%;
  min-height: 44px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.5);
  padding: 0 12px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-primary);
}

.token-input:focus {
  outline: 2px solid var(--accent);
  border-color: transparent;
}

.btn-primary-52 {
  width: 100%;
  min-height: 52px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45), 0 8px 20px rgba(37, 99, 235, 0.35);
  cursor: pointer;
}

.btn-secondary {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}

/* Floating capsule bottom tab bar: Fleet · Sự kiện · Cài đặt */
.bottom-tabbar-wrap {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  z-index: 40;
  max-width: 460px;
  margin: 0 auto;
  padding: 0 calc(16px + env(safe-area-inset-left, 0px));
  pointer-events: none;
}

.bottom-tabbar {
  pointer-events: auto;
  border-radius: 999px;
  padding: 5px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
}

.bottom-tab-item {
  height: 48px;
  min-height: 48px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  cursor: pointer;
}

.bottom-tab-item.active {
  color: var(--accent);
  font-weight: 600;
}

/* Empty & Loading states */
.empty-state,
.loading-state {
  border-radius: 22px;
  padding: 24px 16px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
}

.spinner {
  width: 28px;
  height: 28px;
  margin: 0 auto 10px;
  border: 3px solid rgba(37, 99, 235, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Dark Mode via prefers-color-scheme (Reference screen 6 in screens-set1.html) */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-page: #070a14;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --accent: #3b82f6;
    --accent-strong: #93c5fd;
    --accent-deep: #dbeafe;
    --accent-soft: rgba(147, 197, 253, 0.2);

    --green-dot: #4ade80;
    --green-glow: #4ade80;
    --green-text: #86efac;
    --green-deep: #bbf7d0;
    --green-bg: rgba(34, 197, 94, 0.2);

    --amber-text: #fed7aa;
    --amber-strong: #ffedd5;
    --amber-accent: #fed7aa;
    --amber-bg: rgba(251, 146, 60, 0.25);
    --amber-soft: rgba(251, 146, 60, 0.14);

    --red-dot: #f87171;
    --red-text: #fecaca;
    --red-strong: #fee2e2;
    --red-bg: rgba(248, 113, 113, 0.22);

    --purple-dot: #c084fc;
    --purple-text: #e9d5ff;
    --purple-bg: rgba(192, 132, 252, 0.22);

    --indigo-mono: #c7d2fe;
    --divider-color: rgba(255, 255, 255, 0.12);
    --sheet-backdrop: rgba(2, 6, 23, 0.58);
    --grabber-color: rgba(255, 255, 255, 0.35);

    --blob-1: #3b82f6;
    --blob-1-op: 0.45;
    --blob-2: #ea580c;
    --blob-2-op: 0.35;
    --blob-3: #7c3aed;
    --blob-3-op: 0.45;
  }

  .glass {
    background: linear-gradient(140deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.05));
    backdrop-filter: blur(26px) saturate(170%);
    -webkit-backdrop-filter: blur(26px) saturate(170%);
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 14px 34px rgba(0, 0, 0, 0.45);
  }

  .tile {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.04));
    border: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22);
  }

  .pill {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0.08));
    backdrop-filter: blur(14px) saturate(180%);
    -webkit-backdrop-filter: blur(14px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.28);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4);
  }

  .glass-style-tinted .glass {
    background: linear-gradient(140deg, rgba(59, 130, 246, 0.24), rgba(124, 58, 237, 0.14));
    border-color: rgba(147, 197, 253, 0.28);
  }

  .glass-style-solid .glass,
  .glass-style-solid .tile,
  .glass-style-solid .pill {
    background: #111827 !important;
    border-color: #334155 !important;
  }

  .metric-box.metric-attention-active {
    background: linear-gradient(180deg, rgba(251, 146, 60, 0.32), rgba(251, 146, 60, 0.12));
  }

  .running-badge.is-running {
    color: #bbf7d0;
  }

  .state-busy,
  .chip-busy {
    background: rgba(147, 197, 253, 0.2);
    color: #dbeafe;
  }

  .state-waiting,
  .chip-attn {
    background: rgba(251, 146, 60, 0.25);
    color: #fed7aa;
  }

  .state-limited {
    background: rgba(192, 132, 252, 0.24);
    color: #e9d5ff;
  }

  .state-dead {
    background: rgba(248, 113, 113, 0.24);
    color: #fecaca;
  }

  .state-idle,
  .chip-idle {
    background: rgba(255, 255, 255, 0.12);
    color: #cbd5e1;
  }

  .status-callout {
    background: rgba(255, 255, 255, 0.08);
    color: #f1f5f9;
  }

  .status-callout.tone-danger {
    background: rgba(251, 146, 60, 0.16);
    color: #ffedd5;
  }

  .status-callout.tone-success {
    background: rgba(34, 197, 94, 0.16);
    color: #86efac;
  }

  .queue-card.queue-held {
    background: linear-gradient(140deg, rgba(245, 158, 11, 0.22), rgba(255, 255, 255, 0.06));
  }

  .queue-card-evidence {
    background: rgba(34, 197, 94, 0.18);
    color: #bbf7d0;
  }

  .queue-card-evidence.ev-failed {
    background: rgba(239, 68, 68, 0.22);
    color: #fecaca;
  }

  .event-row-card.tone-danger {
    background: linear-gradient(140deg, rgba(239, 68, 68, 0.22), rgba(255, 255, 255, 0.06));
    color: #fecaca;
  }

  .event-row-card.tone-warning {
    background: linear-gradient(140deg, rgba(251, 146, 60, 0.22), rgba(255, 255, 255, 0.06));
    color: #fed7aa;
  }

  .token-input {
    background: rgba(15, 23, 42, 0.72);
    border-color: rgba(255, 255, 255, 0.22);
    color: #f1f5f9;
  }

  .bottom-tab-item.active,
  .tab-btn.active {
    color: #ffffff;
  }
}

/* Respect prefers-reduced-transparency (fallback: solid #ffffff cards in light mode, #111827 in dark mode) */
@media (prefers-reduced-transparency: reduce) {
  .glass,
  .tile,
  .pill {
    background: #ffffff !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    border-color: #cbd5e1 !important;
  }

  .bg-blob {
    display: none !important;
  }
}

@media (prefers-reduced-transparency: reduce) and (prefers-color-scheme: dark) {
  .glass,
  .tile,
  .pill {
    background: #111827 !important;
    border-color: #334155 !important;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Screen 14: Long-press Context Menu on Agent cards */
.ctx-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.25);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 60;
}

.ctx-overlay-box {
  position: fixed;
  left: 16px;
  right: 16px;
  top: 160px;
  max-width: 428px;
  margin: 0 auto;
  z-index: 65;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ctx-preview-card {
  border-radius: 24px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transform: scale(1.02);
}

.ctx-menu-list {
  width: 265px;
  border-radius: 22px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.ctx-menu-item {
  width: 100%;
  min-height: 46px;
  padding: 12px 16px;
  border: none;
  border-bottom: 1px solid var(--divider-color);
  background: transparent;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15.5px;
  font-weight: 500;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
}

.ctx-menu-item:last-child {
  border-bottom: none;
}

.ctx-menu-item.ctx-accent {
  color: var(--accent-strong);
  font-weight: 600;
}

.card-menu-trigger {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

.pin-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

/* Toast banner for copied status / commander revive sentence */
.toast-pill {
  position: fixed;
  left: 16px;
  right: 16px;
  top: calc(14px + env(safe-area-inset-top, 0px));
  max-width: 428px;
  margin: 0 auto;
  z-index: 75;
  border-radius: 18px;
  padding: 11px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* Screen 17: Bottom glass search bar & search results */
.bottom-search-wrap {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(78px + env(safe-area-inset-bottom, 0px));
  z-index: 39;
  max-width: 460px;
  margin: 0 auto;
  padding: 0 calc(16px + env(safe-area-inset-left, 0px));
  pointer-events: none;
}

.bottom-search-bar {
  pointer-events: auto;
  height: 48px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 15px;
}

.bottom-search-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  outline: none;
}

.bottom-search-input::placeholder {
  color: var(--text-muted);
}

.bottom-search-cancel {
  border: none;
  background: transparent;
  color: var(--accent);
  font-family: inherit;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 6px;
}

.app-shell.with-search-bar {
  padding-bottom: calc(158px + env(safe-area-inset-bottom, 0px));
}

/* Screen 20: iOS Toggle Switch in THÔNG BÁO */
.ios-switch {
  width: 51px;
  height: 31px;
  border-radius: 99px;
  border: none;
  background: rgba(120, 120, 128, 0.28);
  position: relative;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: background-color 0.18s ease;
}

.ios-switch.on {
  background: #22c55e;
}

.ios-switch-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
  transition: transform 0.18s ease;
}

.ios-switch.on .ios-switch-knob {
  transform: translateX(20px);
}

/* v3: long-press cards — no iOS link preview / text selection while holding */
.lp-card {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.lp-hint {
  margin: 4px 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}

/* Tab bar row: capsule + round search button (screen 20 / 17) */
.bottom-tabbar-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.bottom-tabbar-wrap .bottom-tabbar {
  flex: 1;
  min-width: 0;
}

.tab-search-btn {
  pointer-events: auto;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  font-family: inherit;
}

.tab-search-btn.active {
  color: var(--accent);
  border-color: var(--accent-border);
}

/* Screen 17: search results */
.search-result-card {
  border-radius: 20px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--text-primary);
  text-decoration: none;
}

.search-result-state {
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

.search-result-sub {
  font-size: 13px;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.search-event-card {
  text-decoration: none;
  color: var(--text-primary);
}

.toast-pill {
  pointer-events: none;
}

@media (prefers-color-scheme: dark) {
  .ctx-backdrop {
    background: rgba(0, 0, 0, 0.45);
  }
  .ios-switch {
    background: rgba(120, 120, 128, 0.42);
  }
}

/* Several server addresses (home network, Tailscale, …) */
.server-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.server-kind {
  font-weight: 600;
}

.server-url {
  font-size: 12.5px;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.server-badge {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.saved-servers {
  text-align: left;
}

.server-remove {
  flex-shrink: 0;
}
