/* ===== CSS Custom Properties ===== */
:root {
  --accent: #007AFF;
  --accent-light: rgba(0, 122, 255, 0.12);
  --bg: #F2F2F7;
  --bg-card: #FFFFFF;
  --bg-secondary: #F2F2F7;
  --text-primary: #1C1C1E;
  --text-secondary: #6E6E73;
  --text-tertiary: #AEAEB2;
  --separator: rgba(0, 0, 0, 0.08);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.10), 0 2px 6px rgba(0,0,0,0.06);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.15), 0 4px 12px rgba(0,0,0,0.08);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --tab-height: 56px;
  --header-height: 56px;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
}

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ===== Typography ===== */
h1 { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.5px; }
h2 { font-size: 1.375rem; font-weight: 600; letter-spacing: -0.3px; }
h3 { font-size: 1.125rem; font-weight: 600; }
p { color: var(--text-secondary); }
a { color: var(--accent); text-decoration: none; }

/* ===== Layout ===== */
.app-container {
  max-width: 768px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
  background: var(--bg);
}

.page-content {
  padding: calc(var(--header-height) + 16px) 16px calc(var(--tab-height) + 24px);
}

/* ===== Header ===== */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-height);
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--separator);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  max-width: 768px;
  margin: 0 auto;
}

.app-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-primary);
}

.app-logo .logo-icon {
  font-size: 1.5rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ===== Tab Bar ===== */
.tab-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--tab-height);
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--separator);
  display: flex;
  align-items: center;
  z-index: 100;
  max-width: 768px;
  margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: 100%;
  cursor: pointer;
  transition: var(--transition);
  color: var(--text-tertiary);
  position: relative;
  background: none;
  border: none;
  font-family: var(--font);
  padding: 0;
}

.tab-item.active { color: var(--accent); }
.tab-item:active { opacity: 0.7; transform: scale(0.95); }

.tab-icon { font-size: 1.375rem; line-height: 1; }
.tab-label { font-size: 0.625rem; font-weight: 500; letter-spacing: 0.3px; }

.tab-badge {
  position: absolute;
  top: 4px;
  right: calc(50% - 18px);
  background: #FF3B30;
  color: white;
  font-size: 0.625rem;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 5px;
  min-width: 16px;
  text-align: center;
  line-height: 14px;
}

/* ===== Tab Panels ===== */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ===== Cards ===== */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: 12px;
}

.card-header {
  padding: 16px 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--separator);
}

.card-title {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.card-body { padding: 16px; }

/* ===== Stat Cards ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  text-align: center;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
}

/* ===== Points Display ===== */
.points-hero {
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 70%, #000));
  border-radius: var(--radius-xl);
  padding: 32px 24px;
  text-align: center;
  color: white;
  margin-bottom: 16px;
  box-shadow: 0 8px 24px rgba(0, 122, 255, 0.3);
}

.points-amount {
  font-size: 4rem;
  font-weight: 800;
  line-height: 1;
  margin: 8px 0;
  letter-spacing: -2px;
}

.points-label {
  font-size: 1rem;
  opacity: 0.85;
  font-weight: 500;
}

.points-star { font-size: 1.5rem; }

/* ===== List Items ===== */
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--separator);
  transition: var(--transition);
}

.list-item:last-child { border-bottom: none; }
.list-item:active { background: var(--bg-secondary); }

.list-item-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem;
  flex-shrink: 0;
  background: var(--accent-light);
  color: var(--accent);
}

.list-item-content { flex: 1; min-width: 0; }
.list-item-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-item-subtitle {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-top: 1px;
}

.list-item-action { flex-shrink: 0; }

/* ===== Status Badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
}

.badge-pending { background: #E5E5EA; color: #6E6E73; }
.badge-submitted { background: #FFF3E0; color: #FF9500; }
.badge-approved { background: #E8F5E9; color: #34C759; }
.badge-rejected { background: #FFEBEE; color: #FF3B30; }
.badge-prize { background: #F3E8FF; color: #AF52DE; }
.badge-cash { background: #E8F5E9; color: #34C759; }
.badge-privilege { background: #FFF3E0; color: #FF9500; }
.badge-experience { background: #E3F2FD; color: #007AFF; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-size: 0.9375rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { filter: brightness(1.08); }

.btn-secondary { background: var(--accent-light); color: var(--accent); }
.btn-secondary:hover { background: rgba(0,122,255,0.18); }

.btn-danger { background: #FFEBEE; color: #FF3B30; }
.btn-danger:hover { background: rgba(255, 59, 48, 0.18); }

.btn-success { background: #E8F5E9; color: #34C759; }
.btn-success:hover { background: rgba(52, 199, 89, 0.18); }

.btn-sm { padding: 6px 14px; font-size: 0.8125rem; border-radius: var(--radius-sm); }
.btn-lg { padding: 14px 28px; font-size: 1.0625rem; border-radius: var(--radius-lg); width: 100%; }

.btn-icon {
  width: 36px; height: 36px;
  padding: 0;
  border-radius: 50%;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 1.125rem;
  position: relative;
}

.btn-icon .badge-dot {
  position: absolute;
  top: 2px; right: 2px;
  width: 10px; height: 10px;
  background: #FF3B30;
  border-radius: 50%;
  border: 2px solid white;
}

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--separator);
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-size: 1rem;
  color: var(--text-primary);
  background: var(--bg-card);
  transition: var(--transition);
  outline: none;
  appearance: none;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.form-input::placeholder { color: var(--text-tertiary); }
.form-textarea { resize: vertical; min-height: 80px; }

.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236E6E73' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* ===== Modals ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom, 0));
  width: 100%;
  max-width: 768px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay.visible .modal {
  transform: translateY(0);
}

.modal-handle {
  width: 36px; height: 4px;
  background: var(--separator);
  border-radius: 2px;
  margin: 0 auto 16px;
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 20px;
  text-align: center;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.modal-actions .btn { flex: 1; }

/* Desktop modal style */
@media (min-width: 600px) {
  .modal-overlay { align-items: center; }
  .modal {
    border-radius: var(--radius-xl);
    max-width: 480px;
    transform: scale(0.95);
  }
  .modal-overlay.visible .modal { transform: scale(1); }
  .modal-handle { display: none; }
}

/* ===== Login Page ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #F2F2F7 0%, #E8EAED 100%);
}

.login-card {
  background: white;
  border-radius: var(--radius-xl);
  padding: 40px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo .logo-icon { font-size: 3rem; display: block; margin-bottom: 8px; }
.login-logo h1 { font-size: 2rem; font-weight: 800; letter-spacing: -1px; }
.login-logo p { font-size: 0.875rem; color: var(--text-secondary); margin-top: 4px; }

.login-error {
  background: #FFEBEE;
  color: #FF3B30;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 16px;
  display: none;
}

.login-error.visible { display: block; }

/* ===== Kid Card with Avatar ===== */
.kid-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 10px;
  position: relative;
}

.kid-avatar {
  width: 52px; height: 52px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
  overflow: hidden;
}

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

.kid-info { flex: 1; min-width: 0; }
.kid-name { font-size: 1rem; font-weight: 700; }
.kid-points-small {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--accent);
}

.kid-actions { display: flex; gap: 6px; }

/* ===== Progress Ring ===== */
.progress-ring { width: 52px; height: 52px; }
.progress-ring-circle {
  transition: stroke-dashoffset 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
}

/* ===== Color Theme Picker ===== */
.theme-picker {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.theme-swatch {
  width: 40px; height: 40px;
  border-radius: 50%;
  cursor: pointer;
  transition: var(--transition);
  border: 3px solid transparent;
  position: relative;
}

.theme-swatch:active { transform: scale(0.9); }
.theme-swatch.selected { border-color: white; box-shadow: 0 0 0 3px var(--accent), var(--shadow-sm); }

/* ===== Avatar Upload ===== */
.avatar-upload-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px;
  border: 2px dashed var(--separator);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
}

.avatar-upload-area:hover { border-color: var(--accent); background: var(--accent-light); }
.avatar-upload-area:active { transform: scale(0.98); }

.avatar-preview {
  width: 80px; height: 80px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  overflow: hidden;
}

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

/* ===== Rewards Grid ===== */
.rewards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.reward-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.reward-card:active { transform: scale(0.97); }

.reward-icon {
  font-size: 2rem;
  width: 56px; height: 56px;
  background: var(--accent-light);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
}

.reward-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
}

.reward-cost {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
}

/* ===== Chore Item ===== */
.chore-item {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 12px;
}

.chore-points-badge {
  background: var(--accent-light);
  color: var(--accent);
  font-size: 0.8125rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ===== Notification Item ===== */
.notification-item {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--separator);
  transition: var(--transition);
  cursor: pointer;
}

.notification-item:last-child { border-bottom: none; }
.notification-item:active { background: var(--bg-secondary); }
.notification-item.unread { background: rgba(0, 122, 255, 0.04); }

.notification-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  margin-top: 6px;
}

.notification-item.unread .notification-dot { background: var(--accent); }
.notification-item:not(.unread) .notification-dot { background: transparent; }

.notification-message { font-size: 0.9rem; font-weight: 500; }
.notification-time { font-size: 0.75rem; color: var(--text-tertiary); margin-top: 2px; }

/* ===== Section Headers ===== */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  margin-top: 20px;
}

.section-header:first-child { margin-top: 0; }
.section-title { font-size: 1.125rem; font-weight: 700; color: var(--text-primary); }

/* ===== Empty States ===== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
}

.empty-state-icon { font-size: 3rem; margin-bottom: 12px; display: block; }
.empty-state-text { font-size: 1rem; font-weight: 500; }
.empty-state-sub { font-size: 0.875rem; margin-top: 4px; }

/* ===== Skeleton Loading ===== */
@keyframes shimmer {
  0% { background-position: -1000px 0; }
  100% { background-position: 1000px 0; }
}

.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 1000px 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

.skeleton-line { height: 16px; margin-bottom: 8px; }
.skeleton-line.short { width: 60%; }
.skeleton-line.medium { width: 80%; }
.skeleton-card { height: 80px; border-radius: var(--radius-md); margin-bottom: 10px; }

/* ===== Toast Notification ===== */
.toast-container {
  position: fixed;
  top: calc(var(--header-height) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: calc(100% - 32px);
  max-width: 400px;
}

.toast {
  background: var(--text-primary);
  color: white;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toastIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.toast.success { background: #1C7A3B; }
.toast.error { background: #C0392B; }
.toast.info { background: #0071E3; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Segmented Control (filter) ===== */
.segmented-control {
  display: flex;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 2px;
}

.segment-btn {
  flex: 1;
  padding: 7px 12px;
  border-radius: calc(var(--radius-md) - 2px);
  border: none;
  background: none;
  font-family: var(--font);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
}

.segment-btn.active {
  background: white;
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* ===== Divider ===== */
.divider {
  height: 1px;
  background: var(--separator);
  margin: 8px 0;
}

/* ===== Desktop adjustments ===== */
@media (min-width: 600px) {
  :root {
    --header-height: 64px;
    --tab-height: 0px;
  }

  .page-content { padding: calc(var(--header-height) + 24px) 24px 40px; }

  .app-header { left: 50%; transform: translateX(-50%); }

  .tab-bar {
    top: 0;
    bottom: auto;
    height: var(--header-height);
    border-top: none;
    border-bottom: 1px solid var(--separator);
    justify-content: center;
    gap: 4px;
    background: rgba(255,255,255,0.92);
  }

  /* On desktop, show the tab bar alongside header by offsetting content */
  .page-content { padding-top: calc(var(--header-height) * 2 + 24px); }

  .tab-item {
    flex-direction: row;
    gap: 6px;
    padding: 0 16px;
    flex: 0 0 auto;
    height: 40px;
    border-radius: var(--radius-md);
  }

  .tab-icon { font-size: 1rem; }
  .tab-label { font-size: 0.875rem; }

  .tab-item.active {
    background: var(--accent-light);
  }

  .rewards-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}

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

@keyframes countUp {
  from { transform: scale(1.3); color: var(--accent); }
  to { transform: scale(1); }
}

.animate-in { animation: fadeIn 0.3s ease forwards; }
.count-up { animation: countUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1); }

/* ===== Inline actions row ===== */
.action-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

/* ===== Chore status dots ===== */
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.pending { background: var(--text-tertiary); }
.status-dot.submitted { background: #FF9500; }
.status-dot.approved { background: #34C759; }
.status-dot.rejected { background: #FF3B30; }

/* Fix desktop header overlapping tab bar */
@media (min-width: 600px) {
  .app-header { z-index: 200; }
}

/* Fix desktop tab bar position */
@media (min-width: 600px) {
  .tab-bar { top: var(--header-height); height: 48px; }
  .page-content { padding-top: calc(var(--header-height) + 48px + 24px); }
}
