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

:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --border: #2a2a2a;
  --accent: #7c3aed;
  --accent-dim: #5b21b6;
  --text: #e5e5e5;
  --text-dim: #737373;
  --user-bubble: #1e1b4b;
  --ai-bubble: #1a1a1a;
  --green: #10b981;
  --red: #ef4444;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
}

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

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.header h1 { font-size: 17px; font-weight: 600; flex: 1 }
.header .back-btn {
  background: none; border: none; color: var(--accent);
  font-size: 20px; cursor: pointer; padding: 2px 6px;
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--red); flex-shrink: 0;
}
.status-dot.online { background: var(--green) }

/* ── Screen system ── */
.screen { flex: 1; display: none; flex-direction: column; overflow: hidden }
.screen.active { display: flex }

/* ── Session list ── */
.session-list { flex: 1; overflow-y: auto; padding: 12px 0 }

.session-item {
  display: flex; flex-direction: column; gap: 4px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background 0.15s;
  active: background var(--surface);
}
.session-item:active { background: var(--surface) }
.session-item .project {
  font-size: 12px; color: var(--accent); font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.session-item .preview {
  font-size: 14px; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.session-item .meta {
  font-size: 12px; color: var(--text-dim);
}
.session-item .session-id {
  font-size: 11px; color: var(--text-dim); font-family: monospace;
}

/* ── New session FAB ── */
.fab {
  position: fixed; bottom: 24px; right: 20px;
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--accent); border: none; color: white;
  font-size: 26px; cursor: pointer;
  box-shadow: 0 4px 16px rgba(124,58,237,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 20;
}

/* ── Chat screen ── */
.chat-messages {
  flex: 1; overflow-y: auto;
  padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}

.bubble {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 16px;
  line-height: 1.5;
  font-size: 14px;
  word-break: break-word;
  white-space: pre-wrap;
}
.bubble.user {
  align-self: flex-end;
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
}
.bubble.assistant {
  align-self: flex-start;
  background: var(--ai-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.bubble .ts {
  font-size: 11px; color: var(--text-dim); margin-top: 4px; text-align: right;
}

/* ── Chat input ── */
.chat-input-bar {
  display: flex; gap: 8px;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.chat-input-bar textarea {
  flex: 1; resize: none;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 12px;
  color: var(--text); font-size: 14px; font-family: inherit;
  line-height: 1.4; max-height: 120px; outline: none;
}
.chat-input-bar textarea:focus { border-color: var(--accent) }
.chat-input-bar button {
  width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent); border: none; color: white;
  font-size: 18px; cursor: pointer; align-self: flex-end;
}
.chat-input-bar button:disabled { opacity: 0.4; cursor: default }

/* ── New session modal ── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.7); z-index: 30;
  align-items: flex-end;
}
.modal-overlay.open { display: flex }
.modal {
  background: var(--surface); width: 100%;
  border-radius: 20px 20px 0 0;
  padding: 20px 16px calc(24px + env(safe-area-inset-bottom));
}
.modal h2 { font-size: 16px; font-weight: 600; margin-bottom: 16px }
.modal input {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px;
  color: var(--text); font-size: 14px; outline: none; margin-bottom: 12px;
}
.modal input:focus { border-color: var(--accent) }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end }
.modal-actions button {
  padding: 10px 20px; border-radius: 10px; border: none;
  font-size: 14px; cursor: pointer; font-weight: 500;
}
.btn-cancel { background: var(--border); color: var(--text) }
.btn-start { background: var(--accent); color: white }

/* ── Empty / loading states ── */
.empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--text-dim); gap: 12px; text-align: center; padding: 32px;
}
.empty .icon { font-size: 48px }
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--border);
  padding: 10px 18px; border-radius: 10px;
  font-size: 13px; color: var(--text);
  opacity: 0; transition: opacity 0.2s; pointer-events: none; z-index: 40;
}
.toast.show { opacity: 1 }

/* ── Connecting banner ── */
.bridge-banner {
  background: #7c2d12; color: #fed7aa;
  text-align: center; font-size: 13px; padding: 6px;
  display: none;
}
.bridge-banner.show { display: block }
