/* UI enhancements: hero, progress, streak, confetti canvas, micro-reward */
.hero-card{
  margin: 8px 12px;
  background: linear-gradient(135deg, rgba(84,160,255,0.08), rgba(94,230,140,0.06));
  border-radius: 10px;
  padding: 8px 12px;
  box-shadow: 0 2px 8px rgba(50,60,80,0.06);
  border: 1px solid rgba(0,0,0,0.04);
}
.hero-inner{display:flex;align-items:center;justify-content:space-between;gap:8px;flex-wrap:wrap}
.hero-left{display:flex;align-items:center;gap:8px;flex:1;min-width:0}
.progress-label{font-size:13px;color:var(--text-secondary);font-weight:600;white-space:nowrap}
.progress-bar-wrap{flex:1;min-width:60px;max-width:120px;height:6px;background:var(--border-color);border-radius:999px;overflow:hidden}
.progress-bar{height:100%;background:linear-gradient(90deg,var(--primary-color),var(--secondary-color));border-radius:999px;transition:width 500ms ease}
.progress-stats{font-size:12px;color:var(--text-secondary);white-space:nowrap}
.hero-right{display:flex;align-items:center;gap:6px}
.streak{font-weight:700;font-size:13px;color:var(--primary-color);background:var(--card-bg);padding:4px 8px;border-radius:999px;white-space:nowrap;display:flex;align-items:center;gap:4px;border:1px solid var(--border-color);box-shadow:0 1px 3px rgba(0,0,0,0.08)}
.reward-history-btn{background:none;border:none;cursor:pointer;font-size:14px;padding:2px 4px;border-radius:6px;transition:background 150ms;color:inherit}
.reward-history-btn:hover{background:rgba(0,0,0,0.05)}

/* Confetti canvas covers body but pointer-events none */
#confettiCanvas{position:fixed;left:0;top:0;right:0;bottom:0;pointer-events:none;z-index:2000}

/* Micro reward popup */
.reward-burst{position:fixed;right:24px;top:80px;background:linear-gradient(135deg,var(--secondary-color),#ffd66b);padding:8px 12px;border-radius:999px;color:#082;box-shadow:0 6px 20px rgba(0,0,0,0.12);transform:translateY(-10px);opacity:0;transition:all 420ms ease;font-weight:600;z-index:2001}
.reward-burst.show{opacity:1;transform:translateY(0)}

/* Small toast */
.quick-toast{position:fixed;left:50%;transform:translateX(-50%) translateY(20px);bottom:24px;background:linear-gradient(90deg,var(--primary-color),var(--secondary-color));color:white;padding:10px 18px;border-radius:999px;box-shadow:0 8px 30px rgba(0,0,0,0.18);opacity:0;transition:all 300ms;font-weight:500;z-index:2001}
.quick-toast.show{opacity:1;transform:translateX(-50%) translateY(0)}

/* Reward History Panel */
.reward-history-panel{position:fixed;right:12px;top:70px;width:220px;max-height:260px;background:var(--card-bg);border-radius:10px;box-shadow:0 6px 24px rgba(0,0,0,0.12);display:none;z-index:999;overflow:hidden;border:1px solid var(--border-color)}
.reward-history-panel.show{display:block}
.reward-history-header{padding:8px 12px;font-weight:600;font-size:13px;border-bottom:1px solid var(--border-color);display:flex;justify-content:space-between;align-items:center}
.reward-history-close{background:none;border:none;cursor:pointer;font-size:16px}
.reward-history-list{max-height:200px;overflow-y:auto;padding:6px}
.reward-history-item{display:flex;align-items:center;gap:6px;padding:5px 6px;border-radius:5px;margin-bottom:3px;background:rgba(0,0,0,0.02);font-size:12px}
.reward-history-empty{padding:20px;text-align:center;color:var(--text-secondary);font-size:12px}

/* ===== OFFLINE BANNER ===== */
.offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: linear-gradient(90deg, #ff6b6b, #ee5a5a);
  color: white;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  z-index: 10000;
  transform: translateY(-100%);
  transition: transform 0.3s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.offline-banner.show {
  transform: translateY(0);
}

.offline-icon {
  font-size: 16px;
  animation: pulse-offline 2s infinite;
}

@keyframes pulse-offline {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.offline-text {
  text-align: center;
}

/* Adjust container when offline banner is visible */
body:has(.offline-banner.show) .container {
  padding-top: 44px;
}

body:has(.offline-banner.show) header {
  top: 44px;
}

/* ===== INSTALL BANNER ===== */
.install-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(135deg, #3478c8, #2860a0);
  color: white;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 9999;
  transform: translateY(100%);
  transition: transform 0.3s ease;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.15);
  /* Safe area for devices with home indicator */
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
}

.install-banner.show {
  transform: translateY(0);
}

.install-content {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.install-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.install-text {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.3;
}

.install-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.install-btn {
  background: white;
  color: #3478c8;
  border: none;
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.install-btn:hover {
  background: #f0f4f8;
  transform: scale(1.02);
}

.install-btn:active {
  transform: scale(0.98);
}

.install-dismiss {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.8);
  font-size: 24px;
  padding: 4px 8px;
  cursor: pointer;
  transition: color 0.2s ease;
  line-height: 1;
}

.install-dismiss:hover {
  color: white;
}

/* iOS-specific install banner adjustments */
.install-banner.ios .install-text {
  font-size: 13px;
}

/* ===== MOBILE PWA ENHANCEMENTS ===== */

/* Safe area insets for notched devices */
@supports (padding: env(safe-area-inset-top)) {
  header {
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
  }
  
  .container {
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  }
  
  .sync-status {
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  }
  
  .quick-toast {
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  }
}

/* Improved touch targets for mobile */
@media (max-width: 600px) {
  /* Larger touch targets */
  .task-checkbox {
    width: 24px;
    height: 24px;
    min-width: 24px;
  }
  
  .btn-skip,
  .btn-complete-skipped {
    min-height: 36px;
    padding: 8px 14px;
  }
  
  .tab-btn {
    min-height: 36px;
    padding: 8px 12px;
  }
  
  .menu-btn {
    min-width: 44px;
    min-height: 44px;
  }
  
  /* Prevent text selection on interactive elements */
  .task-card,
  .tab-btn,
  .menu-btn,
  .btn-skip,
  .btn-complete-skipped {
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
  
  /* Better scrolling performance */
  .tasks-container,
  .optional-section,
  .modal-content {
    -webkit-overflow-scrolling: touch;
  }
  
  /* Prevent pull-to-refresh when scrolling up */
  body {
    overscroll-behavior-y: contain;
  }
  
  /* Card spacing adjustments */
  .task-card {
    margin-bottom: 10px;
    padding: 14px;
  }
  
  /* Filter tabs scroll hint */
  .filter-tabs {
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
  }
  
  .tab-btn {
    scroll-snap-align: start;
  }
  
  /* Better bottom spacing when install banner might be visible */
  .container {
    padding-bottom: 100px;
  }
}

/* Standalone mode specific styles */
@media (display-mode: standalone) {
  /* Hide browser-specific elements */
  .install-banner {
    display: none !important;
  }
  
  /* Slightly different header styling in standalone */
  header {
    padding-top: calc(16px + env(safe-area-inset-top, 0px));
  }
}

/* Dark mode for offline and install banners */
@media (prefers-color-scheme: dark) {
  .offline-banner {
    background: linear-gradient(90deg, #dc2626, #b91c1c);
  }
  
  .install-banner {
    background: linear-gradient(135deg, #1e40af, #1e3a8a);
  }
  
  .install-btn {
    background: #e5e7eb;
    color: #1e3a8a;
  }
  
  .install-btn:hover {
    background: #f3f4f6;
  }
  
  .reward-history-panel {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  }
  
  .reward-history-header {
    border-bottom-color: var(--border-color);
  }
  
  .reward-history-item {
    background: rgba(255,255,255,0.03);
  }
  
  /* Hero card dark mode */
  .hero-card {
    background: linear-gradient(135deg, rgba(96,165,250,0.08), rgba(74,222,128,0.06));
    border-color: var(--border-color);
    box-shadow: 0 2px 12px rgba(0,0,0,0.2);
  }
  
  .streak {
    background: var(--surface-elevated, #1f1f23);
    border-color: var(--border-color);
    color: var(--primary-color);
  }
  
  .progress-bar-wrap {
    background: rgba(255,255,255,0.08);
  }
  
  .reward-history-btn:hover {
    background: rgba(255,255,255,0.08);
  }
}

/* Desktop enhancements */
@media (min-width:601px){
  .hero-card{margin:12px auto;max-width:740px;padding:10px 16px}
  .hero-inner{gap:16px}
  .progress-bar-wrap{max-width:180px}
  
  /* Center banners on desktop */
  .offline-banner,
  .install-banner {
    max-width: 768px;
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    border-radius: 0 0 12px 12px;
  }
  
  .offline-banner.show {
    transform: translateX(-50%) translateY(0);
  }
  
  .install-banner {
    transform: translateX(-50%) translateY(100%);
    border-radius: 12px 12px 0 0;
  }
  
  .install-banner.show {
    transform: translateX(-50%) translateY(0);
  }
}

@media (max-width:600px){
  .hero-inner{flex-wrap:nowrap}
}

/* ===== NOTIFICATION SETTINGS MODAL ===== */
.notification-settings-modal {
  max-width: 400px;
}

.notification-settings-modal h3 {
  margin-bottom: 16px;
  font-size: 18px;
}

.notification-permission-status {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 16px;
  text-align: center;
}

.notification-permission-status.granted {
  background: rgba(74, 222, 128, 0.12);
  color: #15803d;
}

.notification-permission-status.pending {
  background: rgba(251, 191, 36, 0.12);
  color: #b45309;
}

.notification-setting-group {
  margin-bottom: 16px;
}

.notification-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
}

.notification-toggle input[type="checkbox"] {
  display: none;
}

.toggle-slider {
  width: 44px;
  height: 24px;
  background: #ccc;
  border-radius: 24px;
  position: relative;
  transition: background 0.3s ease;
  flex-shrink: 0;
}

.toggle-slider::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: transform 0.3s ease;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.notification-toggle input:checked + .toggle-slider {
  background: var(--primary-color);
}

.notification-toggle input:checked + .toggle-slider::after {
  transform: translateX(20px);
}

.notification-toggle input:disabled + .toggle-slider {
  opacity: 0.5;
  cursor: not-allowed;
}

.toggle-label {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
}

.notification-toggle.small .toggle-slider {
  width: 36px;
  height: 20px;
}

.notification-toggle.small .toggle-slider::after {
  width: 16px;
  height: 16px;
}

.notification-toggle.small input:checked + .toggle-slider::after {
  transform: translateX(16px);
}

.notification-toggle.small .toggle-label {
  font-size: 14px;
}

.notification-times {
  background: var(--bg-color);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 16px;
  transition: opacity 0.3s ease;
  border: 1px solid var(--border-color);
}

.notification-times.disabled {
  opacity: 0.5;
  pointer-events: none;
}

.notification-time-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
}

.notification-time-row:first-child {
  padding-top: 0;
}

.notification-time-row:last-child {
  padding-bottom: 0;
}

.notification-time-row:not(:last-child) {
  border-bottom: 1px solid rgba(0,0,0,0.08);
}

.time-input {
  padding: 8px 12px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  background: var(--card-bg);
  color: var(--text-primary);
  width: 110px;
  text-align: center;
}

.time-input:focus {
  outline: none;
  border-color: var(--primary-color);
}

/* 12-Hour Time Picker */
.time-picker-12h {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--card-bg);
  border: 2px solid var(--border-color);
  border-radius: 8px;
  padding: 4px 8px;
}

.time-select {
  border: none;
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  padding: 4px 2px;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  text-align: center;
}

.time-select:focus {
  outline: none;
}

.time-select option {
  background: var(--card-bg);
  color: var(--text-primary);
}

#morningHour, #eveningHour {
  width: 32px;
}

#morningMinute, #eveningMinute {
  width: 36px;
}

.time-select.period {
  width: 42px;
  font-weight: 700;
  color: var(--primary-color);
}

.time-colon {
  font-weight: 700;
  color: var(--text-secondary);
}

.notification-info {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 1.5;
  padding: 10px;
  background: rgba(var(--primary-color-rgb, 96, 165, 250), 0.08);
  border-radius: 8px;
  border: 1px solid rgba(var(--primary-color-rgb, 96, 165, 250), 0.15);
}

/* Permission request button */
.notification-settings-modal .btn-primary#requestPermissionBtn {
  margin-bottom: 12px;
  width: 100%;
  padding: 12px 16px;
  border-radius: 8px;
}

/* Modal actions layout fix */
.notification-settings-modal .modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.notification-settings-modal .modal-actions .btn-secondary,
.notification-settings-modal .modal-actions .btn-primary {
  flex: 1;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
}

.notification-settings-modal .modal-actions .btn-secondary {
  background: var(--bg-color);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.notification-settings-modal .modal-actions .btn-secondary:hover {
  background: var(--card-bg);
}

.notification-settings-modal .modal-actions .btn-secondary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.notification-settings-modal .modal-actions .btn-primary {
  background: var(--primary-color);
  color: white;
}

.notification-settings-modal .modal-actions .btn-primary:hover {
  background: #2860a0;
}

/* Dark mode for notification settings */
@media (prefers-color-scheme: dark) {
  .notification-permission-status.granted {
    background: rgba(74, 222, 128, 0.15);
    color: var(--secondary-color);
  }
  
  .notification-permission-status.pending {
    background: rgba(251, 191, 36, 0.15);
    color: var(--warning-color);
  }
  
  .notification-times {
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border-color);
  }
  
  .notification-time-row:not(:last-child) {
    border-bottom-color: var(--border-color);
  }
  
  .toggle-slider {
    background: var(--border-color);
  }
  
  .notification-info {
    background: rgba(96, 165, 250, 0.1);
    border: 1px solid rgba(96, 165, 250, 0.2);
  }
  
  .notification-settings-modal .modal-actions .btn-secondary {
    background: var(--surface-elevated, #1f1f23);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
  }
  
  .notification-settings-modal .modal-actions .btn-secondary:hover {
    background: var(--surface-hover, #27272a);
  }
  
  .time-picker-12h {
    background: var(--surface-elevated, #1f1f23);
    border-color: var(--border-color);
  }
  
  .time-select {
    color: var(--text-primary);
  }
  
  .time-select option {
    background: var(--card-bg);
    color: var(--text-primary);
  }
  
  .time-select.period {
    color: var(--primary-color);
  }
}
