/*
 * Copyright (c) 2026 Write Words - Make Magic, LLC. All rights reserved.
 * SPDX-License-Identifier: LicenseRef-Proprietary
 */

.calendar-widget {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    max-width: 900px;
    width: 100%;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.01);
    transition: max-width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Widens the widget when a schedule is loaded on desktop screens */
@media (min-width: 920px) {
    .calendar-widget.has-schedule {
        max-width: 1220px;
    }
}

.search-row {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    align-items: center;
}

.search-input-container {
    position: relative;
    display: flex;
    align-items: center;
    flex-grow: 1;
    width: 100%;
}

.search-input-container input[type="text"] {
    width: 100%;
    padding-right: 32px;
    box-sizing: border-box;
}

.btn-clear-search {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--text-secondary, #94a3b8);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    padding: 3px 6px;
    line-height: 1;
    border-radius: 4px;
    display: none;
    transition: color 0.15s ease, background-color 0.15s ease;
    user-select: none;
}

.btn-clear-search:hover {
    color: var(--text-primary, #f1f5f9);
    background-color: rgba(255, 255, 255, 0.12);
}

.btn-clear-search.visible {
    display: block;
}

.search-buttons-group {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

@media (max-width: 600px) {
    .search-row {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .search-input-container {
        width: 100%;
    }

    .search-input-container input[type="text"] {
        width: 100%;
    }

    .search-buttons-group {
        display: flex;
        gap: 8px;
        width: 100%;
    }

    .search-buttons-group button {
        flex: 1;
        text-align: center;
        justify-content: center;
    }
}

/* Two-Column Responsive Layout */
.widget-content-layout {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.schedule-sidebar,
.calendar-pane {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    box-sizing: border-box;
}

@media (min-width: 920px) {
    .has-schedule .widget-content-layout {
        display: grid;
        grid-template-columns: 340px 1fr;
        gap: 20px;
        align-items: stretch;
    }

    .has-schedule .schedule-sidebar {
        display: flex;
        flex-direction: column;
        min-width: 0;
        height: 100%;
    }

    .has-schedule .schedule-sidebar .event-list {
        flex: 1 1 0px;
        max-height: none;
        height: 0;
        min-height: 0;
        overflow-y: auto;
    }

    .has-schedule .calendar-pane {
        display: flex;
        flex-direction: column;
        min-width: 0;
    }
}

.actions-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 10px;
    margin-bottom: 20px;
    width: 100%;
}

.btn-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--btn-secondary-bg);
    color: var(--text);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
    text-align: center;
    box-sizing: border-box;
}

.btn-action:hover {
    background: var(--border);
}

/* Sidebar Header */
.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    min-height: 33px;
}

.match-count-badge {
    font-size: 0.76rem;
    font-weight: 600;
    background: var(--match-badge-bg);
    color: var(--text-muted);
    padding: 3px 8px;
    border-radius: 12px;
    border: 1px solid var(--border);
}

/* Events List */
.event-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 480px;
    overflow-y: auto;
    padding-right: 6px;
    padding-top: 6px;
    flex: 1;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.event-list::-webkit-scrollbar {
    width: 6px;
}

.event-list::-webkit-scrollbar-track {
    background: transparent;
}

.event-list::-webkit-scrollbar-thumb {
    background-color: var(--border);
    border-radius: 4px;
}

.event-list::-webkit-scrollbar-thumb:hover {
    background-color: var(--text-muted);
}

.event-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    background: var(--bg-sub);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: stretch;
    transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
    position: relative;
}

.event-card.has-media-actions {
    padding-bottom: 12px;
}

.event-card:hover {
    background: var(--bg-sub-hover);
    border-color: var(--text-muted);
    transform: translateY(-1px);
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.08);
}

.event-card.highlighted {
    border-color: var(--primary);
    background: var(--primary-light);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.event-card.holiday-card {
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-left: 4px solid #f59e0b;
}

[data-theme="dark"] .event-card.holiday-card {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-left: 4px solid #f59e0b;
}

.event-card.holiday-card .event-details strong {
    color: #92400e;
}

[data-theme="dark"] .event-card.holiday-card .event-details strong {
    color: #fde68a;
}

.event-details strong {
    display: block;
    font-size: 0.92rem;
    margin-bottom: 2px;
    color: var(--text-strong);
}

.event-details span {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.btn-event-camera,
.btn-event-image,
.btn-event-scores {
    background: var(--bg-surface, rgba(25, 25, 25, 1));
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 8px;
    width: 34px;
    height: 34px;
    padding: 0;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.15s ease;
    text-decoration: none;
    box-sizing: border-box;
}

body.ctrl-down .btn-event-camera {
    display: inline-flex;
    position: absolute;
    right: 8px;
    top: 2px;
}

body.ctrl-down .btn-event-image {
    display: inline-flex;
    position: absolute;
    right: 8px;
    top: 37px;
}

body.ctrl-down .btn-event-scores {
    display: inline-flex;
    position: absolute;
    right: 8px;
    top: 72px;
}

.btn-event-camera:hover,
.btn-event-image:hover,
.btn-event-scores:hover {
    color: var(--primary, #3b82f6);
    border-color: var(--primary, #3b82f6);
    transform: scale(1.06);
}

.btn-event-camera:active,
.btn-event-image:active,
.btn-event-scores:active {
    transform: scale(0.95);
}

.btn-event-replay {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    background: rgba(168, 85, 247, 0.12);
    border: 1px solid rgba(168, 85, 247, 0.35);
    color: #c084fc;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
    width: auto;
    box-sizing: border-box;
}

.btn-event-replay:hover {
    background: rgba(168, 85, 247, 0.25);
    border-color: #c084fc;
    color: #ffffff;
    box-shadow: 0 0 10px rgba(192, 132, 252, 0.3);
    transform: translateY(-1px);
}

.btn-event-replay:active {
    transform: translateY(0);
}

.btn-event-video {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.38);
    color: #f87171;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
    width: auto;
    box-sizing: border-box;
}

.btn-event-video:hover {
    background: rgba(239, 68, 68, 0.26);
    border-color: #fca5a5;
    color: #ffffff;
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.35);
    transform: translateY(-1px);
}

.btn-event-video:active {
    transform: translateY(0);
}

[data-theme="light"] .btn-event-video {
    background: #fef2f2;
    border-color: #fca5a5;
    color: #dc2626;
}

[data-theme="light"] .btn-event-video:hover {
    background: #dc2626;
    border-color: #b91c1c;
    color: #ffffff;
    box-shadow: 0 0 8px rgba(220, 38, 38, 0.25);
}

.event-bottom-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    box-sizing: border-box;
}

[data-theme="light"] .event-bottom-actions {
    border-top-color: rgba(0, 0, 0, 0.08);
}

.event-bottom-actions .btn-event-video {
    margin-right: auto;
}

.event-bottom-actions .btn-event-replay {
    margin-left: auto;
}

.status-item {
    list-style: none;
    padding: 16px 0;
    text-align: center;
    font-size: 0.92rem;
    color: var(--text-muted);
}

.status-error {
    color: #ef4444;
}

/* Visual Month-to-Month Calendar */
.cal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    min-height: 33px;
}

.cal-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-strong);
}

.cal-nav-buttons {
    display: flex;
    gap: 6px;
}

.btn-cal-nav {
    background: var(--btn-nav-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 5px 9px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--text);
    transition: background 0.15s, border-color 0.15s;
}

.btn-cal-nav:hover {
    background: var(--border);
    border-color: var(--text-muted);
}

.cal-grid-weekdays {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: 6px;
    width: 100%;
    box-sizing: border-box;
}

.cal-grid-weekdays div {
    text-align: center;
    font-size: 0.74rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    padding: 6px 0;
    border-radius: 6px;
    background: var(--cal-weekday-bg);
    letter-spacing: 0.03em;
    box-sizing: border-box;
}

.cal-grid-days {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 6px;
    width: 100%;
    box-sizing: border-box;
}

.calendar-pane {
    padding-left: 28px;
    box-sizing: border-box;
}

.cal-day-cell {
    min-height: 74px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 5px 6px;
    background: var(--cal-cell-bg);
    display: flex;
    flex-direction: column;
    min-width: 0;
    box-sizing: border-box;
    overflow: visible;
    position: relative;
    transition: background-color 0.15s, border-color 0.15s;
}

.cal-day-cell:hover {
    border-color: var(--text-muted);
}

.cal-day-cell.other-month {
    background: var(--cal-cell-other);
    opacity: 0.42;
}

.cal-day-cell.today {
    border-color: var(--primary);
    background: var(--cal-today-bg);
    box-shadow: inset 0 0 0 1px var(--primary);
}

.cal-day-number {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 2px;
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.cal-day-cell.today .cal-day-number {
    background: var(--primary);
    color: #ffffff;
    font-weight: 700;
}

/* Day and Week Gallery Buttons (visible on Ctrl key down) */
.btn-day-gallery {
    display: none;
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    padding: 0;
    background: var(--bg-surface, rgba(25, 25, 25, 0.92));
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 4px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s ease;
    z-index: 10;
    box-sizing: border-box;
}

.btn-week-gallery {
    display: none;
    position: absolute;
    left: -26px;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    padding: 0;
    background: var(--bg-surface, rgba(25, 25, 25, 0.92));
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 5px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s ease;
    z-index: 15;
    box-sizing: border-box;
}

body.ctrl-down .btn-day-gallery {
    display: inline-flex;
}

body.ctrl-down .btn-week-gallery {
    display: inline-flex;
}

.btn-day-gallery:hover,
.btn-week-gallery:hover {
    color: var(--primary, #3b82f6);
    border-color: var(--primary, #3b82f6);
    transform: scale(1.15);
}

.btn-week-gallery:hover {
    transform: translateY(-50%) scale(1.15);
}

.btn-day-gallery:active,
.btn-week-gallery:active {
    transform: scale(0.95);
}

.btn-week-gallery:active {
    transform: translateY(-50%) scale(0.95);
}

.cal-event-pill {
    background: var(--pill-bg);
    border: 1px solid var(--pill-border);
    color: var(--pill-text);
    border-radius: 4px;
    padding: 2px 5px;
    font-size: 0.69rem;
    font-weight: 600;
    margin-top: 2px;
    line-height: 1.25;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    transition: background-color 0.15s, color 0.15s, border-color 0.15s, transform 0.1s;
}

.cal-event-pill:hover {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
    transform: translateY(-1px);
}

.cal-event-pill.cal-holiday-pill {
    background: #fef3c7;
    border-color: #fcd34d;
    color: #92400e;
    font-weight: 700;
}

[data-theme="dark"] .cal-event-pill.cal-holiday-pill {
    background: rgba(245, 158, 11, 0.22);
    border-color: rgba(245, 158, 11, 0.5);
    color: #fde68a;
}

.cal-event-pill.cal-holiday-pill:hover {
    background: #f59e0b;
    border-color: #d97706;
    color: #ffffff;
}

.cal-event-pill.cal-emn-pill {
    background: linear-gradient(135deg, #7c3aed, #9333ea);
    border: 1px solid rgba(192, 132, 252, 0.4);
    color: #ffffff;
    font-weight: 700;
    box-shadow: 0 1px 3px rgba(124, 58, 237, 0.3);
}

.cal-event-pill.cal-emn-pill:hover {
    background: linear-gradient(135deg, #6d28d9, #7e22ce);
    border-color: #c084fc;
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.5);
    transform: translateY(-1px);
}

.cal-event-pill.cal-video-pill {
    background: rgba(239, 68, 68, 0.14);
    border: 1px solid rgba(239, 68, 68, 0.45);
    color: #fca5a5;
    font-weight: 600;
}

[data-theme="light"] .cal-event-pill.cal-video-pill {
    background: #fef2f2;
    border-color: #fca5a5;
    color: #b91c1c;
}

.cal-event-pill.cal-video-pill:hover {
    background: rgba(220, 38, 38, 0.32);
    border-color: #f87171;
    color: #ffffff;
    box-shadow: 0 1px 6px rgba(239, 68, 68, 0.35);
    transform: translateY(-1px);
}

.cal-event-pill.cal-emn-pill.cal-video-pill {
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.9), rgba(220, 38, 38, 0.85));
    border: 1px solid rgba(248, 113, 113, 0.55);
    color: #ffffff;
    box-shadow: 0 1px 4px rgba(220, 38, 38, 0.3);
}

.cal-event-pill.cal-emn-pill.cal-video-pill:hover {
    background: linear-gradient(135deg, #7c3aed, #dc2626);
    border-color: #fca5a5;
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.5);
}

.cal-day-cell.other-month .cal-event-pill,
.cal-event-pill.other-month-pill {
    opacity: 0.45;
    filter: grayscale(40%);
    cursor: pointer;
}

.cal-day-cell.other-month .cal-event-pill:hover,
.cal-event-pill.other-month-pill:hover {
    opacity: 0.9;
    filter: none;
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
}

.cal-day-cell.other-month .cal-event-pill.cal-holiday-pill:hover,
.cal-event-pill.other-month-pill.cal-holiday-pill:hover {
    background: #f59e0b;
    border-color: #d97706;
    color: #ffffff;
}

.hidden {
    display: none !important;
}

/* Mobile Responsiveness down to 350px */
@media (max-width: 480px) {
    body {
        padding: 14px 6px;
    }

    .calendar-widget {
        padding: 16px 10px;
        border-radius: 12px;
    }

    .schedule-sidebar,
    .calendar-pane {
        padding: 12px 8px;
    }

    .cal-day-cell {
        min-height: 56px;
        padding: 3px 2px;
    }

    .cal-day-number {
        font-size: 0.7rem;
        width: 16px;
        height: 16px;
    }

    .cal-event-pill {
        font-size: 0.62rem;
        padding: 1px 3px;
    }
}

/* Standalone Image Viewer & Gallery Modes */
.image-viewer-container {
    width: 100%;
    max-width: 1300px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
    box-sizing: border-box;
}

.image-viewer-toolbar {
    width: 100%;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-surface, #1e293b);
    border: 1px solid var(--border, rgba(255, 255, 255, 0.1));
    border-radius: 12px;
    padding: 12px 18px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    flex-wrap: wrap;
    gap: 10px;
}

.image-viewer-toolbar h4 {
    margin: 0;
    font-size: 1.05rem;
    color: var(--text-main, #f8fafc);
    font-weight: 600;
    word-break: break-word;
}

.image-viewer-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.btn-viewer-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--bg-secondary, rgba(255, 255, 255, 0.08));
    border: 1px solid var(--border, rgba(255, 255, 255, 0.12));
    border-radius: 8px;
    color: var(--text-main, #f8fafc);
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s ease;
}

.btn-viewer-action:hover {
    background: var(--primary, #3b82f6);
    border-color: var(--primary, #3b82f6);
    color: #ffffff;
    transform: translateY(-1px);
}

.btn-viewer-primary {
    background: var(--primary, #3b82f6);
    border-color: var(--primary, #3b82f6);
    color: #ffffff;
}

.btn-viewer-primary:hover {
    background: #2563eb;
    border-color: #2563eb;
}

.image-card-display {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(10, 15, 29, 0.6);
    border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    overflow: hidden;
}

.image-card-display canvas,
.image-card-display img {
    max-width: 100%;
    height: auto;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    display: block;
}

/* Gallery Grid View */
.gallery-grid {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 380px), 1fr));
    gap: 20px;
}

.gallery-card-item {
    background: var(--bg-surface, #1e293b);
    border: 1px solid var(--border, rgba(255, 255, 255, 0.1));
    border-radius: 14px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
    transition: transform 0.15s ease, border-color 0.15s ease;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    overflow: hidden;
}

.gallery-card-item:hover {
    border-color: var(--primary, #3b82f6);
    transform: translateY(-2px);
}

.gallery-card-preview {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    border-radius: 10px;
    overflow: hidden;
    background: #0a0f1d;
    display: flex;
    justify-content: center;
    align-items: center;
}

.gallery-card-preview canvas,
.gallery-card-preview img {
    max-width: 100%;
    width: 100%;
    height: auto;
    display: block;
    object-fit: contain;
}

.gallery-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

.gallery-card-title {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-main, #f8fafc);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    flex: 1;
}