/* Two themes. Light is the default and follows CarerVoiz (ai.carervoiz.com): grey-50 page, white cards, grey text,
 * blue-600 accent, system font. Dark is the launcher's original navy, chosen with the header toggle
 * (client/src/theme.jsx), which sets <html data-theme="dark">. Every colour below is a variable, so both stay whole. */
:root {
  --bg: #f9fafb;
  --panel: #ffffff;
  --panel-2: #f3f4f6;
  --line: #e5e7eb;
  --line-soft: #f3f4f6;
  --line-strong: #d1d5db;
  --text: #111827;
  --muted: #6b7280;
  --faint: #9ca3af;
  --hover: #f3f4f6;
  --accent: #2563eb;
  --on-accent: #ffffff;
  --ok: #059669;
  --ok-line: #a7f3d0;
  --warn: #d97706;
  --danger: #b91c1c;
  --danger-line: #fecaca;
  --bar-bg: #ffffff;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow-md: 0 10px 24px rgba(16, 24, 40, .10);
  --shadow-drawer: -8px 0 24px rgba(16, 24, 40, .12);
  --overlay: rgba(17, 24, 39, .35);
  --bubble-member: #f3f4f6;
  --bubble-agent: #eff6ff;
  --bubble-agent-line: #bfdbfe;
  --subcase: #f9fafb;
  --scroll-thumb: #d1d5db;
  /* A step not reached yet: faded, but its white button text must stay readable on a light page. */
  --upcoming-opacity: .72;
  --bar-h: 52px;
  /* One colour per app a step opens: CarerVoiz, CarerKMS, Hospilot, CarerVoiz, HITL. */
  --s1: #2563eb;
  --s2: #9333ea;
  --s3: #ea580c;
  --s4: #059669;
  --s5: #db2777;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0b1020;
  --panel: #111831;
  --panel-2: #0e1528;
  --line: #233150;
  --line-soft: #16203a;
  --line-strong: #2c3c61;
  --text: #e8edf7;
  --muted: #93a1c0;
  --faint: #5d6e93;
  --hover: #0f1830;
  --accent: #6c8cff;
  --on-accent: #0b1020;
  --ok: #37d39b;
  --ok-line: #1d4a36;
  --warn: #f5b74e;
  --danger: #ffb4b4;
  --danger-line: #5a2a2a;
  --bar-bg: linear-gradient(180deg, #121a33, #0d1426);
  --shadow-sm: none;
  --shadow-md: 0 6px 18px rgba(0, 0, 0, .35);
  --shadow-drawer: -8px 0 24px rgba(0, 0, 0, .4);
  --overlay: rgba(0, 0, 0, .35);
  --bubble-member: #16203a;
  --bubble-agent: #10283a;
  --bubble-agent-line: #1d4060;
  --subcase: #0d152a;
  --scroll-thumb: #22304f;
  --upcoming-opacity: .55;
  --s1: #6c8cff;
  --s2: #c77dff;
  --s3: #ffa14a;
  --s4: #37d39b;
  --s5: #ff7aa8;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

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

/* ---- single toolbar: wordmark + step tabs + current station's tools ---- */
.bar {
  display: flex; align-items: center; gap: 6px;
  padding: 0 16px; height: var(--bar-h); flex: 0 0 auto;
  background: var(--bar-bg);
  border-bottom: 1px solid var(--line);
}
.brand {
  flex: 0 0 auto; font-size: 18px; font-weight: 700; letter-spacing: -.01em;
  color: var(--text); white-space: nowrap; padding-right: 4px;
}
.brand + .run-title { border-left: 1px solid var(--line); padding-left: 12px; margin-left: 6px; }

.stepper { display: flex; gap: 4px; flex: 0 1 auto; overflow-x: auto; scrollbar-width: none; }
.stepper::-webkit-scrollbar { display: none; }
.step {
  display: flex; align-items: center; gap: 6px; flex: 0 0 auto;
  background: transparent; color: var(--muted);
  border: 1px solid transparent; border-radius: 8px;
  padding: 5px 10px; cursor: pointer; white-space: nowrap;
  font: inherit; font-size: 12.5px; transition: background .15s, color .15s, border-color .15s;
}
.step:hover { background: var(--hover); color: var(--text); }
.step.active { background: var(--hover); color: var(--text); border-color: var(--step-color, var(--accent)); }
.step .num {
  width: 18px; height: 18px; flex: 0 0 auto;
  display: grid; place-items: center; border-radius: 50%;
  background: var(--step-color, var(--accent)); color: var(--on-accent);
  font-weight: 700; font-size: 10.5px;
}

.bar-tools { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.bar-spacer { flex: 1 1 auto; }
.bar-link {
  background: var(--panel); color: var(--text); border: 1px solid var(--line-strong);
  border-radius: 8px; padding: 6px 12px; font: inherit; font-size: 13px; font-weight: 500; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.bar-link:hover { background: var(--hover); border-color: var(--accent); }
.bar-link.on { border-color: var(--step-color, var(--accent)); color: var(--text); }
.theme-toggle { padding: 6px 8px; }
.theme-toggle svg { width: 16px; height: 16px; display: block; }

/* Phone: the wordmark and the buttons keep their room; the crumb (also the page's own subject) gives way. */
@media (max-width: 600px) {
  .bar { padding: 0 10px; gap: 4px; }
  .brand { font-size: 16px; }
  .brand + .run-title { display: none; }
  /* The flow is a vertical list right below on a phone, so its step tabs only crowd the bar. */
  .stepper { display: none; }
  .bar-link { padding: 5px 8px; font-size: 12px; }
}

/* ---- page body: a plain scrollable column, centered, not a full-bleed stage
   (there's no iframe anymore — every station is a link that opens a new tab) ---- */
.page-root { flex: 1 1 auto; overflow-y: auto; padding: 24px 28px 60px; max-width: 900px; width: 100%; margin: 0 auto; }

.flow-intro { font-size: 13px; color: var(--muted); margin: 0 0 20px; line-height: 1.6; }

.station-list { display: flex; flex-direction: column; gap: 0; }
.flow-connector { display: flex; justify-content: center; color: var(--line-strong); font-size: 15px; margin: 2px 0; }
.station-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-sm);
  padding: 16px 20px; display: flex; align-items: center; gap: 16px;
}
.station-card .num {
  width: 30px; height: 30px; border-radius: 50%; flex: 0 0 auto;
  background: var(--step-color, var(--accent)); color: var(--on-accent);
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.station-card .info { flex: 1 1 auto; min-width: 0; }
.station-card .info h3 { margin: 0 0 3px; font-size: 14px; }
.station-card .info p { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.station-card .actions { display: flex; gap: 8px; flex-wrap: wrap; flex: 0 0 auto; }
.station-card .actions a {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 14px; font-size: 12.5px; text-decoration: none; white-space: nowrap;
}
.station-card .actions a.primary { background: var(--step-color, var(--accent)); color: var(--on-accent); font-weight: 600; border-color: transparent; }
.station-card .actions a:hover { filter: brightness(1.08); }

/* ---- event rail: an on-demand overlay drawer, not permanent layout space ---- */
.rail {
  position: fixed; top: var(--bar-h); right: 0; bottom: 0; width: min(360px, 90vw);
  display: flex; flex-direction: column; z-index: 60;
  background: var(--panel); border-left: 1px solid var(--line);
  transform: translateX(100%); transition: transform .2s ease;
  box-shadow: var(--shadow-drawer);
}
.rail.open { transform: translateX(0); }
.rail-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-bottom: 1px solid var(--line);
  font-size: 12px; font-weight: 600; letter-spacing: .3px;
}
.rail-status { font-size: 11px; color: var(--muted); font-weight: 500; }
.rail-status.ok { color: var(--ok); }
.rail-status.off { color: var(--warn); }
.rail-log { flex: 1 1 auto; overflow-y: auto; padding: 8px 10px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; }
.rail-line { padding: 5px 6px; border-bottom: 1px solid var(--line-soft); color: var(--muted); white-space: pre-wrap; word-break: break-word; }
.rail-line .ts { color: var(--faint); margin-right: 6px; }
.rail-line.evt { color: var(--text); }
.rail-line.sys { color: var(--accent); }
.rail-foot { margin: 0; padding: 8px 12px; font-size: 10.5px; color: var(--faint); border-top: 1px solid var(--line); }

.rail-log::-webkit-scrollbar { width: 9px; }
.rail-log::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 6px; }

/* ---- sign-in page ---- */
.login-page { flex: 1 1 auto; display: flex; align-items: center; justify-content: center; padding: 24px; position: relative; }
.login-page .theme-toggle { position: absolute; top: 16px; right: 16px; }
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-md);
  padding: 32px 28px; width: 100%; max-width: 360px;
}
.login-card h1 { margin: 0 0 4px; font-size: 18px; }
.login-card .sub { margin: 0 0 20px; font-size: 13px; color: var(--muted); }
.login-card input {
  width: 100%; background: var(--panel); border: 1px solid var(--line-strong); border-radius: 8px;
  color: var(--text); padding: 9px 12px; margin-bottom: 12px; font: inherit; font-size: 14px;
}
.login-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.login-card button[type="submit"] {
  width: 100%; background: var(--accent); color: var(--on-accent); font-weight: 600;
  border: none; border-radius: 8px; padding: 10px; cursor: pointer; font: inherit; font-size: 14px;
}
.login-card button[type="submit"]:disabled { opacity: .6; cursor: default; }
.login-error { color: var(--danger); font-size: 12.5px; margin: 0 0 12px; }
