*,*::before,*::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  /* Sonic core */
  --sonic-white: #F5F5F5;
  --sonic-black: #141416;
  --sonic-hero-orange: #FE9A4C;
  --sonic-hero-orange-deep: #ED5409;
  --sonic-hero-yellow: #FFCB67;
  --sonic-light-shade: #FFF3E5;
  --sonic-shade-01: #10283C;
  --sonic-shade-02: #506179;
  --sonic-shade-03: #214E81;

  /* Sonic gradient (259°, from style guide) */
  --sonic-gradient: linear-gradient(259deg, #214E81 0%, #506179 22.22%, #ED5409 65.15%, #FFCB67 100%);
  --sonic-gradient-45: linear-gradient(45deg, #214E81 0%, #506179 22.22%, #ED5409 65.15%, #FFCB67 100%);

  /* Surfaces */
  --bg-primary: #141416;
  --bg-secondary: #1a1a1d;
  --bg-tertiary: #202024;
  --bg-hover: #26262b;
  --bg-active: #2d2d33;
  --surface: #1a1a1d;
  --surface-hover: #242429;
  --border: #2a2a30;
  --border-light: #3a3a42;
  --border-strong: #4a4a54;

  /* Text */
  --text-primary: #F5F5F5;
  --text-secondary: #b8b8c0;
  --text-tertiary: #808088;

  /* Semantic aliases */
  --accent: var(--sonic-hero-orange);
  --accent-hover: var(--sonic-hero-yellow);
  --accent-dim: rgba(254,154,76,0.14);
  --accent-soft: rgba(254,154,76,0.08);
  --accent-blue: var(--sonic-shade-03);

  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;

  /* Radii & motion */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --sidebar-width: 268px;
  --header-height: 56px;
  --transition: 0.18s cubic-bezier(0.4,0,0.2,1);
  --transition-slow: 0.32s cubic-bezier(0.4,0,0.2,1);
}

@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;
  }
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: 'Urbanist', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

#app {
  height: 100vh;
  position: relative;
  isolation: isolate;
}

/* ─── Ambient background blobs (Sonic style) ─── */
.ambient-blobs {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
.ambient-blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.55;
  will-change: transform;
}
.ambient-blob-1 {
  width: 560px; height: 560px;
  top: -180px; left: -120px;
  background: radial-gradient(circle, rgba(33,78,129,0.55), transparent 70%);
}
.ambient-blob-2 {
  width: 480px; height: 480px;
  bottom: -160px; right: -120px;
  background: radial-gradient(circle, rgba(80,97,121,0.45), transparent 70%);
}
.ambient-blob-3 {
  width: 420px; height: 420px;
  top: 40%; right: 20%;
  background: radial-gradient(circle, rgba(16,40,60,0.6), transparent 70%);
}
@media (prefers-reduced-motion: no-preference) {
  .ambient-blob-1 { animation: blob-drift-a 28s ease-in-out infinite alternate; }
  .ambient-blob-2 { animation: blob-drift-b 34s ease-in-out infinite alternate; }
  .ambient-blob-3 { animation: blob-drift-c 40s ease-in-out infinite alternate; }
}
@keyframes blob-drift-a {
  from { transform: translate(0,0); }
  to   { transform: translate(60px, 40px); }
}
@keyframes blob-drift-b {
  from { transform: translate(0,0); }
  to   { transform: translate(-40px, -60px); }
}
@keyframes blob-drift-c {
  from { transform: translate(0,0); }
  to   { transform: translate(-50px, 30px); }
}

/* ─── LOGIN ─── */
#login-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
  padding: 24px;
}

.login-card {
  position: relative;
  text-align: center;
  padding: 44px 40px 40px;
  background: rgba(26,26,29,0.82);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-radius: var(--radius-lg);
  max-width: 400px;
  width: 100%;
  z-index: 1;
}
/* Glowing gradient hairline border */
.login-card::before {
  content: '';
  position: absolute;
  inset: 0;
  padding: 1.5px;
  border-radius: inherit;
  background: var(--sonic-gradient);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  pointer-events: none;
}
.login-card::after {
  content: '';
  position: absolute;
  inset: -30px;
  border-radius: 28px;
  background: var(--sonic-gradient);
  filter: blur(40px);
  opacity: 0.18;
  z-index: -1;
  pointer-events: none;
}

.login-logo {
  width: 64px;
  height: 64px;
  background: var(--sonic-gradient);
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 22px;
  color: white;
  box-shadow: 0 10px 30px rgba(254,154,76,0.22);
}
.login-logo svg { width: 30px; height: 30px; }

.login-card h1 {
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}
.login-tagline {
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
  letter-spacing: -0.005em;
}
.login-subtitle {
  color: var(--text-tertiary);
  font-size: 13px;
  margin-bottom: 28px;
}

.btn-google {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 11px 26px;
  background: white;
  color: #1f1f1f;
  text-decoration: none;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  letter-spacing: -0.005em;
  transition: box-shadow var(--transition), transform var(--transition);
}
.btn-google:hover {
  box-shadow: 0 10px 30px rgba(254,154,76,0.18), 0 2px 12px rgba(0,0,0,0.4);
  transform: translateY(-1px);
}

.login-error {
  margin: 0 0 18px;
  padding: 12px 14px;
  background: rgba(248,113,113,0.08);
  border: 1px solid rgba(248,113,113,0.3);
  border-radius: var(--radius-sm);
  color: #fecaca;
  font-size: 13px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.login-error.hidden { display: none; }
.login-error-title {
  font-weight: 700;
  font-size: 13.5px;
  letter-spacing: -0.005em;
  color: #fee2e2;
}
.login-error-title:empty { display: none; }
.login-error-msg {
  color: #fecaca;
  line-height: 1.45;
}
.login-error-msg:empty { display: none; }
.login-error-network {
  background: rgba(251,191,36,0.08);
  border-color: rgba(251,191,36,0.32);
  color: #fde68a;
}
.login-error-network .login-error-title { color: #fef3c7; }
.login-error-network .login-error-msg { color: #fde68a; }
.login-error-server {
  background: rgba(248,113,113,0.08);
  border-color: rgba(248,113,113,0.3);
  color: #fecaca;
}
.login-retry-btn {
  align-self: flex-start;
  margin-top: 4px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font: 600 12.5px/1 inherit;
  letter-spacing: -0.005em;
  color: var(--text-primary);
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
}
.login-retry-btn:hover:not(:disabled) {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.24);
}
.login-retry-btn:active:not(:disabled) { transform: scale(0.97); }
.login-retry-btn:disabled { opacity: 0.7; cursor: not-allowed; }
.login-retry-btn.loading .login-retry-icon {
  animation: login-retry-spin 0.9s linear infinite;
}
@keyframes login-retry-spin {
  to { transform: rotate(360deg); }
}

/* ─── CHAT LAYOUT ─── */
#chat-app {
  display: flex;
  height: 100vh;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

/* ─── SIDEBAR ─── */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: rgba(20,20,22,0.78);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  display: flex;
  flex-direction: column;
  transition: margin-left var(--transition-slow), opacity var(--transition);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

#sidebar.collapsed {
  margin-left: calc(-1 * var(--sidebar-width));
  opacity: 0;
  pointer-events: none;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  height: var(--header-height);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition), transform var(--transition);
  flex-shrink: 0;
  text-decoration: none;
  font-family: inherit;
}
.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.icon-btn:active { transform: scale(0.96); }

/* New Chat button with gradient-border hover */
#new-chat-btn {
  position: relative;
}
#new-chat-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: var(--sonic-gradient);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  opacity: 0;
  transition: opacity var(--transition);
  pointer-events: none;
}
#new-chat-btn:hover::before { opacity: 1; }
#new-chat-btn:hover { background: transparent; color: var(--text-primary); }

#mode-tabs {
  display: flex;
  gap: 2px;
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
  position: relative;
}
.mode-tab {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  font: 600 12px/1.2 inherit;
  letter-spacing: -0.005em;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.mode-tab:hover { background: var(--bg-hover); color: var(--text-secondary); }
.mode-tab.active { color: var(--text-primary); }
.mode-tab.active::after {
  content: '';
  position: absolute;
  left: 16%;
  right: 16%;
  bottom: -10px;
  height: 2px;
  border-radius: 2px;
  background: var(--sonic-gradient);
}
.mode-tab svg { flex-shrink: 0; }
.mode-tab .wizard-tab-icon { display: inline-flex; align-items: center; justify-content: center; }

.chat-list-empty {
  padding: 14px 12px;
  font-size: 12.5px;
  color: var(--text-tertiary);
  text-align: left;
  line-height: 1.5;
}

#chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.chat-item-icon {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

.chat-item {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  letter-spacing: -0.005em;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
  position: relative;
  min-height: 36px;
}
.chat-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.chat-item.active {
  background: var(--bg-active);
  color: var(--text-primary);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.04), inset 2px 0 0 0 var(--accent);
}
.chat-item-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.4;
}
.chat-item-delete {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 4px;
  font-size: 14px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity var(--transition), color var(--transition);
}
.chat-item:hover .chat-item-delete,
.chat-item.active .chat-item-delete { opacity: 1; }
.chat-item-delete:hover { color: var(--err); }

.chat-item-status {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-tertiary);
  display: inline-block;
}
.chat-item-status.running {
  background: var(--warn);
  box-shadow: 0 0 0 0 rgba(251,191,36,0.6);
  animation: pulse-ring 1.6s infinite ease-out;
}
.chat-item-status.finished { background: var(--ok); }
.chat-item-status.error { background: var(--err); }
.chat-item-status.stopped,
.chat-item-status.idle { background: var(--text-tertiary); }

/* "Recent jobs" header — only visible on wizard tabs. Lives between the
   mode-tab row and the chat list, with a literal "+ New job" button so
   users see the job-submission affordance even before they scan the
   sidebar's icon column. */
.wizard-jobs-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
}
body.wizard-tab-active .wizard-jobs-header {
  display: flex;
}
.wizard-jobs-header-title {
  font-weight: 600;
}
.wizard-jobs-new-btn {
  background: none;
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: none;
  padding: 3px 9px;
  border-radius: 999px;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
}
.wizard-jobs-new-btn:hover {
  color: var(--text-primary);
  border-color: var(--accent);
  background: rgba(255,255,255,0.04);
}

/* Wizard tab "Recent jobs" rows: stacked layout with status pill on top,
   prompt title in the middle, and branch + relative time at the bottom. */
.chat-item.job-row {
  display: block;
  padding: 10px 12px;
  min-height: 0;
}
.chat-item.job-row .job-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.chat-item.job-row .job-row-title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 13px;
  line-height: 1.35;
  color: var(--text-primary);
  word-break: break-word;
}
.chat-item.job-row .job-row-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  min-height: 16px;
}
.job-row-status {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: rgba(255,255,255,0.06);
  color: var(--text-secondary);
  border: 1px solid rgba(255,255,255,0.08);
}
.job-row-status.wizard-status-running {
  background: rgba(251,191,36,0.12);
  border-color: rgba(251,191,36,0.35);
  color: #fbbf24;
}
.job-row-status.wizard-status-finished {
  background: rgba(34,197,94,0.12);
  border-color: rgba(34,197,94,0.35);
  color: #4ade80;
}
.job-row-status.wizard-status-error {
  background: rgba(248,113,113,0.12);
  border-color: rgba(248,113,113,0.35);
  color: #fca5a5;
}
.job-row-status.wizard-status-cancelled {
  background: rgba(148,163,184,0.12);
  border-color: rgba(148,163,184,0.3);
  color: #cbd5e1;
}
.job-row-branch {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-tertiary);
  text-decoration: none;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 999px;
  padding: 1px 7px 1px 6px;
  max-width: 60%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  transition: color var(--transition), border-color var(--transition);
}
.job-row-branch span {
  overflow: hidden;
  text-overflow: ellipsis;
}
.job-row-branch:hover {
  color: var(--accent);
  border-color: var(--accent);
}
.job-row-time {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-tertiary);
  white-space: nowrap;
}

.chat-item-branch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 4px;
  border-radius: 4px;
  color: var(--text-tertiary);
  text-decoration: none;
  opacity: 0;
  transition: opacity var(--transition), color var(--transition), background var(--transition);
}
.chat-item:hover .chat-item-branch,
.chat-item.active .chat-item-branch { opacity: 1; }
.chat-item-branch:hover { color: var(--text-primary); background: var(--bg-hover); }

.sidebar-bottom {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  padding: 4px 8px 4px 4px;
  border-radius: 999px;
  transition: background var(--transition);
}
.user-pill:hover { background: var(--bg-hover); }
.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(254,154,76,0.25);
}
.user-name-text {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-icon { color: var(--text-tertiary); }
.logout-icon:hover { color: var(--text-primary); }

/* ─── MAIN CHAT AREA ─── */
#chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: transparent;
  position: relative;
}

#chat-header {
  height: var(--header-height);
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* ─── Custom model dropdown ─── */
.model-selector-wrapper { position: relative; }

#model-select {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 1px;
  height: 1px;
}

.model-dropdown-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  color: var(--text-primary);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 6px 10px 6px 12px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  letter-spacing: -0.005em;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}
.model-dropdown-btn:hover { background: var(--bg-hover); }
.model-dropdown-btn[aria-expanded="true"] {
  background: var(--bg-hover);
  border-color: var(--border-light);
}
.model-dropdown-btn .chev {
  transition: transform var(--transition);
  opacity: 0.7;
}
.model-dropdown-btn[aria-expanded="true"] .chev { transform: rotate(180deg); }

.model-dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 220px;
  background: rgba(26,26,29,0.96);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  z-index: 50;
  display: none;
  flex-direction: column;
  gap: 2px;
}
.model-dropdown-menu.open { display: flex; }
.model-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border: none;
  background: transparent;
  text-align: left;
  font-family: inherit;
  width: 100%;
  transition: background var(--transition), color var(--transition);
}
.model-option:hover { background: var(--bg-hover); color: var(--text-primary); }
.model-option[aria-selected="true"] { background: var(--accent-dim); color: var(--text-primary); }
.model-option .check {
  margin-left: auto;
  opacity: 0;
  color: var(--accent);
}
.model-option[aria-selected="true"] .check { opacity: 1; }

#wizard-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: 4px;
  min-width: 0;
  flex-wrap: wrap;
}
.wizard-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px 6px 8px;
  background: rgba(26,26,29,0.9);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--text-primary);
  white-space: nowrap;
  position: relative;
}
.wizard-pill::before {
  content: '';
  position: absolute;
  inset: 0;
  padding: 1px;
  border-radius: inherit;
  background: var(--sonic-gradient);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  pointer-events: none;
}
.wizard-pill-icon { display: inline-flex; }

.wizard-status-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-secondary);
}
.wizard-status-chip a { color: var(--accent); text-decoration: none; }
.wizard-status-chip a:hover { text-decoration: underline; }
.wizard-status-chip .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-tertiary);
}
.wizard-status-chip.running .dot {
  background: var(--warn);
  animation: pulse-ring 1.6s infinite ease-out;
}
.wizard-status-chip.running { border-color: rgba(251,191,36,0.4); color: #fde68a; }
.wizard-status-chip.finished .dot { background: var(--ok); }
.wizard-status-chip.finished { border-color: rgba(52,211,153,0.4); color: #a7f3d0; }
.wizard-status-chip.error .dot { background: var(--err); }
.wizard-status-chip.error { border-color: rgba(248,113,113,0.4); color: #fecaca; }

/* ─── WIZARD EMAIL-IN-FLIGHT NOTICE ─── */
/* Shown inside the streaming assistant bubble while a wizard turn is
   running. Replaced by the email-status pill once the turn finishes. */
.wizard-email-notice {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0 10px;
  padding: 6px 10px;
  background: rgba(254,154,76,0.08);
  border: 1px solid rgba(254,154,76,0.25);
  border-radius: var(--radius-sm);
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-secondary);
  max-width: fit-content;
}
.wizard-email-notice-icon {
  flex-shrink: 0;
  color: var(--sonic-hero-orange);
}

/* ─── SUBMIT-A-JOB VIEW (wizard tabs welcome) ───
   Wizard tabs reframe each chat as a one-shot job: this view shows the
   inline composer (submit + suggestions) instead of relying on the bottom
   chat composer (which is hidden on wizard tabs). */
.submit-job-view .submit-job-form {
  width: 100%;
  max-width: 720px;
  margin: 8px auto 4px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: 0 1px 0 rgba(255,255,255,0.03) inset, 0 1px 4px rgba(0,0,0,0.18);
}
.submit-job-textarea {
  width: 100%;
  min-height: 96px;
  max-height: 320px;
  resize: vertical;
  padding: 10px 12px;
  background: var(--bg-input, var(--bg-base));
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 14px;
  line-height: 1.5;
  outline: none;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.submit-job-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(254,154,76,0.18);
}
.submit-job-textarea[disabled] {
  opacity: .6;
  cursor: not-allowed;
}
.submit-job-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.submit-job-hint {
  font-size: 11px;
  color: var(--text-muted);
}
.submit-job-btn {
  background: var(--accent);
  color: #1a0f06;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: filter .12s ease, transform .04s ease;
}
.submit-job-btn:hover:not(:disabled) { filter: brightness(1.05); }
.submit-job-btn:active:not(:disabled) { transform: translateY(1px); }
.submit-job-btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}
.submit-job-suggestions-label {
  margin: 18px auto 8px;
  width: 100%;
  max-width: 720px;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.submit-job-suggestions {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
}
.submit-job-suggestions .suggestion-card {
  text-align: left;
  font: inherit;
  cursor: pointer;
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

/* When the wizard tab is active, the bottom composer is hidden entirely;
   give the messages area a bit more breathing room at the bottom so the
   "Run another job" button isn't hugging the viewport edge. Also hide the
   page-header status chip — its info is now in the job-detail strip. */
body.wizard-tab-active #messages {
  padding-bottom: 24px;
}
body.wizard-tab-active #wizard-status-chip {
  display: none !important;
}

/* ─── JOB DETAIL VIEW (wizard chat surface) ───
   Replaces the bubble thread for wizard chats. Shows the prompt as a
   title, status + email + branch in one strip, the activity log + summary
   in the body, and a "Run another job" button at the foot. */
.job-detail {
  width: 100%;
  max-width: 880px;
  margin: 24px auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.job-header {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.job-header-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.job-kind-badge {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
}
.job-title {
  margin: 0;
  font-size: 22px;
  line-height: 1.3;
  font-weight: 600;
  color: var(--text-primary);
  word-break: break-word;
  flex: 1 1 auto;
}
.job-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-muted);
}
.job-meta-sep { opacity: .6; }
.job-status-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-height: 24px;
}
.job-status-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.03);
  color: var(--text-secondary);
}
.job-status-chip.wizard-status-running {
  border-color: rgba(251,191,36,0.4);
  color: #fde68a;
  background: rgba(251,191,36,0.08);
}
.job-status-chip.wizard-status-finished {
  border-color: rgba(52,211,153,0.4);
  color: #a7f3d0;
  background: rgba(52,211,153,0.08);
}
.job-status-chip.wizard-status-error {
  border-color: rgba(248,113,113,0.4);
  color: #fecaca;
  background: rgba(248,113,113,0.08);
}
.job-status-chip.wizard-status-cancelled {
  border-color: rgba(148,163,184,0.4);
  color: #cbd5e1;
  background: rgba(148,163,184,0.08);
}
.job-branch-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.03);
  color: var(--text-secondary);
  text-decoration: none;
}
.job-branch-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.job-status-strip .wizard-email-notice,
.job-status-strip .job-email-notice {
  margin: 0;
}
.job-stop-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid rgba(248,113,113,0.4);
  background: rgba(248,113,113,0.08);
  color: #fecaca;
  cursor: pointer;
  transition: background-color .12s ease, border-color .12s ease;
}
.job-stop-btn:hover {
  background: rgba(248,113,113,0.16);
  border-color: rgba(248,113,113,0.6);
}
.job-stop-btn:active { transform: translateY(1px); }
.job-prompt {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}
.job-prompt > summary {
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  user-select: none;
}
.job-prompt > summary::-webkit-details-marker { display: none; }
.job-prompt > summary::before {
  content: '▸';
  font-size: 10px;
  transition: transform .12s ease;
}
.job-prompt[open] > summary::before { transform: rotate(90deg); }
.job-prompt-text {
  margin: 8px 0 0;
  padding: 10px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13px;
  color: var(--text-primary);
  font-family: inherit;
}
.job-body {
  display: flex;
  flex-direction: column;
}
/* Strip the avatar/sender chrome from the assistant bubble used inside the
   job detail. The body becomes a simple summary panel. */
.job-summary-message {
  display: block;
  padding: 0;
  margin: 0;
  background: transparent;
}
.job-summary-message .message-avatar { display: none; }
.job-summary-body {
  margin: 0;
  padding: 0;
  background: transparent;
  border: 0;
  width: 100%;
  max-width: none;
}
.job-summary-body .message-content {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-primary);
}
.job-footer {
  display: flex;
  justify-content: flex-start;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}
.run-another-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #1a0f06;
  border: 0;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: filter .12s ease, transform .04s ease;
}
.run-another-btn:hover { filter: brightness(1.05); }
.run-another-btn:active { transform: translateY(1px); }

/* ─── WIZARD LOGO (sonic orb + wizard hat) ─── */
.wizard-logo {
  position: relative;
  display: inline-block;
  width: var(--wlogo-size, 16px);
  height: var(--wlogo-size, 16px);
  flex-shrink: 0;
  vertical-align: middle;
}
.wizard-logo-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: block;
  object-fit: cover;
  background: white;
}
.wizard-logo-hat {
  position: absolute;
  width: 78%;
  height: 78%;
  top: -38%;
  left: 11%;
  pointer-events: none;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.45));
  transform: rotate(-12deg);
  transform-origin: 50% 100%;
}

.welcome-logo-wizard {
  background: transparent !important;
  width: auto !important;
  height: auto !important;
  margin-bottom: 28px;
  box-shadow: none !important;
}
.welcome-logo-wizard .wizard-logo {
  width: 96px;
  height: 96px;
}

.message-avatar.wizard-assistant-avatar {
  background: #1a0b3a;
  padding: 0;
  overflow: visible;
}
.message-avatar.wizard-assistant-avatar .wizard-logo {
  width: 24px;
  height: 24px;
}

/* ─── FLYING TULIP WIZARD VARIANTS ─── */
/* Mirrors of the Sonic Wizard rules, themed pink/magenta to distinguish
   the Flying Tulip kind. Sidebar tab + header pill + welcome logo +
   message-bubble avatar. The base `.wizard-logo` rules above already
   handle the orb sizing — `.tulip-logo-bloom` just nudges the bloom into
   place and `.tulip-pill` swaps the gradient border. */
.mode-tab .tulip-tab-icon { display: inline-flex; align-items: center; justify-content: center; }

.wizard-pill.tulip-pill::before {
  background: linear-gradient(135deg, #ec4899 0%, #f472b6 50%, #34d399 100%);
}

.tulip-logo-bloom {
  /* The tulip motif sits more upright than the wizard hat; remove the
     hat tilt so the bloom rises straight off the orb. */
  transform: rotate(0deg);
  width: 86%;
  height: 86%;
  top: -42%;
  left: 7%;
}

.welcome-logo-tulip {
  background: transparent !important;
  width: auto !important;
  height: auto !important;
  margin-bottom: 28px;
  box-shadow: none !important;
}
.welcome-logo-tulip .wizard-logo {
  width: 96px;
  height: 96px;
}

.message-avatar.tulip-assistant-avatar {
  background: #4a044e;
  padding: 0;
  overflow: visible;
}
.message-avatar.tulip-assistant-avatar .wizard-logo {
  width: 24px;
  height: 24px;
}

.wizard-warning {
  margin: 8px auto 16px;
  padding: 10px 14px;
  background: rgba(248,113,113,0.08);
  border: 1px solid rgba(248,113,113,0.3);
  border-radius: var(--radius-sm);
  color: #fecaca;
  font-size: 13px;
  max-width: 540px;
}

/* ─── MESSAGES ─── */
#messages-container {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
  position: relative;
}

#messages {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px 24px 120px;
  width: 100%;
}

/* ─── WELCOME SCREEN ─── */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - var(--header-height) - 180px);
  text-align: center;
  padding: 40px 20px;
}

.welcome-logo {
  width: 56px;
  height: 56px;
  background: var(--sonic-gradient);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 22px;
  box-shadow: 0 12px 34px rgba(254,154,76,0.22);
}

.welcome-logo svg {
  width: 26px;
  height: 26px;
  color: white;
}

.welcome h1 {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 8px;
  background: linear-gradient(180deg, #fff, #d4d4dc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome p {
  font-size: 15px;
  color: var(--text-tertiary);
  margin-bottom: 32px;
  letter-spacing: -0.005em;
}

.suggestions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-width: 580px;
  width: 100%;
}

.suggestion-card {
  text-align: left;
  padding: 14px 16px;
  background: rgba(26,26,29,0.75);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  letter-spacing: -0.005em;
}
.suggestion-card:hover {
  background: var(--bg-tertiary);
  border-color: var(--border-light);
  color: var(--text-primary);
  transform: translateY(-1px);
}

/* ─── MESSAGE BUBBLES ─── */
.message {
  display: flex;
  gap: 16px;
  padding: 20px 0;
}
.message + .message {
  border-top: 1px solid rgba(255,255,255,0.04);
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  margin-top: 2px;
}

.message-avatar.user-avatar-msg {
  background: var(--accent-dim);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(254,154,76,0.25);
}

.message-avatar.assistant-avatar-msg {
  background: var(--sonic-gradient);
  color: white;
  font-size: 12px;
  box-shadow: 0 6px 16px rgba(254,154,76,0.22);
}

.message-avatar.assistant-avatar-msg svg {
  width: 16px;
  height: 16px;
}

.message-body {
  flex: 1;
  min-width: 0;
}

.message-sender {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -0.005em;
  margin-bottom: 6px;
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.email-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.4;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: default;
  user-select: none;
}
.email-pill::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-tertiary);
  flex-shrink: 0;
}
.email-pill-sent {
  border-color: rgba(52, 211, 153, 0.4);
  background: rgba(52, 211, 153, 0.10);
  color: #a7f3d0;
}
.email-pill-sent::before { background: var(--ok); }
.email-pill-failed {
  border-color: rgba(248, 113, 113, 0.45);
  background: rgba(248, 113, 113, 0.10);
  color: #fecaca;
  cursor: pointer;
  font-family: inherit;
}
button.email-pill-failed { padding: 2px 8px; }
.email-pill-failed:hover {
  background: rgba(248, 113, 113, 0.18);
  border-color: rgba(248, 113, 113, 0.6);
}
.email-pill-failed:focus-visible {
  outline: 2px solid rgba(248, 113, 113, 0.7);
  outline-offset: 2px;
}
.email-pill-failed::before { background: var(--err); }

.email-pill-failed-wrap {
  position: relative;
  display: inline-flex;
}
.email-failure-popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 50;
  min-width: 260px;
  max-width: min(420px, 90vw);
  background: var(--bg-secondary, #1b1b1f);
  border: 1px solid rgba(248, 113, 113, 0.45);
  border-radius: 8px;
  padding: 10px 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  color: var(--text-primary);
  font-size: 12.5px;
  line-height: 1.45;
}
.email-failure-popover[hidden] { display: none; }
.email-failure-popover:focus { outline: none; }
.email-failure-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.email-failure-title {
  font-weight: 600;
  color: #fecaca;
  font-size: 12.5px;
}
.email-failure-close {
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
}
.email-failure-close:hover { color: var(--text-primary); background: rgba(255,255,255,0.06); }
.email-failure-close:focus-visible { outline: 2px solid rgba(248, 113, 113, 0.7); outline-offset: 1px; }
.email-failure-row {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}
.email-failure-row-stack { flex-direction: column; gap: 2px; }
.email-failure-label {
  color: var(--text-tertiary);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.email-failure-value {
  color: var(--text-primary);
  word-break: break-all;
}
.email-failure-reason {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 220px;
  overflow: auto;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--text-primary);
}
@media (max-width: 540px) {
  .email-failure-popover { min-width: 220px; max-width: 86vw; }
}
.email-pill-skipped {
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-tertiary);
}

.message-content {
  font-size: 14.5px;
  line-height: 1.7;
  color: var(--text-primary);
  word-wrap: break-word;
  overflow-wrap: break-word;
  letter-spacing: -0.005em;
}

.message-content p { margin-bottom: 10px; }
.message-content p:last-child { margin-bottom: 0; }

.message-content code {
  background: rgba(80,97,121,0.18);
  color: #ffd4a8;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: ui-monospace, 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

.message-content pre {
  background: #0e1a26;
  border-radius: var(--radius-md);
  margin: 14px 0;
  overflow: hidden;
  border: 1px solid rgba(80,97,121,0.3);
}

.message-content pre .code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: rgba(16,40,60,0.6);
  border-bottom: 1px solid rgba(80,97,121,0.25);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-tertiary);
  letter-spacing: 0;
}

.message-content pre .copy-btn {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 4px;
  font-family: inherit;
  font-weight: 600;
  transition: color var(--transition), background var(--transition);
}
.message-content pre .copy-btn:hover { color: var(--text-primary); background: rgba(255,255,255,0.06); }

.message-content pre code {
  display: block;
  padding: 14px 16px;
  overflow-x: auto;
  background: none;
  border-radius: 0;
  font-size: 13px;
  line-height: 1.6;
  color: #e7eef6;
}

.message-content ul, .message-content ol {
  margin: 8px 0;
  padding-left: 22px;
}
.message-content li { margin-bottom: 4px; }

.message-content blockquote {
  border-left: 3px solid var(--sonic-shade-02);
  padding: 4px 14px;
  color: var(--text-secondary);
  margin: 12px 0;
  font-style: italic;
  background: rgba(80,97,121,0.08);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.message-content table { border-collapse: collapse; margin: 12px 0; width: 100%; font-size: 13px; }
.message-content th, .message-content td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.message-content th { background: var(--bg-tertiary); font-weight: 600; }
.message-content a {
  color: var(--sonic-hero-orange);
  text-decoration: none;
  border-bottom: 1px solid rgba(254,154,76,0.3);
  transition: color var(--transition), border-color var(--transition);
}
.message-content a:hover {
  color: var(--sonic-hero-yellow);
  border-bottom-color: var(--sonic-hero-yellow);
}

/* ─── REASONING BLOCKS ─── */
.reasoning-container:empty { display: none; }

.reasoning-block {
  margin-bottom: 12px;
  border: 1px solid rgba(254,154,76,0.18);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: rgba(254, 154, 76, 0.04);
}

.reasoning-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  list-style: none;
  user-select: none;
  transition: background var(--transition);
}

.reasoning-toggle::-webkit-details-marker { display: none; }
.reasoning-toggle::marker { display: none; content: ''; }

.reasoning-toggle:hover {
  background: rgba(254, 154, 76, 0.08);
}

.reasoning-icon { flex-shrink: 0; opacity: 0.9; }
.reasoning-label { flex: 1; }
.reasoning-chevron { flex-shrink: 0; transition: transform var(--transition); }

details.reasoning-block[open] .reasoning-chevron { transform: rotate(180deg); }

.reasoning-content {
  padding: 10px 14px 12px;
  font-size: 13px;
  line-height: 1.65;
  color: var(--text-secondary);
  border-top: 1px solid rgba(254,154,76,0.15);
  max-height: 400px;
  overflow-y: auto;
}

.reasoning-content p { margin-bottom: 6px; }
.reasoning-content p:last-child { margin-bottom: 0; }
.reasoning-content code {
  background: var(--bg-tertiary);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 12px;
}

.streaming-dot::after {
  content: '';
  display: inline-block;
  width: 8px;
  height: 14px;
  background: var(--accent);
  border-radius: 2px;
  margin-left: 4px;
  animation: streaming-blink 1s ease-in-out infinite;
  vertical-align: text-bottom;
  box-shadow: 0 0 12px rgba(254,154,76,0.5);
}

@keyframes streaming-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; }
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1); }
}
@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 rgba(251,191,36,0.55); }
  70% { box-shadow: 0 0 0 6px rgba(251,191,36,0); }
  100% { box-shadow: 0 0 0 0 rgba(251,191,36,0); }
}

/* ─── Scroll to latest ─── */
.scroll-to-latest {
  position: absolute;
  bottom: 118px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: rgba(26,26,29,0.92);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: -0.005em;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition), transform var(--transition), background var(--transition);
  z-index: 5;
  box-shadow: 0 10px 24px rgba(0,0,0,0.35);
  font-family: inherit;
}
.scroll-to-latest.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}
.scroll-to-latest:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}
.scroll-to-latest svg { width: 14px; height: 14px; }

/* ─── INPUT AREA ─── */
#input-area {
  padding: 0 24px 20px;
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
  position: relative;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
}

#input-box {
  position: relative;
  display: flex;
  align-items: flex-end;
  background: rgba(26,26,29,0.9);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 6px 6px 6px 20px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
#input-box:focus-within {
  border-color: rgba(254,154,76,0.45);
  box-shadow: 0 0 0 3px rgba(254,154,76,0.12), 0 10px 30px rgba(0,0,0,0.3);
}

#message-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 14.5px;
  resize: none;
  outline: none;
  max-height: 200px;
  padding: 10px 0;
  font-family: inherit;
  line-height: 1.5;
  letter-spacing: -0.005em;
}
#message-input::placeholder { color: var(--text-tertiary); }

.input-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-bottom: 2px;
}

#send-btn, #stop-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), transform var(--transition), opacity var(--transition), box-shadow var(--transition);
  font-family: inherit;
  position: relative;
}

#send-btn {
  background: var(--sonic-hero-orange);
  color: #1a1a1d;
}
#send-btn:hover:not(:disabled) {
  background: var(--sonic-hero-yellow);
  transform: scale(1.05);
  box-shadow: 0 8px 18px rgba(254,154,76,0.35);
}
#send-btn:disabled { opacity: 0.3; cursor: default; transform: none; }

#stop-btn {
  background: var(--bg-hover);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
}
#stop-btn:hover { background: var(--bg-active); border-color: var(--accent); }
#stop-btn .stop-spinner {
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: var(--accent);
  animation: activity-spin 0.8s linear infinite;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
#stop-btn.stopping .stop-spinner { opacity: 1; }
#stop-btn.stopping svg { opacity: 0.3; }

.input-footer {
  text-align: center;
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 8px;
  letter-spacing: 0;
}
.input-footer kbd {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  font-family: ui-monospace, monospace;
  font-size: 10.5px;
  color: var(--text-secondary);
}

/* ─── Retry from here ─── */
.retry-from-here {
  margin-top: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: rgba(254,154,76,0.1);
  border: 1px solid rgba(254,154,76,0.3);
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 600;
  font-family: inherit;
  letter-spacing: -0.005em;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}
.retry-from-here:hover {
  background: rgba(254,154,76,0.18);
  border-color: var(--accent);
}
.retry-from-here svg { width: 13px; height: 13px; }

/* ─── Toast system ─── */
#toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1000;
  max-width: calc(100vw - 32px);
  width: 360px;
  pointer-events: none;
}
.toast {
  position: relative;
  pointer-events: auto;
  padding: 12px 14px 12px 16px;
  border-radius: var(--radius-md);
  background: rgba(26,26,29,0.96);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border-light);
  box-shadow: 0 14px 40px rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13.5px;
  letter-spacing: -0.005em;
  color: var(--text-primary);
  animation: toast-in 0.24s cubic-bezier(0.16,1,0.3,1);
  overflow: hidden;
}
.toast.toast-leaving { animation: toast-out 0.2s cubic-bezier(0.4,0,0.2,1) forwards; }
.toast-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}
.toast-body { flex: 1; min-width: 0; line-height: 1.45; }
.toast-title { font-weight: 700; margin-bottom: 2px; }
.toast-msg { font-size: 12.5px; color: var(--text-secondary); }
.toast-action {
  margin-top: 6px;
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  font-family: inherit;
  letter-spacing: -0.005em;
  transition: background var(--transition);
}
.toast-action:hover { background: rgba(255,255,255,0.12); }
.toast-close {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
  transition: color var(--transition);
  font-family: inherit;
}
.toast-close:hover { color: var(--text-primary); }
.toast.info    { border-color: rgba(80,97,121,0.5); }
.toast.success { border-color: rgba(52,211,153,0.45); }
.toast.warn    { border-color: rgba(251,191,36,0.45); }
.toast.error   { border-color: rgba(248,113,113,0.5); }
.toast.info    .toast-icon { color: var(--sonic-shade-02); }
.toast.success .toast-icon { color: var(--ok); }
.toast.warn    .toast-icon { color: var(--warn); }
.toast.error   .toast-icon { color: var(--err); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(16px); }
}

/* ─── Connection status indicator ─── */
#connection-status {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%) translateY(-60px);
  background: rgba(248,113,113,0.12);
  border: 1px solid rgba(248,113,113,0.5);
  color: #fecaca;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: -0.005em;
  z-index: 999;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: transform var(--transition-slow), background var(--transition), border-color var(--transition), color var(--transition);
  pointer-events: none;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
#connection-status.show { transform: translateX(-50%) translateY(0); }
#connection-status.reconnected {
  background: rgba(52,211,153,0.12);
  border-color: rgba(52,211,153,0.5);
  color: #a7f3d0;
}
#connection-status .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--err);
  animation: pulse 1.4s ease-in-out infinite;
}
#connection-status.reconnected .dot { background: var(--ok); animation: none; }

/* ─── SCROLLBAR ─── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.18); }

/* ─── Sidebar mobile scrim ─── */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(2px);
  z-index: 99;
  opacity: 0;
  transition: opacity var(--transition);
  pointer-events: none;
}
.sidebar-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

/* ─── RESPONSIVE ─── */
@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    z-index: 100;
    height: 100vh;
    left: 0;
    top: 0;
    box-shadow: 24px 0 60px rgba(0,0,0,0.5);
  }
  #sidebar.collapsed {
    margin-left: calc(-1 * var(--sidebar-width));
    opacity: 1;
  }
  .suggestions { grid-template-columns: 1fr; }
  #messages { padding: 12px 16px 120px; }
  #input-area { padding: 0 12px 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
  .message { gap: 10px; }
  #toast-container { top: 10px; right: 10px; left: 10px; width: auto; }
}

/* ─── Wizard activity log (timeline) ───────────────────────── */
.activity-log {
  position: relative;
  margin: 10px 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(80,97,121,0.06);
  overflow: hidden;
  font-size: 13px;
}
.activity-log[open] { background: rgba(80,97,121,0.10); }
.activity-summary {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 14px;
  cursor: pointer;
  user-select: none;
  list-style: none;
  color: var(--text-secondary);
  font-weight: 600;
  letter-spacing: -0.005em;
}
.activity-summary::-webkit-details-marker { display: none; }
.activity-summary::marker { display: none; content: ''; }
.activity-summary:hover { background: rgba(255,255,255,0.03); }
.activity-label { flex: 0 0 auto; }
.activity-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 20px;
  padding: 0 7px;
  border-radius: 10px;
  background: rgba(254,154,76,0.15);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.activity-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-left: 8px;
}
.activity-filter-chip {
  appearance: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-tertiary);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  cursor: pointer;
  line-height: 1.4;
  letter-spacing: -0.005em;
  font-family: inherit;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.activity-filter-chip:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text-secondary);
}
.activity-filter-chip.on {
  background: rgba(254,154,76,0.12);
  border-color: rgba(254,154,76,0.4);
  color: var(--accent);
}
.activity-log.hide-file    .activity-entry[data-category="file"],
.activity-log.hide-tool    .activity-entry[data-category="tool"],
.activity-log.hide-commit  .activity-entry[data-category="commit"],
.activity-log.hide-command .activity-entry[data-category="command"],
.activity-log.hide-thinking .activity-entry[data-category="thinking"],
.activity-log.hide-status  .activity-entry[data-category="status"],
.activity-log.hide-other   .activity-entry[data-category="other"] {
  display: none;
}
.activity-group-count {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 9px;
  background: rgba(254,154,76,0.18);
  color: var(--accent);
  font-size: 10.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.activity-chevron {
  margin-left: auto;
  transition: transform var(--transition);
  opacity: 0.7;
}
.activity-log[open] .activity-chevron { transform: rotate(180deg); }
.activity-spinner {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(254,154,76,0.25);
  border-top-color: var(--accent);
  animation: activity-spin 0.8s linear infinite;
  flex: 0 0 auto;
}
.activity-log-done .activity-spinner { display: none; }
@keyframes activity-spin { to { transform: rotate(360deg); } }

.activity-entries {
  max-height: 280px;
  overflow-y: auto;
  padding: 6px 0;
  border-top: 1px solid var(--border);
  position: relative;
}
/* Timeline rail */
.activity-entries::before {
  content: '';
  position: absolute;
  left: 22px;
  top: 8px;
  bottom: 8px;
  width: 1px;
  background: linear-gradient(180deg, transparent, rgba(254,154,76,0.35), rgba(33,78,129,0.35), transparent);
  pointer-events: none;
}
.activity-entry {
  position: relative;
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 10px;
  align-items: baseline;
  padding: 7px 14px 7px 34px;
  font-size: 12.5px;
  line-height: 1.45;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.activity-entry::before {
  content: '';
  position: absolute;
  left: 18px;
  top: 12px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--bg-secondary);
  border: 2px solid var(--sonic-shade-02);
}
.activity-entry[data-category="file"]::before    { border-color: var(--sonic-hero-orange); }
.activity-entry[data-category="tool"]::before    { border-color: var(--sonic-shade-03); }
.activity-entry[data-category="commit"]::before  { border-color: var(--ok); }
.activity-entry[data-category="command"]::before { border-color: var(--sonic-hero-yellow); }
.activity-entry[data-category="thinking"]::before{ border-color: var(--sonic-shade-02); }
.activity-entry[data-category="status"]::before  { border-color: var(--text-tertiary); }
.activity-entry:last-child { border-bottom: none; }
.activity-time {
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  white-space: nowrap;
}
.activity-type {
  color: var(--text-primary);
  font-weight: 600;
  white-space: nowrap;
  text-transform: capitalize;
  letter-spacing: -0.005em;
}
.activity-detail {
  color: var(--text-secondary);
  word-break: break-word;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  opacity: 0.9;
}
