:root {
  --bg: #F7F8FA;
  --surface: #FFFFFF;
  --surface-2: #F0F2F5;
  --text: #1A202C;
  --text-2: #4A5568;
  --text-3: #718096;
  --accent: #2A6F6F;
  --accent-2: #4A9D9C;
  --accent-soft: #E6F2F2;
  --danger: #C53030;
  --danger-soft: #FFF5F5;
  --warn: #B7791F;
  --warn-soft: #FFFAEB;
  --success: #2F855A;
  --success-soft: #F0FFF4;
  --border: #E2E8F0;
  --shadow: 0 1px 3px rgba(26,32,44,0.08), 0 4px 12px rgba(26,32,44,0.05);
}

* { box-sizing: border-box; }

html {
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

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

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

.logo-icon {
  font-size: 1.8rem;
}

.logo-text h1 {
  margin: 0;
  font-size: 1.15rem;
  color: var(--text);
}

.logo-text p {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: var(--text-3);
}

.crisis-banner {
  background: var(--danger-soft);
  color: var(--danger);
  padding: 12px 24px;
  text-align: center;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border);
}

.crisis-banner a {
  color: var(--danger);
  font-weight: 700;
}

.main-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 24px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

.chat-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 24px;
  min-height: 500px;
}

.intro-card {
  text-align: center;
  padding: 48px 20px;
}

.intro-card h2 {
  margin: 0 0 10px;
  font-size: 1.4rem;
}

.intro-card p {
  color: var(--text-2);
  margin: 0 0 28px;
}

.topic-chips {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.topic-chips p {
  margin: 0 0 12px;
  font-size: 0.9rem;
  color: var(--text-2);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.chip {
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.chip:hover {
  background: var(--accent-soft);
  border-color: var(--accent-2);
  color: var(--accent);
}

.suggested-questions {
  margin-bottom: 12px;
}

.suggestions-label {
  font-size: 0.78rem;
  color: var(--text-3);
  margin: 0 0 8px;
}

.question-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.question-pill {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent-2);
  border-radius: 16px;
  padding: 8px 14px;
  font-size: 0.88rem;
  cursor: pointer;
  transition: background 0.15s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.question-pill:hover {
  background: var(--accent-2);
  color: white;
}

.btn-primary {
  background: var(--accent);
  color: white;
  border: 0;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary:hover {
  background: var(--accent-2);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
}

.btn-large {
  padding: 14px 28px;
  font-size: 1.1rem;
}

.btn-mic {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 0;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 1.6rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.2s, background 0.2s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn-mic:hover {
  transform: scale(1.05);
}

.btn-mic:active {
  transform: scale(0.96);
}

.btn-mic.listening {
  background: var(--danger);
  color: white;
  animation: pulse 1.2s infinite;
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

.chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.status-pill {
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 0.85rem;
  color: var(--text-2);
  font-weight: 500;
  margin-bottom: 16px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-3);
  transition: background 0.3s;
}

.status-pill.listening .status-dot {
  background: var(--danger);
  animation: blinkDot 1s infinite;
}

.status-pill.speaking .status-dot {
  background: var(--accent);
  animation: blinkDot 0.6s infinite;
}

.status-pill.thinking .status-dot {
  background: var(--warn);
}

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

.live-transcript {
  align-self: center;
  background: var(--accent-soft);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 20px;
  font-size: 0.95rem;
  margin-bottom: 12px;
  max-width: 80%;
  min-height: 40px;
}

.live-cursor {
  display: inline-block;
  width: 2px;
  animation: cursorBlink 1s step-end infinite;
}

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

.messages {
  flex: 1;
  min-height: 180px;
  max-height: 360px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.message {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 0.95rem;
}

.message.user {
  align-self: flex-end;
  background: var(--accent-soft);
  color: var(--text);
  border-bottom-right-radius: 4px;
}

.message.ai {
  align-self: flex-start;
  background: var(--surface-2);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.input-area {
  display: flex;
  gap: 10px;
  align-items: center;
}

.input-area input {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
}

.hint {
  font-size: 0.78rem;
  color: var(--text-3);
  margin: 8px 0 0;
  text-align: center;
}

.typing {
  display: flex;
  gap: 4px;
  padding: 12px;
}

.typing .dot {
  width: 8px;
  height: 8px;
  background: var(--text-3);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.typing .dot:nth-child(1) { animation-delay: -0.32s; }
.typing .dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

.map-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 20px;
  height: fit-content;
}

.map-section h3 {
  margin: 0 0 16px;
  font-size: 1.05rem;
}

.map-card {
  background: var(--surface-2);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 20px;
}

.map-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.map-row:last-child {
  border-bottom: 0;
}

.map-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.map-value {
  font-size: 0.9rem;
  color: var(--text);
  text-align: right;
  max-width: 60%;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

.badge-none { background: var(--success-soft); color: var(--success); }
.badge-watch { background: var(--warn-soft); color: var(--warn); }
.badge-crisis { background: var(--danger-soft); color: var(--danger); }

.resources h4 {
  margin: 0 0 10px;
  font-size: 0.85rem;
  color: var(--text-2);
}

.resources ul {
  margin: 0;
  padding-left: 18px;
  font-size: 0.85rem;
}

.resources li {
  margin: 6px 0;
}

.resources a {
  color: var(--accent);
}

/* Dashboard */
.dashboard-layout {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

.login-card {
  max-width: 360px;
  margin: 48px auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.login-card h2 {
  margin: 0 0 20px;
  font-size: 1.2rem;
}

.login-card label {
  display: block;
  margin: 12px 0 4px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-2);
}

.login-card input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 12px;
}

.login-card button {
  width: 100%;
  margin-top: 8px;
}

.error {
  color: var(--danger);
  font-size: 0.85rem;
}

.filters {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.filter-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 0.85rem;
}

.filter-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.session-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

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

.session-item:last-child {
  border-bottom: 0;
}

.session-item:hover {
  background: var(--surface-2);
}

.session-meta {
  font-size: 0.75rem;
  color: var(--text-3);
  margin-top: 4px;
}

.detail-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 20px;
  margin-top: 24px;
}

.detail-panel h2 {
  margin: 0 0 16px;
  font-size: 1.1rem;
}

.transcript {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 400px;
  overflow-y: auto;
  margin-bottom: 16px;
}

.detail-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.detail-actions textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 80px;
}

.empty {
  padding: 24px;
  color: var(--text-3);
  text-align: center;
}

.traits-card {
  background: var(--surface-2);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 20px;
}

.traits-card h4 {
  margin: 0 0 10px;
  font-size: 0.9rem;
  color: var(--text-2);
}

.traits-summary {
  margin: 0 0 14px;
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.5;
}

.traits-section {
  margin-bottom: 12px;
}

.traits-label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-3);
  margin-bottom: 6px;
}

.capability-bars {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.capability-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.capability-name {
  font-size: 0.78rem;
  color: var(--text-2);
  width: 110px;
  flex-shrink: 0;
}

.capability-track {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.capability-fill {
  height: 100%;
  background: var(--accent-2);
  border-radius: 4px;
  transition: width 0.4s ease;
}

.trait-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.trait-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px 10px;
  font-size: 0.78rem;
  color: var(--text-2);
}

.why-toggle {
  background: transparent;
  border: 0;
  padding: 0;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  text-decoration: underline;
  touch-action: manipulation;
}

.why-text {
  margin: 8px 0 0;
  font-size: 0.82rem;
  color: var(--text-2);
  line-height: 1.5;
  padding: 10px;
  background: var(--surface);
  border-radius: 8px;
}

@media (max-width: 800px) {
  .main-layout {
    grid-template-columns: 1fr;
    padding: 12px;
    gap: 12px;
  }
  .map-section {
    order: -1;
  }
  .chat-section {
    padding: 16px;
    min-height: auto;
  }
  .intro-card {
    padding: 32px 16px;
  }
  .messages {
    max-height: 50vh;
    min-height: 140px;
  }
  .input-area input {
    font-size: 16px; /* prevents iOS zoom */
  }
  .capability-name {
    width: 90px;
  }
}

@media (max-width: 480px) {
  .app-header {
    padding: 12px 16px;
  }
  .logo-icon {
    font-size: 1.6rem;
  }
  .logo-text h1 {
    font-size: 1rem;
  }
  .crisis-banner {
    font-size: 0.82rem;
    padding: 10px 12px;
  }
  .btn-mic {
    width: 64px;
    height: 64px;
    font-size: 1.8rem;
  }
  .btn-primary {
    padding: 12px 16px;
  }
}
