/* ==========================================================================
   RN Family Progress Tracker — Design Tokens & Core Styles
   Strictly following design-system/MASTER.md (Trust-First / Human / Accessible)
   ========================================================================== */

:root {
  /* Core Semantic Palette */
  --bg-app: #F8FAFC;
  --bg-card: #FFFFFF;
  --bg-subtle: #F1F5F9;
  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-muted: #94A3B8;
  --border-subtle: #E2E8F0;
  --border-focus: #0284C7;

  /* Clinical Trust Palette */
  --brand-primary: #0284C7;
  --brand-primary-hover: #0369A1;
  --brand-accent: #0D9488;
  --brand-accent-light: #CCFBF1;

  /* Alert & Status Tokens */
  --color-urgent: #EA580C;
  --color-urgent-bg: #FFEDD5;
  --color-urgent-border: #FDBA74;
  --color-success: #16A34A;
  --color-success-bg: #DCFCE7;
  --color-success-border: #86EFAC;
  --color-warning: #CA8A04;
  --color-warning-bg: #FEF9C3;

  /* Role Identity Tokens */
  --role-glen: #1E40AF;
  --role-glen-bg: #DBEAFE;
  --role-emily: #0F766E;
  --role-emily-bg: #CCFBF1;
  --role-mavis: #9D174D;
  --role-mavis-bg: #FCE7F3;

  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans TC", "Helvetica Neue", Arial, sans-serif;

  /* Elevation */
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 10px 25px -5px rgba(15, 23, 42, 0.1);

  /* Radius */
  --radius-card: 16px;
  --radius-btn: 10px;
  --radius-badge: 9999px;
  
  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.16, 1, 0.3, 1);
  /* Typography Scale Factors */
  --font-scale: 1;
  --base-font-size: 15px;
}

/* Font Size Modifiers */
html[data-font-size="standard"] {
  --font-scale: 1;
  --base-font-size: 15px;
}

html[data-font-size="large"] {
  --font-scale: 1.15;
  --base-font-size: 17px;
}

html[data-font-size="xlarge"] {
  --font-scale: 1.30;
  --base-font-size: 19px;
}

/* Base Reset & Box Sizing */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.6;
  font-size: var(--base-font-size, 15px);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 12px 12px 64px 12px;
  transition: font-size var(--transition-fast);
}

/* App Container */
.app-container {
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
}

/* Top Navigation / App Header */
.app-header {
  background: var(--bg-card);
  padding: 14px 18px;
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-subtle);
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.header-main-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.header-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
}

.header-title-group {
  min-width: 0;
}

.header-title-group h1 {
  font-size: calc(18px * var(--font-scale, 1));
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Font Size Picker Segmented Control */
.font-size-picker {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--bg-subtle);
  padding: 3px 4px;
  border-radius: 9999px;
  border: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.font-picker-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  padding: 0 4px 0 6px;
  user-select: none;
}

.font-size-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  min-height: 28px;
  border-radius: 9999px;
  cursor: pointer;
  transition: all var(--transition-fast);
  line-height: 1.2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.font-size-btn:hover {
  color: var(--text-primary);
}

.font-size-btn.active {
  background: #FFFFFF;
  color: var(--brand-primary);
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
}

.header-sub-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
}

.header-badges {
  display: flex;
  gap: 6px;
}

.badge-tag {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: var(--radius-badge);
  background: var(--bg-subtle);
  color: var(--brand-primary);
  border: 1px solid var(--border-subtle);
}

/* Family Cloud Sync Bar */
.sync-status-bar {
  background: var(--bg-card);
  padding: 8px 14px;
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-subtle);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
}

.sync-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94A3B8;
  display: inline-block;
  transition: background-color var(--transition-fast);
}

.sync-dot.synced {
  background: #16A34A;
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.2);
}

.sync-dot.syncing {
  background: #CA8A04;
  box-shadow: 0 0 0 3px rgba(202, 138, 4, 0.2);
}

.sync-dot.offline {
  background: #EA580C;
  box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.2);
}

.sync-text {
  color: var(--text-secondary);
  font-weight: 500;
}

.sync-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  min-height: 32px;
  background: var(--bg-subtle);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.sync-btn:hover {
  background: #E2E8F0;
  color: var(--text-primary);
}

.sync-btn.rotating .sync-icon {
  animation: spin-sync 0.8s linear infinite;
}

@keyframes spin-sync {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* HUD Countdown Section */
.hud-countdown-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.hud-card {
  background: var(--bg-card);
  padding: 14px 16px;
  border-radius: var(--radius-card);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}

.hud-card.urgent {
  background: linear-gradient(135deg, #FFFFFF 0%, var(--color-urgent-bg) 100%);
  border-color: var(--color-urgent-border);
}

.hud-card.highlight {
  background: linear-gradient(135deg, #FFFFFF 0%, var(--brand-accent-light) 100%);
  border-color: #99F6E4;
}

.hud-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.hud-number-row {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin-top: 6px;
}

.hud-number {
  font-size: 28px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
}

.hud-card.urgent .hud-number {
  color: var(--color-urgent);
}

.hud-card.highlight .hud-number {
  color: var(--brand-accent);
}

.hud-unit {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.hud-subtext {
  font-size: calc(11px * var(--font-scale, 1));
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Role Selector Tabs */
.role-tabs-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  background: var(--bg-subtle);
  padding: 6px;
  border-radius: var(--radius-card);
  margin-bottom: 16px;
  border: 1px solid var(--border-subtle);
}

.role-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 6px;
  border-radius: 12px;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  color: var(--text-secondary);
  min-height: 56px;
}

.role-tab .role-avatar {
  font-size: 20px;
  line-height: 1;
  margin-bottom: 3px;
}

.role-tab .role-name {
  font-size: calc(13px * var(--font-scale, 1));
  font-weight: 700;
}

.role-tab .role-desc {
  font-size: calc(10px * var(--font-scale, 1));
  opacity: 0.85;
}

/* Active States for Role Tabs */
.role-tab.active.glen {
  background: var(--bg-card);
  color: var(--role-glen);
  box-shadow: var(--shadow-sm);
  border: 1.5px solid var(--role-glen);
}

.role-tab.active.emily {
  background: var(--bg-card);
  color: var(--role-emily);
  box-shadow: var(--shadow-sm);
  border: 1.5px solid var(--role-emily);
}

.role-tab.active.mavis {
  background: var(--bg-card);
  color: var(--role-mavis);
  box-shadow: var(--shadow-sm);
  border: 1.5px solid var(--role-mavis);
}

/* Global Progress Header Card */
.progress-card {
  background: var(--bg-card);
  padding: 16px 20px;
  border-radius: var(--radius-card);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

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

.progress-title {
  font-size: calc(14px * var(--font-scale, 1));
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.progress-percent {
  font-size: 16px;
  font-weight: 800;
  color: var(--brand-primary);
}

.progress-bar-bg {
  width: 100%;
  height: 10px;
  background: var(--bg-subtle);
  border-radius: var(--radius-badge);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--brand-primary), var(--brand-accent));
  width: 0%;
  transition: width 400ms cubic-bezier(0.16, 1, 0.3, 1);
  border-radius: var(--radius-badge);
}

.progress-footer {
  margin-top: 6px;
  font-size: calc(12px * var(--font-scale, 1));
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
}

/* Quick Action Bar (Contacts & Links) */
.quick-action-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 10px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-btn);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  min-height: 48px;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.action-btn:active {
  background: var(--bg-subtle);
  transform: translateY(1px);
}

.action-btn.call-btn {
  color: #1E40AF;
  border-color: #BFDBFE;
}

.action-btn.web-btn {
  color: #0F766E;
  border-color: #99F6E4;
}

/* Phase Checklist Container */
.phase-group {
  margin-bottom: 14px;
  background: var(--bg-card);
  border-radius: var(--radius-card);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.phase-header {
  padding: 14px 18px;
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition-fast);
  border-bottom: 1px solid transparent;
}

.phase-header:hover {
  background: #F8FAFC;
}

.phase-header.expanded {
  border-bottom-color: var(--border-subtle);
  background: #F8FAFC;
}

.phase-title-col {
  display: flex;
  align-items: center;
  gap: 10px;
}

.phase-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--bg-subtle);
  color: var(--text-secondary);
}

.phase-title {
  font-size: calc(15px * var(--font-scale, 1));
  font-weight: 700;
  color: var(--text-primary);
}

.phase-owner-tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--radius-badge);
  font-weight: 600;
}

.owner-glen {
  background: var(--role-glen-bg);
  color: var(--role-glen);
}

.owner-emily {
  background: var(--role-emily-bg);
  color: var(--role-emily);
}

.owner-both {
  background: #FEF3C7;
  color: #B45309;
}

.phase-items-list {
  padding: 10px 18px 16px 18px;
  display: none;
  flex-direction: column;
  gap: 12px;
}

.phase-items-list.show {
  display: flex;
}

/* Task Checkbox Row */
.task-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-app);
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  transition: all var(--transition-fast);
}

.task-item.completed {
  background: #F0FDF4;
  border-color: var(--color-success-border);
}

.task-checkbox-container {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 2px;
}

.task-checkbox {
  width: 22px;
  height: 22px;
  accent-color: var(--color-success);
  cursor: pointer;
}

.task-content {
  flex: 1;
}

.task-title {
  font-size: calc(14px * var(--font-scale, 1));
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.4;
}

.task-item.completed .task-title {
  text-decoration: line-through;
  color: var(--text-muted);
}

.task-desc {
  font-size: calc(13px * var(--font-scale, 1));
  color: var(--text-secondary);
  margin-top: 3px;
  line-height: 1.5;
}

.task-alert-tag {
  display: inline-block;
  font-size: calc(12px * var(--font-scale, 1));
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--color-urgent-bg);
  color: var(--color-urgent);
  border: 1px solid var(--color-urgent-border);
  margin-top: 4px;
}

/* Mavis Panoramic View Specifics */
.mavis-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.mavis-box {
  background: var(--bg-card);
  padding: 16px;
  border-radius: var(--radius-card);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
}

.mavis-box-title {
  font-size: calc(13px * var(--font-scale, 1));
  font-weight: 700;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

.mavis-progress-label {
  display: flex;
  justify-content: space-between;
  font-size: calc(12px * var(--font-scale, 1));
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.mavis-sub-hint {
  font-size: calc(11px * var(--font-scale, 1));
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.4;
  display: flex;
  align-items: center;
  gap: 4px;
}

.mavis-milestones-card {
  background: var(--bg-card);
  padding: 16px 20px;
  border-radius: var(--radius-card);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

.milestone-timeline {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
}

.timeline-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  position: relative;
}

.timeline-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--brand-primary);
  margin-top: 4px;
  flex-shrink: 0;
}

.timeline-dot.done {
  background: var(--color-success);
}

.timeline-content {
  flex: 1;
}

.timeline-date {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
}

.timeline-text {
  font-size: calc(14px * var(--font-scale, 1));
  font-weight: 600;
  color: var(--text-primary);
}

/* Family Cheer Note Board */
.cheer-board {
  background: linear-gradient(135deg, #FFF1F2 0%, #FFFFFF 100%);
  border: 1.5px solid #FECDD3;
  padding: 18px;
  border-radius: var(--radius-card);
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.cheer-header {
  font-size: calc(15px * var(--font-scale, 1));
  font-weight: 700;
  color: var(--role-mavis);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.cheer-body {
  font-size: calc(14px * var(--font-scale, 1));
  color: var(--text-secondary);
  line-height: 1.6;
}

/* Modal / Emergency FAQ Accordion */
.faq-section {
  background: var(--bg-card);
  padding: 16px 20px;
  border-radius: var(--radius-card);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
}

.faq-title {
  font-size: calc(15px * var(--font-scale, 1));
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.faq-item {
  border-bottom: 1px solid var(--border-subtle);
  padding: 10px 0;
}

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

.faq-question {
  font-size: calc(14px * var(--font-scale, 1));
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
}

.faq-answer {
  font-size: calc(13px * var(--font-scale, 1));
  color: var(--text-secondary);
  margin-top: 6px;
  display: none;
  line-height: 1.5;
}

.faq-answer.show {
  display: block;
}

/* Footer & Attribution */
.app-footer {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 32px;
  line-height: 1.8;
}

/* Responsiveness */
@media (max-width: 480px) {
  body {
    padding: 8px 8px 56px 8px;
  }
  .app-header {
    padding: 12px 14px;
  }
  .header-logo {
    width: 36px;
    height: 36px;
  }
  .header-title-group h1 {
    font-size: calc(16px * var(--font-scale, 1));
  }
  .font-size-picker {
    padding: 2px 3px;
  }
  .font-picker-label {
    display: none; /* 極小螢幕下精簡標籤，保留直觀的三段切換按鈕 */
  }
  .font-size-btn {
    padding: 3px 8px;
    font-size: 11px;
    min-height: 26px;
  }
  .hud-number {
    font-size: 24px;
  }
  .quick-action-bar {
    grid-template-columns: repeat(3, 1fr);
  }
  .action-btn {
    font-size: 12px;
    padding: 8px 4px;
  }
}
