/* Portal Styles - The Man Plan */
/* Brand Colors: Blue #2E3748, White #EDE8D0, Red #E63946 */

/* ═══════════════════════════════════════════════════════════════════════════
   CSS VARIABLES / DESIGN TOKENS
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  /* Brand Colors */
  --brand-blue: #2E3748;
  --brand-white: #EDE8D0;
  --brand-red: #E63946;

  /* State Colors */
  --state-stable: #8FAE8B;
  --state-monitoring: #D4A84B;
  --state-recommendation: #2A7B7B;
  --state-escalation: #C66B3D;
  --state-active: #4A6FA5;

  /* Semantic Colors */
  --primary: var(--brand-red);
  --primary-dark: #c42d39;
  --primary-light: rgba(230, 57, 70, 0.15);
  --success: #4ade80;
  --warning: #fbbf24;
  --error: #ef4444;

  /* Dark Theme */
  --bg: var(--brand-blue);
  --bg-card: #3a4556;
  --bg-input: #252d3a;
  --text: var(--brand-white);
  --text-light: #a8a28f;
  --text-muted: #7a7a6a;
  --border: #4a5568;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.3);

  /* Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 50%;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   RESET & BASE
   ═══════════════════════════════════════════════════════════════════════════ */

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
}

/* ═══════════════════════════════════════════════════════════════════════════
   TOAST NOTIFICATION
   ═══════════════════════════════════════════════════════════════════════════ */

.toast {
  position: fixed;
  top: 16px;
  right: 16px;
  padding: 12px 20px;
  background: var(--bg-card);
  color: var(--text);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  z-index: 1000;
  transform: translateX(120%);
  transition: transform 0.3s ease;
  border: 1px solid var(--border);
}

.toast.visible {
  transform: translateX(0);
}

/* ═══════════════════════════════════════════════════════════════════════════
   HEADER
   ═══════════════════════════════════════════════════════════════════════════ */

.portal-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
}

.brand-logo {
  height: 28px;
  width: auto;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

/* TODO: Phase 2 — Restore Health Radar button styles when radar feature launches
.radar-btn {
  padding: 6px 12px;
  border-radius: var(--radius-md);
  background: var(--bg-input);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-light);
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  border: 1px solid var(--border);
}

.radar-btn:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
*/

.profile-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--bg-input);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-light);
  cursor: pointer;
  transition: background 0.2s;
}

.profile-avatar:hover {
  background: var(--border);
}

/* ═══════════════════════════════════════════════════════════════════════════
   DEMO SWITCHER (Development Only)
   ═══════════════════════════════════════════════════════════════════════════ */

.demo-switcher {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
}

.demo-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 8px;
  max-width: 640px;
  margin-left: auto;
  margin-right: auto;
}

.demo-buttons {
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.demo-btn {
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
  border: none;
  background: var(--bg-input);
  color: var(--text-light);
  transition: all 0.2s;
}

.demo-btn:hover {
  background: var(--border);
}

.demo-btn.active {
  color: var(--brand-white);
}

.demo-btn.active[data-state="stable"] { background: var(--state-stable); }
.demo-btn.active[data-state="monitoring"] { background: var(--state-monitoring); }
.demo-btn.active[data-state="recommendation"] { background: var(--state-recommendation); }
.demo-btn.active[data-state="escalation"] { background: var(--state-escalation); }

/* Mode Toggle (Demo/Live) */
.demo-mode-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 640px;
  margin: 0 auto 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.demo-mode-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.demo-mode-btn {
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  transition: all 0.2s;
  cursor: pointer;
}

.demo-mode-btn:hover {
  border-color: var(--text-light);
  color: var(--text-light);
}

.demo-mode-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.demo-mode-btn.active[data-mode="live"] {
  background: var(--success);
  border-color: var(--success);
}

.demo-mode-btn.active[data-mode="demo"] {
  background: var(--warning);
  border-color: var(--warning);
  color: var(--brand-blue);
}

/* ═══════════════════════════════════════════════════════════════════════════
   MAIN CONTENT
   ═══════════════════════════════════════════════════════════════════════════ */

.portal-main {
  max-width: 640px;
  margin: 0 auto;
  padding: var(--space-lg) var(--space-md);
}

/* ═══════════════════════════════════════════════════════════════════════════
   STATE CARDS
   ═══════════════════════════════════════════════════════════════════════════ */

.state-card-container {
  margin-bottom: var(--space-lg);
}

.state-card {
  animation: fadeSlideIn 0.3s ease;
}

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

.state-card-inner {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  gap: var(--space-md);
}

/* State-specific border accents */
.state-card.stable .state-card-inner {
  border-left: 4px solid var(--state-stable);
}

.state-card.monitoring .state-card-inner {
  border-left: 4px solid var(--state-monitoring);
}

.state-card.recommendation .recommendation-card {
  border-left: 4px solid var(--state-recommendation);
}

.state-card.escalation .escalation-card {
  border-left: 6px solid var(--state-escalation);
  box-shadow: var(--shadow-md);
}

/* State Indicators */
.state-indicator {
  font-size: 1.5rem;
  line-height: 1;
  flex-shrink: 0;
}

.state-card.stable .state-indicator { color: var(--state-stable); }
.state-card.monitoring .state-indicator { color: var(--state-monitoring); }
.state-card.recommendation .state-indicator { color: var(--state-recommendation); }
.state-card.escalation .state-indicator { color: var(--state-escalation); }

/* "Got it" dismiss button */
.btn-got-it {
  flex-shrink: 0;
  align-self: center;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-light);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn-got-it:hover {
  background: var(--bg-input);
  color: var(--text);
}

/* State Content */
.state-content {
  flex: 1;
}

.state-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: var(--space-sm);
  color: var(--text);
}

.state-description {
  font-size: 0.9375rem;
  color: var(--text-light);
  line-height: 1.6;
}

.state-link {
  display: inline-block;
  margin-top: var(--space-md);
  font-size: 0.875rem;
  color: var(--state-recommendation);
  transition: opacity 0.2s;
}

.state-link:hover {
  opacity: 0.8;
}

/* State Intro (for Recommendation/Escalation) */
.state-intro {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.state-intro-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
}

/* Recommendation Card */
.recommendation-card {
  display: block;
}

.rec-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: var(--space-md);
}

.rec-description {
  font-size: 0.875rem;
  color: var(--text-light);
  line-height: 1.5;
  margin-bottom: var(--space-md);
}

.rec-section {
  margin-bottom: var(--space-md);
}

.rec-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-light);
  margin-bottom: var(--space-xs);
}

.rec-text {
  font-size: 0.875rem;
  color: var(--text-light);
  line-height: 1.6;
}

.rec-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-top: var(--space-lg);
}

/* Escalation Card */
.escalation-card {
  display: block;
}

.esc-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: var(--space-md);
}

.esc-description {
  font-size: 0.875rem;
  color: var(--text-light);
  line-height: 1.5;
  margin-bottom: var(--space-md);
}

.esc-section {
  margin-bottom: var(--space-md);
}

.esc-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-light);
  margin-bottom: var(--space-xs);
}

.esc-text {
  font-size: 0.875rem;
  color: var(--text-light);
  line-height: 1.6;
}

.esc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-top: var(--space-lg);
}

/* Chat Trigger (support link below action buttons) */
.chat-trigger-btn {
  display: block;
  margin-top: var(--space-md);
  font-size: 0.8125rem;
  color: var(--text-muted);
  transition: color 0.2s;
}

.chat-trigger-btn:hover {
  color: var(--text-light);
}

/* ═══════════════════════════════════════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════════════════════════════════════ */

.btn {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  border: none;
  transition: all 0.2s;
}

.btn-recommendation {
  background: var(--state-recommendation);
  color: var(--brand-white);
}

.btn-recommendation:hover {
  filter: brightness(1.1);
}

.btn-outline-recommendation {
  background: transparent;
  border: 1px solid var(--state-recommendation);
  color: var(--state-recommendation);
}

.btn-outline-recommendation:hover {
  background: rgba(42, 123, 123, 0.1);
}

.btn-escalation {
  background: var(--state-escalation);
  color: var(--brand-white);
}

.btn-escalation:hover {
  filter: brightness(1.1);
}

.btn-outline-escalation {
  background: transparent;
  border: 1px solid var(--state-escalation);
  color: var(--state-escalation);
}

.btn-outline-escalation:hover {
  background: rgba(198, 107, 61, 0.1);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  color: var(--text-light);
}

.btn-log {
  width: 100%;
  margin-top: var(--space-md);
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-log:hover {
  background: var(--border);
}

/* ═══════════════════════════════════════════════════════════════════════════
   ACTIVE ITEMS
   ═══════════════════════════════════════════════════════════════════════════ */

.active-items-section {
  margin-bottom: var(--space-lg);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-md);
}

.section-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.section-link {
  font-size: 0.875rem;
  color: var(--state-recommendation);
}

.section-link:hover {
  opacity: 0.8;
}

.active-items-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-md);
}

@media (max-width: 480px) {
  .active-items-grid {
    grid-template-columns: 1fr;
  }
}

.active-item-card {
  display: block;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  transition: transform 0.2s, box-shadow 0.2s;
}

.active-item-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-sm);
}

.item-title {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text);
}

.item-badge {
  font-size: 0.625rem;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
}

.item-badge.stalled {
  background: rgba(212, 168, 75, 0.2);
  color: var(--state-monitoring);
}

.item-description {
  font-size: 0.75rem;
  color: var(--text-light);
  line-height: 1.4;
  margin-bottom: var(--space-sm);
}

.item-progress-text {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: var(--space-sm);
}

.item-progress-bar {
  height: 8px;
  background: var(--bg-input);
  border-radius: 4px;
  overflow: hidden;
}

.item-progress-fill {
  height: 100%;
  background: var(--state-active);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.item-progress-fill.stalled {
  background: var(--state-monitoring);
}

.item-percent {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: right;
  margin-top: var(--space-xs);
}

/* Medical Consult Dashboard Card */
.consult-card {
  border-left: 4px solid var(--state-active) !important;
}

.consult-card.consult-completed {
  border-left-color: var(--state-stable) !important;
}

.consult-card.consult-missed {
  border-left-color: var(--state-escalation) !important;
}

.item-badge.consult-upcoming {
  background: rgba(74, 111, 165, 0.2);
  color: var(--state-active);
}

.item-badge.consult-missed {
  background: rgba(198, 107, 61, 0.2);
  color: var(--state-escalation);
}

/* ═══════════════════════════════════════════════════════════════════════════
   QUICK LOG
   ═══════════════════════════════════════════════════════════════════════════ */

.quick-log-section {
  margin-bottom: var(--space-lg);
}

.quick-log-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

.quick-log-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-md);
}

.log-input-group {
  text-align: center;
}

.log-label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: var(--space-sm);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.log-input-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.log-input {
  width: 100%;
  max-width: 80px;
  padding: 8px;
  text-align: center;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 1rem;
  transition: border-color 0.2s;
}

.log-input::placeholder {
  color: var(--text-muted);
}

.log-input:focus {
  outline: none;
  border-color: var(--text-light);
}

.log-unit {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Energy Dots */
.energy-dots {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.energy-dot {
  width: 20px;
  height: 20px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: transparent;
  transition: all 0.2s;
}

.energy-dot:hover {
  border-color: var(--text-light);
}

.energy-dot.selected {
  background: var(--state-active);
  border-color: var(--state-active);
}

/* Quick Log — Compact Completion State */
.quick-log-compact {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xs);
}

.quick-log-compact-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
}

.log-compact-check {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(74, 222, 128, 0.15);
  color: var(--success);
  font-size: 0.875rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.log-compact-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
}

.log-compact-stats {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.log-compact-link {
  font-size: 0.75rem;
  color: var(--state-recommendation);
  text-decoration: none;
}

.log-compact-link:hover {
  opacity: 0.8;
}

/* ═══════════════════════════════════════════════════════════════════════════
   BOTTOM NAVIGATION
   ═══════════════════════════════════════════════════════════════════════════ */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 8px 16px;
  display: flex;
  justify-content: space-around;
  z-index: 100;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 16px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  transition: color 0.2s;
}

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

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

.nav-label {
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.nav-spacer {
  height: 80px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 480px) {
  .state-card-inner {
    padding: var(--space-md);
  }

  .state-title {
    font-size: 1.125rem;
  }

  .rec-actions,
  .esc-actions {
    flex-direction: column;
  }

  .rec-actions .btn,
  .esc-actions .btn {
    width: 100%;
    text-align: center;
  }

  .quick-log-grid {
    grid-template-columns: 1fr;
    gap: var(--space-lg);
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   REDUCED MOTION
   ═══════════════════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
