:root {
  --bg: #0a0a0a;
  --bg-surface: #141414;
  --bg-elevated: #1a1a1a;
  --bg-hover: #222222;
  --text: #e4e4e7;
  --text-muted: #71717a;
  --text-dim: #52525b;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --orange: #f97316;
  --border: #27272a;
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* Login Screen */
.login-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 24px;
  gap: 24px;
}

.login-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 15px;
}

.pin-display {
  display: flex;
  gap: 16px;
  padding: 16px 0;
}

.pin-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border);
  transition: all 0.15s ease;
}

.pin-dot.filled {
  background: var(--accent);
  border-color: var(--accent);
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 80px);
  gap: 12px;
}

.pin-btn {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: none;
  background: var(--bg-surface);
  color: var(--text);
  font-size: 28px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.1s;
  -webkit-user-select: none;
  user-select: none;
}

.pin-btn:active {
  background: var(--bg-hover);
}

.pin-error {
  color: var(--red);
  font-size: 14px;
  min-height: 20px;
}

/* Session List */
.sessions-screen {
  display: flex;
  flex-direction: column;
  height: 100%;
}

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

.sessions-header h1 {
  font-size: 20px;
  font-weight: 700;
}

.sessions-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
}

.session-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--bg-surface);
  border-radius: var(--radius);
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.1s, transform 0.2s;
  position: relative;
  overflow: hidden;
}

.session-card:active {
  background: var(--bg-hover);
}

.session-card .session-info {
  flex: 1;
  min-width: 0;
}

.session-card .session-name {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-card .session-meta {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 2px;
}

.session-card .session-delete {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 80px;
  background: var(--red);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 13px;
  font-weight: 600;
  transform: translateX(80px);
  transition: transform 0.2s;
}

.status-badge {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-badge.running { background: var(--green); }
.status-badge.waiting { background: var(--yellow); animation: pulse 1.5s infinite; }
.status-badge.done { background: var(--text-dim); }

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

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  gap: 12px;
  padding: 40px;
  text-align: center;
}

.empty-state-icon {
  font-size: 48px;
  opacity: 0.3;
}

/* New Session Button */
.new-session-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  font-size: 28px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: transform 0.1s;
}

.new-session-btn:active {
  transform: scale(0.92);
}

/* Modal / Bottom Sheet */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  animation: fadeIn 0.15s ease;
}

.modal {
  width: 100%;
  background: var(--bg-elevated);
  border-radius: 20px 20px 0 0;
  padding: 20px;
  max-height: 80vh;
  overflow-y: auto;
  animation: slideUp 0.2s ease;
}

.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 16px;
}

.modal h2 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 16px;
}

.modal-section {
  margin-bottom: 20px;
}

.modal-section-title {
  font-size: 13px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* Target Selector */
.target-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.target-option {
  padding: 16px;
  background: var(--bg-surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s;
}

.target-option.selected {
  border-color: var(--accent);
}

.target-option.offline {
  opacity: 0.4;
  pointer-events: none;
}

.target-option .target-icon {
  font-size: 24px;
  margin-bottom: 4px;
}

.target-option .target-label {
  font-size: 14px;
  font-weight: 600;
}

.target-option .target-status {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Project List */
.project-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.project-item {
  padding: 14px 16px;
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.1s;
  display: flex;
  align-items: center;
  gap: 10px;
}

.project-item:active {
  background: var(--bg-hover);
}

.project-item .project-icon {
  color: var(--accent);
  font-size: 16px;
  width: 20px;
  text-align: center;
}

.project-item .project-label {
  font-size: 15px;
}

.custom-path-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  outline: none;
  margin-top: 8px;
}

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

.modal-submit-btn {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
}

.modal-submit-btn:disabled {
  opacity: 0.4;
  pointer-events: none;
}

/* Tab Bar */
.tab-bar {
  display: flex;
  overflow-x: auto;
  padding: 8px 16px;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tab-bar::-webkit-scrollbar { display: none; }

.tab {
  flex-shrink: 0;
  padding: 6px 14px;
  background: var(--bg-surface);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.1s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tab.active {
  background: var(--accent);
  color: white;
}

/* Chat Screen */
.chat-screen {
  display: flex;
  flex-direction: column;
  height: 100%;
}

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

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.chat-back-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
}

.chat-session-name {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.chat-header-btn {
  background: var(--bg-surface);
  border: none;
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
}

.chat-header-btn:active {
  background: var(--bg-hover);
}

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

.chat-bubble {
  max-width: 100%;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
}

.chat-bubble.output {
  background: var(--bg-surface);
  font-family: var(--font-mono);
  font-size: 13px;
  white-space: pre-wrap;
}

.chat-bubble.input {
  background: var(--accent);
  color: white;
  align-self: flex-end;
  border-radius: var(--radius) var(--radius) 4px var(--radius);
}

.chat-bubble.system {
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 8px;
}

/* Markdown in bubbles */
.chat-bubble code {
  background: var(--bg-hover);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 13px;
}

.chat-bubble pre {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
}

.chat-bubble pre code {
  background: none;
  padding: 0;
}

/* Collapsible output */
.collapse-toggle {
  display: block;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 0;
  margin-top: 4px;
}

.collapsed-content {
  display: none;
}

.collapsed-content.expanded {
  display: block;
}

/* Quick Actions */
.quick-actions {
  display: flex;
  gap: 8px;
  padding: 8px 16px;
  overflow-x: auto;
  border-top: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

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

.quick-action-btn {
  flex-shrink: 0;
  padding: 8px 20px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.1s;
}

.quick-action-btn:active {
  background: var(--bg-hover);
}

.quick-action-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* Permission Card */
.permission-card {
  background: var(--bg-surface);
  border: 1px solid var(--yellow);
  border-radius: var(--radius);
  padding: 16px;
  margin: 8px 0;
}

.permission-card .perm-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 8px;
  color: var(--yellow);
}

.permission-card .perm-context {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
  white-space: pre-wrap;
}

.permission-card .perm-actions {
  display: flex;
  gap: 8px;
}

.perm-approve {
  flex: 1;
  padding: 10px;
  background: var(--green);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

.perm-reject {
  flex: 1;
  padding: 10px;
  background: var(--red);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

/* Diff View */
.diff-block {
  background: var(--bg);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin: 8px 0;
  border: 1px solid var(--border);
}

.diff-header {
  padding: 8px 12px;
  background: var(--bg-surface);
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.diff-line {
  padding: 2px 12px;
  font-family: var(--font-mono);
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-all;
}

.diff-line.add {
  background: rgba(34, 197, 94, 0.1);
  color: var(--green);
}

.diff-line.remove {
  background: rgba(239, 68, 68, 0.1);
  color: var(--red);
}

.diff-line.context {
  color: var(--text-dim);
}

/* Reconnect Banner */
.reconnect-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: 8px 16px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  z-index: 200;
  transition: transform 0.2s, opacity 0.2s;
}

.reconnect-banner.hidden {
  transform: translateY(-100%);
  opacity: 0;
}

.reconnect-banner.connecting {
  background: var(--yellow);
  color: #000;
}

.reconnect-banner.connected {
  background: var(--green);
  color: #000;
}

.reconnect-banner.offline {
  background: var(--red);
  color: white;
  cursor: pointer;
}

/* Input Bar */
.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.input-bar textarea {
  flex: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  padding: 10px 16px;
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.4;
  overflow-y: auto;
}

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

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

.send-btn, .mic-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  font-size: 18px;
}

.send-btn {
  background: var(--accent);
  color: white;
}

.send-btn:disabled {
  opacity: 0.3;
}

.mic-btn {
  background: var(--bg-surface);
  color: var(--text-muted);
}

.mic-btn.recording {
  background: var(--red);
  color: white;
  animation: pulse 1s infinite;
}

/* Terminal */
.terminal-screen {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: #000;
}

.terminal-container {
  flex: 1;
  padding: 4px;
}

.terminal-back-btn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  font-size: 20px;
  cursor: pointer;
  z-index: 10;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Loading */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* Safe area for notch phones */
@supports (padding: env(safe-area-inset-top)) {
  .chat-header, .sessions-header {
    padding-top: calc(12px + env(safe-area-inset-top));
  }
  .input-bar {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
}
