/* ClauTerm — Mobile-first CSS */
/* Dark theme, OLED-friendly, 48px touch targets, safe area insets */

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

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-hover: #1c2128;
  --border: #30363d;
  --text: #c9d1d9;
  --text-dim: #8b949e;
  --text-bright: #f0f6fc;
  --green: #3fb950;
  --green-dim: #238636;
  --amber: #d29922;
  --amber-dim: #9e6a03;
  --red: #f85149;
  --red-dim: #da3633;
  --blue: #58a6ff;
  --blue-dim: #1f6feb;

  --radius: 8px;
  --radius-lg: 12px;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', 'Menlo', 'Monaco', 'Courier New', monospace;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ──────────────────────────────────
   Header
   ────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: max(12px, var(--safe-top));
  padding-left: max(16px, var(--safe-left));
  padding-right: max(16px, var(--safe-right));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 48px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 600;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Status dot */
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--red);
  display: inline-block;
  flex-shrink: 0;
}

.status-dot.connected {
  background: var(--green);
}

.status-dot.reconnecting {
  background: var(--amber);
  animation: pulse 1s infinite;
}

.status-dot.error {
  background: var(--red);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Agent status badge */
.agent-status-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.agent-status-badge.idle {
  background: var(--green-dim);
  color: var(--green);
}

.agent-status-badge.working {
  background: var(--blue-dim);
  color: var(--blue);
  animation: pulse 1.5s infinite;
}

.agent-status-badge.needs-input {
  background: var(--amber-dim);
  color: var(--amber);
  animation: pulse 1s infinite;
}

/* Back button */
.btn-back {
  display: none;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--blue);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  padding: 0;
  min-width: 48px;
  min-height: 48px;
  -webkit-tap-highlight-color: transparent;
}

.btn-back.visible {
  display: flex;
}

/* Controller badge */
.controller-badge {
  display: none;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--blue-dim);
  color: var(--text-bright);
}

.controller-badge.active {
  display: inline-block;
}

.observer-badge {
  display: none;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--border);
  color: var(--text-dim);
}

.observer-badge.active {
  display: inline-block;
}

/* ──────────────────────────────────
   Views (routing)
   ────────────────────────────────── */
.view {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
}

.view.active {
  display: flex;
}

/* ──────────────────────────────────
   Dashboard
   ────────────────────────────────── */
.dashboard {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  padding-left: max(16px, var(--safe-left));
  padding-right: max(16px, var(--safe-right));
}

.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.dashboard-header h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Pull-to-refresh indicator */
.pull-indicator {
  text-align: center;
  padding: 8px 0;
  color: var(--text-dim);
  font-size: 13px;
  transition: opacity 0.2s;
  opacity: 0;
  height: 0;
  overflow: hidden;
}

.pull-indicator.visible {
  opacity: 1;
  height: auto;
  padding: 12px 0;
}

.pull-indicator.refreshing {
  opacity: 1;
  height: auto;
  padding: 12px 0;
}

/* Session cards */
.session-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
  min-height: 48px;
}

.session-card:active {
  border-color: var(--blue);
  background: var(--surface-hover);
}

.session-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.session-card-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-bright);
}

.session-card-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
}

.session-card-status.attached {
  color: var(--green);
}

.session-card-status.detached {
  color: var(--text-dim);
}

.session-card-meta {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.4;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}

.empty-state h2 {
  font-size: 20px;
  margin-bottom: 8px;
  color: var(--text);
}

.empty-state p {
  font-size: 14px;
  line-height: 1.6;
}

.empty-state code {
  background: var(--surface);
  padding: 2px 8px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 13px;
}

/* ──────────────────────────────────
   Token Input View
   ────────────────────────────────── */

.token-container {
  max-width: 400px;
  margin: 0 auto;
  padding: 60px 24px;
  text-align: center;
}

.token-container h2 {
  font-size: 22px;
  color: var(--text-bright);
  margin-bottom: 12px;
}

.token-container p {
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.6;
  margin-bottom: 16px;
}

.token-hint {
  display: block;
  background: var(--surface);
  padding: 8px 14px;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--blue);
  margin-bottom: 24px;
}

.token-input-row {
  display: flex;
  gap: 8px;
}

.token-field {
  flex: 1;
  padding: 12px 14px;
  font-size: 14px;
  font-family: var(--font-mono);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  min-height: 48px;
}

.token-field:focus {
  border-color: var(--blue);
}

.token-field::placeholder {
  color: var(--text-dim);
}

.token-error {
  color: var(--red);
  font-size: 13px;
  margin-top: 12px;
  min-height: 20px;
}

/* ──────────────────────────────────
   Session View
   ────────────────────────────────── */

/* Output area */
.output {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 16px;
  padding-left: max(16px, var(--safe-left));
  padding-right: max(16px, var(--safe-right));
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

/* xterm.js container — sibling of #output, fills session view */
.xterm-container {
  display: none;
  flex: 1;
  overflow: hidden;
  position: relative;
  /* No padding — xterm manages its own viewport */
}

/* Scroll-to-bottom indicator */
.scroll-indicator {
  display: none;
  position: fixed;
  bottom: 210px;
  right: 20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  z-index: 10;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.scroll-indicator.visible {
  display: flex;
}

/* ──────────────────────────────────
   Approval Card
   ────────────────────────────────── */
.approval-card {
  display: none;
  flex-shrink: 0;
  background: var(--surface);
  border-top: 2px solid var(--amber);
  padding: 16px;
  padding-left: max(16px, var(--safe-left));
  padding-right: max(16px, var(--safe-right));
  animation: slideUp 0.2s ease-out;
}

.approval-card.visible {
  display: block;
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.approval-tool {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--amber);
  margin-bottom: 4px;
}

.approval-description {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  margin-bottom: 12px;
  word-break: break-word;
}

.approval-detail {
  display: none;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-dim);
  background: var(--bg);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 12px;
  max-height: 120px;
  overflow-y: auto;
  word-break: break-all;
  white-space: pre-wrap;
}

.approval-detail.visible {
  display: block;
}

.approval-buttons {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.approval-feedback-row {
  display: flex;
  gap: 8px;
}

.approval-feedback-input {
  flex: 1;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 14px;
  font-family: var(--font-sans);
  min-height: 44px;
}

.approval-feedback-input::placeholder {
  color: var(--text-dim);
}

.approval-feedback-input:focus {
  outline: none;
  border-color: var(--blue);
}

/* ──────────────────────────────────
   Action Bar (bottom-anchored)
   ────────────────────────────────── */
.action-bar {
  display: none;
  flex-shrink: 0;
  padding: 12px 16px;
  padding-bottom: max(12px, var(--safe-bottom));
  padding-left: max(16px, var(--safe-left));
  padding-right: max(16px, var(--safe-right));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.action-bar.visible {
  display: block;
}

.action-buttons {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.input-row {
  display: flex;
  gap: 8px;
}

/* ──────────────────────────────────
   Buttons
   ────────────────────────────────── */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  min-height: 48px;
  padding: 12px 16px;
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn:active {
  opacity: 0.7;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-approve {
  flex: 1;
  background: var(--green);
  color: #000;
  min-height: 56px;
  font-size: 17px;
}

.btn-reject {
  flex: 1;
  background: var(--border);
  color: var(--text);
  min-height: 56px;
  font-size: 17px;
}

.btn-interrupt {
  background: var(--amber);
  color: #000;
  min-height: 48px;
  flex: 0 0 auto;
  padding: 12px 20px;
}

.btn-send {
  background: var(--blue);
  color: #000;
  width: 48px;
  min-height: 48px;
  border: none;
  border-radius: var(--radius);
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.btn-send:active {
  opacity: 0.7;
}

/* Feedback input */
.feedback-input {
  flex: 1;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  font-size: 15px;
  font-family: var(--font-sans);
  min-height: 48px;
}

.feedback-input::placeholder {
  color: var(--text-dim);
}

.feedback-input:focus {
  outline: none;
  border-color: var(--blue);
}

.feedback-input:read-only {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ──────────────────────────────────
   Connection banner
   ────────────────────────────────── */
.connection-banner {
  display: none;
  padding: 8px 16px;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  flex-shrink: 0;
}

.connection-banner.reconnecting {
  display: block;
  background: var(--amber-dim);
  color: var(--text-bright);
}

.connection-banner.error {
  display: block;
  background: var(--red-dim);
  color: var(--text-bright);
}

.connection-banner.offline {
  display: block;
  background: var(--amber-dim);
  color: var(--text-bright);
}

/* ──────────────────────────────────
   Push Notifications
   ────────────────────────────────── */
.push-section {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px 12px;
}
.btn-push {
  width: 100%;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-sans);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  min-height: 48px;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, background 0.15s;
}
.btn-push:active {
  background: var(--surface-hover);
}
.btn-push.active {
  background: var(--green-dim);
  color: var(--text-bright);
  border-color: var(--green);
}
.push-status {
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
}

/* ──────────────────────────────────
   Install Banner
   ────────────────────────────────── */
.install-banner {
  display: none;
  padding: 12px 16px;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  margin: 16px;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}
.install-banner.visible { display: flex; }
.btn-install {
  background: #238636;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-install-dismiss {
  background: none;
  border: none;
  color: #8b949e;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
}

/* ──────────────────────────────────
   Utilities
   ────────────────────────────────── */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ──────────────────────────────────
   Virtual Navigation Keys
   ────────────────────────────────── */
.nav-keys {
  display: none;
  flex-shrink: 0;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  padding-left: max(16px, var(--safe-left));
  padding-right: max(16px, var(--safe-right));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.nav-keys.visible { display: flex; }

.nav-key {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, background 0.1s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.nav-key:active {
  transform: scale(0.92);
  background: var(--blue-dim);
  color: var(--text-bright);
  border-color: var(--blue);
}

.nav-key:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
}

/* Ctrl button */
.nav-key-ctrl { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.nav-key-ctrl-active { background: var(--blue); color: var(--text-bright); border-color: var(--blue); }
.nav-key-ctrl-locked { background: var(--blue); color: var(--text-bright); border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue-dim); }

/* Overflow button */
.nav-key-overflow { font-size: 14px; letter-spacing: 2px; }

/* Ctrl overlay */
.ctrl-overlay {
  display: none;
  position: fixed;
  bottom: calc(192px + env(safe-area-inset-bottom, 0px));
  left: 16px;
  right: 16px;
  z-index: 25;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
.ctrl-overlay.visible { display: flex; }
.ctrl-overlay-label { color: var(--blue); font-weight: 600; font-size: 16px; }
.ctrl-input {
  flex: 1;
  height: 44px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 20px;
  text-align: center;
  text-transform: lowercase;
}
.ctrl-input:focus { outline: none; border-color: var(--blue); }
.ctrl-overlay-cancel {
  width: 44px;
  height: 44px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
}

/* Overflow panel */
.overflow-panel {
  display: none;
  position: fixed;
  bottom: calc(192px + env(safe-area-inset-bottom, 0px));
  left: 16px;
  right: 16px;
  z-index: 25;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.overflow-panel.visible { display: grid; }

@media (prefers-reduced-motion: reduce) {
  .nav-key { transition: none; }
}

/* ──────────────────────────────────
   Search Bar
   ────────────────────────────────── */
.btn-search {
  display: none;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  width: 44px;
  height: 44px;
  -webkit-tap-highlight-color: transparent;
}

.btn-search:active {
  color: var(--text-bright);
}

.search-bar {
  display: none;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  padding-left: max(12px, var(--safe-left));
  padding-right: max(12px, var(--safe-right));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 20;
}

.search-input {
  flex: 1;
  height: 40px;
  padding: 0 12px;
  font-size: 14px;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
}

.search-input:focus {
  border-color: var(--blue);
}

.search-input::placeholder {
  color: var(--text-dim);
}

.btn-search-nav {
  width: 40px;
  height: 40px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.btn-search-nav:active {
  background: var(--surface-hover);
}

.btn-search-close {
  width: 40px;
  height: 40px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.btn-search-close:active {
  color: var(--text-bright);
}

/* ──────────────────────────────────
   Quick Action Buttons
   ────────────────────────────────── */
.quick-actions {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  min-width: 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.quick-actions::-webkit-scrollbar {
  display: none;
}

.btn-quick-action {
  background: var(--surface-hover);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  min-height: 40px;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-quick-action:active {
  background: var(--blue-dim);
  border-color: var(--blue);
  color: var(--text-bright);
}

/* ──────────────────────────────────
   Audit Log View
   ────────────────────────────────── */
.audit-link-section {
  padding: 0 16px 12px;
}

.btn-audit {
  width: 100%;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-sans);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  min-height: 48px;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, background 0.15s;
}

.btn-audit:active {
  background: var(--surface-hover);
}

.audit-container {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  padding-left: max(16px, var(--safe-left));
  padding-right: max(16px, var(--safe-right));
}

.audit-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.audit-filter {
  flex: 1;
  padding: 10px 12px;
  font-size: 14px;
  font-family: var(--font-sans);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 44px;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.audit-count {
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
}

.audit-loading {
  display: none;
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
  font-size: 14px;
}

.audit-empty {
  display: none;
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
  font-size: 14px;
}

.audit-entries {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.audit-entry {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.audit-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 4px;
  margin-right: 8px;
}

.audit-danger {
  background: var(--red-dim);
  color: var(--text-bright);
}

.audit-success {
  background: var(--green-dim);
  color: var(--text-bright);
}

.audit-info {
  background: var(--blue-dim);
  color: var(--text-bright);
}

.audit-warn {
  background: var(--amber-dim);
  color: var(--text-bright);
}

.audit-dim {
  background: var(--border);
  color: var(--text-dim);
}

.audit-ts {
  font-size: 12px;
  color: var(--text-dim);
}

.audit-meta {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 6px;
  line-height: 1.4;
  word-break: break-all;
}

.btn-load-more {
  display: none;
  width: 100%;
  padding: 12px 16px;
  margin-top: 12px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-sans);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  min-height: 48px;
  -webkit-tap-highlight-color: transparent;
}

.btn-load-more:active {
  background: var(--surface-hover);
}

.btn-load-more:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ──────────────────────────────────
   Create Session Modal
   ────────────────────────────────── */
.btn-create-session {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: none;
  border: 2px solid var(--blue);
  color: var(--blue);
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s;
  min-width: 48px;
  min-height: 48px;
}

.btn-create-session:active {
  background: var(--blue);
  color: var(--bg);
}

.create-session-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 50;
  align-items: flex-end;
  justify-content: center;
}

.create-session-modal.visible {
  display: flex;
}

.create-session-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.create-session-sheet {
  position: relative;
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-top: 2px solid var(--blue);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 20px 16px;
  padding-bottom: max(20px, var(--safe-bottom));
  padding-left: max(16px, var(--safe-left));
  padding-right: max(16px, var(--safe-right));
  animation: slideUp 0.2s ease-out;
}

.create-session-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.create-session-header h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-bright);
}

.btn-create-close {
  width: 44px;
  height: 44px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.btn-create-close:active {
  color: var(--text-bright);
}

.create-session-body {
  margin-bottom: 16px;
}

.create-session-body label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.create-session-body label + label {
  margin-top: 14px;
}

.create-session-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 14px;
  font-family: var(--font-mono);
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  min-height: 48px;
}

.create-session-input:focus {
  border-color: var(--blue);
}

.create-session-input::placeholder {
  color: var(--text-dim);
}

/* -- Project list (Step 1) -- */
.project-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
  margin-top: 6px;
}

.project-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 14px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  font-family: var(--font-sans);
  cursor: pointer;
  min-height: 48px;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, background 0.15s;
}

.project-option:active {
  background: var(--surface-hover);
  border-color: var(--blue);
}

.project-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.project-name {
  font-family: var(--font-mono);
  font-size: 14px;
}

.project-loading, .project-empty {
  padding: 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
}

/* -- Selected project display (Step 2 header) -- */
.selected-project-display {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--blue);
  margin-bottom: 14px;
}

/* -- Mode list (Step 2) -- */
.mode-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}

.mode-option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  min-height: 56px;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, background 0.15s;
}

.mode-option:active {
  background: var(--surface-hover);
  border-color: var(--green);
}

.mode-icon {
  font-size: 20px;
  width: 32px;
  text-align: center;
  flex-shrink: 0;
  color: var(--text-dim);
}

.mode-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mode-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-bright);
}

.mode-desc {
  font-size: 12px;
  color: var(--text-dim);
}

.mode-desc code {
  font-family: var(--font-mono);
  color: var(--text);
  background: var(--surface);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 11px;
}

/* -- Conversation list (Resume step) -- */
.conversation-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 280px;
  overflow-y: auto;
  margin-top: 6px;
}

.conversation-option {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  padding: 12px 14px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: var(--font-sans);
  cursor: pointer;
  min-height: 48px;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, background 0.15s;
}

.conversation-option:active {
  background: var(--surface-hover);
  border-color: var(--blue);
}

.convo-main {
  display: flex;
  align-items: center;
  gap: 8px;
}

.convo-preview {
  font-size: 13px;
  color: var(--text);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.convo-time {
  font-size: 11px;
  color: var(--text-dim);
}

.convo-summary-preview {
  font-size: 12px;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* -- Confirm summary (Step 3) -- */
.confirm-summary {
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
}

.summary-row + .summary-row {
  border-top: 1px solid var(--border);
  margin-top: 4px;
  padding-top: 8px;
}

.summary-label {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.summary-value {
  font-size: 14px;
  color: var(--text-bright);
  font-family: var(--font-sans);
}

.summary-value code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--surface);
  padding: 2px 6px;
  border-radius: 3px;
}

/* -- Back button -- */
.btn-create-back {
  width: 100%;
  background: var(--surface-hover);
  color: var(--text);
  min-height: 48px;
  font-size: 15px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
}

.create-session-error {
  color: var(--red);
  font-size: 13px;
  margin-top: 10px;
  min-height: 18px;
}

.btn-create-submit {
  width: 100%;
  background: var(--green);
  color: #000;
  min-height: 52px;
  font-size: 16px;
}

/* ──────────────────────────────────
   Kill Session (header button)
   ────────────────────────────────── */
.btn-kill-session {
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  padding: 6px 14px;
  min-height: 36px;
  min-width: 48px;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s;
}

.btn-kill-session.visible {
  display: flex;
}

.btn-kill-session:active {
  opacity: 0.7;
}

/* ──────────────────────────────────
   Kill button on dashboard cards
   ────────────────────────────────── */
.session-card-kill {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  background: none;
  border: 1px solid var(--red-dim);
  color: var(--red);
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, border-color 0.15s;
  margin-left: 8px;
}

.session-card-kill:active {
  background: var(--red-dim);
  border-color: var(--red);
  color: var(--text-bright);
}

/* ──────────────────────────────────
   Confirm Modal
   ────────────────────────────────── */
.confirm-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 60;
  align-items: center;
  justify-content: center;
}

.confirm-modal.visible {
  display: flex;
}

.confirm-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.confirm-sheet {
  position: relative;
  width: calc(100% - 48px);
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 20px;
  animation: slideUp 0.2s ease-out;
}

.confirm-sheet p {
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  margin-bottom: 20px;
  text-align: center;
}

.confirm-buttons {
  display: flex;
  gap: 10px;
}

.btn-confirm-destructive {
  flex: 1;
  background: var(--red);
  color: #fff;
  min-height: 52px;
  font-size: 16px;
}

.btn-confirm-cancel {
  flex: 1;
  background: var(--border);
  color: var(--text);
  min-height: 52px;
  font-size: 16px;
}

/* ──────────────────────────────────
   Toast notification
   ────────────────────────────────── */
.toast {
  position: fixed;
  top: max(20px, env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: 14px;
  color: var(--text);
  z-index: 70;
  animation: toastIn 0.2s ease-out;
  pointer-events: none;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ==========================================================================
   Structured View — Conversation UI
   ========================================================================== */

.structured-container {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px;
  padding-left: max(16px, var(--safe-left));
  padding-right: max(16px, var(--safe-right));
  gap: 16px;
}

/* View toggle button in header */
.btn-view-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 12px;
  min-height: 36px;
  -webkit-tap-highlight-color: transparent;
}

.btn-view-toggle.visible {
  display: flex;
}

/* Empty state */
.sv-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  flex: 1;
}

.sv-empty-icon {
  font-size: 40px;
  color: var(--text-dim);
  margin-bottom: 12px;
  opacity: 0.5;
}

.sv-empty-text {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.sv-empty-hint {
  font-size: 13px;
  color: var(--text-dim);
  max-width: 280px;
}

/* Turn card */
.sv-turn {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* User bubble */
.sv-user-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
}

.sv-bubble-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.sv-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sv-label-user {
  color: var(--blue);
}

.sv-label-agent {
  color: var(--green);
}

.sv-time {
  font-size: 11px;
  color: var(--text-dim);
}

.sv-user-text {
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-bright);
  word-break: break-word;
  white-space: pre-wrap;
}

/* Agent bubble */
.sv-agent-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
}

.sv-agent-text {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  word-break: break-word;
}

.sv-agent-done {
  opacity: 0.7;
}

.sv-text-dim {
  color: var(--text-dim);
  font-style: italic;
}

/* Code blocks in agent response */
.sv-code-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  margin: 8px 0;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre;
}

.sv-inline-code {
  background: var(--bg);
  padding: 2px 5px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.9em;
}

/* Tool strip */
.sv-tools {
  padding: 0 4px;
}

.sv-tools-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 36px;
  padding: 4px 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  border-radius: var(--radius);
}

.sv-tools-header:active {
  background: var(--surface-hover);
}

.sv-tools-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
}

.sv-tools-chevron {
  font-size: 12px;
  color: var(--text-dim);
  transition: transform 0.15s ease;
}

.sv-tools-chevron.rotated {
  transform: rotate(90deg);
}

.sv-tools-list {
  display: none;
  padding: 4px 12px 8px;
}

.sv-tools-list.expanded {
  display: block;
}

.sv-tool-item {
  font-size: 12px;
  color: var(--text-dim);
  padding: 3px 0;
  line-height: 1.4;
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.sv-tool-name {
  color: var(--text);
  font-weight: 600;
  font-family: var(--font-mono);
  font-size: 11px;
  flex-shrink: 0;
}

.sv-tool-input {
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sv-tool-check {
  color: var(--green);
  font-size: 11px;
  flex-shrink: 0;
}

.sv-tool-spinner {
  color: var(--blue);
  font-size: 8px;
  flex-shrink: 0;
  animation: svPulse 1.5s infinite;
}

/* Working indicator */
.sv-working {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  color: var(--blue);
  font-size: 13px;
}

.sv-working-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--blue);
  animation: svPulse 1.5s infinite;
}

@keyframes svPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Task widget */
.sv-tasks {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.sv-tasks-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: 8px 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.sv-tasks-header:active {
  background: var(--surface-hover);
}

.sv-tasks-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.sv-tasks-chevron {
  font-size: 12px;
  color: var(--text-dim);
  transition: transform 0.15s ease;
}

.sv-tasks-chevron.rotated {
  transform: rotate(90deg);
}

.sv-tasks-list {
  display: none;
  padding: 0 16px 12px;
}

.sv-tasks-list.expanded {
  display: block;
}

.sv-task-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 13px;
  color: var(--text);
}

.sv-task-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.sv-task-done {
  color: var(--text-dim);
  text-decoration: line-through;
}

.sv-task-active {
  color: var(--blue);
}

.sv-task-subject {
  word-break: break-word;
}

