/* Sian's Meal Planner - Custom Styles with Light/Dark Theme */

* {
    -webkit-tap-highlight-color: transparent;
}

/* ========== CSS VARIABLES FOR THEMING ========== */
:root {
    /* Primary colors */
    --primary: #8b5cf6;
    --primary-dark: #7c3aed;
    --primary-light: #a78bfa;

    /* Background colors */
    --bg-body: #f9fafb;
    --bg-card: #ffffff;
    --bg-card-hover: #f9fafb;
    --bg-card-active: #f3f4f6;
    --bg-header: linear-gradient(to right, #9333ea, #7c3aed);
    --bg-nav: #ffffff;
    --bg-input: #ffffff;

    /* Text colors */
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --text-inverse: #ffffff;

    /* Border colors */
    --border-light: #f3f4f6;
    --border-medium: #e5e7eb;
    --border-dark: #d1d5db;

    /* Meal category colors - Light theme */
    --veg-bg: #dcfce7;
    --veg-text: #166534;
    --chicken-bg: #fef3c7;
    --chicken-text: #92400e;
    --beef-bg: #fee2e2;
    --beef-text: #991b1b;
    --special-bg: #ede9fe;
    --special-text: #5b21b6;

    /* Week card */
    --week-card-bg: #ffffff;

    /* Modal */
    --modal-backdrop: rgba(0, 0, 0, 0.5);
    --modal-bg: #ffffff;

    /* Stats */
    --stats-bg: #ffffff;

    /* Today highlight */
    --today-bg: #faf5ff;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
}

/* ========== DARK THEME ========== */
[data-theme="dark"] {
    /* Background colors */
    --bg-body: #0f172a;
    --bg-card: #1e293b;
    --bg-card-hover: #334155;
    --bg-card-active: #475569;
    --bg-header: linear-gradient(to right, #581c87, #4c1d95);
    --bg-nav: #1e293b;
    --bg-input: #334155;

    /* Text colors */
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-inverse: #ffffff;

    /* Border colors */
    --border-light: #334155;
    --border-medium: #475569;
    --border-dark: #64748b;

    /* Meal category colors - Dark theme (slightly muted) */
    --veg-bg: #166534;
    --veg-text: #bbf7d0;
    --chicken-bg: #92400e;
    --chicken-text: #fef3c7;
    --beef-bg: #991b1b;
    --beef-text: #fecaca;
    --special-bg: #5b21b6;
    --special-text: #e9d5ff;

    /* Week card */
    --week-card-bg: #1e293b;

    /* Modal */
    --modal-backdrop: rgba(0, 0, 0, 0.7);
    --modal-bg: #1e293b;

    /* Stats */
    --stats-bg: #1e293b;

    /* Today highlight */
    --today-bg: #2e1065;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);
}

/* ========== BASE STYLES ========== */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ========== HEADER ========== */
header {
    background: var(--bg-header);
}

/* Navigation bar below header */
.nav-bar {
    background-color: var(--bg-nav);
    border-color: var(--border-medium);
}

/* ========== THEME TOGGLE BUTTON ========== */
.theme-toggle {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 8px;
    padding: 8px 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: white;
    font-size: 16px;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

.theme-toggle:active {
    transform: scale(0.95);
}

/* Icon visibility */
.theme-toggle .sun-icon {
    display: none;
}

.theme-toggle .moon-icon {
    display: inline;
}

[data-theme="dark"] .theme-toggle .sun-icon {
    display: inline;
}

[data-theme="dark"] .theme-toggle .moon-icon {
    display: none;
}

/* ========== CALENDAR ========== */
.calendar-container {
    background-color: var(--bg-card);
    box-shadow: var(--shadow-sm);
}

/* Day headers */
.day-header {
    background-color: var(--bg-card-hover);
    color: var(--text-secondary);
    border-color: var(--border-medium);
}

/* Calendar Day Cells */
.calendar-day {
    min-height: 90px;
    border-right: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
    padding: 4px;
    cursor: pointer;
    transition: background-color 0.15s ease;
    position: relative;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-card);
}

.calendar-day:hover {
    background-color: var(--bg-card-hover);
}

.calendar-day:active {
    background-color: var(--bg-card-active);
}

.calendar-day.outside-month {
    background-color: var(--bg-card-hover);
    opacity: 0.5;
}

.calendar-day.today {
    background-color: var(--today-bg);
}

.calendar-day.today::before {
    content: '';
    position: absolute;
    top: 4px;
    right: 4px;
    width: 6px;
    height: 6px;
    background-color: var(--primary);
    border-radius: 50%;
}

.day-number {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 3px;
    flex-shrink: 0;
}

.calendar-day.today .day-number {
    color: var(--primary);
    font-weight: 700;
}

/* ========== MEAL PILLS ========== */
.meal-pill {
    font-size: 9px;
    padding: 4px 5px;
    border-radius: 4px;
    line-height: 1.25;
    display: block;
    flex: 1;
    white-space: normal;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.meal-pill.veg {
    background-color: var(--veg-bg);
    color: var(--veg-text);
}

.meal-pill.chicken {
    background-color: var(--chicken-bg);
    color: var(--chicken-text);
}

.meal-pill.beef {
    background-color: var(--beef-bg);
    color: var(--beef-text);
}

.meal-pill.special {
    background-color: var(--special-bg);
    color: var(--special-text);
}

/* Expensive indicator */
.meal-pill.expensive::after {
    content: ' $';
    font-weight: bold;
}

/* ========== MODALS ========== */
#meal-modal,
#special-modal,
#change-meal-modal {
    transition: opacity 0.2s ease;
    background-color: var(--modal-backdrop);
}

#meal-modal.show,
#special-modal.show,
#change-meal-modal.show {
    display: flex !important;
}

#meal-modal > div,
#special-modal > div,
#change-meal-modal > div {
    transform: scale(0.95);
    transition: transform 0.2s ease;
    background-color: var(--modal-bg);
}

#meal-modal.show > div,
#special-modal.show > div,
#change-meal-modal.show > div {
    transform: scale(1);
}

/* Modal content */
.modal-header {
    border-color: var(--border-medium);
}

.modal-title {
    color: var(--text-primary);
}

.modal-close {
    color: var(--text-muted);
}

.modal-close:hover {
    background-color: var(--bg-card-hover);
}

/* ========== MEAL OPTIONS ========== */
.meal-option {
    padding: 12px;
    border: 1px solid var(--border-medium);
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
    background-color: var(--bg-card);
    color: var(--text-primary);
}

.meal-option:hover {
    border-color: var(--primary);
    background-color: var(--today-bg);
}

.meal-option:active {
    transform: scale(0.98);
}

.meal-option.expensive {
    border-style: dashed;
}

.meal-option.expensive::after {
    content: 'Expensive';
    font-size: 10px;
    background: var(--chicken-bg);
    color: var(--chicken-text);
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
}

/* ========== TAB BUTTONS ========== */
.meal-tab {
    transition: all 0.15s ease;
}

.meal-tab.active[data-category="veg"] {
    background-color: #22c55e;
    color: white;
}

.meal-tab.active[data-category="chicken"] {
    background-color: #f59e0b;
    color: white;
}

.meal-tab.active[data-category="beef"] {
    background-color: #ef4444;
    color: white;
}

.meal-tab:not(.active) {
    background-color: var(--bg-card-hover);
    color: var(--text-secondary);
}

/* ========== WEEK SUMMARY CARDS ========== */
.week-card {
    background: var(--week-card-bg);
    border-radius: 8px;
    padding: 8px;
    box-shadow: var(--shadow-sm);
    text-align: center;
}

.week-card-title {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.week-card-counts {
    display: flex;
    justify-content: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
}

.week-card-counts .veg { color: #22c55e; }
.week-card-counts .chicken { color: #f59e0b; }
.week-card-counts .beef { color: #ef4444; }

/* ========== STATS BAR ========== */
.stats-bar {
    background-color: var(--stats-bg);
    box-shadow: var(--shadow-sm);
}

.stats-label {
    color: var(--text-secondary);
}

/* ========== INPUTS ========== */
input[type="text"],
input[type="number"] {
    background-color: var(--bg-input);
    border-color: var(--border-medium);
    color: var(--text-primary);
}

input[type="text"]::placeholder,
input[type="number"]::placeholder {
    color: var(--text-muted);
}

input[type="text"]:focus,
input[type="number"]:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.2);
}

/* ========== LEGEND ========== */
.legend {
    background-color: var(--bg-card);
    border-color: var(--border-medium);
}

.legend-text {
    color: var(--text-secondary);
}

/* ========== ACTIVE SCALE EFFECT ========== */
.active\:scale-95:active {
    transform: scale(0.95);
}

.active\:scale-98:active {
    transform: scale(0.98);
}

/* ========== RESPONSIVE DESIGN ========== */

/* Extra small devices (phones in portrait) */
@media (max-width: 380px) {
    .calendar-day {
        min-height: 75px;
        padding: 3px;
    }

    .meal-pill {
        font-size: 8px;
        padding: 3px 4px;
        -webkit-line-clamp: 3;
    }

    .day-number {
        font-size: 10px;
    }

    .week-card {
        padding: 6px;
    }

    .week-card-title {
        font-size: 10px;
    }

    .week-card-counts {
        font-size: 11px;
        gap: 4px;
    }

    .theme-toggle {
        padding: 6px 8px;
        font-size: 14px;
    }
}

/* Small devices (phones in landscape, small tablets) */
@media (min-width: 381px) and (max-width: 640px) {
    .calendar-day {
        min-height: 85px;
        padding: 4px;
    }

    .meal-pill {
        font-size: 9px;
        padding: 4px 5px;
        -webkit-line-clamp: 4;
    }

    .day-number {
        font-size: 11px;
    }
}

/* Medium devices (tablets) */
@media (min-width: 641px) and (max-width: 900px) {
    .calendar-day {
        min-height: 100px;
        padding: 6px;
    }

    .meal-pill {
        font-size: 11px;
        padding: 5px 7px;
        -webkit-line-clamp: 3;
    }

    .day-number {
        font-size: 12px;
    }
}

/* Large devices (desktops) */
@media (min-width: 901px) {
    .calendar-day {
        min-height: 110px;
        padding: 8px;
    }

    .meal-pill {
        font-size: 12px;
        padding: 6px 8px;
        -webkit-line-clamp: 3;
        line-height: 1.3;
    }

    .day-number {
        font-size: 13px;
        margin-bottom: 4px;
    }
}

/* ========== PRINT STYLES ========== */
@media print {
    header, #generate-btn, #stats-bar, #week-summaries, .theme-toggle {
        display: none;
    }

    .calendar-day {
        border: 1px solid #ccc !important;
        min-height: 80px;
    }

    .meal-pill {
        font-size: 10px;
        -webkit-line-clamp: none;
    }

    body {
        background: white;
        color: black;
    }
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* Focus states for accessibility */
button:focus-visible,
input:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Loading state */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* Smooth theme transition */
* {
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

/* Disable transitions on page load to prevent flash */
.no-transition * {
    transition: none !important;
}
