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

:root {
    --bg-color: #fafafa;
    --text-color: #333;
    --border-color: #e0e0e0;
    --hover-color: #f0f0f0;
    
    --habit-study: #e74c3c;
    --habit-capoeira: #27ae60;
    --habit-reading: #3498db;
    --habit-diet: #2c3e50;
    --habit-others: #95a5a6;
    
    --dot-size: 6px;
    --dot-gap: 3px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 20px;
}

.app-container {
    width: 100%;
    max-width: 600px;
    position: relative;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding: 0 8px;
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 500;
    letter-spacing: -0.5px;
}

.nav-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-color);
    padding: 8px 16px;
    border-radius: 8px;
    transition: background-color 0.15s ease;
}

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

/* Progress Bar */
.progress-container {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    padding: 0 8px;
}

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

.progress-fill {
    height: 100%;
    background-color: var(--text-color);
    border-radius: 4px;
    transition: width 0.3s ease;
    width: 0%;
}

.progress-text {
    font-size: 0.875rem;
    font-weight: 500;
    min-width: 40px;
    text-align: right;
}

/* Calendar */
.calendar {
    background-color: white;
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    text-align: center;
    font-size: 0.75rem;
    font-weight: 500;
    color: #888;
    margin-bottom: 8px;
}

.days-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
}

.day-cell {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.15s ease;
    position: relative;
    min-height: 50px;
}

.day-cell:hover {
    background-color: var(--hover-color);
}

.day-cell.empty {
    cursor: default;
}

.day-cell.empty:hover {
    background-color: transparent;
}

.day-number {
    font-size: 0.875rem;
    font-weight: 400;
    margin-bottom: 4px;
}

.day-cell.today .day-number {
    font-weight: 600;
}

.day-cell.today {
    background-color: var(--hover-color);
}

.habit-dots {
    display: flex;
    gap: var(--dot-gap);
    flex-wrap: wrap;
    justify-content: center;
    max-width: 40px;
}

.habit-dot {
    width: var(--dot-size);
    height: var(--dot-size);
    border-radius: 50%;
    background-color: var(--border-color);
}

.habit-dot.active.study { background-color: var(--habit-study); }
.habit-dot.active.capoeira { background-color: var(--habit-capoeira); }
.habit-dot.active.reading { background-color: var(--habit-reading); }
.habit-dot.active.diet { background-color: var(--habit-diet); }
.habit-dot.active.others { background-color: var(--habit-others); }

/* Habit Popover */
.habit-popover {
    position: absolute;
    background-color: white;
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
    z-index: 100;
    min-width: 180px;
    transform: translateX(-50%);
}

.habit-popover.hidden {
    display: none;
}

.popover-date {
    font-size: 0.75rem;
    color: #888;
    margin-bottom: 12px;
    text-align: center;
}

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

.habit-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border: none;
    background: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.15s ease;
    width: 100%;
    text-align: left;
}

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

.habit-btn .habit-dot {
    width: 10px;
    height: 10px;
    flex-shrink: 0;
}

.habit-btn .habit-dot.study { background-color: var(--habit-study); }
.habit-btn .habit-dot.capoeira { background-color: var(--habit-capoeira); }
.habit-btn .habit-dot.reading { background-color: var(--habit-reading); }
.habit-btn .habit-dot.diet { background-color: var(--habit-diet); }
.habit-btn .habit-dot.others { background-color: var(--habit-others); }

.habit-btn.completed .habit-dot {
    box-shadow: 0 0 0 2px white, 0 0 0 4px currentColor;
}

.habit-btn.completed.study { color: var(--habit-study); }
.habit-btn.completed.capoeira { color: var(--habit-capoeira); }
.habit-btn.completed.reading { color: var(--habit-reading); }
.habit-btn.completed.diet { color: var(--habit-diet); }
.habit-btn.completed.others { color: var(--habit-others); }

.habit-label {
    font-size: 0.875rem;
}

/* Responsive */
@media (max-width: 480px) {
    body {
        padding: 12px;
    }
    
    .header h1 {
        font-size: 1.25rem;
    }
    
    .calendar {
        padding: 12px;
    }
    
    .day-cell {
        min-height: 44px;
    }
    
    .day-number {
        font-size: 0.75rem;
    }
    
    .habit-dot {
        width: 5px;
        height: 5px;
    }
    
    .habit-popover {
        min-width: 160px;
        padding: 10px;
    }
    
    /* Métricas responsive */
    .metrics-section {
        padding: 12px;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ============================================
/* Métricas Section
/* ============================================ */

.metrics-section {
    margin-top: 24px;
    background-color: white;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.metrics-header {
    margin-bottom: 16px;
}

.metrics-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-color);
}

/* Streak */
.streak-container {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%);
    border-radius: 12px;
    margin-bottom: 20px;
}

.streak-icon {
    font-size: 2rem;
}

.streak-info {
    display: flex;
    flex-direction: column;
}

.streak-count {
    font-size: 1.75rem;
    font-weight: 700;
    color: #e65100;
    line-height: 1;
}

.streak-label {
    font-size: 0.75rem;
    color: #bf360c;
    margin-top: 2px;
}

/* Habit Stats */
.habit-stats {
    margin-top: 8px;
}

.stats-title {
    font-size: 0.75rem;
    font-weight: 500;
    color: #888;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}

.stat-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 8px;
    border-radius: 10px;
    background-color: var(--bg-color);
    transition: transform 0.15s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
}

.stat-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-bottom: 8px;
}

.stat-dot.study { background-color: var(--habit-study); }
.stat-dot.capoeira { background-color: var(--habit-capoeira); }
.stat-dot.reading { background-color: var(--habit-reading); }
.stat-dot.diet { background-color: var(--habit-diet); }
.stat-dot.others { background-color: var(--habit-others); }

.stat-value {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-color);
}

.stat-label {
    font-size: 0.625rem;
    color: #888;
    margin-top: 2px;
    text-align: center;
}

/* ============================================
   Estilos de Autenticación
   ============================================ */

/* Utility */
.hidden {
    display: none !important;
}

/* Pantalla de Auth */
.auth-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    z-index: 999;
}

.auth-screen.hidden {
    display: none;
}

.auth-container {
    text-align: center;
    background: white;
    padding: 40px;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 400px;
    width: 100%;
    margin: 20px;
}

.auth-header {
    margin-bottom: 32px;
}

.auth-title {
    font-size: 2rem;
    color: #333;
    margin: 0 0 8px 0;
}

.auth-subtitle {
    color: #666;
    margin: 0;
}

.auth-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.auth-btn {
    padding: 14px 24px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.auth-btn.primary {
    background: #667eea;
    color: white;
}

.auth-btn.primary:hover {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.auth-btn.secondary {
    background: transparent;
    color: #667eea;
    border: 2px solid #667eea;
}

.auth-btn.secondary:hover {
    background: #667eea;
    color: white;
}

/* Modales */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.hidden {
    display: none;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: white;
    padding: 32px;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 400px;
    width: 90%;
    animation: modalSlideIn 0.3s ease;
}

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

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    font-size: 24px;
    color: #999;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: #f5f5f5;
    color: #333;
}

.modal-title {
    font-size: 1.5rem;
    color: #333;
    margin: 0 0 24px 0;
    text-align: center;
}

/* Formularios */
.auth-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 0.9rem;
    color: #555;
    font-weight: 500;
}

.form-group input {
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.3s ease;
}

.form-group input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-group input::placeholder {
    color: #aaa;
}

.form-error {
    background: #fee2e2;
    color: #dc2626;
    padding: 12px;
    border-radius: 8px;
    font-size: 0.9rem;
    text-align: center;
}

.form-error.hidden {
    display: none;
}

.submit-btn {
    padding: 14px 24px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 8px;
}

.submit-btn:hover {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.submit-btn:active {
    transform: translateY(0);
}

.auth-switch {
    text-align: center;
    margin-top: 20px;
    color: #666;
}

.link-btn {
    background: none;
    border: none;
    color: #667eea;
    font-weight: 600;
    cursor: pointer;
    font-size: inherit;
}

.link-btn:hover {
    text-decoration: underline;
}

.no-habits-message {
    text-align: center;
    padding: 10px;
    font-size: 12px;
    color: #666;
}

.habit-action-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 20px;
}

.habit-action-options .submit-btn {
    width: 100%;
}

/* User Bar */
.user-bar {
    position: fixed;
    top: 0;
    right: 0;
    background: white;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    z-index: 100;
    border-radius: 0 0 0 16px;
}

.user-bar.hidden {
    display: none;
}

#userEmail {
    color: #666;
    font-size: 0.9rem;
}

.logout-btn {
    padding: 8px 16px;
    background: #f5f5f5;
    color: #666;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.logout-btn:hover {
    background: #e0e0e0;
    color: #333;
}

/* App container adjustments for fixed user bar */
.app-container {
    margin-top: 60px;
}

/* Settings button */
.settings-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.2s;
}

.settings-btn:hover {
    background: #f0f0f0;
}

/* Setup Modal */
.setup-modal {
    max-width: 450px;
}

.setup-subtitle {
    text-align: center;
    color: #666;
    margin-bottom: 24px;
}

.habits-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.habit-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: #f8f9fa;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.habit-option:hover {
    background: #e9ecef;
}

.habit-option input[type="checkbox"] {
    display: none;
}

.habit-check {
    width: 20px;
    height: 20px;
    border: 2px solid #ddd;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.habit-option input[type="checkbox"]:checked + .habit-check {
    background: #667eea;
    border-color: #667eea;
}

.habit-option input[type="checkbox"]:checked + .habit-check::after {
    content: '✓';
    color: white;
    font-size: 12px;
}

.habit-option.custom-habit {
    flex-wrap: wrap;
}

.habit-option input[type="text"] {
    flex: 1;
    min-width: 120px;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
}

.habit-option input[type="text"]:focus {
    outline: none;
    border-color: #667eea;
}

.habit-option input[type="text"]:disabled {
    background: #eee;
    cursor: not-allowed;
}

.habit-color {
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    padding: 0;
    margin-left: auto;
}

.habit-color::-webkit-color-swatch-wrapper {
    padding: 0;
}

.habit-color::-webkit-color-swatch {
    border: 2px solid #ddd;
    border-radius: 50%;
}

.add-custom-btn {
    width: 30px;
    height: 30px;
    border: 2px solid #667eea;
    border-radius: 50%;
    background: white;
    color: #667eea;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    padding: 0;
    margin-left: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.add-custom-btn:hover {
    background: #667eea;
    color: white;
}

.add-custom-btn:disabled {
    border-color: #ddd;
    color: #ddd;
    cursor: not-allowed;
    background: #f5f5f5;
}

.dynamic-habit-row {
    animation: habitSlideIn 0.3s ease;
}

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

.remove-habit-btn {
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 50%;
    background: #fee2e2;
    color: #dc2626;
    font-size: 0.9rem;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.remove-habit-btn:hover {
    background: #dc2626;
    color: white;
}

/* ============================================
   Responsive Auth
   ============================================ */

@media (max-width: 480px) {
    .auth-container {
        padding: 24px;
    }
    
    .auth-title {
        font-size: 1.5rem;
    }
    
    .modal-content {
        padding: 24px;
    }
    
    .user-bar {
        padding: 8px 12px;
        gap: 8px;
    }
}
