/* ─── Design tokens ──────────────────────────────────────── */
:root {
  --bg:          #1a1523;
  --bg2:         #221c33;
  --bg3:         #2d2440;
  --surface:     rgba(255,255,255,0.05);
  --surface2:    rgba(255,255,255,0.09);
  --border:      rgba(255,255,255,0.08);
  --accent:      #b084f0;
  --accent2:     #7c3aed;
  --text:        #e8e3f0;
  --text2:       #a89ec0;
  --text3:       #6b5e8a;
  --user-bubble: #2d2440;
  --ai-bubble:   transparent;
  --radius:      16px;
  --radius-sm:   10px;
  --nav-h:       52px;
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bot:    env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
}

/* ─── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; width: 100%; max-width: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button { background: none; border: none; cursor: pointer; color: inherit; font: inherit; }
input, textarea { font: inherit; color: inherit; font-size: max(16px, 1em); }

/* ─── App shell ──────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  position: relative;
}

/* ─── Screen transition ──────────────────────────────────── */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  transition: transform 0.28s cubic-bezier(.4,0,.2,1), opacity 0.28s ease;
  will-change: transform;
}
.screen.hidden   { display: none; }
.screen.slide-in { transform: translateX(100%); }
.screen.slide-in.active { transform: translateX(0); }
.screen.slide-out { transform: translateX(-30%); opacity: 0.5; }

/* ─── Nav bar ────────────────────────────────────────────── */
.nav {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(var(--safe-top) + 8px) 16px 8px;
  height: calc(var(--nav-h) + var(--safe-top));
  background: rgba(26, 21, 35, 0.85);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 10;
}
.nav-title {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.3px;
  text-align: center;
}
.nav-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--accent);
  font-size: 20px;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.nav-btn:active { background: var(--surface2); }
.nav-btn.active { background: var(--surface2); color: var(--accent); }
.nav-btn.back { font-size: 22px; color: var(--accent); }
.nav-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ─── PIN screen ─────────────────────────────────────────── */
#pin-screen {
  justify-content: center;
  align-items: center;
  gap: 40px;
  padding: var(--safe-top) var(--safe-right) var(--safe-bot) var(--safe-left);
}
.pin-logo {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  background: linear-gradient(135deg, #7c3aed, #b084f0);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  box-shadow: 0 8px 32px rgba(176,132,240,0.3);
}
.pin-title { font-size: 22px; font-weight: 700; letter-spacing: -0.5px; }
.pin-subtitle { font-size: 14px; color: var(--text2); margin-top: 4px; text-align: center; }
.pin-dots {
  display: flex;
  gap: 14px;
}
.pin-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  transition: background 0.15s, border-color 0.15s;
}
.pin-dot.filled {
  background: var(--accent);
  border-color: var(--accent);
}
.pin-dot.error {
  background: #ef4444;
  border-color: #ef4444;
  animation: shake 0.3s ease;
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 260px;
}
.pin-key {
  height: 68px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 22px;
  font-weight: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.pin-key sub { font-size: 9px; color: var(--text3); letter-spacing: 1px; margin-top: 2px; }
.pin-key:active { background: var(--surface2); transform: scale(0.95); }
.pin-key.del { font-size: 18px; color: var(--accent); }
.pin-error { font-size: 13px; color: #ef4444; text-align: center; min-height: 20px; }

/* ─── Sessions screen ────────────────────────────────────── */
#sessions-screen { overflow: hidden; }
.sessions-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding-bottom: var(--safe-bot);
}

/* Search bar */
.search-wrap {
  padding: 8px 16px;
  flex-shrink: 0;
}
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface2);
  border-radius: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  width: 100%;
  box-sizing: border-box;
}
.search-bar input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-size: 16px;
  color: var(--text);
}
.search-bar input::placeholder { color: var(--text3); }
.search-icon { color: var(--text3); font-size: 16px; }

/* Filter dropdown button */
.nav-filter-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px 5px 10px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(176, 132, 240, 0.1);
  border: 1px solid rgba(176, 132, 240, 0.2);
  max-width: 140px;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
  flex-shrink: 0;
}
.nav-filter-btn span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-filter-btn:active { background: rgba(176, 132, 240, 0.22); }

/* Filter dropdown — styled like the New Chat sheet */
.filter-dropdown {
  position: absolute;
  top: calc(var(--nav-h) + var(--safe-top) + 4px);
  left: 10px;
  right: 10px;
  z-index: 200;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 55vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: 0 12px 40px rgba(0,0,0,0.6);
  padding: 8px;
  opacity: 0;
  transform: translateY(-8px) scale(0.97);
  transform-origin: top center;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.filter-dropdown.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.filter-option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  text-align: left;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s;
}
.filter-option:last-child { margin-bottom: 0; }
.filter-option:active { background: var(--surface2); }
.filter-option.active {
  background: rgba(176,132,240,0.12);
  border-color: rgba(176,132,240,0.3);
  color: var(--accent);
}
.filter-option-icon { font-size: 18px; width: 26px; text-align: center; flex-shrink: 0; }

/* Section headers */
.section-header {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text3);
  padding: 16px 16px 6px;
}

/* Swipe-to-delete row */
.session-row {
  position: relative;
  margin: 0 12px 6px;
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.row-delete-btn {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 82px;
  background: #dc2626;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
  -webkit-tap-highlight-color: transparent;
}
.row-delete-btn svg { flex-shrink: 0; }

/* Session card */
.session-card {
  margin: 0;
  padding: 12px 14px;
  background: var(--bg2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  position: relative;
  z-index: 1;
  -webkit-tap-highlight-color: transparent;
}
.session-card:active { background: var(--bg3); }

/* Inline delete confirmation */
.card-confirm {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px;
  min-height: 62px;
}
.card-confirm-msg {
  font-size: 14px;
  color: var(--text2);
  flex: 1;
  min-width: 0;
}
.card-confirm-btns { display: flex; gap: 8px; flex-shrink: 0; }
.card-confirm-cancel {
  padding: 7px 13px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text2);
  -webkit-tap-highlight-color: transparent;
}
.card-confirm-delete {
  padding: 7px 13px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  background: #dc2626;
  color: #fff;
  -webkit-tap-highlight-color: transparent;
}
.card-body { min-width: 0; }
.card-title {
  font-size: 15px;
  font-weight: 500;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--text);
  margin-bottom: 5px;
}
.card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text3);
}
.card-badge {
  background: rgba(176,132,240,0.12);
  color: var(--accent);
  padding: 1px 7px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
}
.card-dot { width: 2px; height: 2px; border-radius: 50%; background: var(--text3); flex-shrink: 0; }

/* FAB — New chat */
.fab {
  position: absolute;
  bottom: calc(20px + var(--safe-bot));
  right: 20px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  box-shadow: 0 4px 20px rgba(176,132,240,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  color: white;
  transition: transform 0.15s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
  z-index: 20;
}
.fab:active { transform: scale(0.93); box-shadow: 0 2px 10px rgba(176,132,240,0.3); }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 32px;
  color: var(--text3);
}
.empty-state .icon { font-size: 48px; margin-bottom: 16px; }
.empty-state p { font-size: 15px; line-height: 1.5; }

/* ─── Bottom sheet ───────────────────────────────────────── */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  z-index: 100;
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}
.sheet-overlay.visible { opacity: 1; pointer-events: all; }
.sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg2);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--border);
  padding: 0 16px calc(16px + var(--safe-bot));
  z-index: 101;
  transform: translateY(100%);
  transition: transform 0.32s cubic-bezier(.4,0,.2,1);
  max-height: 80dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sheet-scroll {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  min-height: 0;
}
.sheet.open { transform: translateY(0); }
.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 10px auto 20px;
  flex-shrink: 0;
}
.sheet-title { font-size: 13px; font-weight: 600; color: var(--text3); text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 12px; flex-shrink: 0; }
.sheet-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  margin-bottom: 10px;
  font-size: 15px;
  font-weight: 500;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.sheet-item:active { background: var(--surface2); }
.sheet-item-danger { color: #f87171; }
.sheet-item .icon { font-size: 20px; width: 28px; text-align: center; }
.sheet-cancel {
  text-align: center;
  padding: 14px;
  color: var(--accent);
  font-size: 16px;
  font-weight: 500;
  margin-top: 4px;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

/* ─── Chat screen ────────────────────────────────────────── */
#chat-screen { overflow: hidden; }

.chat-history {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: 16px 0 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Terminal view */
.term-view {
  display: none;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  background: #0d0b14;
  padding: 14px 16px;
}
.term-view.visible { display: block; }
.term-pre {
  font-family: "SF Mono", "Menlo", "JetBrains Mono", ui-monospace, monospace;
  font-size: 13px;
  line-height: 1.6;
  color: #c8c4d4;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

/* Message bubbles */
.msg {
  padding: 4px 16px;
  display: flex;
  flex-direction: column;
}
.msg.user { align-items: flex-end; }
.msg.assistant { align-items: flex-start; }

.bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.5;
  word-break: break-word;
}
.msg.user .bubble {
  background: var(--user-bubble);
  border: 1px solid rgba(176,132,240,0.2);
  border-bottom-right-radius: 4px;
  color: var(--text);
}
.msg.assistant .bubble {
  background: var(--ai-bubble);
  border-radius: 0;
  padding: 8px 0;
  max-width: 100%;
  color: var(--text);
}
.msg.assistant .bubble-inner {
  max-width: 100%;
}

/* Markdown in assistant bubbles */
.bubble p { margin-bottom: 10px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3 {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 8px;
  margin-top: 12px;
  color: var(--text);
}
.bubble h1:first-child, .bubble h2:first-child, .bubble h3:first-child { margin-top: 0; }
.bubble code {
  background: rgba(255,255,255,0.08);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 13px;
  font-family: "SF Mono", "JetBrains Mono", monospace;
  color: #e0c8ff;
}
.bubble pre {
  background: rgba(0,0,0,0.3);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  max-width: 100%;
  margin: 8px 0;
  border: 1px solid var(--border);
}
.bubble pre code {
  background: none;
  padding: 0;
  font-size: 13px;
  color: #d4b8ff;
}
.bubble ul, .bubble ol { padding-left: 20px; margin-bottom: 10px; }
.bubble li { margin-bottom: 4px; }
.bubble strong { font-weight: 700; color: var(--text); }
.bubble em { font-style: italic; }
.bubble a { color: var(--accent); text-decoration: none; }
.bubble blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  color: var(--text2);
  margin: 8px 0;
}

/* Tool use indicator */
.tool-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px;
  margin: 2px 16px;
}

/* Thinking / loading */
.thinking {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  color: var(--text3);
  font-size: 14px;
}
.thinking-dots { display: flex; gap: 4px; }
.thinking-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce 1.2s infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%,80%,100% { transform: scale(0.7); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

/* Divider between history and live terminal */
.history-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  flex-shrink: 0;
}
.history-divider::before, .history-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.history-divider span {
  font-size: 11px;
  color: var(--text3);
  white-space: nowrap;
  letter-spacing: 0.5px;
}

/* ─── Terminal panel ─────────────────────────────────────── */
.terminal-panel {
  flex-shrink: 0;
  background: #0d0b14;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: height 0.3s cubic-bezier(.4,0,.2,1);
}
.terminal-panel.collapsed { height: 0; border-top: none; }
.terminal-panel.expanded { flex: 1; }

.terminal-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(0,0,0,0.3);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}
.terminal-toolbar-title {
  flex: 1;
  font-size: 12px;
  color: var(--text3);
  font-family: "SF Mono", monospace;
}
.terminal-toolbar-btn {
  font-size: 13px;
  color: var(--text3);
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.terminal-toolbar-btn:active { background: var(--surface2); }

.xterm-container {
  flex: 1;
  overflow: hidden;
  padding: 6px 4px;
}

/* ─── Bottom area (status bar + input bar) ───────────────── */
.bottom-area {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-bot);
  position: relative;
}

/* ─── Status bar (ticker) ────────────────────────────────── */
.status-bar {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: 4px 14px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  font-family: "SF Mono", ui-monospace, "Menlo", monospace;
  font-size: 11px;
  overflow: hidden;
  flex-shrink: 0;
}
.status-row {
  display: flex;
  align-items: center;
  white-space: nowrap;
  overflow: hidden;
  line-height: 1.3;
}
.st-dir        { color: var(--text2); }
.st-branch     { color: #4ade80; }
.st-ctx        { }
.ctx-ok        { color: #4ade80; }
.ctx-mid       { color: #f59e0b; }
.ctx-high      { color: #ef4444; }
.st-model      { color: var(--accent); }
.st-sep        { color: var(--text3); }
.st-connecting { color: var(--text3); font-style: italic; }

/* ─── Slash command picker ───────────────────────────────── */
.cmd-picker {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  z-index: 50;
  max-height: 240px;
  overflow-y: auto;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  box-shadow: 0 -8px 24px rgba(0,0,0,0.35);
  display: none;
  -webkit-overflow-scrolling: touch;
}
.cmd-picker.open { display: block; }
.cmd-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 10px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  -webkit-tap-highlight-color: transparent;
}
.cmd-item:last-child { border-bottom: none; }
.cmd-item.focused, .cmd-item:active { background: var(--surface2); }
.cmd-section-header {
  padding: 5px 16px 3px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.6px;
  color: var(--text3);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  user-select: none;
}
.cmd-item-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  font-family: "SF Mono", ui-monospace, "Menlo", monospace;
}
.cmd-item-system .cmd-item-name {
  color: var(--text2);
}
.cmd-item-desc {
  font-size: 12px;
  color: var(--text3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── Input wrapper + overlay ────────────────────────────── */
.input-wrapper {
  flex: 1;
  min-width: 0;
  position: relative;
}
.input-overlay {
  position: absolute;
  top: 1px; left: 1px; right: 1px; bottom: 1px;
  padding: 10px 16px;
  font-size: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  line-height: 1.4;
  pointer-events: none;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: hidden;
  color: var(--text);
  border-radius: 20px;
  z-index: 1;
  box-sizing: border-box;
}
.cmd-token {
  color: var(--accent);
  font-weight: 600;
}
.input-box.has-cmd {
  color: transparent;
  caret-color: var(--text);
}

/* ─── Input bar ──────────────────────────────────────────── */
.input-bar {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  width: 100%;
  box-sizing: border-box;
}
.input-box {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 16px; /* 16px prevents iOS auto-zoom on focus */
  color: var(--text);
  outline: none;
  resize: none;
  max-height: 120px;
  min-height: 40px;
  line-height: 1.4;
  overflow-y: auto;
  transition: border-color 0.2s;
  -webkit-appearance: none;
}
.input-box:focus { border-color: rgba(176,132,240,0.5); }
.input-box::placeholder { color: var(--text3); }
.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.send-btn:disabled { background: var(--surface); opacity: 0.5; }
.send-btn:not(:disabled):active { transform: scale(0.9); }
.send-btn svg { width: 18px; height: 18px; fill: white; }

/* ─── Ctrl key bar (above keyboard) ─────────────────────── */
.ctrl-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg3);
  border-top: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: none;
}
.ctrl-bar::-webkit-scrollbar { display: none; }
.ctrl-key {
  flex-shrink: 0;
  padding: 5px 12px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12px;
  font-family: "SF Mono", monospace;
  color: var(--text2);
  transition: background 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.ctrl-key:active { background: var(--surface2); }
.ctrl-key.active { background: rgba(176,132,240,0.2); border-color: var(--accent); color: var(--accent); }

/* ─── Loading skeleton ───────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface2) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 8px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.skeleton-card { height: 72px; margin: 0 12px 8px; border-radius: var(--radius-sm); }
.skeleton-msg { height: 48px; margin: 4px 16px; border-radius: 12px; }

/* ─── Toast ──────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(80px + var(--safe-bot));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 18px;
  font-size: 14px;
  color: var(--text);
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  white-space: nowrap;
  z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ─── Scrollbar ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ─── xterm overrides ────────────────────────────────────── */
.xterm { padding: 0; }
.xterm-viewport { background: transparent !important; }
.xterm-screen canvas { border-radius: 0; }

/* ─── Responsive / Desktop ───────────────────────────────── */
@media (min-width: 768px) {
  #app {
    max-width: 900px;
    margin: 0 auto;
    height: 100dvh;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }

  body {
    background: #110e1d;
  }

  .pin-pad { width: 280px; }
  .pin-key { height: 72px; }

  .bubble { font-size: 15px; }
  .msg.user { padding-right: 24px; }
  .msg.assistant { padding-left: 24px; }

  /* Sidebar layout for wide screens */
  .chat-history { padding: 24px 0; }
  .msg.user .bubble { max-width: 72%; }

  .input-bar { padding: 12px 20px; }
  .input-box { font-size: 15px; }

  /* Terminal always tall on desktop */
  .terminal-panel.expanded { min-height: 300px; }

  .ctrl-bar { padding: 8px 20px; }
}

@media (min-width: 1100px) {
  #app { max-width: 760px; }
}
