/**
 * Phoenix Mobile - CSS Design System
 *
 * Principles:
 * - Rauno Freiberg functional minimalism
 * - Vercel aesthetics (clean, rounded, subtle)
 * - No decorative animations for frequent actions
 * - Information density over whitespace theater
 */

/* ============================================
   Design Tokens
   ============================================ */

:root {
  /* Color Scheme Declaration */
  color-scheme: light dark;

  /* Colors - Light Mode */
  --bg: #ffffff;
  --fg: #171717;
  --fg-muted: #737373;
  --accent: #0070f3;
  --accent-hover: #0060df;
  --card-bg: #f5f5f5;
  --card-border: #e5e5e5;
  --badge-p0-bg: #fef3c7;
  --badge-p0-fg: #92400e;
  --badge-p1-bg: #dbeafe;
  --badge-p1-fg: #1e40af;
  --badge-p2-bg: #f3f4f6;
  --badge-p2-fg: #374151;
  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;

  /* Spacing (8px base grid) */
  --sp-1: 0.5rem;   /* 8px */
  --sp-2: 1rem;     /* 16px */
  --sp-3: 1.5rem;   /* 24px */
  --sp-4: 2rem;     /* 32px */
  --sp-5: 3rem;     /* 48px */

  /* Typography */
  --font-base: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'SF Mono', Monaco, 'Cascadia Code', 'Courier New', monospace;
  --font-size-xs: 0.75rem;   /* 12px */
  --font-size-sm: 0.875rem;  /* 14px */
  --font-size-base: 1rem;    /* 16px - iOS minimum to prevent zoom */
  --font-size-lg: 1.125rem;  /* 18px */
  --font-size-xl: 1.25rem;   /* 20px */
  --line-height-tight: 1.25;
  --line-height-base: 1.6;
  --line-height-loose: 1.75;

  /* Shadows (subtle, Rauno-style) */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.12);

  /* Border Radius */
  --radius-sm: 0.375rem;  /* 6px */
  --radius-md: 0.5rem;    /* 8px */
  --radius-lg: 0.75rem;   /* 12px */
  --radius-xl: 1rem;      /* 16px */

  /* Transitions (fast by default) */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Z-index */
  --z-banner: 100;
  --z-nav: 200;
  --z-modal: 300;
}

/* Dark Mode */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0a;
    --fg: #ededed;
    --fg-muted: #a3a3a3;
    --accent: #4C9DFF;
    --accent-hover: #60A5FA;
    --card-bg: #1a1a1a;
    --card-border: #333333;
    --badge-p0-bg: #422006;
    --badge-p0-fg: #FDE68A;
    --badge-p1-bg: #1e3a8a;
    --badge-p1-fg: #93c5fd;
    --badge-p2-bg: #1f2937;
    --badge-p2-fg: #d1d5db;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.6);
  }
}

/* Manual Theme Override */
[data-theme="light"] {
  color-scheme: light;
  /* Light tokens (same as :root defaults) */
}

[data-theme="dark"] {
  color-scheme: dark;
  /* Dark tokens (same as @media dark) */
}


/* ============================================
   Base Styles
   ============================================ */

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

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-base);
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
  color: var(--fg);
  background: var(--bg);

  /* iOS safe areas (notch, home indicator) */
  padding-top: env(safe-area-inset-top);
  padding-bottom: calc(env(safe-area-inset-bottom) + 60px); /* 60px = bottom nav height */
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);

  /* Prevent overscroll bounce */
  overscroll-behavior-y: contain;

  /* Prevent pull-to-refresh (we have custom implementation) */
  overscroll-behavior: none;
}

/* Prevent double-tap zoom on buttons */
button {
  touch-action: manipulation;
}

/* Smooth scrolling (but not for reduced motion) */
@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}


/* ============================================
   Main Layout
   ============================================ */

#app {
  min-height: 100vh;
  padding: var(--sp-2);
  padding-bottom: var(--sp-5); /* Extra space for bottom nav */
}

/* Section Headings */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--sp-2);
  padding-bottom: var(--sp-1);
  border-bottom: 1px solid var(--card-border);
}

.section-title {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--fg);
}

.section-count {
  font-size: var(--font-size-sm);
  color: var(--fg-muted);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: var(--sp-5);
  color: var(--fg-muted);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: var(--sp-2);
  opacity: 0.5;
}

.empty-state-text {
  font-size: var(--font-size-base);
}


/* ============================================
   Update Banner Component
   ============================================ */

update-banner {
  display: block;
  position: sticky;
  top: 0;
  z-index: var(--z-banner);
  background: var(--card-bg);
  border-bottom: 1px solid var(--card-border);
  padding: var(--sp-1) var(--sp-2);
}

update-banner[status="fresh"] {
  background: var(--card-bg);
}

update-banner[status="aging"] {
  background: var(--warning);
  color: white;
}

update-banner[status="stale"] {
  background: var(--error);
  color: white;
}

.banner-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: var(--font-size-sm);
}

.banner-content button {
  background: transparent;
  border: 1px solid currentColor;
  color: currentColor;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-md);
  font-size: var(--font-size-xs);
  cursor: pointer;
  font-weight: 500;
}

.banner-content button:active {
  opacity: 0.7;
}


/* ============================================
   Task Card Component
   ============================================ */

task-card {
  display: block;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: var(--sp-2);
  margin-bottom: var(--sp-2);
  cursor: pointer;
  transition: all var(--transition-fast);

  /* Tap target minimum 44px */
  min-height: 44px;
}

task-card:active {
  transform: scale(0.98);
  box-shadow: var(--shadow-sm);
}

task-card.expanded {
  background: var(--bg);
  box-shadow: var(--shadow-md);
}

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

.priority-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  font-size: 1.25rem;
  border-radius: var(--radius-md);
  flex-shrink: 0;
}

.priority-badge[data-priority="P0"] {
  background: var(--badge-p0-bg);
  color: var(--badge-p0-fg);
}

.priority-badge[data-priority="P1"] {
  background: var(--badge-p1-bg);
  color: var(--badge-p1-fg);
}

.priority-badge[data-priority="P2"] {
  background: var(--badge-p2-bg);
  color: var(--badge-p2-fg);
}

.effort {
  font-size: var(--font-size-sm);
  color: var(--fg-muted);
  background: var(--card-border);
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
}

.task-title {
  font-size: var(--font-size-base);
  font-weight: 600;
  line-height: var(--line-height-tight);
  color: var(--fg);
  margin-bottom: var(--sp-1);
}

.first-step {
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  color: var(--fg-muted);
  line-height: var(--line-height-base);
  background: var(--bg);
  padding: 0.375rem 0.5rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--card-border);
}

.task-details {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: all var(--transition-base);
}

task-card.expanded .task-details {
  max-height: 500px;
  opacity: 1;
  margin-top: var(--sp-2);
  padding-top: var(--sp-2);
  border-top: 1px solid var(--card-border);
}

/* Structured Notes Sections */
.notes-context {
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
  color: var(--fg);
  margin-bottom: var(--sp-2);
}

.notes-section {
  margin-bottom: var(--sp-2);
  padding: var(--sp-2);
  background: var(--bg);
  border-radius: var(--radius-md);
  border: 1px solid var(--card-border);
}

.notes-header {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--sp-1);
}

.checklist {
  list-style: none;
  padding: 0;
  margin: 0;
}

.checklist li {
  padding-left: 1.5rem;
  position: relative;
  margin-bottom: 0.375rem;
  color: var(--fg-muted);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-base);
}

.checklist li::before {
  content: '✓';
  position: absolute;
  left: 0;
  color: var(--success);
  font-weight: 700;
  font-size: var(--font-size-base);
}

/* Callouts (NEW DEVELOPMENT, DECISION NEEDED, BLOCKER, etc.) */
.notes-callout {
  padding: var(--sp-2);
  border-radius: var(--radius-md);
  margin-bottom: var(--sp-2);
  border-left: 3px solid;
}

.callout-info {
  background: rgba(59, 130, 246, 0.1);
  border-left-color: #3b82f6;
}

.callout-warning {
  background: rgba(245, 158, 11, 0.1);
  border-left-color: #f59e0b;
}

.callout-error {
  background: rgba(239, 68, 68, 0.1);
  border-left-color: #ef4444;
}

@media (prefers-color-scheme: dark) {
  .callout-info {
    background: rgba(59, 130, 246, 0.15);
  }

  .callout-warning {
    background: rgba(245, 158, 11, 0.15);
  }

  .callout-error {
    background: rgba(239, 68, 68, 0.15);
  }
}

.notes-callout h4 {
  font-size: var(--font-size-sm);
  font-weight: 600;
  margin-bottom: var(--sp-1);
  color: var(--fg);
}

.notes-callout p {
  font-size: var(--font-size-sm);
  line-height: var(--line-height-base);
  color: var(--fg);
  margin: 0;
}

.source-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--accent);
  text-decoration: none;
  font-size: var(--font-size-sm);
  font-weight: 500;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-md);
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  transition: all var(--transition-fast);

  /* Tap target */
  min-height: 44px;
}

.source-link:active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}


/* ============================================
   Deal Card Component
   ============================================ */

deal-card {
  display: block;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: var(--sp-2);
  margin-bottom: var(--sp-2);
}

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

.deal-company {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--fg);
}

.deal-stage-badge {
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  background: var(--badge-p1-bg);
  color: var(--badge-p1-fg);
}

.deal-stage-badge[data-stage="closing"] {
  background: var(--badge-p0-bg);
  color: var(--badge-p0-fg);
}

.deal-current-stage {
  font-size: var(--font-size-sm);
  color: var(--fg-muted);
  margin-bottom: var(--sp-1);
}

.deal-milestone {
  font-size: var(--font-size-base);
  color: var(--fg);
  font-weight: 500;
}

.deal-milestone::before {
  content: '→ ';
  color: var(--accent);
}

.deal-blocker {
  margin-top: var(--sp-2);
  padding: var(--sp-1) var(--sp-2);
  background: var(--error);
  color: white;
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
}

.deal-blocker::before {
  content: '🚨 ';
}

.deal-updated {
  margin-top: var(--sp-1);
  font-size: var(--font-size-xs);
  color: var(--fg-muted);
}


/* ============================================
   Itinerary Day Component
   ============================================ */

itinerary-day {
  display: block;
}

.trip-header {
  margin-bottom: var(--sp-3);
}

.trip-name {
  font-size: var(--font-size-xl);
  font-weight: 600;
  color: var(--fg);
  margin-bottom: var(--sp-1);
}

.trip-dates {
  font-size: var(--font-size-sm);
  color: var(--fg-muted);
}

.timeline {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.time-block {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: var(--sp-2);
}

.time-block-header {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  margin-bottom: var(--sp-2);
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--fg);
}

.time-icon {
  font-size: 1.5rem;
}

.time-block-content {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.time-item {
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
  color: var(--fg);
}

.time-item-time {
  font-weight: 600;
  color: var(--accent);
}

.address-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--accent);
  text-decoration: none;
  font-size: var(--font-size-sm);
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  margin-top: 0.5rem;
  transition: all var(--transition-fast);

  /* Tap target */
  min-height: 44px;
}

.address-link:active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.address-link::after {
  content: '📍';
  font-size: 1.125rem;
}


/* ============================================
   Bottom Navigation
   ============================================ */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: var(--z-nav);

  display: flex;
  justify-content: space-around;
  align-items: center;

  background: var(--card-bg);
  border-top: 1px solid var(--card-border);
  box-shadow: var(--shadow-lg);

  /* iOS safe area */
  padding-bottom: env(safe-area-inset-bottom);

  /* Backdrop blur (iOS-style) */
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;

  padding: 0.5rem;
  background: transparent;
  border: none;
  color: var(--fg-muted);
  cursor: pointer;

  transition: color var(--transition-fast);

  /* Tap target */
  min-height: 60px;
}

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

.nav-item:active {
  opacity: 0.6;
}

.nav-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.nav-label {
  font-size: var(--font-size-xs);
  font-weight: 500;
  letter-spacing: 0.02em;
}


/* ============================================
   Loading State
   ============================================ */

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 50vh;
  gap: var(--sp-2);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--card-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.loading-state p {
  color: var(--fg-muted);
  font-size: var(--font-size-base);
}


/* ============================================
   Accessibility
   ============================================ */

/* Focus Styles */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Skip to Content (for screen readers) */
.skip-to-content {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--accent);
  color: white;
  padding: 0.5rem 1rem;
  text-decoration: none;
  border-radius: 0 0 var(--radius-md) 0;
  z-index: 1000;
}

.skip-to-content:focus {
  top: 0;
}

/* Reduce Motion Preference */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .spinner {
    animation: none;
    border-top-color: var(--card-border);
  }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
  :root {
    --card-border: #666;
  }

  task-card,
  deal-card,
  .time-block {
    border-width: 2px;
  }
}


/* ============================================
   Utility Classes
   ============================================ */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.hidden {
  display: none !important;
}

.fade-in {
  animation: fadeIn var(--transition-base);
}

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


/* ============================================
   Pull to Refresh
   ============================================ */

.pull-to-refresh {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%) translateY(-100%);
  padding: var(--sp-1) var(--sp-2);
  background: var(--card-bg);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  box-shadow: var(--shadow-md);
  z-index: var(--z-banner);

  transition: transform var(--transition-base);
}

.pull-to-refresh.visible {
  transform: translateX(-50%) translateY(0);
}

.pull-to-refresh-icon {
  animation: spin 1s linear infinite;
}


/* ============================================
   Responsive Breakpoints
   ============================================ */

/* Small phones (< 375px) */
@media (max-width: 374px) {
  :root {
    --font-size-base: 0.9375rem; /* 15px */
  }

  .task-title {
    font-size: var(--font-size-sm);
  }
}

/* Tablets (> 768px) */
@media (min-width: 768px) {
  #app {
    max-width: 600px;
    margin: 0 auto;
  }

  .bottom-nav {
    max-width: 600px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
}

/* Large tablets / Desktop (> 1024px) */
@media (min-width: 1024px) {
  body {
    background: var(--card-bg);
  }

  #app {
    max-width: 700px;
    background: var(--bg);
    border-left: 1px solid var(--card-border);
    border-right: 1px solid var(--card-border);
    box-shadow: var(--shadow-lg);
  }
}