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

:root {
    --primary-color: #2196F3;
    --success-color: #4CAF50;
    --warning-color: #FFC107;
    --danger-color: #F44336;
    --purple-color: #9C27B0;
    --background: #f5f5f5;
    --surface: #ffffff;
    --text-primary: #212121;
    --text-secondary: #757575;
    --border-color: #e0e0e0;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
    --radius: 12px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    padding-bottom: 80px;
}

.app-header {
    background: linear-gradient(135deg, var(--primary-color), var(--purple-color));
    color: white;
    padding: 1rem;
    text-align: center;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.app-main {
    padding: 1rem;
    max-width: 1200px;
    margin: 0 auto;
}

.screen {
    display: none;
    animation: fadeIn 0.3s ease-in-out;
}

.screen.active {
    display: block;
}

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

/* Welcome Card */
.welcome-card {
    background: linear-gradient(135deg, var(--success-color), var(--primary-color));
    color: white;
    padding: 2rem;
    border-radius: var(--radius);
    text-align: center;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
}

.welcome-card h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--surface);
    padding: 1.5rem 1rem;
    border-radius: var(--radius);
    text-align: center;
    box-shadow: var(--shadow);
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

.stat-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
    margin-bottom: 0.25rem;
}

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

/* Quick Actions */
.quick-actions {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

.quick-actions h3 {
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.action-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
}

.action-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 1rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.action-btn:hover {
    background: #1976D2;
    transform: translateY(-1px);
}

/* Recovery Suggestions */
.recovery-suggestions {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border-left: 4px solid var(--warning-color);
}

.recovery-suggestions h3 {
    color: var(--warning-color);
    margin-bottom: 1rem;
}

.suggestion-item {
    background: #fff3cd;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    border-left: 3px solid var(--warning-color);
}

/* Section Header */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.section-header h2 {
    color: var(--text-primary);
    font-size: 1.5rem;
}

/* Buttons */
.btn-primary, .btn-secondary {
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

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

.btn-primary:hover {
    background: #1976D2;
    transform: translateY(-1px);
}

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

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

.btn-icon {
    background: transparent;
    border: none;
    padding: 0.5rem;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-secondary);
}

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

/* Habits List */
.habits-list {
    display: grid;
    gap: 1rem;
}

.habit-card {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: var(--transition);
    position: relative;
}

.habit-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

.habit-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.habit-info h3 {
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.habit-category {
    font-size: 0.8rem;
    color: var(--text-secondary);
    background: var(--background);
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
}

.habit-actions {
    display: flex;
    gap: 0.5rem;
}

.habit-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1rem;
}

.habit-stat {
    text-align: center;
}

.habit-stat-value {
    font-size: 1.25rem;
    font-weight: bold;
    color: var(--primary-color);
}

.habit-stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.habit-progress {
    margin-bottom: 1rem;
}

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

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success-color), var(--primary-color));
    transition: width 0.3s ease;
}

.habit-actions-bottom {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    border-radius: 8px;
}

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

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

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 1rem;
}

.modal-content {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow: hidden;
    animation: modalSlideIn 0.3s ease-out;
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--primary-color);
    color: white;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: white;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.modal-body {
    padding: 1.5rem;
    max-height: 60vh;
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    background: var(--background);
}

/* Form Groups */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    font-weight: 500;
    font-size: 0.9rem;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    transition: var(--transition);
    background: white;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

/* Modal Form */
#habitModalForm {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.modal-footer button {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    min-width: 100px;
}

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

.modal-footer .btn-primary:hover {
    background: #1976D2;
    transform: translateY(-1px);
}

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

.modal-footer .btn-secondary:hover {
    background: #e0e0e0;
}

/* Calendar */
.calendar-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

#currentMonth {
    font-weight: 600;
    color: var(--text-primary);
}

.habit-filter {
    margin-bottom: 2rem;
}

.habit-filter select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--surface);
}

.calendar-container {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 2rem;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
}

.calendar-day {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    font-size: 0.9rem;
}

.calendar-day.header {
    background: var(--background);
    font-weight: 600;
    color: var(--text-secondary);
    cursor: default;
}

.calendar-day.other-month {
    color: var(--text-secondary);
    opacity: 0.5;
}

.calendar-day.today {
    background: var(--primary-color);
    color: white;
}

.calendar-day.streak-none {
    background: #fafafa;
}

.calendar-day.streak-low {
    background: #e8f5e8;
    color: var(--success-color);
}

.calendar-day.streak-medium {
    background: #c8e6c9;
    color: var(--success-color);
}

.calendar-day.streak-high {
    background: #a5d6a7;
    color: white;
}

.calendar-day.streak-max {
    background: var(--success-color);
    color: white;
}

.calendar-legend {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.calendar-legend h4 {
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.legend-items {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

/* Analytics */
.analytics-tabs {
    display: flex;
    margin-bottom: 2rem;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 0.25rem;
    box-shadow: var(--shadow);
}

.tab-btn {
    flex: 1;
    padding: 0.75rem;
    background: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    font-weight: 500;
}

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

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.chart-container {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

.chart-container canvas {
    max-width: 100%;
    height: auto;
}

.trends-summary {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.correlations-list {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.correlation-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 1rem;
}

.correlation-strength {
    font-weight: bold;
    color: var(--primary-color);
}

.performance-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.metric-card {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
}

.metric-value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.metric-label {
    color: var(--text-secondary);
}



/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    display: flex;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
    z-index: 1000;
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.75rem 0.5rem;
    text-decoration: none;
    color: var(--text-secondary);
    transition: var(--transition);
    font-size: 0.8rem;
}

.nav-item.active {
    color: var(--primary-color);
    background: rgba(33, 150, 243, 0.1);
}



/* FAQ Styles */
.faq-container {
    max-width: 800px;
    margin: 0 auto;
}

.faq-item {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 1rem;
    overflow: hidden;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.faq-question {
    width: 100%;
    padding: 1.5rem;
    background: transparent;
    border: none;
    text-align: left;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 500;
    font-size: 1rem;
    color: var(--text-primary);
    transition: var(--transition);
}

.faq-question:hover {
    background: var(--background);
}

.faq-question[aria-expanded="true"] {
    background: var(--background);
    border-bottom: 1px solid var(--border-color);
}

.faq-question[aria-expanded="true"] .faq-icon {
    transform: rotate(45deg);
}

.faq-icon {
    transition: transform 0.3s ease;
    font-weight: bold;
    color: var(--primary-color);
    font-size: 1.25rem;
    margin-left: 1rem;
}

.faq-answer {
    padding: 0 1.5rem 1.5rem;
    color: var(--text-secondary);
    line-height: 1.6;
    background: var(--surface);
}

.faq-answer[hidden] {
    display: none;
}

.faq-answer p {
    margin-bottom: 1rem;
}

.faq-answer ul, .faq-answer ol {
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}

.faq-answer li {
    margin-bottom: 0.5rem;
}

.faq-answer strong {
    color: var(--text-primary);
    font-weight: 600;
}

/* FAQ Page Specific Styles */
.faq-page {
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

.faq-header {
    text-align: center;
    margin-bottom: 3rem;
}

.faq-header h1 {
    color: var(--primary-color);
    font-size: 2.5rem;
    margin-bottom: 1rem;
}

.faq-header p {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.faq-search {
    margin-bottom: 2rem;
}

.faq-search input {
    width: 100%;
    padding: 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 1rem;
    transition: var(--transition);
}

.faq-search input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

.faq-detailed {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 2rem;
}

.faq-detailed h2 {
    background: var(--primary-color);
    color: white;
    padding: 1.5rem;
    margin: 0;
    text-align: center;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--primary-color);
    text-decoration: none;
    margin-bottom: 2rem;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    transition: var(--transition);
}

.back-link:hover {
    background: rgba(33, 150, 243, 0.1);
}

.nav-item i {
    font-size: 1.25rem;
    margin-bottom: 0.25rem;
}

/* Footer */
footer, .app-footer {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    border-top: 1px solid var(--border-color);
    margin-top: 2rem;
    background: var(--surface);
}

.app-footer a {
    color: var(--primary-color);
    text-decoration: none;
    transition: var(--transition);
}

.app-footer a:hover {
    text-decoration: underline;
}

/* Responsive Design */
@media (max-width: 768px) {
    .app-main {
        padding: 0.5rem;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .section-header {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }
    
    .calendar-day {
        font-size: 0.8rem;
    }
    
    .legend-items {
        flex-direction: column;
    }
    
    .analytics-tabs {
        flex-direction: column;
    }
    
    .tab-btn {
        text-align: center;
    }
    
    .modal-overlay {
        padding: 0.5rem;
    }
    
    .modal-content {
        max-height: 95vh;
        margin: 0;
        border-radius: 8px;
    }
    
    .modal-header {
        padding: 1rem;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    .modal-footer {
        flex-direction: column;
        gap: 0.5rem;
        padding: 1rem;
    }
    
    .modal-footer button {
        width: 100%;
        min-width: auto;
    }
    
    /* FAQ Responsive */
    .faq-question {
        padding: 1rem;
        font-size: 0.9rem;
    }
    
    .faq-answer {
        padding: 0 1rem 1rem;
    }
    
    .faq-icon {
        font-size: 1rem;
    }
    
    .faq-search {
        margin-bottom: 1rem;
    }
    
    .faq-search input {
        padding: 0.75rem;
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .action-buttons {
        grid-template-columns: 1fr;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .calendar-day {
        font-size: 0.7rem;
    }
    
    .performance-metrics {
        grid-template-columns: 1fr;
    }
}

/* Animations */
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.pulse {
    animation: pulse 2s infinite;
}

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

.slide-up {
    animation: slideUp 0.3s ease-out;
}

/* Streak indicators */
.streak-indicator {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success-color);
}

.streak-indicator.high {
    background: var(--warning-color);
}

.streak-indicator.max {
    background: var(--danger-color);
}

/* Loading states */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top: 2px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
