/* CSS Variables */
:root {
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-dark: #4f46e5;
    --success: #22c55e;
    --success-light: #86efac;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg: #f8fafc;
    --bg-card: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* Navigation */
.nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo {
    font-size: 24px;
}

.brand-name {
    font-weight: 700;
    font-size: 18px;
    color: var(--primary);
}

.nav-links {
    display: flex;
    gap: 8px;
}

.nav-btn {
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
}

.nav-btn:hover {
    background: var(--bg);
    color: var(--text-primary);
}

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

.points-display {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border-radius: 20px;
    font-weight: 600;
    color: #92400e;
}

.points-icon {
    font-size: 14px;
}

.points-value {
    font-size: 16px;
}

.points-label {
    font-size: 12px;
    opacity: 0.8;
}

/* Main Content */
.main-content {
    padding: 84px 20px 40px;
    max-width: 600px;
    margin: 0 auto;
}

/* Pages */
.page {
    display: none;
    animation: fadeIn 0.3s ease;
}

.page.active {
    display: block;
}

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

/* Date Header */
.date-header {
    text-align: center;
    margin-bottom: 24px;
}

.date-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.date-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
}

/* Progress Card */
.progress-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}

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

.progress-label {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

.progress-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
}

.progress-bar {
    height: 10px;
    background: var(--border);
    border-radius: 5px;
    overflow: hidden;
    margin-bottom: 10px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary) 0%, var(--primary-light) 100%);
    border-radius: 5px;
    transition: width 0.5s ease;
    width: 0%;
}

.progress-hint {
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
}

/* Add Habit Section */
.add-habit-section {
    margin-bottom: 24px;
}

.add-habit-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px;
    background: var(--bg-card);
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
    color: var(--text-secondary);
}

.add-habit-toggle:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(99, 102, 241, 0.05);
}

.toggle-icon {
    font-size: 20px;
    font-weight: 300;
}

.add-habit-form {
    display: none;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow);
}

.add-habit-form.active {
    display: block;
    animation: slideDown 0.3s ease;
}

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

.form-group {
    margin-bottom: 16px;
}

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

.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    transition: border-color 0.2s;
    font-family: inherit;
}

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

.suggested-habits {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.suggested-btn {
    padding: 8px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

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

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

.btn-primary, .btn-secondary {
    flex: 1;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    border: none;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--bg);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

/* Habits Section */
.habits-section {
    margin-bottom: 40px;
}

.section-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.habit-count {
    color: var(--text-muted);
    font-weight: 400;
}

.habits-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

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

.habit-item:hover {
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}

.habit-checkbox {
    width: 28px;
    height: 28px;
    border: 3px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.habit-checkbox:hover {
    border-color: var(--primary);
}

.habit-checkbox.checked {
    background: var(--success);
    border-color: var(--success);
}

.habit-checkbox.checked::after {
    content: '✓';
    color: white;
    font-size: 16px;
    font-weight: 700;
}

.habit-info {
    flex: 1;
}

.habit-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.habit-name.completed {
    text-decoration: line-through;
    color: var(--text-muted);
}

.habit-streak {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
}

.habit-streak.active {
    color: var(--warning);
}

.habit-actions {
    display: flex;
    gap: 8px;
}

.habit-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--bg);
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: var(--text-muted);
}

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

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 2px dashed var(--border);
}

.empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.empty-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.empty-desc {
    font-size: 14px;
    color: var(--text-secondary);
}

/* Dashboard */
.dashboard-header {
    text-align: center;
    margin-bottom: 24px;
}

.dashboard-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 4px;
}

.dashboard-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
}

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

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

.stat-icon {
    font-size: 28px;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 4px;
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Dashboard Sections */
.dashboard-section {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}

/* Weekly Calendar */
.weekly-calendar {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-top: 16px;
}

.week-day {
    flex: 1;
    text-align: center;
}

.week-day-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.week-day-box {
    aspect-ratio: 1;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
}

.week-day-box.empty {
    background: var(--bg);
    color: var(--text-muted);
}

.week-day-box.partial {
    background: #dbeafe;
    color: #1e40af;
}

.week-day-box.good {
    background: #bbf7d0;
    color: #166534;
}

.week-day-box.excellent {
    background: var(--success);
    color: white;
}

.week-day-box.today {
    box-shadow: 0 0 0 2px var(--primary);
}

/* Monthly Heatmap */
.monthly-heatmap {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin-top: 16px;
}

.heatmap-day {
    aspect-ratio: 1;
    border-radius: 4px;
    background: var(--bg);
}

.heatmap-day.level-1 { background: #dbeafe; }
.heatmap-day.level-2 { background: #93c5fd; }
.heatmap-day.level-3 { background: #3b82f6; }
.heatmap-day.level-4 { background: #1d4ed8; }

.heatmap-legend {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 12px;
    font-size: 12px;
    color: var(--text-muted);
}

.legend-boxes {
    display: flex;
    gap: 4px;
}

.legend-box {
    width: 16px;
    height: 16px;
    border-radius: 3px;
}

.legend-box.level-0 { background: var(--bg); }
.legend-box.level-1 { background: #dbeafe; }
.legend-box.level-2 { background: #93c5fd; }
.legend-box.level-3 { background: #3b82f6; }
.legend-box.level-4 { background: #1d4ed8; }

/* Habit Stats List */
.habit-stats-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 16px;
}

.habit-stat-item {
    display: flex;
    align-items: center;
    gap: 12px;
}

.habit-stat-info {
    flex: 1;
}

.habit-stat-name {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
}

.habit-stat-bar {
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.habit-stat-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary) 0%, var(--success) 100%);
    border-radius: 4px;
    transition: width 0.5s ease;
}

.habit-stat-rate {
    font-size: 14px;
    font-weight: 600;
    color: var(--primary);
    min-width: 45px;
    text-align: right;
}

/* Rewards Section */
.rewards-section {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
}

.reward-desc {
    font-size: 14px;
    color: #92400e;
    margin-bottom: 16px;
}

.reward-progress {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: rgba(255,255,255,0.6);
    border-radius: var(--radius);
}

.reward-week {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.reward-label {
    font-size: 12px;
    color: #92400e;
}

.reward-value {
    font-size: 20px;
    font-weight: 700;
    color: #92400e;
}

.status-badge {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.status-badge.pending {
    background: #fbbf24;
    color: #92400e;
}

.status-badge.achieved {
    background: var(--success);
    color: white;
}

/* Toast */
.toast-container {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--text-primary);
    color: white;
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 14px;
    animation: slideUp 0.3s ease;
    box-shadow: var(--shadow-lg);
}

.toast.success {
    background: var(--success);
}

.toast.points {
    background: linear-gradient(135deg, #f59e0b 0%, #fbbf24 100%);
    color: #92400e;
    font-weight: 600;
}

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

/* Responsive */
@media (max-width: 480px) {
    .nav {
        padding: 0 16px;
    }
    
    .nav-links {
        gap: 4px;
    }
    
    .nav-btn {
        padding: 6px 12px;
        font-size: 13px;
    }
    
    .brand-name {
        display: none;
    }
    
    .main-content {
        padding: 80px 16px 30px;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .weekly-calendar {
        gap: 4px;
    }
    
    .week-day-label {
        font-size: 10px;
    }
}

/* PWA Support */
@media (display-mode: standalone) {
    .nav {
        padding-top: env(safe-area-inset-top);
        height: calc(64px + env(safe-area-inset-top));
    }
    
    .main-content {
        padding-top: calc(84px + env(safe-area-inset-top));
        padding-bottom: calc(40px + env(safe-area-inset-bottom));
    }
}