/* ===== DareWorthy — Habitica-inspired Goal Tracker ===== */
:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-card: #1f2940;
  --bg-card-hover: #263350;
  --bg-input: #162040;
  --bg-nav: #0f1629;
  --text-primary: #e8e8f0;
  --text-secondary: #9ca3b8;
  --text-muted: #636b82;
  --border-color: #2a3550;
  --accent-purple: #6C3AED;
  --accent-purple-light: #8B5CF6;
  --accent-pink: #E91E8C;
  --accent-gold: #F59E0B;
  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;

  --cat-marriage: #E91E8C;
  --cat-kids: #FF6B35;
  --cat-health: #4CAF50;
  --cat-faith: #7C3AED;
  --cat-finances: #0D9488;
  --cat-home: #F59E0B;
  --cat-growth: #3B82F6;
  --cat-social: #FF6B6B;
  --cat-hobbies: #EAB308;
  --cat-travel: #0EA5E9;
  --cat-volunteering: #6B9E6B;
  --cat-general: #8B8FA3;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

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

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }

/* ===== Login Screen ===== */
.login-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px;
  padding-top: calc(24px + var(--safe-top));
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #1a1a2e 100%);
}

.login-logo { width: 100px; height: 100px; margin-bottom: 16px; border-radius: 24px; box-shadow: 0 8px 32px rgba(108, 58, 237, 0.3); }

.login-title {
  font-size: 28px; font-weight: 800;
  background: linear-gradient(135deg, var(--accent-purple-light), var(--accent-pink));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
  margin-bottom: 4px;
}

.login-subtitle { color: var(--text-secondary); font-size: 14px; margin-bottom: 32px; }

.login-card {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: 20px; padding: 28px 24px; width: 100%; max-width: 360px;
}

.login-card h2 { font-size: 18px; margin-bottom: 20px; text-align: center; }
.user-select-btns { display: flex; gap: 10px; margin-bottom: 16px; }

.user-select-btn {
  flex: 1; padding: 14px; border: 2px solid var(--border-color); border-radius: 14px;
  background: var(--bg-input); color: var(--text-primary); font-size: 16px; font-weight: 600;
  cursor: pointer; transition: all 0.2s; text-align: center;
}

.user-select-btn:hover, .user-select-btn.active { border-color: var(--accent-purple); background: rgba(108, 58, 237, 0.15); }

.user-select-btn .avatar-circle {
  width: 44px; height: 44px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-pink));
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 800; color: white; margin: 0 auto 6px;
}

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block; font-size: 13px; font-weight: 600; color: var(--text-secondary);
  margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px;
}

.form-input {
  width: 100%; padding: 14px 16px; border: 2px solid var(--border-color); border-radius: 12px;
  background: var(--bg-input); color: var(--text-primary); font-size: 16px;
  transition: border-color 0.2s; -webkit-appearance: none;
}
.form-input:focus { outline: none; border-color: var(--accent-purple); }
.form-input::placeholder { color: var(--text-muted); }
.form-input.input-error { border-color: var(--danger); animation: shake 0.4s ease; }

@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%,60% { transform: translateX(-4px); }
  40%,80% { transform: translateX(4px); }
}

.field-hint {
  font-size: 12px; color: #FCA5A5; margin-top: 4px; display: none;
  background: rgba(239,68,68,0.1); padding: 6px 10px; border-radius: 8px;
}
.field-hint.show { display: block; }

select.form-input { cursor: pointer; }
textarea.form-input { resize: vertical; min-height: 80px; font-family: inherit; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 24px; border: none; border-radius: 12px; font-size: 16px; font-weight: 700;
  cursor: pointer; transition: all 0.2s; width: 100%; min-height: 48px;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-purple-light));
  color: white; box-shadow: 0 4px 16px rgba(108, 58, 237, 0.3);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(108, 58, 237, 0.4); }
.btn-primary:active { transform: translateY(0); }
.btn-success { background: linear-gradient(135deg, #059669, var(--success)); color: white; }
.btn-danger { background: linear-gradient(135deg, #DC2626, var(--danger)); color: white; }
.btn-outline { background: transparent; border: 2px solid var(--border-color); color: var(--text-primary); }
.btn-outline:hover { border-color: var(--accent-purple); }
.btn-sm { padding: 8px 16px; font-size: 13px; min-height: 36px; width: auto; border-radius: 10px; }

.error-msg { background: rgba(239,68,68,0.15); color: #FCA5A5; padding: 10px 14px; border-radius: 10px; font-size: 14px; margin-bottom: 12px; display: none; }
.error-msg.show { display: block; }

/* ===== App Shell ===== */
.app-container { display: none; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.app-container.active { display: flex; }

/* ===== Top Header ===== */
.app-header {
  padding: calc(12px + var(--safe-top)) 16px 10px; background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color); position: sticky; top: 0; z-index: 100;
}

.header-greeting { font-size: 20px; font-weight: 800; margin-bottom: 10px; }
.header-greeting .wave { display: inline-block; animation: wave 1.5s ease-in-out infinite; transform-origin: 70% 70%; }
@keyframes wave { 0%,100%{transform:rotate(0)} 25%{transform:rotate(20deg)} 50%{transform:rotate(-10deg)} 75%{transform:rotate(15deg)} }

/* ===== View Pills (merged nav + stats) ===== */
.view-pills {
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.view-pills::-webkit-scrollbar { display: none; }

.view-pill {
  display: flex; align-items: center; gap: 5px;
  padding: 7px 14px; border-radius: 20px; font-size: 13px; font-weight: 700;
  cursor: pointer; white-space: nowrap; transition: all 0.2s;
  border: 2px solid var(--border-color); background: transparent;
  color: var(--text-secondary); -webkit-tap-highlight-color: transparent;
}
.view-pill.active { background: var(--accent-purple); border-color: var(--accent-purple); color: white; }
.view-pill .vp-icon { font-size: 15px; }
.view-pill .vp-count {
  font-weight: 800; color: var(--accent-gold); font-size: 13px;
  min-width: 16px; text-align: center;
}
.view-pill.active .vp-count { color: #FCD34D; }
.view-pill .vp-label { }

/* ===== Main Content ===== */
.main-content {
  flex: 1; padding: 16px 16px calc(20px + var(--safe-bottom));
  overflow-y: auto;
}

/* ===== Upcoming Section ===== */
.section-title {
  font-size: 14px; font-weight: 700; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 1px; margin-bottom: 12px;
  display: flex; align-items: center; gap: 8px;
}
.section-title .icon { font-size: 16px; }

/* ===== Goal Cards ===== */
.goal-list { display: flex; flex-direction: column; gap: 10px; }

/* Swipe wrapper */
.swipe-wrapper {
  position: relative; overflow: hidden; border-radius: 16px;
}

.swipe-actions {
  position: absolute; right: 0; top: 0; bottom: 0;
  display: flex; align-items: stretch;
  z-index: 1;
}

.swipe-action {
  display: flex; align-items: center; justify-content: center;
  width: 72px; color: white; font-size: 12px; font-weight: 700;
  flex-direction: column; gap: 3px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.swipe-action-complete { background: var(--success); }
.swipe-action-status { background: var(--accent-purple); }
.swipe-action-restore { background: #3B82F6; }
.swipe-action-remove { background: var(--danger); }
.swipe-action .swipe-icon { font-size: 20px; }

.goal-card {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: 16px; padding: 16px; cursor: pointer;
  transition: transform 0.2s ease; position: relative; overflow: hidden;
  -webkit-tap-highlight-color: transparent; z-index: 2;
  will-change: transform;
}
.goal-card.swiping { transition: none; }

.goal-card::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0;
  width: 4px; border-radius: 4px 0 0 4px;
}

/* Category color strips */
.goal-card[data-category="Relationship"]::before { background: var(--cat-marriage); }
.goal-card[data-category="Kids & Family"]::before { background: var(--cat-kids); }
.goal-card[data-category="Health & Fitness"]::before { background: var(--cat-health); }
.goal-card[data-category="Faith & Spiritual"]::before { background: var(--cat-faith); }
.goal-card[data-category="Finances"]::before { background: var(--cat-finances); }
.goal-card[data-category="Home & Projects"]::before { background: var(--cat-home); }
.goal-card[data-category="Personal Growth"]::before { background: var(--cat-growth); }
.goal-card[data-category="Social & Friendships"]::before { background: var(--cat-social); }
.goal-card[data-category="Fun & Hobbies"]::before { background: var(--cat-hobbies); }
.goal-card[data-category="Travel"]::before { background: var(--cat-travel); }
.goal-card[data-category="Volunteering"]::before { background: var(--cat-volunteering); }
.goal-card[data-category="General"]::before { background: var(--cat-general); }

.goal-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.goal-title { font-size: 16px; font-weight: 700; line-height: 1.3; flex: 1; }
.goal-priority { font-size: 11px; font-weight: 800; padding: 3px 8px; border-radius: 6px; text-transform: uppercase; letter-spacing: 0.5px; flex-shrink: 0; }
.goal-priority.high { background: rgba(239, 68, 68, 0.2); color: #FCA5A5; }
.goal-priority.medium { background: rgba(245, 158, 11, 0.2); color: #FCD34D; }
.goal-priority.low { background: rgba(16, 185, 129, 0.2); color: #6EE7B7; }

.goal-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.goal-category-chip { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 8px; display: inline-flex; align-items: center; gap: 4px; }
.goal-date { font-size: 12px; color: var(--text-secondary); display: flex; align-items: center; gap: 4px; }
.goal-date.urgent { color: #FCA5A5; font-weight: 600; }
.goal-owner-badge { font-size: 12px; color: var(--text-muted); margin-left: auto; }
.goal-status-badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 6px; text-transform: uppercase; }
.goal-status-badge.completed { background: rgba(16, 185, 129, 0.2); color: #6EE7B7; }
.goal-status-badge.paused { background: rgba(107, 114, 128, 0.3); color: #9CA3AF; }
.goal-status-badge.active { background: rgba(108, 58, 237, 0.2); color: #C4B5FD; }

.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; }

/* ===== Floating Add Button (FAB) ===== */
.fab {
  position: fixed; bottom: calc(20px + var(--safe-bottom)); right: 20px;
  width: 56px; height: 56px; border-radius: 16px; border: none;
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-pink));
  color: white; font-size: 28px; font-weight: 400; cursor: pointer;
  box-shadow: 0 6px 24px rgba(108, 58, 237, 0.5);
  z-index: 150; display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent; transition: transform 0.2s;
}
.fab:active { transform: scale(0.92); }

/* ===== Goal Detail Modal ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px); z-index: 300; display: none;
  align-items: center; justify-content: center; padding: 24px 16px;
}
.modal-overlay.active { display: flex; }

.modal-sheet {
  background: var(--bg-secondary); border-radius: 20px;
  width: 100%; max-width: 500px; max-height: 85vh; max-height: 85dvh;
  overflow-y: auto; padding: 8px 20px 32px; animation: modalFadeIn 0.25s ease;
}

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

.modal-handle { width: 36px; height: 4px; background: var(--border-color); border-radius: 4px; margin: 8px auto 20px; }
.modal-title { font-size: 22px; font-weight: 800; margin-bottom: 16px; }
.detail-section { margin-bottom: 16px; }
.detail-label { font-size: 12px; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
.detail-value { font-size: 15px; color: var(--text-primary); line-height: 1.5; }
.detail-actions { display: flex; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
.detail-actions .btn { flex: 1; min-width: 100px; }

.history-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.history-item { display: flex; gap: 10px; padding: 10px; background: var(--bg-card); border-radius: 10px; font-size: 13px; }
.history-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent-purple); margin-top: 5px; flex-shrink: 0; }
.history-text { color: var(--text-secondary); line-height: 1.4; }
.history-text strong { color: var(--text-primary); }
.history-time { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ===== Add/Edit Form ===== */
.form-screen {
  display: none; flex-direction: column;
  position: fixed; inset: 0; z-index: 500; background: var(--bg-primary);
}
.form-screen.active { display: flex; }

.form-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(16px + var(--safe-top)) 20px 16px; border-bottom: 1px solid var(--border-color); background: var(--bg-secondary);
}
.form-header h2 { font-size: 18px; font-weight: 700; }

.form-body { flex: 1; padding: 20px; overflow-y: auto; padding-bottom: 20px; }

.category-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.category-chip {
  padding: 8px 14px; border-radius: 10px; font-size: 13px; font-weight: 600;
  cursor: pointer; border: 2px solid transparent; transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.category-chip:hover { opacity: 0.9; }
.category-chip.selected { border-color: white; box-shadow: 0 0 12px rgba(255,255,255,0.2); }

.owner-options { display: flex; gap: 8px; }
.owner-option {
  flex: 1; padding: 12px; border: 2px solid var(--border-color); border-radius: 12px;
  text-align: center; cursor: pointer; font-size: 14px; font-weight: 600;
  background: var(--bg-input); color: var(--text-secondary); transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.owner-option.selected { border-color: var(--accent-purple); background: rgba(108, 58, 237, 0.15); color: var(--text-primary); }
.owner-option .owner-emoji { font-size: 24px; display: block; margin-bottom: 4px; }

.priority-options { display: flex; gap: 8px; }
.priority-option {
  flex: 1; padding: 10px; border: 2px solid var(--border-color); border-radius: 10px;
  text-align: center; cursor: pointer; font-size: 13px; font-weight: 700;
  background: var(--bg-input); color: var(--text-secondary); transition: all 0.2s;
  text-transform: uppercase; -webkit-tap-highlight-color: transparent;
}
.priority-option.selected.high { border-color: var(--danger); background: rgba(239,68,68,0.15); color: #FCA5A5; }
.priority-option.selected.medium { border-color: var(--warning); background: rgba(245,158,11,0.15); color: #FCD34D; }
.priority-option.selected.low { border-color: var(--success); background: rgba(16,185,129,0.15); color: #6EE7B7; }

.form-footer {
  padding: 16px 20px; padding-bottom: calc(16px + var(--safe-bottom));
  background: var(--bg-secondary); border-top: 1px solid var(--border-color); flex-shrink: 0;
}

/* ===== Filter bar ===== */
.filter-bar { display: flex; gap: 8px; margin-bottom: 12px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.filter-bar::-webkit-scrollbar { display: none; }
.filter-select {
  padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border-color);
  background: var(--bg-card); color: var(--text-secondary); font-size: 12px;
  font-weight: 600; cursor: pointer; white-space: nowrap; -webkit-appearance: none;
}

/* ===== Confetti ===== */
.confetti-container { position: fixed; inset: 0; pointer-events: none; z-index: 999; }
.confetti-piece { position: absolute; width: 10px; height: 10px; top: -10px; animation: confettiFall 2s ease-in forwards; }
@keyframes confettiFall { 0% { transform: translateY(0) rotate(0deg); opacity: 1; } 100% { transform: translateY(100vh) rotate(720deg); opacity: 0; } }

/* ===== Status change modal ===== */
.status-modal-content { padding: 8px 0; }
.status-option {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: 12px;
  cursor: pointer; transition: background 0.2s; -webkit-tap-highlight-color: transparent;
}
.status-option:hover { background: var(--bg-card); }
.status-option .status-icon { width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 20px; }
.status-option .status-info { flex: 1; }
.status-option .status-name { font-weight: 700; font-size: 15px; }
.status-option .status-desc { font-size: 12px; color: var(--text-muted); }

/* ===== Toast ===== */
.toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%) translateY(-80px);
  background: var(--bg-card); border: 1px solid var(--border-color);
  color: var(--text-primary); padding: 12px 20px; border-radius: 14px;
  font-size: 14px; font-weight: 600; z-index: 600;
  transition: transform 0.3s ease; white-space: nowrap;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ===== Group headers ===== */
.group-header {
  font-size: 13px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 1px; padding: 16px 0 8px;
  display: flex; align-items: center; gap: 8px;
}
.group-header .group-dot { width: 8px; height: 8px; border-radius: 50%; }

/* ===== Responsive ===== */
@media (min-width: 768px) {
  .main-content { max-width: 600px; margin: 0 auto; padding-left: 24px; padding-right: 24px; }
  .app-header { display: flex; align-items: center; justify-content: center; }
  .app-header > div { max-width: 600px; width: 100%; }
  .fab { right: calc(50% - 300px + 20px); }
}

/* ===== Date input dark mode ===== */
input[type="date"].form-input { color-scheme: dark; }
input[type="date"].form-input::-webkit-calendar-picker-indicator { filter: invert(0.7); cursor: pointer; }

/* ===== Note input in status change ===== */
.note-input-group { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border-color); }
.note-input-group textarea { margin-top: 6px; }

/* ===== Swipe hint ===== */
.swipe-hint {
  text-align: center; font-size: 12px; color: var(--text-muted);
  padding: 8px 0 4px; opacity: 0.7;
}
