* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

input, select, textarea, button {
  font-size: 16px;  /* Prevent iOS zoom on focus */
  touch-action: manipulation;
}

:root {
  --bg: #fef3c7;
  --bg-soft: #fffbeb;
  --card: #ffffff;
  --text: #1f2937;
  --text-soft: #6b7280;
  --border: #e5e7eb;
  --primary: #f59e0b;
  --primary-dark: #d97706;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --shadow: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ==================== LOGIN ==================== */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(180deg, #fef3c7 0%, #fde68a 100%);
}

.login-card {
  background: var(--card);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  padding: 32px 28px;
  max-width: 360px;
  width: 100%;
  text-align: center;
}

.login-logo {
  width: 100%;
  max-width: 320px;
  height: auto;
  display: block;
  margin: 0 auto 8px;
}

.login-sub {
  color: var(--text-soft);
  font-size: 14px;
  margin-bottom: 24px;
}

.brand-bar {
  background: linear-gradient(180deg, #fef3c7 0%, #fffbeb 100%);
  padding: 10px 16px 4px;
  display: flex;
  justify-content: center;
}

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

.pin-display {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-bottom: 28px;
  height: 20px;
}

.pin-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--border);
  transition: all 0.2s;
}

.pin-dot.filled {
  background: var(--primary);
  transform: scale(1.15);
}

.pin-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.pin-key {
  background: var(--bg-soft);
  border: 2px solid var(--border);
  border-radius: 16px;
  font-size: 28px;
  font-weight: 600;
  padding: 20px 0;
  cursor: pointer;
  color: var(--text);
  transition: transform 0.08s, background 0.15s;
}

.pin-key:active {
  transform: scale(0.92);
  background: #fef3c7;
}

.pin-key-blank {
  visibility: hidden;
}

.pin-key-back {
  font-size: 22px;
  color: var(--text-soft);
}

.login-error {
  margin-top: 16px;
  color: var(--danger);
  font-size: 14px;
  min-height: 20px;
}

/* ==================== CHILD VIEW ==================== */
.child-view {
  min-height: 100vh;
  padding-bottom: 40px;
}

.child-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--card);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 10;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 100px;
  color: white;
  font-weight: 600;
  font-size: 15px;
}

.user-chip-emoji {
  font-size: 22px;
}

.header-stats {
  flex: 1;
  display: flex;
  gap: 14px;
  justify-content: flex-end;
  align-items: center;
}

.stat-candy, .stat-days {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-weight: 700;
}

.stat-candy { font-size: 20px; }
.stat-emoji { font-size: 22px; }
.stat-days { color: var(--text-soft); font-size: 13px; }
.stat-days #daysLeft { font-size: 18px; color: var(--text); font-weight: 800; }
.stat-label { font-size: 11px; }

.icon-btn {
  background: transparent;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-soft);
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:active {
  background: var(--border);
}

.progress-jar {
  margin: 16px;
  background: var(--card);
  border-radius: 18px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.jar-track {
  height: 20px;
  background: var(--bg);
  border-radius: 100px;
  overflow: hidden;
  border: 2px solid var(--border);
}

.jar-fill {
  height: 100%;
  background: linear-gradient(90deg, #f59e0b, #ef4444, #ec4899);
  border-radius: 100px;
  transition: width 0.5s cubic-bezier(.4,0,.2,1);
  width: 0%;
}

.jar-label {
  text-align: center;
  margin-top: 8px;
  font-weight: 700;
  font-size: 15px;
  color: var(--text-soft);
}

.tasks-list {
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.time-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.time-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-top: 4px;
  padding-left: 4px;
}

.time-section-header .time-emoji {
  font-size: 22px;
}

.time-section-header .time-count {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-soft);
  font-weight: 600;
  background: var(--card);
  padding: 2px 10px;
  border-radius: 100px;
}

.task-card {
  background: var(--card);
  border-radius: 18px;
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 14px;
  transition: all 0.2s;
}

.task-card.approved {
  background: #ecfdf5;
  border: 2px solid var(--success);
}

.task-card.rejected {
  background: #fef2f2;
  border: 2px solid var(--danger);
}

.task-card.pending {
  background: #fffbeb;
  border: 2px solid var(--warning);
}

.task-check {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid var(--border);
  background: var(--card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  cursor: pointer;
}

.task-check.checked {
  background: var(--success);
  border-color: var(--success);
  color: white;
}

.task-check.rejected {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
}

.task-check.pending {
  background: var(--warning);
  border-color: var(--warning);
  color: white;
}

.task-info {
  flex: 1;
  min-width: 0;
}

.task-name {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 2px;
}

.task-card.approved .task-name {
  text-decoration: line-through;
  color: var(--text-soft);
}

.task-meta {
  font-size: 12px;
  color: var(--text-soft);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.task-badge {
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  background: var(--border);
}

.task-badge-photo { background: #dbeafe; color: #1e40af; }
.task-badge-parent { background: #fef3c7; color: #92400e; }
.task-badge-time { background: #fce7f3; color: #9f1239; }

.task-action {
  flex-shrink: 0;
}

.task-action button {
  background: var(--primary);
  color: white;
  border: none;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.task-action button:active { transform: scale(0.96); }

.task-explanation {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-soft);
  font-style: italic;
  grid-column: 1 / -1;
  width: 100%;
}

.day-reward-banner {
  position: fixed;
  bottom: 16px;
  left: 16px;
  right: 16px;
  background: linear-gradient(135deg, #f59e0b, #ec4899);
  color: white;
  border-radius: 18px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-lg);
  animation: reward-pop 0.5s;
}

.reward-emoji { font-size: 38px; }
.reward-text { font-size: 18px; font-weight: 700; }

@keyframes reward-pop {
  0% { transform: translateY(100px); opacity: 0; }
  60% { transform: translateY(-10px); }
  100% { transform: translateY(0); opacity: 1; }
}

.tasks-empty {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-soft);
}

/* ==================== ADMIN VIEW ==================== */
.admin-view {
  min-height: 100vh;
  padding-bottom: 40px;
}

.admin-header {
  background: var(--card);
  padding: 16px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
}

.admin-title {
  font-size: 20px;
  font-weight: 700;
}

.admin-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

.admin-tabs::-webkit-scrollbar { display: none; }

.admin-tab {
  background: transparent;
  border: none;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-soft);
  cursor: pointer;
  white-space: nowrap;
}

.admin-tab.active {
  background: var(--primary);
  color: white;
}

.admin-panel {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.overview-card {
  background: var(--card);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.overview-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.overview-user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 100px;
  color: white;
  font-weight: 600;
}

.overview-candies {
  margin-left: auto;
  font-size: 16px;
  font-weight: 700;
}

.progress-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.progress-row .progress-bar {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 100px;
  overflow: hidden;
}

.progress-row .progress-bar-fill {
  height: 100%;
  background: var(--success);
  transition: width 0.3s;
}

.progress-text {
  font-size: 12px;
  color: var(--text-soft);
  font-weight: 600;
}

.reward-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 700;
  margin-top: 4px;
}

.reward-badge.earned { background: #d1fae5; color: #065f46; }
.reward-badge.not-earned { background: #fee2e2; color: #991b1b; }

.pending-card {
  background: var(--card);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 12px;
  align-items: center;
}

.pending-photo {
  width: 80px;
  height: 80px;
  border-radius: 12px;
  object-fit: cover;
  background: var(--bg);
  cursor: pointer;
}

.pending-info { flex: 1; min-width: 0; }
.pending-name { font-weight: 600; margin-bottom: 2px; }
.pending-meta { font-size: 12px; color: var(--text-soft); }
.pending-ai { font-size: 12px; color: var(--text-soft); margin-top: 4px; font-style: italic; }

.pending-actions { display: flex; gap: 6px; flex-direction: column; }

.task-admin-card {
  background: var(--card);
  border-radius: 16px;
  padding: 14px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

.task-admin-card.inactive { opacity: 0.5; }

.task-admin-info { flex: 1; min-width: 0; }
.task-admin-name { font-weight: 600; }
.task-admin-meta {
  font-size: 12px;
  color: var(--text-soft);
  margin-top: 2px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.add-task-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  font-size: 32px;
  font-weight: 400;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  z-index: 5;
}

.settings-card {
  background: var(--card);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.settings-card h3 { margin-bottom: 12px; font-size: 16px; }

.user-pin-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.user-pin-row:last-child { border-bottom: none; }

/* ==================== MODAL ==================== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 0;
}

@media (min-width: 640px) {
  .modal { align-items: center; padding: 16px; }
}

.modal-card {
  background: var(--card);
  border-radius: 24px 24px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  animation: modal-slide 0.25s;
}

@media (min-width: 640px) {
  .modal-card { border-radius: 20px; }
}

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

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

.modal-header h2 { font-size: 18px; font-weight: 700; }

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-body label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-soft);
  margin-top: 6px;
}

.modal-body input, .modal-body select {
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: 12px;
  font-size: 15px;
  font-family: inherit;
  background: var(--bg-soft);
}

.modal-body input:focus, .modal-body select:focus {
  outline: none;
  border-color: var(--primary);
}

.checkbox-row {
  display: flex !important;
  align-items: center;
  gap: 8px;
  margin-top: 8px !important;
  font-size: 14px !important;
  color: var(--text) !important;
}

.checkbox-row input { width: auto; margin: 0; }

.modal-footer {
  display: flex;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}

.modal-footer .btn-danger { margin-right: auto; }

.weekday-picker {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}

.wd-btn {
  flex: 1;
  background: var(--bg-soft);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 10px 0;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}

.wd-btn.selected {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.btn {
  background: var(--bg-soft);
  border: 2px solid var(--border);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

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

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
}

.btn-success {
  background: var(--success);
  border-color: var(--success);
  color: white;
}

.btn-large {
  padding: 14px 20px;
  font-size: 16px;
  width: 100%;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 13px;
}

/* ==================== PHOTO MODAL ==================== */
.photo-modal-card { max-width: 440px; }

.photo-prompt {
  background: var(--bg-soft);
  padding: 12px;
  border-radius: 12px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 12px;
}

.photo-preview {
  width: 100%;
  aspect-ratio: 4/3;
  background: var(--bg);
  border-radius: 12px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: var(--text-soft);
  font-size: 14px;
}

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

.photo-status {
  text-align: center;
  padding: 12px;
  color: var(--text-soft);
  font-size: 14px;
  min-height: 20px;
}

.photo-status.success { color: var(--success); font-weight: 600; }
.photo-status.error { color: var(--danger); font-weight: 600; }
.photo-status.loading { color: var(--primary); }

/* ==================== TOAST ==================== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 12px 20px;
  border-radius: 100px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  animation: toast-in 0.25s;
}

@keyframes toast-in {
  from { transform: translate(-50%, 30px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}
