/* The Brain — thebrain.chat */
/* Nordic, calm, professional */

:root {
  --bg: #f8f7f4;
  --bg-card: #ffffff;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --text-light: #9ca3af;
  --border: #e5e7eb;
  --accent: #1a1a2e;
  --accent-light: #374151;
  --green: #4ade80;
  --green-bg: #dcfce7;
  --green-dark: #16a34a;
  --red: #f87171;
  --red-bg: #fee2e2;
  --red-dark: #dc2626;
  --blue: #60a5fa;
  --blue-bg: #dbeafe;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.05), 0 2px 4px rgba(0,0,0,0.04);
  --transition: 0.2s ease;
  --max-w: 640px;
  --nav-h: 72px;
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + 24px);
}

/* Layout */
.container {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 24px 16px;
}

/* Typography */
h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text);
}

h2 {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text);
}

h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 8px;
}

p {
  color: var(--text-muted);
  margin-bottom: 16px;
}

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.card-meta {
  font-size: 0.8125rem;
  color: var(--text-light);
}

.card-text {
  color: var(--text);
  line-height: 1.7;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  gap: 8px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-light);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg);
  border-color: var(--text-light);
}

.btn-danger {
  background: var(--red-bg);
  color: var(--red-dark);
  border: 1px solid var(--red);
}

.btn-danger:hover {
  background: var(--red);
  color: #fff;
}

.btn-sm {
  padding: 8px 16px;
  font-size: 0.875rem;
}

.btn-full {
  width: 100%;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Pulse buttons */
.pulse-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.pulse-btn {
  padding: 40px 24px;
  border-radius: var(--radius);
  border: 3px solid transparent;
  font-size: 1.25rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
}

.pulse-btn-green {
  background: var(--green-bg);
  color: var(--green-dark);
}

.pulse-btn-green:hover, .pulse-btn-green.active {
  background: var(--green);
  color: #fff;
  border-color: var(--green-dark);
  transform: scale(1.02);
}

.pulse-btn-red {
  background: var(--red-bg);
  color: var(--red-dark);
}

.pulse-btn-red:hover, .pulse-btn-red.active {
  background: var(--red);
  color: #fff;
  border-color: var(--red-dark);
  transform: scale(1.02);
}

/* Pulse history */
.pulse-history {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.pulse-dot {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6875rem;
  font-weight: 500;
  color: #fff;
}

.pulse-dot.gron { background: var(--green-dark); }
.pulse-dot.rod { background: var(--red-dark); }

/* Forms */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text);
  font-size: 0.9375rem;
}

.form-input, .form-textarea {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
  background: var(--bg-card);
  transition: border-color var(--transition);
}

.form-input:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(26, 26, 46, 0.08);
}

.form-textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.7;
}

/* Tags */
.tag {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.tag-core { background: #ede9fe; color: #6d28d9; border-color: #c4b5fd; }
.tag-ibk { background: #fef3c7; color: #92400e; border-color: #fcd34d; }
.tag-arrow { background: var(--blue-bg); color: #1d4ed8; border-color: var(--blue); }
.tag-pattern { background: #ecfdf5; color: #065f46; border-color: #6ee7b7; }

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

/* Thread list */
.thread-item {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}

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

.thread-item:last-child {
  border-bottom: none;
}

.thread-from {
  font-weight: 600;
  color: var(--text);
}

.thread-preview {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.thread-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.6875rem;
  font-weight: 600;
  background: var(--red-bg);
  color: var(--red-dark);
  margin-left: 8px;
}

.thread-badge.answered {
  background: var(--green-bg);
  color: var(--green-dark);
}

/* Messages in thread */
.message {
  padding: 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
}

.message-mine {
  background: var(--accent);
  color: #fff;
  margin-left: 40px;
}

.message-theirs {
  background: var(--bg-card);
  border: 1px solid var(--border);
  margin-right: 40px;
}

.message-sender {
  font-weight: 600;
  font-size: 0.8125rem;
  margin-bottom: 4px;
}

.message-mine .message-sender {
  color: rgba(255,255,255,0.7);
}

.message-theirs .message-sender {
  color: var(--text-muted);
}

.message-time {
  font-size: 0.75rem;
  margin-top: 8px;
  opacity: 0.6;
}

/* Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: center;
  z-index: 100;
  padding: 0 8px;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-items {
  display: flex;
  max-width: var(--max-w);
  width: 100%;
  justify-content: space-around;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 4px;
  font-size: 0.625rem;
  color: var(--text-light);
  text-decoration: none;
  cursor: pointer;
  transition: color var(--transition);
  flex: 1;
  max-width: 80px;
  border: none;
  background: none;
}

.nav-item:hover, .nav-item.active {
  color: var(--accent);
}

.nav-icon {
  font-size: 1.25rem;
  margin-bottom: 2px;
  line-height: 1;
}

.nav-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Badge on nav */
.nav-badge {
  position: absolute;
  top: 4px;
  right: calc(50% - 16px);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red);
}

.nav-item {
  position: relative;
}

/* Login */
.login-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80dvh;
  padding: 24px;
  text-align: center;
}

.login-logo {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text);
}

.login-subtitle {
  color: var(--text-muted);
  margin-bottom: 40px;
}

.login-form {
  width: 100%;
  max-width: 360px;
}

.login-message {
  padding: 16px;
  border-radius: var(--radius-sm);
  background: var(--green-bg);
  color: var(--green-dark);
  margin-top: 16px;
  font-size: 0.9375rem;
}

.login-error {
  background: var(--red-bg);
  color: var(--red-dark);
}

/* Flow: Svara */
.flow-question {
  font-size: 1.375rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 24px;
  line-height: 1.4;
}

.flow-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
}

.flow-btn {
  padding: 20px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  background: var(--bg-card);
  font-size: 1.125rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  color: var(--text);
}

.flow-btn:hover {
  border-color: var(--accent);
  background: var(--bg);
}

.flow-btn.selected {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.flow-step {
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Aggregate charts */
.bar-chart {
  margin: 16px 0;
}

.bar-row {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
  gap: 12px;
}

.bar-label {
  font-size: 0.8125rem;
  font-weight: 500;
  min-width: 100px;
  text-align: right;
  color: var(--text-muted);
}

.bar-track {
  flex: 1;
  height: 24px;
  background: var(--bg);
  border-radius: 12px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 12px;
  transition: width 0.6s ease;
  min-width: 2px;
}

.bar-fill-vision { background: #8b5cf6; }
.bar-fill-ambition { background: #f59e0b; }
.bar-fill-mission { background: #10b981; }
.bar-fill-roll { background: #3b82f6; }
.bar-fill-green { background: var(--green-dark); }
.bar-fill-red { background: var(--red-dark); }

.bar-value {
  font-size: 0.8125rem;
  font-weight: 600;
  min-width: 32px;
  color: var(--text);
}

/* Solar system */
.solar-section {
  margin-bottom: 32px;
}

.solar-section h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}

/* Utilities */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.875rem; }
.mt-4 { margin-top: 16px; }
.mt-8 { margin-top: 32px; }
.mb-4 { margin-bottom: 16px; }
.mb-8 { margin-bottom: 32px; }
.hidden { display: none !important; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }

/* Loading spinner */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 40px auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--accent);
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  transition: transform 0.3s ease;
  z-index: 200;
}

.toast.visible {
  transform: translateX(-50%) translateY(0);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-light);
}

.empty-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

/* Responsive */
@media (max-width: 480px) {
  .container {
    padding: 16px 12px;
  }

  h1 {
    font-size: 1.25rem;
  }

  .pulse-btn {
    padding: 32px 16px;
  }

  .bar-label {
    min-width: 72px;
    font-size: 0.75rem;
  }
}
