:root {
  --bg-primary: #09090b;
  --bg-surface: #18181b;
  --bg-elevated: #27272a;
  --bg-hover: #3f3f46;
  --border-color: #27272a;
  --border-active: #52525b;
  --text-primary: #fafafa;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-soft: rgba(59, 130, 246, 0.12);
  --success: #22c55e;
  --danger: #ef4444;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 40px;
}

/* ========== HEADER ========== */
#header {
  width: 100%;
  max-width: 640px;
  margin-bottom: 28px;
}

#header-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 20px 0;
  position: relative;
}

#brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text-primary);
}

#brand svg { color: var(--accent); }
.brand-logo { width: 24px; height: 24px; object-fit: contain; }

#tagline {
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 400;
}

/* ========== TAB BAR ========== */
#tab-bar {
  width: 100%;
  max-width: 640px;
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 4px;
}

.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

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

.tab-btn.active {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

.tab-btn svg { flex-shrink: 0; }

/* ========== TAB CONTENT ========== */
.tab-content { display: none; }
.tab-content.active { display: block; }
.tab-content.active { animation: fadeIn 0.2s ease-out; }

/* ========== MAIN ========== */
#main-content {
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ========== CARDS ========== */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 24px;
  transition: border-color 0.2s ease;
}

.card:hover { border-color: var(--border-active); }

.card-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 20px;
}

.card-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--accent);
}

.card-header h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.card-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 1px;
}

/* ========== BREATHING ========== */
.breathing-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.breathing-ring {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
}

.breathing-circle {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.5;
  transition: all 4s ease-in-out;
}

.breathing-circle.inhale {
  transform: scale(1.6);
  opacity: 0.9;
  background: var(--accent-hover);
  box-shadow: 0 0 40px rgba(59, 130, 246, 0.3);
}

.breathing-circle.exhale {
  transform: scale(1);
  opacity: 0.5;
  box-shadow: none;
}

.breath-text {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* ========== FORM ========== */
#ventForm {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#ventInput {
  width: 100%;
  height: 110px;
  padding: 14px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  font-family: inherit;
  font-size: 14px;
  color: var(--text-primary);
  resize: none;
  outline: none;
  transition: border-color 0.15s ease;
  line-height: 1.5;
}

#ventInput:focus { border-color: var(--accent); }
#ventInput::placeholder { color: var(--text-muted); }

.vent-feedback {
  font-size: 13px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  display: none;
  line-height: 1.4;
}

.vent-feedback.error {
  display: block;
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

.vent-feedback.success {
  display: block;
  color: var(--success);
  background: rgba(34, 197, 94, 0.1);
}

.vent-feedback.loading {
  display: block;
  color: var(--text-secondary);
  background: rgba(161, 161, 170, 0.08);
}

.vent-feedback.warning {
  display: block;
  color: #fbbf24;
  background: rgba(251, 191, 36, 0.12);
  border: 1px solid rgba(251, 191, 36, 0.25);
}

.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 44px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.98); }

/* ========== ANON TOGGLE ========== */
.anon-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 2px 0;
  user-select: none;
}

.anon-toggle input { display: none; }

.anon-toggle-track {
  position: relative;
  width: 36px;
  height: 20px;
  background: var(--bg-elevated);
  border-radius: 10px;
  border: 1px solid var(--border-color);
  transition: background 0.2s ease;
  flex-shrink: 0;
}

.anon-toggle input:checked + .anon-toggle-track {
  background: var(--accent);
  border-color: var(--accent);
}

.anon-toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s ease;
}

.anon-toggle input:checked + .anon-toggle-track .anon-toggle-thumb {
  transform: translateX(16px);
}

.anon-toggle-label {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ========== FEED ========== */
.feed-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 60px;
}

.feed-loading {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
  padding: 20px 0;
}

.text-muted {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
  padding: 20px 0;
}

.vent-post {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  animation: fadeIn 0.3s ease-out;
}

.post-author {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.post-author-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
}

.post-author-avatar.letter {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  flex-shrink: 0;
}

.post-author-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.vent-post p {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-primary);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.vent-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.vent-risk-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.vent-risk-btn:hover {
  transform: scale(1.15);
}

.vent-time {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

/* ========== SCROLLBAR ========== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 3px; }

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

/* ========== CHAT IA ========== */
.card-chat {
  display: flex;
  flex-direction: column;
  height: 480px;
  padding: 0;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: fadeIn 0.2s ease-out;
}

.chat-msg-user {
  align-self: flex-end;
}

.chat-msg-ia {
  align-self: flex-start;
}

.chat-msg-content {
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.6;
  border-radius: var(--radius-lg);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat-msg-user .chat-msg-content {
  background: var(--accent);
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-msg-ia .chat-msg-content {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.chat-msg-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

.chat-msg-user .chat-msg-time {
  text-align: right;
}

.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-surface);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  font-family: inherit;
  font-size: 14px;
  color: var(--text-primary);
  resize: none;
  outline: none;
  transition: border-color 0.15s ease;
  line-height: 1.5;
  max-height: 120px;
}

.chat-input:focus { border-color: var(--accent); }
.chat-input::placeholder { color: var(--text-muted); }

.btn-send {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.btn-send:hover:not(:disabled) { background: var(--accent-hover); }
.btn-send:active:not(:disabled) { transform: scale(0.92); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

.chat-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}

.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.2s infinite ease-in-out;
}

.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

.chat-error {
  text-align: center;
  color: var(--danger);
  font-size: 13px;
  padding: 8px 12px;
  background: rgba(239, 68, 68, 0.1);
  border-radius: var(--radius-md);
  align-self: center;
}

/* ========== MODAL ========== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-overlay.open {
  display: flex;
}

.modal-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 32px 28px 28px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  position: relative;
  animation: fadeIn 0.2s ease-out;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-icon {
  margin-bottom: 16px;
}

.modal-box h3 {
  font-size: 16px;
  font-weight: 600;
  color: #fbbf24;
  margin-bottom: 12px;
  line-height: 1.4;
}

.modal-box p {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.modal-box strong {
  color: var(--text-primary);
}

/* ========== AUTH ========== */
.btn-auth {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-auth:hover {
  background: var(--bg-hover);
  border-color: var(--border-active);
}

.auth-modal {
  max-width: 360px;
}

.auth-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  padding: 3px;
  margin-bottom: 20px;
}

.auth-tab {
  flex: 1;
  height: 34px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.auth-tab.active {
  background: var(--bg-surface);
  color: var(--text-primary);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-input {
  width: 100%;
  height: 42px;
  padding: 0 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 14px;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s ease;
}

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

.auth-error {
  display: none;
  font-size: 13px;
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
  padding: 8px 12px;
  border-radius: var(--radius-md);
  text-align: center;
}

/* ========== PROFILE ========== */
#auth-area {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
}

.profile-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: 2px 0;
  transition: opacity 0.15s ease;
}

.profile-btn:hover { opacity: 0.8; }

.profile-mini-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}

.profile-mini-avatar.letter {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.profile-mini-name {
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-modal {
  max-width: 360px;
}

.profile-avatar-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
}

.profile-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  overflow: hidden;
  border: 2px solid var(--border-color);
}

.profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.profile-upload-btn:hover { opacity: 0.8; }

/* ========== RESPONSIVE ========== */
@media (max-width: 480px) {
  body { padding: 0 12px 32px; }
  .card { padding: 20px; }
  #brand { font-size: 20px; }
}
