/* Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #4A90E2;
    --secondary-color: #357ABD;
    --background: #f5f7fa;
    --surface: #ffffff;
    --text-primary: #2c3e50;
    --text-secondary: #7f8c8d;
    --border: #e1e8ed;
    --shadow: rgba(0, 0, 0, 0.1);
    --success: #2ECC71;
    --danger: #E74C3C;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

.app-container {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
    padding-bottom: 80px;
}

/* Header */
.app-header {
    text-align: center;
    padding: 20px 0;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border-radius: 15px;
    margin-bottom: 20px;
    box-shadow: 0 4px 6px var(--shadow);
    position: relative;
}

.menu-btn {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    width: 45px;
    height: 45px;
    border-radius: 10px;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.menu-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-50%) scale(1.05);
}

.menu-btn:active {
    transform: translateY(-50%) scale(0.95);
}

.app-header h1 {
    font-size: 2rem;
    margin-bottom: 5px;
}

.subtitle {
    font-size: 0.9rem;
    opacity: 0.9;
}

/* Calendar Navigation */
.calendar-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    background: var(--surface);
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 2px 4px var(--shadow);
}

.month-title {
    font-size: 1.3rem;
    color: var(--text-primary);
    flex: 1;
    text-align: center;
}

.nav-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-btn:hover {
    background: var(--secondary-color);
    transform: scale(1.1);
}

.nav-btn:active {
    transform: scale(0.95);
}

/* Calendar Container */
.calendar-container {
    background: var(--surface);
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 2px 4px var(--shadow);
    margin-bottom: 20px;
}

.calendar-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 5px;
    margin-bottom: 10px;
}

.weekday {
    text-align: center;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.85rem;
    padding: 8px 0;
}

.calendar-days {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 5px;
}

.calendar-day {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    background: var(--background);
    font-weight: 500;
}

.calendar-day:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 4px var(--shadow);
}

.calendar-day.other-month {
    color: var(--text-secondary);
    opacity: 0.3;
}

.calendar-day.today {
    border: 3px solid var(--primary-color);
    font-weight: bold;
}

/* Fertility Status Colors */
.calendar-day.period {
    background: #E74C3C;
    color: white;
    font-weight: bold;
}

.calendar-day.predicted-period {
    background: #FFD93D;
    color: #333;
    font-weight: bold;
}

.calendar-day.most-fertile {
    background: #FF6B9D;
    color: white;
    font-weight: bold;
}

.calendar-day.fertile {
    background: #FFC4E1;
    color: #333;
    font-weight: bold;
}

.calendar-day.safe {
    background: #A8E6CF;
    color: #333;
}

.calendar-day.ovulation {
    background: #FF1493;
    color: white;
    font-weight: bold;
    position: relative;
}

.calendar-day.ovulation::after {
    content: '🥚';
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 0.7rem;
}

.calendar-day.period::after {
    content: '🔴';
    position: absolute;
    bottom: 2px;
    right: 2px;
    font-size: 0.6rem;
}

/* Add Period Button */
.add-event-btn {
    width: 100%;
    padding: 15px;
    background: #E74C3C;
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px var(--shadow);
    margin-bottom: 20px;
}

.add-event-btn:hover {
    background: #C0392B;
    transform: translateY(-2px);
    box-shadow: 0 6px 8px var(--shadow);
}

.add-event-btn:active {
    transform: translateY(0);
}

/* Stats Section */
.stats-section {
    background: var(--surface);
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 4px var(--shadow);
    margin-bottom: 20px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    margin-top: 15px;
}

.stat-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 15px;
    border-radius: 10px;
    text-align: center;
    color: white;
}

.stat-label {
    font-size: 0.8rem;
    opacity: 0.9;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: bold;
    margin-bottom: 4px;
}

.stat-sublabel {
    font-size: 0.75rem;
    opacity: 0.8;
}

/* Legend Section */
.legend-section {
    background: var(--surface);
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 4px var(--shadow);
    margin-bottom: 20px;
}

.legend-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-top: 15px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
}

.legend-color {
    width: 24px;
    height: 24px;
    border-radius: 5px;
    flex-shrink: 0;
    box-shadow: 0 2px 4px var(--shadow);
}

/* Info Box */
.info-box {
    background: #E8F4FD;
    border-left: 4px solid var(--primary-color);
    padding: 12px;
    border-radius: 5px;
    margin: 15px 0;
    font-size: 0.9rem;
    color: #2c3e50;
}

/* Events Section */
.events-section {
    background: var(--surface);
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 4px var(--shadow);
}

.section-title {
    margin-bottom: 15px;
    color: var(--text-primary);
    font-size: 1.2rem;
}

.events-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.event-item {
    background: var(--background);
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid #E74C3C;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
}

.event-item:hover {
    transform: translateX(5px);
    box-shadow: 0 2px 4px var(--shadow);
}

.event-info {
    flex: 1;
}

.event-name {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 5px;
    color: var(--text-primary);
}

.event-date {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.event-countdown {
    text-align: right;
    margin-left: 10px;
}

.days-count {
    font-size: 1.2rem;
    font-weight: bold;
    color: #E74C3C;
}

.days-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.delete-event-btn {
    background: var(--danger);
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9rem;
    margin-left: 10px;
    transition: all 0.2s ease;
}

.delete-event-btn:hover {
    background: #c0392b;
    transform: scale(1.05);
}

.exclude-event-btn {
    background: var(--text-secondary);
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9rem;
    margin-left: 5px;
    transition: all 0.2s ease;
}

.exclude-event-btn:hover {
    background: #7f8c8d;
    transform: scale(1.05);
}

.event-item.excluded {
    opacity: 0.5;
    background: linear-gradient(135deg, #ecf0f1, #bdc3c7);
}

.event-item.excluded .event-name {
    text-decoration: line-through;
}

.excluded-badge {
    color: var(--danger);
    font-size: 0.75rem;
    font-weight: bold;
    margin-left: 5px;
}

.no-events {
    text-align: center;
    color: var(--text-secondary);
    padding: 20px;
    font-style: italic;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface);
    border-radius: 15px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 1.3rem;
}

.close-btn {
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: var(--text-secondary);
    line-height: 1;
    transition: color 0.2s ease;
}

.close-btn:hover {
    color: var(--danger);
}

/* QR Modal Specific Styles */
.qr-modal-content {
    max-width: 400px;
}

.qr-modal-body {
    padding: 30px;
    text-align: center;
}

.qr-instruction {
    font-size: 1rem;
    color: var(--text-primary);
    margin-bottom: 20px;
}

#qrCodeContainer {
    display: inline-block;
    padding: 20px;
    background: white;
    border-radius: 10px;
    margin: 20px 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

#qrCodeContainer img {
    display: block;
}

.qr-warning {
    font-size: 0.85rem;
    color: var(--danger);
    margin-top: 20px;
    padding: 10px;
    background: rgba(231, 76, 60, 0.1);
    border-radius: 5px;
}

.qr-info {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: 15px;
    font-style: italic;
}

#qrReader {
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    border-radius: 10px;
    overflow: hidden;
}

#qrReader video {
    width: 100%;
    border-radius: 10px;
}

.qr-debug-log {
    margin-top: 20px;
    padding: 10px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 5px;
    max-height: 200px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.75rem;
    text-align: left;
}

.debug-entry {
    padding: 3px 0;
    color: #495057;
    border-bottom: 1px solid #e9ecef;
}

.debug-entry:last-child {
    border-bottom: none;
}

/* Form */
#eventForm {
    padding: 20px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-primary);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s ease;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--secondary-color);
}

.btn-secondary {
    background: var(--text-secondary);
    color: white;
}

.btn-secondary:hover {
    background: #5d6d7e;
}

/* Install Prompt */
.install-prompt {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    padding: 15px 20px;
    border-radius: 10px;
    box-shadow: 0 4px 12px var(--shadow);
    display: flex;
    gap: 10px;
    align-items: center;
    max-width: 90%;
    z-index: 999;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateX(-50%) translateY(100px);
        opacity: 0;
    }
    to {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

.install-prompt p {
    margin: 0;
    flex: 1;
}

.install-prompt .btn {
    padding: 8px 16px;
    font-size: 0.9rem;
}

/* Responsive Design */
@media (max-width: 480px) {
    .app-container {
        padding: 15px;
    }

    .app-header h1 {
        font-size: 1.5rem;
    }

    .month-title {
        font-size: 1.1rem;
    }

    .calendar-day {
        font-size: 0.8rem;
    }

    .weekday {
        font-size: 0.75rem;
    }

    .event-name {
        font-size: 0.9rem;
    }

    .days-count {
        font-size: 1.2rem;
    }

    .install-prompt {
        flex-direction: column;
        text-align: center;
    }
}

/* Loading State */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* Smooth transitions */
.fade-in {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Settings Menu */
.settings-menu {
    position: fixed;
    top: 0;
    left: -100%;
    width: 100%;
    max-width: 400px;
    height: 100vh;
    background: var(--surface);
    box-shadow: 2px 0 10px var(--shadow);
    transition: left 0.3s ease;
    z-index: 1100;
    overflow-y: auto;
}

.settings-menu.active {
    left: 0;
}

.settings-content {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
}

.settings-header h2 {
    margin: 0;
    font-size: 1.5rem;
}

.settings-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}

.setting-section {
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.setting-section:last-child {
    border-bottom: none;
}

.setting-section h3 {
    margin-bottom: 15px;
    color: var(--text-primary);
    font-size: 1.1rem;
}

.setting-option {
    margin-bottom: 15px;
}

.radio-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 10px;
    border-radius: 8px;
    transition: background 0.2s ease;
}

.radio-label:hover {
    background: var(--background);
}

.radio-label input[type="radio"] {
    margin-right: 10px;
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.radio-label span {
    font-weight: 500;
    color: var(--text-primary);
}

.manual-settings {
    margin-top: 10px;
    padding: 15px;
    background: var(--background);
    border-radius: 8px;
    border-left: 3px solid var(--primary-color);
}

.manual-settings label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-primary);
}

.manual-settings input[type="number"] {
    width: 100%;
    padding: 10px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s ease;
}

.manual-settings input[type="number"]:focus {
    outline: none;
    border-color: var(--primary-color);
}

.setting-description {
    margin-top: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-style: italic;
}

.settings-btn {
    width: 100%;
    padding: 15px;
    margin-bottom: 10px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.settings-btn:hover {
    background: var(--secondary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px var(--shadow);
}

.settings-btn:active {
    transform: translateY(0);
}

.settings-btn span {
    font-size: 1.2rem;
}

.install-app-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    font-weight: 600;
}

.install-app-btn:hover {
    background: linear-gradient(135deg, #5568d3 0%, #653a8a 100%);
}

.setting-info {
    padding: 15px;
    background: var(--background);
    border-radius: 8px;
    font-size: 0.9rem;
    color: var(--text-primary);
    line-height: 1.8;
}

/* Settings Menu Overlay */
.settings-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    z-index: 1050;
}

.settings-overlay.active {
    display: block;
}
