/* RemoteVici design tokens and components (KAN-67).
   Small and owned: every later screen composes from these. */

:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --border: #d9dee8;
  --text: #12161d;
  --muted: #5b6472;
  --accent: #0f7fc4;
  --accent-soft: #dff0fa;
  --danger: #c62f2f;
  --danger-soft: #fbe7e7;
  --ok: #1f8a4c;
  --idle: #8a7a1f;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(10, 14, 20, 0.06), 0 8px 28px rgba(10, 14, 20, 0.07);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f16;
    --surface: #131926;
    --surface-2: #0f141f;
    --border: #232c3d;
    --text: #e8ecf3;
    --muted: #8b95a7;
    --accent: #59c7f5;
    --accent-soft: #10293a;
    --danger: #ff6b6b;
    --danger-soft: #3a1414;
    --ok: #4cd07d;
    --idle: #d9c34a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 34px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.app { min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- centered auth / picker layouts ---------- */

.center-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  width: 100%;
  max-width: 380px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.brand .mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--accent-soft);
  display: grid;
  place-items: center;
  color: var(--accent);
  font-weight: 800;
  font-size: 19px;
}

.brand .name { font-size: 19px; font-weight: 700; letter-spacing: 0.2px; }
.brand .sub { color: var(--muted); font-size: 12.5px; margin-top: 1px; }

.field { margin: 12px 0; }
.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s ease;
}
.field input:focus { border-color: var(--accent); }

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  font-size: 14.5px;
  font-weight: 650;
  cursor: pointer;
  transition: filter 0.12s ease, transform 0.05s ease;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #06212f; } }
.btn.danger { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.btn.block { width: 100%; margin-top: 8px; }
.btn:disabled { opacity: 0.55; cursor: default; }

.auth-note {
  margin-top: 14px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}
.auth-note a { color: var(--accent); cursor: pointer; text-decoration: none; }

.error-banner {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13.5px;
  margin: 10px 0 2px;
}

/* ---------- picker ---------- */

.picker-list { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.picker-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color 0.12s ease;
}
.picker-item:hover { border-color: var(--accent); }
.picker-item .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); }
.picker-item .meta { flex: 1; }
.picker-item .title { font-weight: 700; }
.picker-item .sub { color: var(--muted); font-size: 12.5px; }

/* ---------- home ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar .mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 800; font-size: 15px;
}
.topbar .who { font-weight: 700; }
.topbar .sub { color: var(--muted); font-size: 12px; }
.topbar .spacer { flex: 1; }
.topbar .user { color: var(--muted); font-size: 13px; }

.tabs { display: flex; gap: 4px; padding: 10px 18px 0; }
.tab {
  padding: 8px 14px;
  border-radius: 9px 9px 0 0;
  font-weight: 650;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  border: 1px solid transparent;
  border-bottom: none;
}
.tab.active {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border);
}
.tab.disabled { cursor: default; opacity: 0.55; }

.main {
  flex: 1;
  display: grid;
  gap: 16px;
  padding: 16px 18px 28px;
  grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
  align-items: start;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}
@media (max-width: 860px) { .main { grid-template-columns: 1fr; } }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel .panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 14px;
}
.panel .panel-head .hint { color: var(--muted); font-weight: 500; font-size: 12px; }

.stack { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.live-box { position: relative; background: #05070b; aspect-ratio: 16 / 9; }
/* The cockpit's compact strip: same stream, shorter box — launching
   requires this stream open on the acting device. */
.live-strip { aspect-ratio: 21 / 9; border-radius: 8px; overflow: hidden; flex: none; }
.live-box img,
.live-box canvas { width: 100%; height: 100%; object-fit: contain; display: block; }
.live-idle {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #6a7686;
  font-size: 14px;
}

/* Liveness pill over the video: staleness and reconnection are stated,
   never inferred from a frozen-looking picture. */
.live-status {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 2;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  background: rgba(7, 10, 15, 0.78);
  color: #e8c76a;
}
.live-status.danger { color: #ff9191; }

/* Glass-to-glass latency chip (KAN-87): capture-to-paint, shown only while
   frames are fresh and the instance clock offset is estimated. */
.live-latency {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 2;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  background: rgba(7, 10, 15, 0.78);
  color: #7fd0a7;
}

.controls { display: flex; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border); }
.controls.bare { border-top: none; }

.health-grid { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px 14px; }
.chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.chip .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.chip.ok .dot { background: var(--ok); }
.chip.idle .dot { background: var(--idle); }
.chip.degraded .dot { background: var(--idle); }
.chip.failed .dot { background: var(--danger); }
.chip.unavailable .dot { background: var(--muted); }
.chip .label { font-weight: 650; font-size: 13px; min-width: 88px; }
.chip .detail { color: var(--muted); font-size: 12.5px; flex: 1; }
.chip .metric { color: var(--text); font-size: 12.5px; font-variant-numeric: tabular-nums; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 11px 16px;
  font-size: 13.5px;
  z-index: 50;
  max-width: min(92vw, 460px);
}
.toast.danger { border-color: var(--danger); color: var(--danger); }

/* Persistent outage strip while the events stream is disconnected — the
   liveness signal behind restart detection (KAN-79). */
.connection-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 60;
  text-align: center;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 650;
  background: var(--danger-soft);
  color: var(--danger);
  border-bottom: 1px solid var(--danger);
}

/* ---------- chat (the cockpit) ---------- */

.chat-main { grid-template-columns: 1fr; max-width: 860px; }
.chat-panel { display: flex; flex-direction: column; min-height: 60vh; }

.run-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  max-width: 60%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.run-chip .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--muted); }
.run-chip.running .dot { background: var(--ok); }
.run-chip.running { color: var(--ok); }
.run-chip.held .dot { background: var(--idle); }
.run-chip.held { color: var(--idle); }
.run-chip span { overflow: hidden; text-overflow: ellipsis; }

.feed {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 240px;
  max-height: 56vh;
}
.feed-empty { color: var(--muted); font-size: 13.5px; margin: auto; }

.turn { display: flex; flex-direction: column; gap: 2px; }
.turn-meta { font-size: 11.5px; color: var(--muted); }
.turn-meta .kind { font-weight: 700; letter-spacing: 0.4px; }
.turn-body {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13.5px;
  white-space: pre-wrap;
  word-break: break-word;
}
.turn.lifecycle .turn-body { background: transparent; border-style: dashed; color: var(--muted); font-size: 12.5px; }
.turn.declaration .turn-body { border-color: var(--accent); background: var(--accent-soft); }
.turn.receipt .turn-body { color: var(--muted); font-size: 12.5px; }

.ask-banner {
  margin: 12px 16px 0;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.ask-title { font-weight: 700; font-size: 13px; margin-bottom: 4px; }
.ask-question { font-size: 14px; margin-bottom: 8px; white-space: pre-wrap; }
.ask-row { display: flex; gap: 8px; }
.ask-row input {
  flex: 1;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.ask-row input:focus { border-color: var(--accent); }

.launch-panel { padding: 4px 16px 16px; border-top: 1px solid var(--border); }
.launch-panel textarea {
  width: 100%;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
  font-family: var(--font);
  outline: none;
  resize: vertical;
}
.launch-panel textarea:focus { border-color: var(--accent); }

.guidance-row { display: flex; gap: 8px; padding: 12px 16px 0; }
.guidance-row input {
  flex: 1;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.guidance-row input:focus { border-color: var(--accent); }
