/* CSS Reset & Variables */
:root {
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --bg-hover: #f1f5f9;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --accent: #0ea5e9;
    --border: #e2e8f0;

    --font-main: 'Inter', sans-serif;

    --transition: all 0.2s ease;

    /* Sports Colors */
    --sport-football: #3B82F6;
    --sport-tennis: #EAB308;
    --sport-f1: #EF4444;
    --sport-motogp: #F97316;
    --sport-basketball: #F59E0B;
    --sport-cycling: #10B981;
    --sport-athletics: #8B5CF6;
    --sport-olympics: #0EA5E9;
    --sport-football-us: #881337;
    --sport-default: #64748B;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-body);
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* App Container */
.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 20px;
    /* Ensure visibility against any background */
    position: relative;
    z-index: 1;
}

/* Ensure controls are visible */
.view-switcher,
.filter-bar,
.month-container {
    background-color: var(--bg-card);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Modal Fix */
.modal {
    display: none;
    position: fixed;
    /* RESTORED */
    z-index: 9999;
    /* Ensure high z-index */
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
}

/* Header */
.main-header {
    background-color: var(--bg-card);
    padding: 20px;
    border-radius: 16px;
    box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    border: 1px solid var(--border);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 15px;
}

.logo-icon {
    font-size: 2rem;
    color: var(--accent);
}

h1 {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* Controls */
.view-switcher {
    display: flex;
    background: var(--bg-hover);
    padding: 4px;
    border-radius: 12px;
}

.view-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    transition: var(--transition);
}

.view-btn:hover {
    color: var(--text-primary);
}

.view-btn.active {
    background-color: var(--bg-card);
    color: var(--accent);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Filter Bar */
/* Amazon/Real-Estate Style Filter Bar */
.filter-bar {
    display: flex;
    flex-direction: column;
    gap: 15px;
    background-color: var(--bg-hover);
    padding: 15px;
    border-radius: 12px;
    border: 1px solid var(--border);
    margin-bottom: 30px;
}

/* Row 1: Search and Main Action */
.search-row {
    display: flex;
    gap: 10px;
    width: 100%;
}

.search-wrapper {
    position: relative;
    flex-grow: 1;
}

.search-wrapper i {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    pointer-events: none;
    /* Prevent interaction handling issues */
    z-index: 10;
    /* Ensure it stays above input but below dropdown if needed */
}

.search-wrapper input {
    width: 100%;
    padding: 12px 15px 12px 45px;
    background-color: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    /* Slightly more rounded */
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
    transition: var(--transition);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.search-wrapper input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.2);
}

/* Row 2: Faceted Filters */
.filters-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: center;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.filter-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.filter-select {
    padding: 8px 30px 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background-color: white;
    font-size: 0.9rem;
    color: var(--text-primary);
    cursor: pointer;
    min-width: 150px;
    /* Custom Arrow */
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%2364748b'%3E%3Cpath fill-rule='evenodd' d='M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z' clip-rule='evenodd'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.7rem center;
    background-size: 1.2em;
    transition: var(--transition);
}

.filter-select:hover {
    border-color: #cbd5e1;
}

.filter-select:focus {
    border-color: var(--accent);
    outline: none;
}

/* Quick Access Tags */
.quick-tags {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.quick-tag {
    padding: 6px 12px;
    background-color: white;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    border-color: var(--sport-color, var(--border));
    color: var(--sport-color, var(--text-secondary));
    opacity: 0.8;
}

.quick-tag:hover {
    background-color: var(--bg-hover);
    opacity: 1;
    transform: translateY(-1px);
}

.quick-tag.active {
    background-color: var(--sport-color, var(--accent));
    border-color: var(--sport-color, var(--accent));
    color: white;
    opacity: 1;
}

.toggle-group {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-direction: row;
    /* Horizontal for toggle */
    background: white;
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid var(--border);
}

.toggle-group span {
    font-size: 0.9rem;
    font-weight: 500;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #cbd5e1;
    transition: .4s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--accent);
}

input:checked+.slider:before {
    transform: translateX(26px);
}

/* Calendar Views */

/* Year View */
.year-view {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.month-container {
    background-color: var(--bg-card);
    border-radius: 12px;
    padding: 15px;
    border: 1px solid var(--border);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    height: 100%;
    /* Ensure full height in grid */
}

.month-name {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 12px;
    text-align: center;
    color: var(--text-primary);
    text-transform: capitalize;
}

.month-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    text-align: center;
}

.day-header {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    padding-bottom: 8px;
    display: flex;
    /* Flexbox */
    justify-content: center;
    /* Center Horizontal */
    align-items: center;
    /* Center Vertical */
}

.day {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* Changed from flex-start to center for better alignment */
    padding-top: 0;
    /* Remove top padding if centering */
    font-size: 0.85rem;
    border-radius: 8px;
    cursor: pointer;
    position: relative;
    transition: var(--transition);
    color: var(--text-primary);
}

.day:hover {
    background-color: var(--bg-hover);
}

.day.today {
    background-color: var(--bg-hover);
    font-weight: 700;
    border: 1px solid var(--accent);
}

/* Event Dots Scaling */
.event-dots {
    display: flex;
    position: absolute;
    gap: 3px;
    margin-top: 25px;
    justify-content: center;
    flex-wrap: wrap;
    max-width: 90%;
    align-items: flex-end;
    /* Align to bottom */
    height: 12px;
    /* Fixed height to prevents shift */
}

.dot {
    border-radius: 50%;
    transition: var(--transition);
    background-color: var(--sport-default);
    /* Retained from original */
}

/* Scaling Logic */
.event-dots[data-count="1"] .dot {
    width: 10px;
    height: 10px;
}

.event-dots[data-count="2"] .dot {
    width: 8px;
    height: 8px;
}

.event-dots[data-count="3"] .dot,
.event-dots[data-count="4"] .dot {
    width: 6px;
    height: 6px;
}

/* Default fallback for many dots */
.dot {
    width: 5px;
    height: 5px;
}

/* Month View (Single Large Month) */
.month-view {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.month-navigation {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-card);
    padding: 15px;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.nav-btn {
    background: none;
    border: 1px solid var(--border);
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    color: var(--text-primary);
}

.nav-btn:hover {
    background-color: var(--bg-hover);
}

.large-month-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 1px;
    background-color: var(--border);
    /* Borders between cells */
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.large-day-header {
    background-color: var(--bg-card);
    padding: 15px;
    text-align: center;
    font-weight: 600;
    color: var(--text-secondary);
}

.large-day-cell {
    background-color: var(--bg-card);
    min-height: 120px;
    padding: 8px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.large-day-cell.disabled {
    background-color: #e2e8f0;
    cursor: default;
}

.large-day-cell:hover {
    background-color: #f8fafc;
}

.large-day-number {
    font-weight: 600;
    margin-bottom: 5px;
    color: var(--text-secondary);
}

.large-day-cell.today .large-day-number {
    color: var(--accent);
}

.event-pill {
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
    color: white;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

/* Week View Simplified */
.week-view {
    display: flex;
    flex-direction: column;
    gap: 20px;
    height: calc(100vh - 200px);
}

.week-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    /* 7 equal columns */
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    flex: 1;
}

.week-day-column {
    background-color: var(--bg-card);
    display: flex;
    flex-direction: column;
}

.week-day-header {
    padding: 15px 10px;
    text-align: center;
    background-color: var(--bg-hover);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    color: var(--text-primary);
}

.week-day-content {
    flex: 1;
    padding: 10px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.week-event-card {
    background: white;
    border: 1px solid var(--border);
    border-left-width: 4px;
    /* Color indicator */
    border-radius: 6px;
    padding: 8px;
    font-size: 0.8rem;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    transition: transform 0.1s;
}

.week-event-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* Modal Active State */
.modal.active {
    display: flex;
}

.modal-content {
    background-color: var(--bg-card);
    border-radius: 16px;
    border: 1px solid var(--border);
    width: 90%;
    max-width: 500px;
    padding: 0;
    /* Changed for separation of header/body */
    position: relative;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    animation: modalSlideIn 0.3s ease;
    overflow: hidden;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.close-modal {
    position: absolute;
    right: 20px;
    top: 20px;
    font-size: 1.5rem;
    color: white;
    z-index: 10;
    cursor: pointer;
    text-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
}

.modal-header-bg {
    background-color: var(--accent);
    padding: 40px 30px 30px;
    color: white;
    position: relative;
    background-size: cover;
    background-position: center;
    overflow: hidden;
}

/* Overlay for text readability when image is present */
.modal-header-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.7));
    z-index: 1;
}

.modal-header-content {
    position: relative;
    z-index: 2;
    /* Above overlay */
}

.sport-tag {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    background-color: rgba(255, 255, 255, 0.25);
    color: white;
    margin-bottom: 15px;
    text-transform: uppercase;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

#modal-title {
    font-size: 1.5rem;
    line-height: 1.2;
    font-weight: 700;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.modal-body {
    padding: 30px;
}

.info-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

.info-row i {
    width: 20px;
    text-align: center;
    color: var(--text-primary);
}

.description {
    margin-top: 25px;
    color: var(--text-primary);
    line-height: 1.7;
    border-top: 1px solid var(--border);
    padding-top: 20px;
}

/* Multi-Event List Modal */
.event-list-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background-color 0.2s;
}

.event-list-item:hover {
    background-color: var(--bg-hover);
}

.event-list-item:last-child {
    border-bottom: none;
}

.list-event-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.list-event-info h4 {
    font-size: 1rem;
    margin-bottom: 2px;
    color: var(--text-primary);
}

.list-event-info span {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Search Results Improved (Global) */
.search-results {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    width: 100%;
    background: white;
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    z-index: 100;
    /* Higher z-index */
    display: none;
    max-height: 400px;
    overflow-y: auto;
    padding: 8px 0;
}

.search-results.active {
    display: block;
    animation: slideDown 0.2s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.search-item {
    padding: 12px 20px;
    cursor: pointer;
    border-bottom: 1px solid var(--bg-hover);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
    transition: background-color 0.15s ease;
}

.search-item:last-child {
    border-bottom: none;
}

.search-item:hover {
    background-color: #f8fafc;
}

.search-item-info {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    min-width: 0;
    margin-right: 15px;
}

.search-item-title {
    font-weight: 600;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.search-item-date {
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.search-item .sport-tag {
    margin-bottom: 0 !important;
}

/* Responsive */
@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        align-items: flex-start;
    }

    .view-switcher {
        width: 100%;
        overflow-x: auto;
    }

    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .year-view {
        grid-template-columns: 1fr;
    }

    .large-day-header {
        font-size: 0.8rem;
        padding: 10px 0;
    }

    .large-day-cell {
        min-height: 80px;
    }
}

/* Search Results Improved (Mobile Overrides) */
@media (max-width: 768px) {
    .search-results {
        top: 100%;
        background: var(--bg-card);
        border-radius: 8px;
        margin-top: 5px;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
        z-index: 50;
        max-height: 300px;
    }

    .search-item {
        padding: 10px 15px;
        border-bottom: 1px solid var(--border);
        background: var(--bg-card);
        /* Ensure it uses card background on mobile */
    }

    .search-item:hover {
        background-color: var(--bg-hover);
    }

    .search-item-info {
        margin-right: 10px;
    }

    .search-item-title {
        font-size: 0.9rem;
    }
}