:root {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: #f0f0f0;
  background: #111;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  --accent: #6aa3ff;
  --surface: #1a1a1a;
  --surface-elevated: #222;
  --border: #2a2a2a;
  --text-dim: #8a8a8a;
  --text-muted: #a0a0a0;
  --danger: #ff5b5b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  /* Honor iOS safe-area insets — devices with notches need explicit padding
     so content doesn't tuck under the dynamic island / home indicator. */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* ---------- Shared shell layout (post-connect screens) ---------- */

.shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  padding: 20px 16px 8px;
}

.header-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-center {
  flex: 1;
  min-width: 0;
}

.header-row h1 {
  font-size: 20px;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ghost-btn {
  background: transparent;
  color: var(--accent);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 500;
  border: none;
}

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

code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 12px;
  padding: 2px 4px;
  background: var(--surface-elevated);
  border-radius: 4px;
}

.header h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--text-dim);
  font-size: 13px;
}

.main {
  flex: 1;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.status {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 13px;
  color: var(--text-muted);
  padding: 12px 14px;
  background: var(--surface);
  border-radius: 8px;
}

.hint {
  margin: 0;
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.5;
}

.error {
  margin-top: 12px;
  padding: 10px 12px;
  background: #2a1a1a;
  border: 1px solid var(--danger);
  border-radius: 8px;
  color: var(--danger);
  font-size: 13px;
}

/* ---------- Buttons ---------- */

button {
  border: none;
  border-radius: 10px;
  padding: 14px 16px;
  font-size: 16px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 100ms ease;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

.primary {
  background: var(--accent);
  color: #0a1a30;
  width: 100%;
}

.secondary {
  background: var(--surface);
  color: #e0e0e0;
  width: 100%;
}

.secondary:hover {
  background: var(--surface-elevated);
}

/* ---------- ConnectScreen ---------- */

.connect-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  gap: 24px;
}

.connect-header h1 {
  margin: 0;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.connect-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-title {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.conn-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.conn-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.conn-row-main {
  flex: 1;
  background: var(--surface);
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  border-radius: 10px;
}

.conn-row-main:hover {
  background: var(--surface-elevated);
}

.conn-name {
  font-size: 16px;
  font-weight: 500;
  color: #f0f0f0;
}

.conn-host {
  font-size: 13px;
  color: var(--text-dim);
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

.conn-forget {
  background: transparent;
  color: var(--text-dim);
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
}

.conn-forget:hover {
  color: var(--danger);
  border-color: var(--danger);
}

.paste-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.paste-input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  color: #e0e0e0;
  font-size: 14px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  outline: none;
}

.paste-input:focus {
  border-color: var(--accent);
}

.footnote {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
}

/* ---------- ChatScreen ---------- */

.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

.bubble {
  max-width: 86%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble-user {
  align-self: flex-end;
  background: var(--accent);
  color: #0a1a30;
  border-bottom-right-radius: 4px;
}

.bubble-assistant {
  align-self: flex-start;
  background: var(--surface);
  color: #e0e0e0;
  border-bottom-left-radius: 4px;
}

.bubble-system {
  align-self: center;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
  max-width: 100%;
}

.bubble-streaming {
  /* Subtle animation hint that the assistant is still writing —
     a steady opacity pulse rather than a spinner so the visual
     weight stays on the streamed text. */
  animation: pulse-opacity 1.4s ease-in-out infinite;
}

@keyframes pulse-opacity {
  0%, 100% { opacity: 0.95; }
  50% { opacity: 0.75; }
}

.bubble-thinking {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
  border-left: 2px solid var(--border);
  padding-left: 8px;
  font-style: italic;
}

.bubble-content {
  margin: 0;
}

.composer {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: #111;
  align-items: flex-end;
}

.composer-input {
  flex: 1;
}

.composer-send {
  width: auto;
  padding: 12px 18px;
  flex-shrink: 0;
}

/* ---------- AskQuestionSheet ---------- */

.sheet-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  animation: scrim-fade 150ms ease-out;
}

@keyframes scrim-fade {
  from { background: rgba(0, 0, 0, 0); }
  to { background: rgba(0, 0, 0, 0.6); }
}

.sheet {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
  animation: sheet-slide 200ms ease-out;
}

@keyframes sheet-slide {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.sheet-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.sheet-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sheet-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
}

.question-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.question-text {
  margin: 0;
  font-size: 15px;
  font-weight: 500;
  color: #f0f0f0;
}

.option-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.option {
  background: var(--surface-elevated);
  color: #e0e0e0;
  padding: 10px 14px;
  border-radius: 10px;
  text-align: left;
  font-size: 14px;
}

.option:hover {
  background: #2a2a2a;
}

.option-selected {
  background: var(--accent);
  color: #0a1a30;
}

/* ---------- PlanApprovalCard ---------- */

.plan-card {
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--accent);
  padding: 14px;
  margin: 8px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-self: stretch;
}

.plan-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.plan-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.plan-body {
  background: var(--surface-elevated);
  border-radius: 8px;
  padding: 10px 12px;
  max-height: 40vh;
  overflow-y: auto;
}

.plan-text {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 13px;
  white-space: pre-wrap;
  margin: 0;
  color: #d0d0d0;
}

.plan-actions {
  display: flex;
  gap: 8px;
}

.plan-actions button {
  flex: 1;
}
