/* Calendar Page - TikTok Style Dark Theme */

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

#app {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

main {
    width: 100%;
}

/* Calendar Wrapper */
.calendar-wrapper {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 12px var(--shadow-light);
}

/* Integrated Calendar Header */
.calendar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    gap: 16px;
}

.month-display {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    flex: 1;
    text-align: center;
    min-width: 180px;
}

.nav-btn {
    width: 40px;
    height: 40px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 18px;
    font-weight: 600;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-btn:hover {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
    transform: scale(1.05);
}

.btn-upload {
    padding: 10px 16px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-upload:hover {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
    transform: translateY(-2px);
}

.btn-upload svg {
    flex-shrink: 0;
}

/* Calendar Container */
#calendar-container {
    padding: 24px;
}

/* Calendar Table */
.calendar {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-top: 10px;
}

.calendar th {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    padding: 14px 8px;
    text-align: center;
    font-weight: 700;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border: 1px solid var(--border-color);
}

.calendar th:first-child {
    border-top-left-radius: 8px;
}

.calendar th:last-child {
    border-top-right-radius: 8px;
}

.calendar td {
    border: 1px solid var(--border-color);
    padding: 8px;
    vertical-align: top;
    height: 120px;
    width: 14.28%; /* Fixed width for each column (100% / 7 days) */
    max-width: 14.28%;
    position: relative;
    background: var(--bg-primary);
    transition: background 0.2s;
}

.calendar td:hover {
    background: var(--bg-secondary);
}

.calendar td.empty {
    background: var(--bg-tertiary);
    opacity: 0.5;
}

.calendar td.today {
    background: rgba(254, 44, 85, 0.1);
    border-color: var(--accent-primary);
}

.day-number {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.calendar td.empty .day-number {
    color: var(--text-muted);
}

.calendar td.today .day-number {
    color: var(--accent-primary);
}

/* Meals Container */
.meals-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.meal-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 12px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.meal-item:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-primary);
    transform: translateX(2px);
}

/* Source-based color coding - MUST come after general hover */
.meal-item[data-source="bulk"] {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.2), rgba(37, 99, 235, 0.15));
    border-color: #3b82f6 !important;
}

.meal-item[data-source="bulk"]:hover {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.3), rgba(37, 99, 235, 0.2));
    border-color: #60a5fa !important;
}

.meal-item[data-source="tiktok"] {
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.2), rgba(245, 158, 11, 0.15));
    border-color: #f59e0b !important;
    cursor: pointer;
}

.meal-item[data-source="tiktok"]:hover {
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.3), rgba(245, 158, 11, 0.2));
    border-color: #fbbf24 !important;
    transform: translateX(4px);
}

.meal-name {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
    line-height: 1.2;
}

.meal-notes {
    font-size: 10px;
    color: var(--text-tertiary);
    line-height: 1.2;
}

.meal-categories {
    display: flex;
    gap: 3px;
    flex-wrap: wrap;
    margin-top: 3px;
}

.category-badge {
    font-size: 9px;
    padding: 2px 4px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    color: var(--text-tertiary);
}

.leftover-indicator {
    color: var(--accent-primary);
    font-size: 10px;
    font-weight: 600;
}

/* Add Meal Button */
.add-meal-btn {
    width: 100%;
    padding: 8px;
    background: transparent;
    border: 1px dashed var(--border-color);
    border-radius: 6px;
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: 20px;
    transition: all 0.2s;
    margin-top: 4px;
}

.add-meal-btn:hover {
    background: var(--bg-secondary);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 32px;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.4);
}

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

.modal-content h2 {
    color: var(--text-primary);
    margin-bottom: 24px;
    font-size: 24px;
}

.close {
    position: absolute;
    top: 16px;
    right: 16px;
    font-size: 28px;
    color: var(--text-tertiary);
    cursor: pointer;
    transition: color 0.2s;
}

.close:hover {
    color: var(--accent-primary);
}

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

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 14px;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    transition: border-color 0.2s;
}

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

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

.categories-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.category-checkbox {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.category-checkbox:hover {
    border-color: var(--accent-primary);
    background: var(--bg-tertiary);
}

.category-checkbox input[type="checkbox"] {
    width: auto;
    margin: 0;
}

.category-checkbox input[type="checkbox"]:checked + label {
    color: var(--accent-primary);
    font-weight: 600;
}

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.btn-primary,
.btn-secondary {
    flex: 1;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

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

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-2px);
}

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

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

/* Autocomplete */
.autocomplete-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 1001;
    margin-top: 4px;
}

.autocomplete-item {
    padding: 10px 12px;
    cursor: pointer;
    transition: background 0.2s;
}

.autocomplete-item:hover {
    background: var(--bg-tertiary);
}

/* Recipe Details Modal */
.recipe-modal .modal-content {
    max-width: 700px;
}

.recipe-header {
    display: flex;
    gap: 20px;
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.recipe-thumbnail {
    width: 120px;
    height: 210px;
    border-radius: 8px;
    object-fit: cover;
    background: var(--bg-tertiary);
    flex-shrink: 0;
}

.recipe-meta {
    flex: 1;
}

.recipe-meta h3 {
    margin: 0 0 12px 0;
    font-size: 20px;
    color: var(--text-primary);
}

.recipe-info-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-top: 12px;
}

.recipe-info-item {
    padding: 8px 12px;
    background: var(--bg-primary);
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.recipe-info-label {
    font-size: 11px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.recipe-info-value {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-top: 2px;
}

.recipe-section {
    margin-bottom: 24px;
}

.recipe-section h4 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.recipe-section ul,
.recipe-section ol {
    margin: 0;
    padding-left: 20px;
}

.recipe-section li {
    margin-bottom: 8px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.difficulty-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    text-transform: capitalize;
}

.difficulty-easy {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
}

.difficulty-medium {
    background: rgba(251, 191, 36, 0.2);
    color: #fbbf24;
}

.difficulty-hard {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

/* Responsive */
@media (max-width: 768px) {
    .calendar-header {
        padding: 16px;
        flex-wrap: wrap;
    }

    .month-display {
        order: -1;
        width: 100%;
        margin-bottom: 12px;
        font-size: 18px;
    }

    .nav-btn {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }

    /* Mobile Calendar - Vertical Scroll */
    .calendar-wrapper {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        max-height: calc(100vh - 200px);
    }

    #calendar-container {
        padding: 12px;
    }

    /* Hide table structure, convert to vertical cards */
    .calendar {
        display: block;
        width: 100%;
        min-width: unset;
    }

    .calendar thead {
        display: none; /* Hide day names row */
    }

    .calendar tbody {
        display: block;
    }

    .calendar tr {
        display: block;
        margin-bottom: 0;
    }

    .calendar td {
        display: block;
        width: 100% !important;
        max-width: 100% !important;
        min-width: unset;
        height: auto;
        min-height: 80px;
        margin-bottom: 12px;
        border-radius: 12px;
        padding: 12px;
        font-size: 14px;
    }

    .calendar td.empty {
        display: none; /* Hide empty days on mobile */
    }

    .day-number {
        font-size: 16px;
        margin-bottom: 8px;
        display: flex;
        align-items: center;
        gap: 8px;
    }

    /* Add day of week to mobile view */
    .day-number::before {
        content: attr(data-day-name);
        font-size: 12px;
        font-weight: 600;
        color: var(--text-tertiary);
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }

    .meals-container {
        max-height: none;
        overflow-y: visible;
    }

    .meal-item {
        font-size: 13px;
        padding: 8px 10px;
    }

    .recipe-header {
        flex-direction: column;
    }

    .recipe-thumbnail {
        width: 100%;
        height: auto;
        aspect-ratio: 9 / 16;
    }

    .recipe-info-grid {
        grid-template-columns: 1fr 1fr;
    }

    /* Mobile scroll hint */
    .calendar-scroll-hint {
        display: block;
        text-align: center;
        color: var(--text-tertiary);
        font-size: 12px;
        padding: 8px;
        background: var(--bg-tertiary);
        border-bottom: 1px solid var(--border-color);
    }
}

@media (min-width: 769px) {
    .calendar-scroll-hint {
        display: none;
    }
}

/* ==================== Calendar Modal Enhancements ==================== */

/* Larger modal for recipe selection */
.modal-content.modal-large-calendar {
    max-width: 950px !important;
    max-height: 90vh;
    width: 90%;
    overflow-y: auto;
    padding: 32px;
    background: var(--bg-primary);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.modal-content.modal-large-calendar h2 {
    margin-bottom: 20px;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.modal-content.modal-large-calendar h2 #modal-selected-date {
    color: var(--accent-primary);
    font-weight: 700;
}

/* Modal Tabs */
.meal-modal-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 24px;
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 4px;
}

.meal-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.meal-tab svg {
    width: 16px;
    height: 16px;
    stroke-width: 2.5;
}

.meal-tab:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.meal-tab.active {
    color: var(--text-primary);
    background: var(--bg-primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* Tab Content */
.tab-content {
    display: none;
}

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

/* Recipe Search Bar */
.recipe-search-bar {
    position: relative;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 14px;
    padding: 14px 18px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.recipe-search-bar:focus-within {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(254, 44, 85, 0.1);
    background: var(--bg-primary);
}

.recipe-search-bar .search-icon {
    color: var(--text-secondary);
    margin-right: 12px;
    transition: color 0.2s;
}

.recipe-search-bar:focus-within .search-icon {
    color: var(--accent-primary);
}

.recipe-search-bar input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 15px;
    font-weight: 500;
}

.recipe-search-bar input::placeholder {
    color: var(--text-secondary);
    font-weight: 400;
}

.search-count {
    font-size: 13px;
    color: var(--text-secondary);
    margin-left: 12px;
    white-space: nowrap;
    font-weight: 600;
    padding: 4px 10px;
    background: var(--bg-primary);
    border-radius: 8px;
}

/* Recipe Filter Tabs */
.recipe-filter-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    overflow-x: auto;
    padding-bottom: 8px;
    padding-top: 2px;
}

.recipe-filter-tabs::-webkit-scrollbar {
    height: 6px;
}

.recipe-filter-tabs::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 3px;
}

.recipe-filter-tabs::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
    transition: background 0.2s;
}

.recipe-filter-tabs::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
}

.recipe-filter-tab {
    padding: 9px 18px;
    background: var(--bg-secondary);
    border: 2px solid transparent;
    border-radius: 24px;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
}

.recipe-filter-tab:hover {
    background: var(--bg-primary);
    border-color: var(--border-color);
    color: var(--text-primary);
    transform: translateY(-2px);
}

.recipe-filter-tab.active {
    background: linear-gradient(135deg, var(--accent-primary) 0%, #e91e63 100%);
    border-color: var(--accent-primary);
    color: #fff;
    box-shadow: 0 4px 12px rgba(254, 44, 85, 0.3);
    transform: translateY(-2px);
}

/* Calendar Recipes Grid */
.calendar-recipes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    max-height: 520px;
    overflow-y: auto;
    padding: 8px 4px;
}

.calendar-recipes-grid::-webkit-scrollbar {
    width: 8px;
}

.calendar-recipes-grid::-webkit-scrollbar-track {
    background: var(--bg-primary);
    border-radius: 4px;
}

.calendar-recipes-grid::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.calendar-recipes-grid::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
}

.calendar-recipe-card {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    min-height: 120px;
    display: flex;
    flex-direction: column;
}

.calendar-recipe-card:hover {
    border-color: var(--accent-primary);
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.3);
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
}

.calendar-recipe-card.selected {
    border-color: var(--accent-secondary);
    box-shadow: 0 0 0 3px rgba(37, 244, 238, 0.3), 0 8px 16px rgba(0, 0, 0, 0.25);
    background: linear-gradient(135deg, rgba(37, 244, 238, 0.1) 0%, var(--bg-secondary) 100%);
}

.calendar-recipe-info {
    padding: 16px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.calendar-recipe-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    letter-spacing: -0.01em;
}

.calendar-recipe-creator {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.calendar-recipe-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: auto;
}

.calendar-recipe-tag {
    font-size: 11px;
    padding: 4px 10px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-secondary);
    font-weight: 600;
    transition: all 0.2s;
}

.calendar-recipe-card:hover .calendar-recipe-tag {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

/* Selected indicator */
.calendar-recipe-card .selection-indicator {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    background: var(--accent-secondary);
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.calendar-recipe-card.selected .selection-indicator {
    display: flex;
}

.selection-indicator svg {
    width: 18px;
    height: 18px;
    color: #000;
}

/* Loading and Empty States */
.calendar-loading,
.calendar-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.calendar-loading .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

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

.calendar-empty p {
    margin-bottom: 16px;
    font-size: 15px;
}

.btn-discover-small {
    display: inline-block;
    padding: 10px 20px;
    background: var(--accent-primary);
    color: #fff;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    transition: opacity 0.2s;
}

.btn-discover-small:hover {
    opacity: 0.9;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .modal-content.modal-large-calendar {
        width: 95%;
        max-height: 95vh;
        padding: 16px;
    }

    .modal-content.modal-large-calendar h2 {
        font-size: 18px;
        margin-bottom: 12px;
    }

    .meal-modal-tabs {
        gap: 4px;
    }

    .meal-tab {
        font-size: 12px;
        padding: 8px 10px;
        gap: 4px;
    }

    .meal-tab svg {
        width: 14px;
        height: 14px;
    }

    .calendar-recipes-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 10px;
        max-height: 350px;
    }

    .recipe-search-bar {
        padding: 10px 12px;
        font-size: 14px;
    }

    .recipe-filter-tabs {
        gap: 6px;
    }

    .recipe-filter-tab {
        font-size: 11px;
        padding: 6px 10px;
    }

    .calendar-recipe-name {
        font-size: 13px;
    }

    .calendar-recipe-creator {
        font-size: 11px;
    }
}
