/* ============================================================
   PocketDex — Mobile UI
   Dark theme · GitHub-inspired palette · Mobile-first
   ============================================================ */

/* ── Custom Properties ──────────────────────────────────── */
:root {
  /* Background layers */
  --bg-base:        #0d1117;
  --bg-surface:     #161b22;
  --bg-overlay:     #1c2128;
  --bg-input:       #21262d;

  /* Borders */
  --border:         #30363d;
  --border-muted:   #21262d;

  /* Text */
  --text-primary:   #e6edf3;
  --text-secondary: #8b949e;
  --text-muted:     #484f58;

  /* Brand accents */
  --blue:           #58a6ff;
  --blue-subtle:    rgba(88, 166, 255, 0.12);
  --green:          #3fb950;
  --green-subtle:   rgba(63, 185, 80, 0.12);
  --yellow:         #d29922;
  --yellow-subtle:  rgba(210, 153, 34, 0.12);
  --red:            #f85149;
  --red-subtle:     rgba(248, 81, 73, 0.12);
  --purple:         #bc8cff;
  --purple-subtle:  rgba(188, 140, 255, 0.12);

  /* Sizes */
  --radius-sm:    6px;
  --radius-md:    12px;
  --radius-lg:    16px;
  --radius-pill:  999px;

  /* Typography */
  --font-sans:  -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono:  "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;

  /* Spacing rhythm (8pt) */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;

  /* Safe areas */
  --safe-top:         env(safe-area-inset-top, 0px);
  --safe-bottom:      env(safe-area-inset-bottom, 0px);
  --viewport-height:  100dvh;

  /* Animation tokens */
  --dur-fast:   150ms;
  --dur-normal: 250ms;
  --dur-slow:   400ms;
  --ease-out:   cubic-bezier(0.0, 0.0, 0.2, 1);
  --ease-in:    cubic-bezier(0.4, 0.0, 1, 1);
  --ease-io:    cubic-bezier(0.4, 0.0, 0.2, 1);
}

/* ── Semantic State Tokens ──────────────────────────────── */
:root {
  /* State colors */
  --color-state-idle:        var(--text-muted);
  --color-state-connecting:  var(--blue);
  --color-state-thinking:    var(--yellow);
  --color-state-streaming:   var(--blue);
  --color-state-approval:    var(--red);
  --color-state-success:     var(--green);
  --color-state-error:       var(--red);

  /* Shape tokens */
  --radius-xl:    18px;
  --radius-sheet: 24px;

  /* Shadow tokens */
  --shadow-card:  0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-sheet: 0 -18px 36px rgba(0, 0, 0, 0.28);
  --scrim-bg:     rgba(0, 0, 0, 0.55);

  /* Typography scale */
  --text-xs:         11px;
  --text-sm:         12px;
  --text-base:       14px;
  --text-md:         15px;
  --text-lg:         16px;
  --text-xl:         18px;
  --weight-normal:   400;
  --weight-medium:   500;
  --weight-semibold: 600;
  --weight-bold:     700;
  --leading-tight:   1.2;
  --leading-normal:  1.5;

  /* Motion aliases */
  --motion-instant:    var(--dur-fast);
  --motion-transition: var(--dur-normal);
  --motion-reveal:     var(--dur-slow);
  --motion-spring:     cubic-bezier(0.25, 1, 0.5, 1);

  /* Safe area shorthands */
  --inset-top:    calc(var(--safe-top) + var(--sp-3));
  --inset-bottom: calc(var(--safe-bottom) + var(--sp-3));
}

/* ── Light theme overrides ──────────────────────────────── */
[data-theme="light"] {
  --bg-base:        #ffffff;
  --bg-surface:     #f6f8fa;
  --bg-overlay:     #eaeef2;
  --bg-input:       #f0f2f4;
  --border:         #d0d7de;
  --border-muted:   #e8eaed;
  --text-primary:   #1c2128;
  --text-secondary: #57606a;
  --text-muted:     #8c959f;
  --blue:           #0969da;
  --blue-subtle:    rgba(9, 105, 218, 0.1);
  --green:          #1a7f37;
  --green-subtle:   rgba(26, 127, 55, 0.1);
  --red:            #cf222e;
  --red-subtle:     rgba(207, 34, 46, 0.1);
  --yellow:         #9a6700;
  --yellow-subtle:  rgba(154, 103, 0, 0.1);
  --purple:         #8250df;
  --purple-subtle:  rgba(130, 80, 223, 0.1);
}

/* ── Reset ──────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  height: 100%;
  /* Prevent iOS zoom on input focus */
  font-size: 16px;
}

body {
  height: var(--viewport-height);
  min-height: var(--viewport-height);
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.6;
  overflow: hidden;
  /* Smooth text rendering */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── App Shell ──────────────────────────────────────────── */
#app {
  height: var(--viewport-height);
  min-height: var(--viewport-height);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* ── Screen Layers ──────────────────────────────────────── */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-6);
  transition: opacity var(--dur-normal) var(--ease-io),
              transform var(--dur-normal) var(--ease-io);
}

.screen[hidden] {
  display: none;
}

#device-pairing-panel [hidden] {
  display: none !important;
}

.screen.fade-out {
  opacity: 0;
  transform: scale(0.97);
  pointer-events: none;
}

/* ── Connecting Screen ──────────────────────────────────── */
#screen-connecting {
  gap: var(--sp-5);
  text-align: center;
}

.connect-logo {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-lg);
  background: var(--blue-subtle);
  border: 1.5px solid var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  margin-bottom: var(--sp-2);
}

.connect-logo svg {
  width: 40px;
  height: 40px;
  stroke: var(--blue);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.connect-title {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
}

.connect-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
}

/* Animated dots */
.dots::after {
  content: "";
  animation: dots 1.4s steps(4, end) infinite;
}

@keyframes dots {
  0%   { content: ""; }
  25%  { content: "."; }
  50%  { content: ".."; }
  75%  { content: "..."; }
}

/* Spinner */
.spinner {
  width: 28px;
  height: 28px;
  border: 2.5px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Error Screen ───────────────────────────────────────── */
#screen-error {
  gap: var(--sp-4);
  text-align: center;
}

.error-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--red-subtle);
  border: 1.5px solid var(--red);
  display: flex;
  align-items: center;
  justify-content: center;
}

.error-icon svg {
  width: 32px;
  height: 32px;
  stroke: var(--red);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
}

.error-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.error-message {
  font-size: 14px;
  color: var(--text-secondary);
  max-width: 280px;
}

/* ── Button ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 11px var(--sp-5);
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 500;
  font-family: var(--font-sans);
  border: 1.5px solid transparent;
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
  transition: opacity var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out),
              background var(--dur-fast) var(--ease-out);
  -webkit-user-select: none;
  user-select: none;
}

.btn:active {
  transform: scale(0.96);
  opacity: 0.85;
}

.btn-primary {
  background: var(--blue);
  color: #fff;
}

.btn-primary:active {
  background: #4393e4;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}

.btn-ghost:active {
  background: var(--bg-overlay);
}

.btn-danger {
  background: var(--red-subtle);
  color: var(--red);
  border-color: var(--red);
}

.btn-approve {
  background: var(--green-subtle);
  color: var(--green);
  border-color: var(--green);
  flex: 1;
}

.btn-deny {
  background: var(--red-subtle);
  color: var(--red);
  border-color: var(--red);
  flex: 1;
}

.btn-approve-all {
  background: var(--purple-subtle);
  color: var(--purple);
  border-color: var(--purple);
  flex: 1;
}

.btn-icon {
  padding: var(--sp-2);
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  color: var(--text-secondary);
}

.btn-icon:active {
  background: var(--bg-overlay);
  color: var(--text-primary);
}

.btn-icon svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: block;
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.38;
  pointer-events: none;
}

/* ── Main Screen ────────────────────────────────────────── */
#screen-main {
  display: flex;
  flex-direction: column;
  position: absolute;
  inset: 0;
  padding: 0;
  align-items: stretch;
  justify-content: flex-start;
  min-height: 0;
  overflow: hidden;
}

/* ── Header ─────────────────────────────────────────────── */
#header {
  display: flex;
  flex-direction: column;
  padding-top: var(--inset-top);
  padding-bottom: var(--sp-2);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

/* Prevent flex-grow:1 / flex-basis:100% in account.css from
   over-expanding the insights bar inside a flex-column header */
#header-insights {
  flex: 0 0 auto;
}

.header-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-3);
  min-height: 48px;
}

.header-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  flex-shrink: 0;
}

.header-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Status dot (legacy — keep for backward compat during transition) */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  transition: background var(--dur-normal) var(--ease-out);
}

.status-dot.connected  { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.thinking   { background: var(--yellow); animation: pulse 1s ease-in-out infinite; }
.status-dot.error      { background: var(--red); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* ── Status Pill ─────────────────────────────────────────── */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 8px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
  transition: background var(--motion-transition) var(--ease-out),
              border-color var(--motion-transition) var(--ease-out),
              color var(--motion-transition) var(--ease-out);
}

.status-pill-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

/* State: idle — no background, muted color */
.status-pill[data-state="idle"] {
  color: var(--color-state-idle);
}

/* State: connecting — blue */
.status-pill[data-state="connecting"] {
  color: var(--color-state-connecting);
  background: color-mix(in srgb, var(--blue) 12%, transparent);
  border-color: color-mix(in srgb, var(--blue) 30%, transparent);
}
.status-pill[data-state="connecting"] .status-pill-dot {
  animation: status-pulse 1.2s ease-in-out infinite;
}

/* State: thinking — yellow */
.status-pill[data-state="thinking"] {
  color: var(--color-state-thinking);
  background: color-mix(in srgb, var(--yellow) 10%, transparent);
  border-color: color-mix(in srgb, var(--yellow) 25%, transparent);
}
.status-pill[data-state="thinking"] .status-pill-dot {
  animation: status-pulse 1s ease-in-out infinite;
}

/* State: streaming — blue (brighter than connecting) */
.status-pill[data-state="streaming"] {
  color: var(--color-state-streaming);
  background: color-mix(in srgb, var(--blue) 15%, transparent);
  border-color: color-mix(in srgb, var(--blue) 35%, transparent);
}
.status-pill[data-state="streaming"] .status-pill-dot {
  animation: status-pulse 0.7s ease-in-out infinite;
}

/* State: approval — red, urgent */
.status-pill[data-state="approval"] {
  color: var(--color-state-approval);
  background: color-mix(in srgb, var(--red) 12%, transparent);
  border-color: color-mix(in srgb, var(--red) 30%, transparent);
}
.status-pill[data-state="approval"] .status-pill-dot {
  animation: status-pulse 0.5s ease-in-out infinite;
}

/* State: error — red, static */
.status-pill[data-state="error"] {
  color: var(--color-state-error);
  background: color-mix(in srgb, var(--red) 10%, transparent);
  border-color: color-mix(in srgb, var(--red) 25%, transparent);
}

/* State: connected (default idle-connected) — green dot, no bg */
.status-pill[data-state="connected"] {
  color: var(--color-state-success);
}

@keyframes status-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.75); }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .status-pill-dot { animation: none !important; }
}

/* Model selector */
#model-picker {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 5px var(--sp-2) 5px var(--sp-3);
  border-radius: var(--radius-pill);
  background: transparent;
  border: 1px solid var(--border-muted);
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-family: var(--font-sans);
  cursor: pointer;
  min-height: 32px;
  opacity: 0.8;
  transition: border-color var(--dur-fast) var(--ease-out),
              opacity var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
  width: min(42vw, 190px);
  max-width: 190px;
}

#model-picker:hover,
#model-picker:focus {
  opacity: 1;
  border-color: var(--border);
  color: var(--text-secondary);
}

#model-picker:focus-visible {
  outline: none;
  border-color: var(--blue);
  color: var(--text-primary);
}

#model-picker option {
  background: var(--bg-overlay);
  color: var(--text-primary);
}

/* ── Chat Messages ──────────────────────────────────────── */
#messages {
  flex: 1 1 0%;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--sp-4);
  padding-bottom: max(var(--sp-4), calc(var(--safe-bottom) + 8px));
  scroll-behavior: smooth;
  /* Custom scrollbar */
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}

#messages::-webkit-scrollbar {
  width: 4px;
}

#messages::-webkit-scrollbar-track {
  background: transparent;
}

#messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-pill);
}

/* Empty state */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-4);
  text-align: center;
  padding: var(--sp-6);
  color: var(--text-muted);
  animation: empty-fade-in 0.6s var(--ease-out) both;
}

@keyframes empty-fade-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.empty-state-icon {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  animation: icon-float 3s ease-in-out infinite;
}

/* Subtle glow ring behind icon */
.empty-state-icon::before {
  content: '';
  position: absolute;
  inset: -8px;
  border-radius: calc(var(--radius-lg) + 8px);
  background: radial-gradient(circle, var(--blue-subtle) 0%, transparent 70%);
  animation: icon-glow 3s ease-in-out infinite;
  pointer-events: none;
}

@keyframes icon-float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-6px); }
}

@keyframes icon-glow {
  0%, 100% { opacity: 0.3; transform: scale(0.85); }
  50%       { opacity: 1;   transform: scale(1.15); }
}

.empty-state-icon svg {
  opacity: 0.45;
}

.empty-state-text {
  font-size: 14px;
  line-height: 1.6;
}

.empty-state-hint {
  font-size: 12px;
  color: var(--text-muted);
  opacity: 0.6;
  animation: empty-fade-in 0.8s 0.35s var(--ease-out) both;
}

/* ── Message Bubbles ────────────────────────────────────── */
.message {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  max-width: 100%;
  animation: msg-enter var(--dur-normal) var(--ease-out) both;
}

@keyframes msg-enter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message-user {
  align-items: flex-end;
}

.message-ai {
  align-items: flex-start;
}

.message-label {
  font-size: 11px;
  color: var(--text-muted);
  padding: 0 var(--sp-2);
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.bubble {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-lg);
  font-size: 15px;
  line-height: 1.6;
  max-width: min(86%, 520px);
  word-break: break-word;
  overflow-wrap: break-word;
}

.message-user .bubble {
  background: var(--blue);
  color: #fff;
  border-bottom-right-radius: var(--radius-sm);
}

.message-ai .bubble {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-muted);
  border-bottom-left-radius: var(--radius-sm);
}

.activity-card {
  display: grid;
  gap: 8px;
  width: min(100%, 560px);
  padding: 12px 14px;
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-muted);
  border-left: 3px solid transparent;
  background: color-mix(in srgb, var(--bg-surface) 90%, var(--bg-base));
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.08);
  animation: msg-enter var(--dur-normal) var(--ease-out) both;
}

.activity-card.is-expandable {
  cursor: pointer;
}

.activity-card.is-expandable:active {
  transform: scale(0.995);
}

.activity-card[data-tone="running"] {
  border-color: var(--border-muted);           /* neutral outer border (all 4 sides) */
  border-left-color: var(--color-state-streaming); /* override left side — comes after */
  background: var(--bg-surface);               /* no color fill */
}

.activity-card[data-tone="success"] {
  border-left-color: var(--color-state-success);
}

.activity-card[data-tone="warning"] {
  border-left-color: var(--color-state-thinking);
}

.activity-card[data-tone="error"] {
  border-left-color: var(--color-state-error);
}

.activity-card.is-expandable[data-expand="0"]::after {
  content: "Tap for details";
  display: block;
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-align: right;
  margin-top: var(--sp-1);
  opacity: 0.6;
}

.activity-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.activity-card-right {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.activity-card-copy {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.activity-card-kicker {
  margin: 0;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.activity-card-title {
  margin: 0;
  font-size: 14px;
  font-weight: 650;
  color: var(--text-primary);
  word-break: break-word;
}

.activity-card-meta {
  margin: 0;
  font-size: 12px;
  color: var(--text-secondary);
}

.activity-card-badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.activity-card-badge::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.7;
}

.activity-card[data-tone="running"] .activity-card-badge {
  color: var(--blue);
}

.activity-card[data-tone="running"] .activity-card-badge::before {
  width: 8px;
  height: 8px;
  background: none;
  border: 1.5px solid var(--blue);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  opacity: 1;
}

.activity-card[data-tone="success"] .activity-card-badge {
  color: var(--green);
}

.activity-card[data-tone="warning"] .activity-card-badge {
  color: #b77700;
}

.activity-card[data-tone="error"] .activity-card-badge {
  color: var(--red);
}

.activity-card-chevron {
  width: 10px;
  height: 10px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  color: var(--text-muted);
  transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1), color 200ms ease;
}

.activity-card[data-expand="1"] .activity-card-chevron {
  transform: rotate(225deg);
}

.activity-card[data-expand="2"] .activity-card-chevron {
  transform: rotate(225deg) scale(1.08);
  color: var(--text-primary);
}

.activity-card-details,
.activity-card-full {
  display: none;
  gap: 8px;
}

.activity-card[data-expand="1"] .activity-card-details,
.activity-card[data-expand="2"] .activity-card-details,
.activity-card[data-expand="2"] .activity-card-full {
  display: grid;
}

.activity-card-preview {
  margin: 0;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--bg-base);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-mono);
}

.activity-card-preview--full {
  max-height: 280px;
  overflow: auto;
}

.activity-card-files {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.activity-card-file {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 12px;
}

.activity-card-steps {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.activity-card-step {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 8px;
  align-items: start;
  padding: 8px 10px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--bg-input) 88%, transparent);
  border: 1px solid var(--border);
}

.activity-card-step .step-icon {
  font-size: 12px;
  line-height: 1.3;
  color: var(--text-muted);
}

.activity-card-step.step-inProgress .step-icon {
  color: var(--blue);
}

.activity-card-step.step-completed .step-icon {
  color: var(--green);
}

.activity-card-step .step-text {
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-secondary);
}

@media (prefers-reduced-motion: reduce) {
  .activity-card.is-expandable:active {
    transform: none;
  }

  .activity-card-chevron {
    transition: none;
  }
}

/* ── Tool Group — wraps all tool calls within a turn ─────── */
.tool-group {
  width: min(100%, 560px);
  border: 1px solid var(--border-muted);
  border-left: 3px solid var(--border-muted);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-surface);
  animation: msg-enter var(--dur-normal) var(--ease-out) both;
  transition: border-left-color var(--motion-transition) var(--ease-out);
}

.tool-group.running { border-left-color: var(--color-state-streaming); }
.tool-group.done    { border-left-color: var(--color-state-success); }
.tool-group.error   { border-left-color: var(--color-state-error); }

.tool-group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  min-height: 40px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  background: color-mix(in srgb, var(--bg-overlay) 60%, var(--bg-surface));
  transition: background var(--dur-fast) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}

.tool-group-header:active {
  background: var(--bg-overlay);
}

.tool-group.running .tool-group-header,
.tool-group.done    .tool-group-header,
.tool-group.error   .tool-group-header {
  background: transparent;
}

.tool-group-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

.tool-group-status-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.tool-group-status-icon.ok { stroke: var(--green); }
.tool-group-status-icon.fail { stroke: var(--red); }

.tool-group-label {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-group.running .tool-group-label { color: var(--blue); }
.tool-group.done    .tool-group-label { color: var(--green); }
.tool-group.error   .tool-group-label { color: var(--red); }

.tool-group-count {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  flex-shrink: 0;
}

.tool-group-chevron {
  width: 14px;
  height: 14px;
  stroke: var(--text-muted);
  flex-shrink: 0;
  transition: transform var(--dur-fast) var(--ease-out);
}

.tool-group.open .tool-group-chevron {
  transform: rotate(180deg);
}

.tool-group-body {
  display: none;
  flex-direction: column;
}

.tool-group.open .tool-group-body {
  display: flex;
}

/* Cards nested inside tool-group lose their outer chrome */
.tool-group-body .activity-card {
  border-radius: 0;
  box-shadow: none;
  width: 100%;
  max-width: 100%;
  border: none;
  border-top: 1px solid var(--border-muted);
  animation: none;
}

.tool-group-body .tool-card {
  border-radius: 0;
  width: 100%;
  max-width: 100%;
  border: none;
  border-top: 1px solid var(--border-muted);
  animation: none;
}

@media (prefers-reduced-motion: reduce) {
  .tool-group-chevron {
    transition: none;
  }
}

/* Streaming cursor (element-based for RAF integration) */
.stream-cursor {
  animation: blink 0.9s step-start infinite;
  color: var(--blue);
  margin-left: 2px;
  user-select: none;
}

.stream-placeholder {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 22px;
  color: var(--text-secondary);
}

.stream-placeholder-label {
  font-size: 14px;
  font-weight: 500;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ── Markdown inside bubbles ────────────────────────────── */
.bubble p { margin-bottom: var(--sp-2); }
.bubble p:last-child { margin-bottom: 0; }

.bubble code {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--bg-input);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-sm);
  padding: 1px 5px;
  color: var(--text-primary);
}

.bubble pre {
  position: relative;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-3) var(--sp-4);
  overflow-x: auto;
  margin: var(--sp-2) 0;
}

.bubble pre::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 24px;
  background: linear-gradient(to right, transparent, var(--bg-base));
  pointer-events: none;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.bubble pre.no-overflow::after {
  display: none;
}

.bubble pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
  line-height: 1.5;
}

.bubble ul, .bubble ol {
  padding-left: var(--sp-5);
  margin: var(--sp-2) 0;
}

.bubble li { margin-bottom: var(--sp-1); }

.bubble blockquote {
  border-left: 3px solid var(--blue);
  padding-left: var(--sp-3);
  color: var(--text-secondary);
  margin: var(--sp-2) 0;
}

.bubble h1, .bubble h2, .bubble h3 {
  font-weight: 600;
  margin: var(--sp-3) 0 var(--sp-2);
  line-height: 1.3;
}

.bubble h1 { font-size: 18px; }
.bubble h2 { font-size: 16px; }
.bubble h3 { font-size: 15px; }

.bubble a {
  color: var(--blue);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--sp-3) 0;
}

/* ── Thinking / Reasoning Block — timeline entry style ───── */
.thinking-block {
  width: 100%;
  max-width: 520px;
  border-left: 2px solid var(--color-state-thinking);
  padding-left: var(--sp-3);
  margin-bottom: var(--sp-2);
  animation: msg-enter var(--dur-normal) var(--ease-out) both;
  /* No background, no border-radius, no box-shadow */
}

.thinking-block.is-done {
  border-left-color: var(--border-muted);
  opacity: 0.7;
  transition: border-color var(--motion-transition) var(--ease-out),
              opacity var(--motion-transition) var(--ease-out);
}

.thinking-header {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-1) 0;
  cursor: pointer;
  min-height: 32px;
  user-select: none;
}

.thinking-header svg {
  width: 16px;
  height: 16px;
  stroke: var(--color-state-thinking);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  flex-shrink: 0;
}

.thinking-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-state-thinking);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.thinking-block.is-done .thinking-label {
  color: var(--text-muted);
}

/* Live dots: only shown when NOT is-done */
.thinking-live {
  display: inline-flex;
  gap: 3px;
  align-items: center;
}

.thinking-block.is-done .thinking-live {
  display: none;
}

.thinking-live span {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.28;
  animation: thinking-dots 1.2s ease-in-out infinite;
}

.thinking-live span:nth-child(2) {
  animation-delay: 0.18s;
}

.thinking-live span:nth-child(3) {
  animation-delay: 0.36s;
}

.thinking-live-inline {
  color: var(--blue);
}

.thinking-chevron {
  margin-left: auto;
  width: 16px;
  height: 16px;
  stroke: var(--text-muted);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.5;
  transition: transform var(--motion-instant) var(--ease-out);
  flex-shrink: 0;
}

.thinking-block.open .thinking-chevron {
  transform: rotate(180deg);
}

.thinking-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height var(--motion-reveal) var(--ease-out);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.6;
}

.thinking-block.open .thinking-content {
  max-height: 280px;
  overflow-y: auto;
}

.thinking-text {
  padding: 0 0 var(--sp-3);
  font-size: 13px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

@keyframes thinking-dots {
  0%, 80%, 100% {
    transform: translateY(0);
    opacity: 0.28;
  }
  40% {
    transform: translateY(-2px);
    opacity: 1;
  }
}

/* ── Input Bar ──────────────────────────────────────────── */
.composer-context-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: 10px var(--sp-4) 0;
  background: var(--bg-surface);
}

.composer-context-copy {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.composer-context-kicker {
  font-size: 10px;
  line-height: 1.2;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.composer-context-summary {
  font-size: 12px;
  line-height: 1.35;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-status-stack {
  flex-shrink: 0;
  padding: 0 var(--sp-4) var(--sp-2);
  background: linear-gradient(180deg, transparent, color-mix(in srgb, var(--bg-surface) 88%, transparent));
}

.chat-status-stack[hidden] {
  display: none !important;
}

#input-bar {
  flex-shrink: 0;
  display: grid;
  gap: var(--sp-2);
  position: relative;
  padding: 10px var(--sp-4) var(--sp-3);
  padding-bottom: calc(var(--safe-bottom) + var(--sp-3));
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
}
.composer-topline {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
}
.input-bar-main {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-2);
  min-width: 0;
}

#user-input {
  flex: 1;
  min-height: 44px;
  max-height: 140px;
  padding: 10px var(--sp-4);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  font-size: 15px;
  font-family: var(--font-sans);
  line-height: 1.5;
  resize: none;
  overflow-y: auto;
  transition: border-color var(--dur-fast) var(--ease-out);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#user-input::placeholder {
  color: var(--text-muted);
}

#user-input:focus-visible {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.12);
}

/* Send / Stop button */
#send-btn, #stop-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-out),
              opacity var(--dur-fast) var(--ease-out);
}

#send-btn:active, #stop-btn:active {
  transform: scale(0.92);
}

#send-btn {
  background: var(--blue);
  color: #fff;
}

#send-btn:disabled {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}

#send-btn svg, #stop-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#stop-btn {
  background: var(--red-subtle);
  color: var(--red);
  border: 1.5px solid var(--red);
  display: none;
}

#stop-btn.visible {
  display: flex;
}

#send-btn.hidden {
  display: none;
}

/* Send button → Stop mode during active turn */
#send-btn .stop-icon { display: none; }
#send-btn.stop-mode .send-icon { display: none; }
#send-btn.stop-mode .stop-icon { display: block; }

#send-btn.stop-mode {
  background: var(--red-subtle);
  color: var(--red);
  border: 1.5px solid var(--red);
}

/* ── Approval Overlay ───────────────────────────────────── */
#approval-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--dur-normal) var(--ease-io);
}

#approval-overlay.open {
  pointer-events: auto;
  opacity: 1;
}

.approval-scrim {
  position: absolute;
  inset: 0;
  background: var(--scrim-bg);
}

.approval-sheet {
  position: relative;
  background: var(--bg-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  border-top: 1px solid var(--border);
  padding: var(--sp-5) var(--sp-5);
  padding-bottom: calc(var(--safe-bottom) + var(--sp-5));
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  transform: translateY(100%);
  transition: transform var(--dur-slow) var(--ease-out);
  max-height: 75dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

#approval-overlay.open .approval-sheet {
  transform: translateY(0);
}

.approval-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 4px var(--sp-3);
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.approval-badge.cmd {
  background: var(--yellow-subtle);
  color: var(--yellow);
  border: 1px solid var(--yellow);
}

.approval-badge.file {
  background: var(--purple-subtle);
  color: var(--purple);
  border: 1px solid var(--purple);
}

.approval-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.approval-detail {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-3) var(--sp-4);
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  word-break: break-all;
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
}

.approval-detail-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--sp-2);
}

.approval-actions {
  display: flex;
  gap: var(--sp-2);
}

@media (max-width: 399px) {
  .approval-actions {
    flex-direction: column;
  }
  .approval-actions .btn {
    min-height: 52px;
  }
}

/* ── Disconnected Banner ────────────────────────────────── */
#disconnected-banner {
  display: none;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: calc(var(--safe-top) + var(--sp-2)) var(--sp-4) var(--sp-2);
  background: var(--red-subtle);
  border-bottom: 1px solid var(--red);
  font-size: 13px;
  color: var(--red);
  font-weight: 500;
}

#disconnected-banner.visible {
  display: flex;
}

/* ── Toast ──────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 80px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-overlay);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-2) var(--sp-4);
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-primary);
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--dur-normal) var(--ease-out),
              transform var(--dur-normal) var(--ease-out);
  z-index: 200;
  width: fit-content;
  max-width: min(calc(100vw - 24px), 560px);
  white-space: normal;
  text-align: center;
  overflow-wrap: anywhere;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Utility ────────────────────────────────────────────── */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* ── Tool Call Card ─────────────────────────────────────── */
.tool-card {
  width: 100%;
  max-width: 520px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  overflow: hidden;
  animation: msg-enter var(--dur-normal) var(--ease-out) both;
  transition: border-color var(--dur-normal) var(--ease-out);
}

.tool-card.running {
  border-color: var(--blue);
}

.tool-card.success {
  border-color: var(--green);
}

.tool-card.error {
  border-color: var(--red);
}

.tool-card-header {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  min-height: 44px;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.tool-card.running .tool-card-header {
  background: var(--blue-subtle);
}

.tool-card.success .tool-card-header {
  background: var(--green-subtle);
}

.tool-card.error .tool-card-header {
  background: var(--red-subtle);
}

.tool-icon {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--bg-overlay);
}

.tool-card.running  .tool-icon { background: var(--blue-subtle); }
.tool-card.success  .tool-icon { background: var(--green-subtle); }
.tool-card.error    .tool-icon { background: var(--red-subtle); }

.tool-icon svg {
  width: 14px;
  height: 14px;
  stroke: var(--text-secondary);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tool-card.running .tool-icon svg { stroke: var(--blue); }
.tool-card.success .tool-icon svg { stroke: var(--green); }
.tool-card.error   .tool-icon svg { stroke: var(--red); }

.tool-card-name {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-card.running .tool-card-name { color: var(--blue); }
.tool-card.success .tool-card-name { color: var(--green); }
.tool-card.error   .tool-card-name { color: var(--red); }

/* Status indicator — spinner or checkmark/cross */
.tool-status {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
}

.tool-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.tool-done-icon {
  width: 16px;
  height: 16px;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.tool-done-icon.ok   { stroke: var(--green); }
.tool-done-icon.fail { stroke: var(--red); }

/* Chevron */
.tool-chevron {
  width: 14px;
  height: 14px;
  stroke: var(--text-muted);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform var(--dur-fast) var(--ease-out);
  flex-shrink: 0;
}

.tool-card.open .tool-chevron {
  transform: rotate(180deg);
}

/* Collapsible body */
.tool-card-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height var(--dur-slow) var(--ease-out);
}

.tool-card.open .tool-card-body {
  max-height: 300px;
}

.tool-card-content {
  padding: 0 var(--sp-3) var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.tool-field-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: var(--sp-1);
}

.tool-field-value {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-base);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-sm);
  padding: var(--sp-2) var(--sp-3);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-y: auto;
  max-height: 120px;
}

.tool-result-value {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-base);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-sm);
  padding: var(--sp-2) var(--sp-3);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-y: auto;
  max-height: 120px;
}

.tool-card.error .tool-result-value {
  border-color: var(--red);
  color: var(--red);
}

/* ── Approval Args List ──────────────────────────────────── */
.approval-args-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.approval-args-list .arg-item {
  display: flex;
  gap: var(--sp-2);
  align-items: baseline;
  font-family: var(--font-mono);
  font-size: 13px;
}

.approval-args-list .arg-index {
  color: var(--text-muted);
  font-size: 11px;
  min-width: 20px;
  flex-shrink: 0;
}

.approval-args-list .arg-value {
  color: var(--text-primary);
  word-break: break-word;
}

.approval-file-info {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.approval-file-row {
  display: flex;
  gap: var(--sp-3);
  align-items: center;
  font-size: 13px;
}

.approval-file-row .file-key {
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.04em;
  min-width: 52px;
  flex-shrink: 0;
}

.approval-file-row .file-val {
  font-family: var(--font-mono);
  color: var(--text-primary);
  word-break: break-all;
}

.approval-op-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.approval-op-badge.create  { background: var(--green-subtle);  color: var(--green);  }
.approval-op-badge.update  { background: var(--blue-subtle);   color: var(--blue);   }
.approval-op-badge.delete  { background: var(--red-subtle);    color: var(--red);    }
.approval-op-badge.unknown { background: var(--bg-overlay);    color: var(--text-secondary); }

/* ── PWA Install Banner ─────────────────────────────────── */
#install-banner {
  display: none;
  align-items: center;
  gap: var(--sp-3);
  padding: 8px 12px;
  border-radius: 14px;
  border-bottom: 1px solid var(--blue);
  animation: slide-down var(--dur-normal) var(--ease-out) forwards;
  flex-shrink: 0;
  font-size: 13px;
  width: 100%;
  max-width: none;
}

#install-banner.visible {
  display: flex;
  min-height: 38px;
}

.install-banner-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  overflow: hidden;
}

.install-banner-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.install-banner-text {
  flex: 1;
}

.install-banner-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.install-banner-sub {
  font-size: 12px;
  color: var(--text-secondary);
}

.install-banner-actions {
  display: flex;
  gap: var(--sp-2);
  flex-shrink: 0;
}

.btn-install {
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  background: var(--blue);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  min-height: 34px;
  transition: opacity var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}

.btn-install:active {
  transform: scale(0.95);
  opacity: 0.85;
}

.btn-install-dismiss {
  padding: 7px 12px;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  border: none;
  cursor: pointer;
  min-height: 34px;
  transition: color var(--dur-fast) var(--ease-out);
}

.btn-install-dismiss:active {
  color: var(--text-secondary);
}

/* ── Enhanced connecting screen ─────────────────────────── */
/* Pulsing glow behind the logo */
.connect-logo {
  position: relative;
}

.connect-logo::before {
  content: '';
  position: absolute;
  inset: -8px;
  border-radius: calc(var(--radius-lg) + 8px);
  background: var(--blue-subtle);
  animation: logo-pulse 2.4s ease-in-out infinite;
  pointer-events: none;
}

@keyframes logo-pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.95); }
  50%       { opacity: 0.8; transform: scale(1.05); }
}

/* ── Header accent line ─────────────────────────────────── */
#header::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: linear-gradient(90deg,
    transparent 0%,
    var(--blue) 30%,
    var(--green) 70%,
    transparent 100%);
  opacity: 0;
  transition: opacity var(--dur-slow) var(--ease-out);
}

#header.thinking-active::after {
  opacity: 1;
  animation: header-sweep 1.8s linear infinite;
  background-size: 200% 100%;
}

@keyframes header-sweep {
  0%   { background-position: -100% 0; }
  100% { background-position: 200% 0; }
}

/* ── Enhanced user bubble — gradient ────────────────────── */
.message-user .bubble {
  background: linear-gradient(135deg, color-mix(in srgb, var(--blue) 90%, #0d1117 10%) 0%, var(--blue) 100%);
  color: #fff;
  border-bottom-right-radius: var(--radius-sm);
  box-shadow: 0 2px 12px rgba(88, 166, 255, 0.25);
  transition: box-shadow var(--dur-fast) var(--ease-out);
}

/* ── Enhanced AI bubble ─────────────────────────────────── */
.message-ai .bubble {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-bottom-left-radius: var(--radius-sm);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

/* ── Message stagger entrance ───────────────────────────── */
/* Each new message gets a slightly delayed entrance */
.message:nth-last-child(1) { animation-delay: 0ms; }
.message:nth-last-child(2) { animation-delay: 0ms; }

/* ── Send button hover glow ─────────────────────────────── */
#send-btn:not(:disabled):hover {
  box-shadow: 0 0 0 4px rgba(88, 166, 255, 0.2);
  transform: scale(1.05);
}

/* ── Stop button pulse ──────────────────────────────────── */
#stop-btn.visible {
  display: flex;
  animation: stop-pulse 1.8s ease-in-out infinite;
}

@keyframes stop-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248, 81, 73, 0.3); }
  50%       { box-shadow: 0 0 0 6px rgba(248, 81, 73, 0); }
}

/* ── Tool card success flash ────────────────────────────── */
.tool-card.success {
  animation: tool-success-flash 0.4s var(--ease-out) both;
}

@keyframes tool-success-flash {
  0%   { box-shadow: 0 0 0 2px var(--green); }
  100% { box-shadow: none; }
}

/* ── Focus ring ─────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ── Apple touch icon hint (iOS install) ────────────────── */
#ios-install-hint {
  display: none;
  position: fixed;
  bottom: calc(var(--safe-bottom) + 80px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-overlay);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-3) var(--sp-4);
  font-size: 13px;
  color: var(--text-primary);
  z-index: 200;
  text-align: center;
  max-width: 280px;
  opacity: 0;
  transition: opacity var(--dur-normal) var(--ease-out),
              transform var(--dur-normal) var(--ease-out);
  pointer-events: none;
}

#ios-install-hint.show {
  display: block;
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#ios-install-hint strong {
  color: var(--blue);
}

/* Downward arrow indicator */
#ios-install-hint::after {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 8px solid var(--border);
}

/* ── Reduced Motion ─────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .dots::after {
    content: "...";
    animation: none;
  }
}

/* ── Header titles / CWD ────────────────────────────────── */
.header-titles {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  gap: 1px;
}

.header-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.header-cwd {
  font-size: var(--text-xs);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: var(--leading-tight);
  max-width: 160px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.header-cwd:not(:empty) {
  opacity: 1;
}

/* ���� Copy button �������������������������������������������������������������������������������������� */
.copy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.copy-btn:hover,
.copy-btn:focus-visible {
  color: var(--text-secondary);
  background: var(--bg-overlay);
  border-color: var(--border-muted);
  outline: none;
}

.copy-btn.copied {
  color: var(--green);
}

/* Copy button on AI bubble (top-right corner) */
.copy-btn-bubble {
  position: absolute;
  top: 6px;
  right: 6px;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease;
}

.message-ai:hover .copy-btn-bubble,
.message-ai:focus-within .copy-btn-bubble {
  opacity: 1;
}

/* Make message-ai position relative for the absolute copy button */
.message-ai {
  position: relative;
}

/* Copy button inside code block (pre) */
.copy-btn-code {
  position: absolute;
  top: 6px;
  right: 6px;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease;
  z-index: 1;
}

pre:hover .copy-btn-code,
pre:focus-within .copy-btn-code {
  opacity: 1;
}

/* ���� Voice button ������������������������������������������������������������������������������������ */
.btn-voice {
  display: none;  /* Hidden until Web Speech API is confirmed available */
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-muted);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.btn-voice.available {
  display: inline-flex;
}

.btn-voice:hover,
.btn-voice:focus-visible {
  color: var(--blue);
  border-color: var(--blue);
  background: var(--blue-subtle);
  outline: none;
}

.btn-voice.listening {
  color: var(--red);
  border-color: var(--red);
  background: var(--red-subtle);
  animation: mic-pulse 1.4s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248, 81, 73, 0.3); }
  50% { box-shadow: 0 0 0 6px rgba(248, 81, 73, 0); }
}

/* ─── File diff in approval overlay ─────────────────────── */
.approval-diff {
  margin: var(--sp-2) 0 0;
  padding: var(--sp-2) var(--sp-3);
  background: var(--bg-base);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-secondary);
  max-height: 160px;
  overflow-y: auto;
  white-space: pre;
  word-break: break-all;
}

/* ── Scroll-to-bottom button ────────────────────────────── */
.scroll-bottom-btn {
  position: absolute;
  bottom: calc(64px + 12px);
  right: 16px;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: var(--bg-overlay);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  transition: opacity 0.2s, transform 0.2s;
  z-index: 20;
}

.scroll-bottom-btn.has-new {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

/* ── Approval timer bar ──────────────────────────────────── */
.approval-timer-bar {
  height: 3px;
  background: var(--bg-overlay);
  border-radius: 2px;
  margin-bottom: var(--sp-3);
  overflow: hidden;
}

.approval-timer-fill {
  height: 100%;
  background: var(--red);
  width: 100%;
}

.approval-timer-fill.urgent {
  animation: timer-pulse 0.5s ease-in-out infinite;
}

@keyframes timer-pulse {
  50% { opacity: 0.5; }
}

/* ── Turn progress bar ──────────────────────────────────── */
#turn-progress-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  z-index: 100;
}

#turn-progress-bar.active {
  opacity: 1;
}

#turn-progress-fill {
  height: 100%;
  background: var(--blue);
  width: 0;
}

/* Turn stats badge in header */
.turn-stats-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 2px var(--sp-3);
  font-size: var(--text-xs);
  color: var(--text-muted);
  background: color-mix(in srgb, var(--blue) 8%, transparent);
  border-top: 1px solid var(--border-muted);
}
.turn-stats-badge[hidden] { display: none; }

/* ── Turn summary (turn/completed) ──────────────────────── */
.turn-summary {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: var(--sp-2);
  padding-top: var(--sp-2);
  border-top: 1px solid var(--border-muted);
  animation: fadeIn 0.3s ease;
}

.turn-summary-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-secondary);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── Prism.js overrides (Item 1) ─────────────────────────── */
pre[class*="language-"] {
  background: var(--bg-base) !important;
  margin: 0 !important;
  padding: var(--sp-3) var(--sp-4) !important;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm) !important;
}
.code-lang-badge {
  font-size: 10px;
  color: var(--text-muted);
  position: absolute;
  top: 6px;
  left: 8px;
  font-family: var(--font-mono);
  pointer-events: none;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── Swipe to approve/deny (Item 2) ──────────────────────── */
.approval-sheet {
  transition: transform 0.25s ease, background-color 0.15s;
}
.approval-sheet.swipe-approve {
  background-color: rgba(63, 185, 80, 0.15) !important;
}
.approval-sheet.swipe-deny {
  background-color: rgba(248, 81, 73, 0.15) !important;
}

/* ── Colored diff (Item 3) ───────────────────────────────── */
.approval-diff-container pre {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  padding: var(--sp-2) 0;
  overflow-x: auto;
}
.diff-file-header {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  padding: var(--sp-1) var(--sp-2);
  font-family: var(--font-mono);
  border-bottom: 1px solid var(--border-muted);
  margin-bottom: var(--sp-1);
}
.diff-add  { color: #3fb950; background: rgba(63, 185, 80, 0.08); display: block; padding: 0 var(--sp-2); }
.diff-del  { color: #f85149; background: rgba(248, 81, 73, 0.08); display: block; padding: 0 var(--sp-2); }
.diff-hunk { color: var(--blue); display: block; padding: 0 var(--sp-2); }
.diff-ctx  { color: var(--text-secondary); display: block; padding: 0 var(--sp-2); }

/* ── Context menu (Item 12) ──────────────────────────────── */
.ctx-menu {
  position: fixed;
  background: var(--bg-overlay);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  min-width: 160px;
  overflow: hidden;
  z-index: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.ctx-menu-item {
  padding: var(--sp-3) var(--sp-4);
  cursor: pointer;
  font-size: 14px;
  color: var(--text-primary);
  transition: background 0.1s;
}
.ctx-menu-item:hover,
.ctx-menu-item:focus-visible {
  background: var(--bg-subtle);
  outline: none;
}

/* ── Slash command menu (Item 7) ─────────────────────────── */
.slash-menu {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg-overlay);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  z-index: 200;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.3);
}
.slash-menu-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  cursor: pointer;
  transition: background 0.1s;
}
.slash-menu-item:hover,
.slash-menu-item.selected {
  background: var(--bg-subtle);
}
.slash-cmd {
  font-family: var(--font-mono);
  color: var(--blue);
  font-size: 13px;
  font-weight: 500;
  min-width: 90px;
}
.slash-desc {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ── Image attach (Item 9) ───────────────────────────────── */
.btn-attach {
  width: 36px;
  height: 36px;
  min-width: 36px;
  background: var(--bg-input);
  border: 1px solid var(--border-muted);
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0;
  border-radius: var(--radius-pill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.2s ease, background-color 0.2s ease, border-color 0.2s ease, transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.btn-attach:hover,
.btn-attach:focus-visible,
.btn-attach[aria-expanded="true"] {
  color: var(--blue);
  background: var(--blue-subtle);
  border-color: color-mix(in srgb, var(--blue) 60%, var(--border-muted));
  outline: none;
}
.btn-attach[aria-expanded="true"] {
  transform: translateY(-1px);
}
.composer-tools-menu {
  position: absolute;
  left: var(--sp-4);
  bottom: calc(100% + 10px);
  width: min(280px, calc(100vw - (var(--sp-4) * 2)));
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: color-mix(in srgb, var(--bg-surface) 94%, var(--bg-overlay));
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.22);
  display: grid;
  gap: 12px;
  opacity: 0;
  transform: translateY(10px) scale(0.98);
  transform-origin: bottom left;
  pointer-events: none;
  transition: opacity 180ms ease, transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
  z-index: 40;
}
.composer-tools-menu.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.composer-tools-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.composer-tools-actions-stack {
  grid-template-columns: 1fr;
}
.composer-tool-action {
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-input);
  color: var(--text-primary);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 200ms ease, background-color 200ms ease, color 200ms ease, transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.composer-tool-action:hover,
.composer-tool-action:focus-visible {
  border-color: var(--blue);
  background: var(--blue-subtle);
  color: var(--blue);
  outline: none;
}
.composer-tools-section {
  display: grid;
  gap: 7px;
}
.composer-tools-label {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.composer-segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}
.composer-segmented-three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.composer-segment-btn {
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 200ms ease, background-color 200ms ease, color 200ms ease, transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.composer-segment-btn:hover,
.composer-segment-btn:focus-visible {
  border-color: color-mix(in srgb, var(--blue) 48%, var(--border));
  color: var(--text-primary);
  outline: none;
}
.composer-segment-btn.is-active {
  border-color: var(--blue);
  background: var(--blue-subtle);
  color: var(--blue);
}
.image-preview-area {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  flex-wrap: wrap;
}
.image-preview-thumb {
  position: relative;
  display: inline-block;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}
.image-preview-file {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  max-width: min(220px, 100%);
  padding: 0 28px 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-input);
}
.image-preview-file-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: var(--text-primary);
}
.image-preview-file-meta {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.composer-sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 452;
}

.composer-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(1, 4, 9, 0.42);
  backdrop-filter: blur(5px);
}

.composer-sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  gap: 14px;
  padding: 18px 18px calc(var(--safe-bottom, 0px) + 18px);
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-surface) 94%, var(--bg-base));
  box-shadow: 0 -18px 36px rgba(0, 0, 0, 0.28);
  animation: composer-sheet-in 220ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes composer-sheet-in {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.composer-sheet-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.composer-sheet-kicker {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--blue);
}

.composer-sheet-title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
}

.composer-sheet-close-btn {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.composer-sheet-close-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.composer-sheet-close-btn:hover,
.composer-sheet-close-btn:focus-visible {
  border-color: color-mix(in srgb, var(--blue) 46%, var(--border));
  color: var(--blue);
  outline: none;
}

.composer-sheet-action-list {
  display: grid;
  gap: 10px;
}

.composer-sheet-action {
  display: grid;
  gap: 4px;
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  background: var(--bg-input);
  text-align: left;
  color: var(--text-primary);
}

.composer-sheet-action-title {
  font-size: 15px;
  font-weight: 650;
}

.composer-sheet-action-hint,
.composer-sheet-hint,
.composer-sheet-status {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-secondary);
}

.composer-sheet-input {
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-primary);
  font: inherit;
}

.composer-sheet-input:focus-visible {
  outline: none;
  border-color: color-mix(in srgb, var(--blue) 60%, var(--border));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 18%, transparent);
}

.composer-sheet-textarea {
  min-height: 90px;
  padding: 12px 14px;
  resize: vertical;
}

.workspace-search-results {
  display: grid;
  gap: 8px;
  max-height: min(46vh, 360px);
  overflow-y: auto;
}

.workspace-search-result {
  display: grid;
  gap: 3px;
  width: 100%;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  text-align: left;
  color: var(--text-primary);
}

.workspace-search-result-name {
  font-size: 14px;
  font-weight: 650;
}

.workspace-search-result-path {
  font-size: 12px;
  color: var(--text-secondary);
  word-break: break-word;
}

.composer-sheet-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.command-sheet-output {
  min-height: 160px;
  max-height: min(42vh, 360px);
  margin: 0;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--bg-base);
  color: var(--text-primary);
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.55;
}

.command-sheet-output:empty::before {
  content: attr(data-empty);
  color: var(--text-muted);
}

@media (prefers-reduced-motion: reduce) {
  .composer-sheet {
    animation: none;
  }
}
.image-preview-thumb img {
  display: block;
  max-height: 80px;
  max-width: 120px;
  object-fit: cover;
}
.image-preview-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 10px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
@media (hover: hover) and (pointer: fine) {
  .btn-attach:hover,
  .composer-tool-action:hover,
  .composer-segment-btn:hover {
    transform: translateY(-1px);
  }
}

/* ════════════════════════════════════════════════════════════
   History Drawer  (left-side panel, slides from left)
   ═══════════════════════════════════════════════════════════ */

/* History icon button in header */
#history-btn {
  flex-shrink: 0;
  order: -1; /* keep it leftmost after status-dot */
}

/* Overlay wrapper */
.history-overlay {
  position: fixed;
  inset: 0;
  z-index: 449; /* just below settings (450) */
}

/* Semi-transparent backdrop */
.history-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(1, 4, 9, 0.45);
  backdrop-filter: blur(4px);
  opacity: 0;
  animation: history-backdrop-in 220ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes history-backdrop-in {
  to { opacity: 1; }
}

/* Left-side drawer panel */
.history-drawer {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: min(85vw, 340px);
  padding: calc(var(--safe-top, 0px) + 20px) 18px calc(var(--safe-bottom, 0px) + 28px);
  background: var(--pd-sheet-bg, var(--bg-surface));
  border: none;
  border-right: 1px solid var(--pd-sheet-border, var(--border));
  box-shadow: 4px 0 32px rgba(0, 0, 0, 0.35);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  /* entry animation: slide from left + fade */
  transform: translateX(-100%);
  opacity: 0;
  animation: history-drawer-in 280ms cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

@keyframes history-drawer-in {
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* Reduced-motion: skip the slide, just fade in */
@media (prefers-reduced-motion: reduce) {
  .history-drawer {
    transform: translateX(0) !important;
    opacity: 0;
    animation: history-drawer-fade 200ms ease forwards;
  }
  @keyframes history-drawer-fade {
    to { opacity: 1; }
  }
}

/* Drawer header row */
.history-drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.history-drawer-kicker {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--blue);
}

.history-drawer-title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  color: var(--pd-title, var(--text-primary));
  text-wrap: balance;
}

/* Toolbar containing the Refresh button */
.history-drawer-toolbar {
  margin-bottom: 12px;
}


/* ── Drag & drop zone ──────────────────────────────────────────── */
body.drop-zone-active #messages::after {
  content: 'Drop images here';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 600;
  color: var(--blue);
  background: var(--blue-subtle);
  border: 2px dashed var(--blue);
  border-radius: var(--radius-lg);
  z-index: 200;
  pointer-events: none;
}
#messages { position: relative; }

/* ── Retry button ──────────────────────────────────────────────── */
.btn-retry {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: var(--sp-2);
  padding: 4px 10px;
  font-size: 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.btn-retry:hover { color: var(--blue); border-color: var(--blue); background: var(--blue-subtle); }

/* ── Message search ──────────────────────────────────────────────── */
.search-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  background: var(--bg-overlay);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 90;
}

.search-bar[hidden] {
  display: none !important;
}

.search-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 6px 12px;
  font-size: 14px;
  color: var(--text-primary);
}
.search-input:focus-visible {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 18%, transparent);
}
.search-count { font-size: 12px; color: var(--text-muted); white-space: nowrap; min-width: 48px; text-align: center; }
.search-nav-btn, .search-close-btn {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  padding: 4px 6px; border-radius: var(--radius-sm); font-size: 14px;
  transition: color 0.15s, background 0.15s;
}
.search-nav-btn:hover, .search-close-btn:hover { color: var(--text-primary); background: var(--bg-input); }
.search-highlight { background: rgba(255, 200, 0, 0.35); border-radius: 2px; padding: 0 1px; }
.search-highlight.current { background: rgba(255, 160, 0, 0.65); outline: 2px solid var(--yellow); border-radius: 2px; }

/* ── Approval queue badge ──────────────────────────────────────── */
.approval-queue-btn {
  display: none;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  background: var(--red);
  border: none;
  cursor: pointer;
  margin-right: var(--sp-1);
}
.approval-queue-btn.visible { display: flex; }
.approval-queue-count { font-size: 12px; font-weight: 700; color: #fff; line-height: 1; }

/* ── Approval queue drawer ─────────────────────────────────────── */
.approval-queue-drawer { position: fixed; inset: 0; z-index: 400; display: none; }
.approval-queue-drawer.open { display: block; }
.approval-queue-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.5); }
.approval-queue-sheet {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: var(--bg-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  max-height: 70vh; overflow-y: auto;
  padding-bottom: var(--safe-bottom);
}
.approval-queue-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-4);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg-surface); z-index: 1;
}
.approval-queue-title { font-size: 16px; font-weight: 600; }
.approval-queue-close-btn { background: none; border: none; font-size: 16px; cursor: pointer; color: var(--text-muted); padding: 4px 8px; }
.approval-queue-item {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border-muted);
  display: flex; align-items: center; gap: var(--sp-3);
}
.approval-queue-item-label {
  flex: 1; font-size: 13px; color: var(--text-primary);
  font-family: var(--font-mono); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.approval-queue-item-actions { display: flex; gap: var(--sp-2); flex-shrink: 0; }
.approval-queue-item-actions .btn { padding: 4px 12px; font-size: 12px; }
.approval-queue-list { padding: var(--sp-2) 0; }

/* ═══════════════════════════════════════════════════════════
   Mobile UI/UX Polish
   ═══════════════════════════════════════════════════════════ */

/* ── Improved message bubble visual refinement ───────────── */
.message-ai .bubble {
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

.message-user .bubble {
  box-shadow: 0 2px 8px rgba(88, 166, 255, 0.25);
}

/* ── Tighter spacing between consecutive tool cards ──────── */
.activity-card + .activity-card,
.tool-card + .activity-card,
.activity-card + .tool-card,
.tool-card + .tool-card {
  margin-top: -10px;
}

/* ── Header icon buttons: ensure 44px touch targets ─────── */
.header-icon-btn,
#search-btn {
  min-width: 40px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  transition: background var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}

.header-icon-btn:active,
#search-btn:active {
  background: var(--bg-overlay);
  transform: scale(0.94);
}

/* ── Input bar subtle top gradient for depth ─────────────── */
#input-bar::before {
  content: '';
  position: absolute;
  top: -24px;
  left: 0;
  right: 0;
  height: 24px;
  background: linear-gradient(to top, var(--bg-surface), transparent);
  pointer-events: none;
}

/* ── Smooth scale on send button press ───────────────────── */
#send-btn:not(:disabled):active {
  transform: scale(0.88);
}

/* ── Approval sheet drag handle indicator ────────────────── */
.approval-handle {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-2) 0 var(--sp-1);
}
.approval-handle-bar {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: var(--radius-pill);
}

/* ── Better scroll momentum on mobile ───────────────────────*/
#messages {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: none;
}

/* ── Improved activity card shadow (lighter on mobile) ───── */
.activity-card {
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

/* ── Subtle visual separation for messages area ─────────── */
#messages {
  scroll-padding-bottom: 24px;
}

/* ── Thinking block: tighter header on mobile ────────────── */
@media (max-width: 480px) {
  .thinking-header {
    padding: 8px 12px;
  }
  .bubble {
    padding: var(--sp-3) 14px;
  }
  #messages {
    padding: var(--sp-3);
    padding-bottom: max(var(--sp-3), calc(var(--safe-bottom) + 6px));
    gap: var(--sp-3);
  }
  .activity-card {
    padding: 10px 12px;
  }
}

/* ── Tool group open animation ───────────────────────────── */
@keyframes slide-down {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* NOTE: Do NOT use animation-fill-mode:both here — it would hold the body
   at opacity:0 if the browser doesn't start the animation after a
   display:none→flex transition, permanently hiding the tool cards. */
.tool-group.open .tool-group-body {
  animation: slide-down var(--dur-fast) var(--ease-out) forwards;
}

/* ── Inline status indicator (Codex-style) ──────────────── */
.inline-status {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 0 3px 2px;
  font-size: 12px;
  color: var(--text-muted);
  animation: msg-enter var(--dur-normal) var(--ease-out) both;
  max-width: min(100%, 560px);
}

.inline-status.is-running {
  color: var(--blue);
}

.inline-status.is-done {
  color: var(--text-muted);
}

.inline-status-icon {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.inline-status-spinner {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 1.5px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.inline-status-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

/* ── Better focus rings for accessibility ────────────────── */
:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

/* Remove default focus ring (replaced by focus-visible) */
:focus:not(:focus-visible) {
  outline: none;
}

/* ── History parent dir breadcrumbs ────────────────────────────────────────── */
.history-parent-dirs {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-parent-dir-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: var(--bg-input);
  border: 1px solid var(--border);
  cursor: pointer;
  text-align: left;
  transition: background var(--dur-fast) var(--ease-out);
  width: 100%;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}

.history-parent-dir-btn:active {
  background: var(--bg-overlay);
}

.history-parent-dir-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.history-parent-dir-path {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  word-break: break-all;
}

.history-parent-empty {
  font-size: 12px;
  color: var(--text-muted);
  padding: var(--sp-2) 0;
}

.history-path-details {
  margin-top: var(--sp-3);
}

.history-path-details-summary {
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: var(--sp-1) 0;
  user-select: none;
  -webkit-user-select: none;
  list-style: none;
  -webkit-tap-highlight-color: transparent;
}

.history-path-details-summary::-webkit-details-marker { display: none; }
.history-path-details-summary::marker { display: none; }

.history-path-details[open] .history-path-details-summary {
  color: var(--text-primary);
  margin-bottom: var(--sp-2);
}

.history-path-details .history-workspace-input,
.history-path-details .history-workspace-start-btn {
  margin-top: var(--sp-2);
}

/* ══════════════════════════════════════════════════════════
   MOBILE BREAKPOINTS
   Order: 390px first, then 375px (so 375px overrides 390px)
   ══════════════════════════════════════════════════════════ */

/* ── 390px — iPhone 14 / 15 Pro ────────────────────────── */
@media (max-width: 390px) {
  .header-cwd {
    max-width: 120px;
  }
}

/* ── 375px — iPhone SE / Mini ───────────────────────────── */
@media (max-width: 375px) {
  .header-row {
    padding: 0 var(--sp-2);
    gap: var(--sp-1);
  }
  .status-pill {
    padding: 3px 8px 3px 6px;
    font-size: 10px;
  }
  .bubble {
    font-size: 13px;
  }
  .composer-wrap {
    padding: var(--sp-2) var(--sp-2);
    padding-bottom: max(var(--sp-2), calc(var(--safe-bottom) + var(--sp-2)));
  }
  #prompt-input {
    font-size: 15px; /* prevent iOS auto-zoom */
  }
}

/* ── 768px+ — tablet / desktop centering ───────────────── */
@media (min-width: 768px) {
  #screen-main {
    max-width: 768px;
    margin: 0 auto;
  }
  #messages {
    padding-left: var(--sp-6);
    padding-right: var(--sp-6);
  }
  .composer-wrap {
    padding-left: var(--sp-6);
    padding-right: var(--sp-6);
  }
  #header {
    max-width: 768px;
    margin: 0 auto;
    width: 100%;
  }
}
