/* ============================================================================
   Self-Compass AI Coach - Optimized CSS v2.2
   ============================================================================
   Architecture: Cookie-based session persistence with multi-session continuity
   Philosophy: Calm → Clarity → Connection
   
   Optimizations:
   - Removed duplicate welcome-back banner code
   - Consolidated button styles with .btn-primary base class
   - Unified animation keyframes
   - Centralized focus states
   - Converted hardcoded colors to CSS variables
   - Email modal preserved (planned feature, currently disabled)
   - FIXED: Layout system changed from Grid to Flexbox (v2.2)
   
   Version History:
   - v1.0: Original (878 lines)
   - v2.0: Optimized (665 lines, 24% reduction)
   - v2.1: Footer spacing fix attempt
   - v2.2: Grid → Flexbox layout for proper footer positioning
   ============================================================================ */

/* ============================================================================
   CSS VARIABLES
   ============================================================================ */
:root {
  /* Brand Colors */
  --bg: #FAFBFC;
  --panel: #FFFFFF;
  --ink: #1D3557;
  --muted: #5C6F82;
  --line: #E6ECF2;
  
  /* Message Bubbles */
  --user: #2F4288;
  --user-ink: #FFFFFF;
  --bot: #F5F5F5;
  --bot-ink: #1D3557;
  
  /* Call-to-Action */
  --cta: #FFB178;
  --cta-ink: #1C2E7A;
  --cta-hov: #D67B4C;
  
  /* Welcome Banner */
  --welcome-bg: #F0F7FF;
  --welcome-border: #B8D4F7;
  
  /* UI Elements */
  --surface-subtle: #F5F5F5;
  --border-subtle: #E0E0E0;
  --border-light: #D7D7D7;
  
  /* Layout */
  --radius: 16px;
  --shadow: 0 4px 12px rgba(29,53,87,.08);
  --bubble-width-desktop: 86%;
  --bubble-width-mobile: 92%;
}

/* ============================================================================
   BASE & LAYOUT
   ============================================================================ */
#scapp, #scapp * { 
  box-sizing: border-box; 
}

html, body { 
  height: 100%; 
  margin: 0; 
}

#scapp {
  height: 100dvh;
  color: var(--ink);
  background: transparent;
  font: 16px/1.55 "Open Sans", system-ui, -apple-system, Segoe UI, Roboto, Arial;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

#scapp .container {
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 980px;
  margin: 0 auto;
  padding: 24px;
  gap: 14px;
}

/* ============================================================================
   HEADER
   ============================================================================ */
#scapp .header {
  display: flex; 
  align-items: center; 
  justify-content: flex-start;
  padding: 16px 24px; 
  border: 1px solid var(--line);
  border-radius: var(--radius); 
  background: var(--panel); 
  box-shadow: var(--shadow);
}

#scapp .brand { 
  display: flex; 
  gap: 12px; 
  align-items: center; 
  min-width: 0; 
}

#scapp .logo { 
  width: 36px; 
  height: 36px; 
  border-radius: 10px; 
  display: grid; 
  place-items: center; 
  overflow: hidden; 
  border: 1px solid var(--border-light); 
  background: #fff; 
  flex: 0 0 auto; 
}

#scapp .logo img { 
  width: 100%; 
  height: 100%; 
  object-fit: contain; 
  display: block; 
}

#scapp .ttl { 
  font-weight: 700; 
  letter-spacing: .3px; 
  white-space: nowrap; 
}

#scapp .sub { 
  font-weight: 300; 
  font-size: 12px; 
  color: var(--muted); 
  white-space: nowrap; 
  overflow: hidden; 
  text-overflow: ellipsis; 
}

/* ============================================================================
   WELCOME BACK BANNER (Active Implementation)
   ============================================================================ */
#scapp .welcome-back {
  margin: 0 0 14px 0;
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

#scapp .welcome-back.welcome-visible {
  opacity: 1;
  transform: translateY(0);
}

#scapp .welcome-content {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  background: linear-gradient(135deg, #F0F7FF 0%, #E6F2FF 100%);
  border: 1px solid #B8D9FF;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(47, 66, 136, 0.08);
  position: relative;
}

#scapp .welcome-icon {
  font-size: 24px;
  flex-shrink: 0;
}

#scapp .welcome-text {
  flex: 1;
  min-width: 0;
}

#scapp .welcome-text strong {
  display: block;
  color: var(--user);
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
}

#scapp .welcome-meta {
  display: block;
  font-size: 12px;
  color: var(--muted);
  font-weight: 400;
}

#scapp .welcome-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  border: none;
  font-size: 24px;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  border-radius: 4px;
  transition: background-color 0.15s ease, color 0.15s ease;
}

#scapp .welcome-close:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--ink);
}

@media (max-width: 640px) {
  #scapp .welcome-content {
    padding: 12px 14px;
    gap: 10px;
  }
  
  #scapp .welcome-icon {
    font-size: 20px;
  }
  
  #scapp .welcome-text strong {
    font-size: 14px;
  }
  
  #scapp .welcome-meta {
    font-size: 11px;
  }
}

/* ============================================================================
   CHAT LOG (Scrollable Message Area)
   ============================================================================ */
#scapp .log {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  overflow-y: auto; 
  flex: 1 1 auto;
  min-height: 300px;
  max-height: 60vh;
}

@media (min-height: 700px) { 
  #scapp .log { 
    min-height: 220px; 
  } 
}

/* Improved scrollbar styling */
#scapp .log::-webkit-scrollbar { 
  width: 10px; 
}

#scapp .log::-webkit-scrollbar-track { 
  background: var(--surface-subtle); 
  border-radius: 10px; 
}

#scapp .log::-webkit-scrollbar-thumb { 
  background: #d0d0d0; 
  border-radius: 10px; 
  transition: background 0.2s ease; 
}

#scapp .log::-webkit-scrollbar-thumb:hover { 
  background: #b0b0b0; 
}

/* ============================================================================
   MESSAGE ROWS & BUBBLES
   ============================================================================ */
#scapp .row { 
  display: flex; 
  gap: 10px; 
  margin: 8px 8px; 
  animation: fadeSlide 0.3s ease-out;
}

#scapp .row.you { 
  justify-content: flex-end; 
}

#scapp .bubble {
  position: relative;
  max-width: var(--bubble-width-desktop);
  padding: 12px 16px;
  line-height: 1.48;
  transition: transform 0.15s ease;
}

#scapp .bubble:hover {
  transform: translateY(-1px);
}

@media (max-width: 640px) {
  #scapp .bubble { 
    max-width: var(--bubble-width-mobile); 
  }
}

/* User messages */
#scapp .you .bubble {
  background: linear-gradient(135deg, var(--user) 0%, #3d5299 100%);
  color: var(--user-ink);
  border-radius: 19px 19px 6px 19px;
}

#scapp .you .bubble .meta { 
  color: #CCC !important; 
}

#scapp .you .bubble .header-text {
  color: #FFFFFF;
}

/* Bot messages */
#scapp .bot .bubble {
  background: var(--bot); 
  color: var(--bot-ink);
  border-radius: 19px 19px 19px 6px;
  border: 1px solid var(--border-subtle);
  box-shadow: 0 1px 3px rgba(0,0,0,.03);
}

#scapp .name { 
  font-size: 12px; 
  color: var(--muted) !important; 
  margin: 0 0 6px 2px; 
}

/* Timestamp - fade on hover */
#scapp .meta { 
  font-size: 11px; 
  color: var(--muted); 
  margin-top: 4px; 
  opacity: 0.5;
  transition: opacity 0.2s ease;
}

#scapp .bubble:hover .meta {
  opacity: 1;
}

/* Link styling */
#scapp .bubble a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: rgba(0,0,0,0.3);
  transition: text-decoration-color 0.15s ease;
}

#scapp .bubble a:hover {
  text-decoration-color: rgba(0,0,0,0.6);
}

/* Thinking indicator */
#scapp .thinking { 
  display: inline-flex; 
  gap: 5px; 
}

#scapp .thinking span { 
  width: 6px; 
  height: 6px; 
  background: var(--muted); 
  border-radius: 50%; 
  animation: thinkingPulse 1.4s ease-in-out infinite;
}

#scapp .thinking span:nth-child(2) { 
  animation-delay: 0.2s; 
}

#scapp .thinking span:nth-child(3) { 
  animation-delay: 0.4s; 
}

/* ============================================================================
   COMPOSER (Message Input Area)
   ============================================================================ */

/* Composer wrapper - contains form + helpers */
#scapp .composer-wrapper {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Character counter (above form) */
#scapp #charcount {
  font-size: 11px;
  color: var(--muted);
  text-align: right;
  padding: 0 4px;
  min-height: 16px;
}

/* Main composer form */
#scapp .composer { 
  display: flex; 
  gap: 8px; 
  align-items: flex-end;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
}

/* Textarea */
#scapp .composer textarea { 
  flex: 1;
  min-height: 42px; 
  max-height: 160px;
  padding: 10px 12px;
  font: inherit;
  color: var(--ink);
  background: var(--surface-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  resize: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#scapp .composer textarea:focus { 
  outline: none;
  border-color: var(--user);
  box-shadow: 0 0 0 3px rgba(47, 66, 136, 0.08);
  background: #FFFFFF;
}

#scapp .composer textarea::placeholder { 
  color: #9CA3AF; 
}

/* Keyboard hint (below form) */
#scapp .keyboard-hint {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  padding: 2px 4px;
  opacity: 0.7;
}

/* Send button (warm orange style) */
#scapp .send {
  background: var(--cta); 
  color: var(--cta-ink); 
  font-weight: 700; 
  padding: 0 18px;
  border: 1px solid rgba(0,0,0,.06);
  border-radius: 10px; 
  cursor: pointer; 
  height: 41px; 
  font-size: 15px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  transition: all 0.15s ease;
}

#scapp .send:hover { 
  background: var(--cta-hov); 
  color: #fff; 
  text-shadow: 0 1px 0 rgba(0,0,0,.15);
  transform: translateY(-1px);
  box-shadow: 0 2px 5px rgba(0,0,0,.12);
}

#scapp .send:disabled { 
  opacity: .5;
  cursor: not-allowed;
  transform: none;
}

/* Stop button (original subtle gray style) */
#scapp .stop {
  display: none;
  background: #EEF3F8; 
  color: var(--ink);
  font-weight: 700; 
  font-size: 15px; 
  height: 41px; 
  padding: 12px 14px;
  border: 1px solid #D8E0EA; 
  border-radius: 10px; 
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  transition: background-color .15s ease, border-color .15s ease, transform .05s ease;
}

#scapp .stop:hover { 
  background: #E7EEF6; 
  border-color: #C9D3E0; 
}

#scapp .stop:active { 
  transform: translateY(.5px); 
}

/* Jump to latest button (original styling) */
#scapp #jump {
  position: absolute;
  bottom: 16px;
  right: 16px;
  display: none;
  background: #FFFFFF;
  color: var(--muted);
  font-weight: 400;
  font-size: 11px;
  line-height: 1;
  padding: 5px 10px;
  border: 1px solid #E0E6ED;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
  cursor: pointer;
  transition: all .18s ease-in-out;
  z-index: 10;
}

#scapp #jump:hover,
#scapp #jump:focus-visible {
  background: #F8F9FA;
  color: var(--ink);
  border-color: #D0D7DE;
  box-shadow: 0 2px 4px rgba(0,0,0,.08);
}

@media (max-width: 640px) {
  #scapp #jump { 
    font-size: 10px;
    padding: 4px 8px;
    bottom: 12px;
    right: 12px;
  }
}

/* ============================================================================
   UNIVERSAL FOCUS STATES (Accessibility)
   ============================================================================ */
#scapp button:focus-visible,
#scapp input:focus-visible,
#scapp textarea:focus-visible {
  outline: 2px solid var(--user);
  outline-offset: 2px;
}

/* ============================================================================
   FOOTER (FIXED v2.1)
   ============================================================================ */
#scapp footer { 
  font-size: 12px; 
  color: var(--muted); 
  text-align: center; 
  padding: 12px 0 8px 0;
  margin-top: 0;
}

#scapp .sep { 
  height: 1px; 
  background: var(--line); 
  margin: 8px 0 8px 0;
}

/* ============================================================================
   ANIMATIONS (Consolidated)
   ============================================================================ */

/* Universal fade + slide animation */
@keyframes fadeSlide {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Thinking pulse */
@keyframes thinkingPulse {
  0%, 100% { 
    opacity: 0.4; 
  }
  50% { 
    opacity: 1; 
  }
}

/* ============================================================================
   EMAIL CAPTURE MODAL (PLANNED FEATURE - Currently Disabled)
   ============================================================================
   This feature is currently disabled in app.js (EMAIL_CAPTURE: false)
   Will be enabled once multi-session coaching continuity is stable.
   Purpose: User identification for cross-device access and GDPR compliance
   ============================================================================ */

#scapp .email-modal {
  display: none; /* Hidden by default, shown via JS */
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(29, 53, 87, 0.75);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

#scapp .email-modal-content {
  position: relative;
  background: #FFFFFF;
  border-radius: 20px;
  padding: 32px 28px;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  text-align: center;
  animation: slideUp 0.3s ease;
}

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

#scapp .email-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: transparent;
  border: none;
  font-size: 28px;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 10px;
  line-height: 1;
  border-radius: 6px;
  transition: background-color 0.15s ease, color 0.15s ease;
}

#scapp .email-modal-close:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--ink);
}

#scapp .email-modal-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

#scapp .email-modal-content h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 12px 0;
}

#scapp .email-modal-content p {
  font-size: 15px;
  line-height: 1.5;
  color: var(--muted);
  margin: 0 0 8px 0;
}

#scapp .email-modal-hint {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 20px !important;
}

#scapp .email-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 20px 0;
}

#scapp .email-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 15px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--surface-subtle);
  color: var(--ink);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#scapp .email-input:focus {
  outline: none;
  border-color: var(--user);
  box-shadow: 0 0 0 3px rgba(47, 66, 136, 0.1);
  background: #FFFFFF;
}

#scapp .email-input::placeholder {
  color: #9CA3AF;
}

#scapp .email-submit {
  width: 100%;
  padding: 14px 20px;
  font-size: 15px;
  font-weight: 700;
  background: var(--cta);
  color: var(--cta-ink);
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

#scapp .email-submit:hover {
  background: var(--cta-hov);
  color: #FFFFFF;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.12);
}

#scapp .email-submit:active {
  transform: translateY(0);
}

#scapp .email-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

#scapp .email-submit.loading::after {
  content: '...';
  animation: loadingDots 1.2s infinite;
}

@keyframes loadingDots {
  0%, 20% { content: '.'; }
  40% { content: '..'; }
  60%, 100% { content: '...'; }
}

#scapp .email-skip {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  padding: 8px;
  margin-top: 8px;
  transition: color 0.15s ease;
}

#scapp .email-skip:hover {
  color: var(--ink);
  text-decoration: underline;
}

#scapp .email-privacy {
  font-size: 12px !important;
  color: var(--muted) !important;
  margin-top: 16px !important;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

/* Mobile adjustments for email modal */
@media (max-width: 640px) {
  #scapp .email-modal {
    padding: 16px;
  }
  
  #scapp .email-modal-content {
    padding: 28px 20px;
    border-radius: 16px;
  }
  
  #scapp .email-modal-content h2 {
    font-size: 20px;
  }
  
  #scapp .email-modal-content p {
    font-size: 14px;
  }
  
  #scapp .email-input,
  #scapp .email-submit {
    font-size: 14px;
    padding: 12px 14px;
  }
}

/* ============================================================================
   END OF STYLESHEET
   ============================================================================ */
