.app-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  background: var(--api-teal);
  color: white;
}
.app-header h1 { margin: 0; font-size: 18px; font-weight: bold; }
.header-right { display: flex; align-items: center; gap: var(--space-md); }
.captured-status {
  font-size: 12px;
  opacity: 0.85;
  max-width: 320px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.spend-pill {
  font-size: 12px;
  padding: var(--space-xs) var(--space-sm);
  background: rgba(255, 255, 255, 0.15);
  border-radius: 999px;
}
.spend-pill.warning { background: var(--api-warning); }
.spend-pill.blocked { background: var(--api-error); }

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-xl);
  border: 2px dashed var(--api-border);
  margin: var(--space-lg);
  border-radius: var(--radius);
  text-align: center;
  cursor: pointer;
}
.empty-state.dragover { background: var(--api-bg-subtle); border-color: var(--api-teal); }

/* === Three-column workspace === */
.workspace {
  display: grid;
  grid-template-columns: 240px 1fr 440px;
  gap: var(--space-md);
  padding: var(--space-md);
  overflow: hidden;
  min-height: 0;
}

/* --- Column 1: TOC sidebar (nav-only in v0.2) --- */
.toc-sidebar {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  border: 1px solid var(--api-border);
  border-radius: var(--radius);
  padding: var(--space-sm);
  background: var(--api-bg);
}
.toc-sidebar .module-label {
  font-size: 12px;
  color: var(--api-text-muted);
  margin-bottom: var(--space-sm);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--api-border);
}
.toc-sidebar .toc-link {
  display: block;
  padding: var(--space-sm);
  font-size: 13px;
  color: var(--api-text);
  text-decoration: none;
  border-radius: var(--radius);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.toc-sidebar .toc-link:hover { background: var(--api-bg-subtle); }
.toc-sidebar .toc-link.active { background: var(--api-bg-subtle); color: var(--api-teal); font-weight: bold; }
.sidebar-footer {
  margin-top: auto;
  padding-top: var(--space-sm);
  border-top: 1px solid var(--api-border);
}
.sidebar-footer button { width: 100%; font-size: 12px; }

/* --- Column 2: Preview with capture toolbar --- */
.preview-column {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  min-height: 0;
}
.preview-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  background: var(--api-bg-subtle);
  border-radius: var(--radius);
  border: 1px solid var(--api-border);
}
.capture-hint {
  font-size: 12px;
  color: var(--api-text-muted);
}
.preview-iframe {
  width: 100%;
  flex: 1;
  border: 1px solid var(--api-border);
  border-radius: var(--radius);
  background: white;
  min-height: 0;
}

/* --- Column 3: Chat panel --- */
.chat-column {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  background: var(--api-bg);
  border: 1px solid var(--api-border);
  border-radius: var(--radius);
  padding: var(--space-md);
  min-height: 0;
  overflow: hidden;
}

.captured-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--api-border);
}
.captured-meta {
  font-size: 12px;
  color: var(--api-text-muted);
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.captured-meta.has-capture { color: var(--api-text); }
.captured-summary button { font-size: 12px; padding: 4px var(--space-sm); }

/* Tabs */
.tab-bar {
  display: flex;
  gap: var(--space-xs);
  border-bottom: 1px solid var(--api-border);
}
.tab {
  background: none;
  color: var(--api-text-muted);
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: var(--space-sm) var(--space-md);
  font-size: 13px;
  cursor: pointer;
}
.tab:hover { background: var(--api-bg-subtle); color: var(--api-text); }
.tab.active {
  color: var(--api-teal);
  border-bottom-color: var(--api-teal);
  font-weight: bold;
}

.tab-panels {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr;
  position: relative;
}
.tab-panel {
  display: none;
  overflow: auto;
  min-height: 200px;
}
.tab-panel.active { display: flex; flex-direction: column; }

.output-iframe {
  width: 100%;
  flex: 1;
  border: 1px solid var(--api-border);
  border-radius: var(--radius);
  background: white;
  min-height: 200px;
}
.output-source {
  flex: 1;
  margin: 0;
  padding: var(--space-md);
  background: var(--api-bg-subtle);
  border: 1px solid var(--api-border);
  border-radius: var(--radius);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: auto;
}

/* Conversation history */
.message-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  padding: var(--space-sm);
  overflow-y: auto;
  background: var(--api-bg-subtle);
  border: 1px solid var(--api-border);
  border-radius: var(--radius);
}
.history-empty {
  color: var(--api-text-muted);
  font-size: 12px;
  text-align: center;
  padding: var(--space-lg);
}
.message {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius);
  font-size: 13px;
  max-width: 100%;
  word-break: break-word;
}
.message.user {
  background: var(--api-teal);
  color: white;
  align-self: flex-end;
  max-width: 85%;
}
.message.assistant {
  background: white;
  color: var(--api-text);
  border: 1px solid var(--api-border);
  align-self: flex-start;
  max-width: 95%;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  white-space: pre-wrap;
}
.message-role {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.7;
  margin-bottom: var(--space-xs);
}

/* Chat input */
.chat-input {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  border-top: 1px solid var(--api-border);
  padding-top: var(--space-md);
}
.chat-input label { font-size: 12px; }
.instruction-input {
  min-height: 70px;
  max-height: 180px;
  resize: vertical;
  font-size: 13px;
}
.chat-buttons {
  display: flex;
  gap: var(--space-sm);
  justify-content: space-between;
}
.chat-buttons #send-button { flex: 1; }
.chat-buttons #lock-button { flex: 1; }

/* Sending state */
.chat-input.sending #send-button { opacity: 0.7; }

/* PIN gate */
.pin-gate-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.pin-gate-card {
  background: white;
  padding: var(--space-xl);
  border-radius: var(--radius);
  width: 360px;
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}
.pin-gate-card h2 { margin: 0; color: var(--api-teal); }
.pin-gate-error { color: var(--api-error); font-size: 12px; }

.hidden { display: none !important; }
