/**
 * Health Calendar Component Styles
 * NexGenHealth.io
 *
 * Integrates FullCalendar with NexGenHealth theme system
 * Uses CSS custom properties from theme-variables.css
 */

/* ============================================
   CALENDAR CONTAINER
   ============================================ */

.health-calendar-container {
    background: var(--gradient-bg);
    border: 2px solid var(--border-primary);
    border-radius: 16px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    position: relative;
}

.health-calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-primary);
}

.health-calendar-title {
    color: var(--accent-primary);
    font-size: 1.5rem;
    font-weight: 700;
    font-family: 'Merriweather', serif;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.health-calendar-actions {
    display: flex;
    gap: 0.75rem;
}

.calendar-action-btn {
    background: var(--accent-primary);
    color: var(--text-inverse);
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-family: 'Merriweather', serif;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.calendar-action-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.calendar-action-btn.secondary {
    background: transparent;
    color: var(--accent-primary);
    border: 2px solid var(--accent-primary);
}

.calendar-action-btn.secondary:hover {
    background: var(--accent-light);
}

/* ============================================
   FULLCALENDAR THEME OVERRIDES
   ============================================ */

/* Calendar wrapper - CRITICAL for proper display */
#healthCalendar {
    --fc-border-color: var(--border-primary);
    --fc-button-bg-color: var(--accent-primary);
    --fc-button-border-color: var(--accent-primary);
    --fc-button-hover-bg-color: var(--accent-hover);
    --fc-button-hover-border-color: var(--accent-hover);
    --fc-button-active-bg-color: var(--accent-hover);
    --fc-button-active-border-color: var(--accent-hover);
    --fc-today-bg-color: var(--accent-lighter);
    --fc-neutral-bg-color: var(--bg-secondary);
    --fc-page-bg-color: transparent;
    --fc-event-bg-color: var(--accent-primary);
    --fc-event-border-color: var(--accent-primary);
    --fc-small-font-size: 0.85rem;
    min-height: 500px;
}

/* Ensure calendar table shows all rows */
#healthCalendar .fc-scrollgrid {
    border: none;
}

#healthCalendar .fc-scrollgrid-section-body table {
    height: auto !important;
}

/* Fix daygrid to show all weeks properly */
#healthCalendar .fc-daygrid-body {
    width: 100% !important;
}

#healthCalendar .fc-daygrid-body-balanced .fc-daygrid-day-events {
    min-height: 2em;
}

/* Toolbar */
.fc .fc-toolbar {
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.fc .fc-toolbar-title {
    color: var(--text-primary);
    font-family: 'Merriweather', serif;
    font-size: 1.25rem;
    font-weight: 700;
}

/* Toolbar buttons */
.fc .fc-button {
    font-family: 'Merriweather', serif;
    font-weight: 600;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    text-transform: capitalize;
}

.fc .fc-button-primary:not(:disabled).fc-button-active,
.fc .fc-button-primary:not(:disabled):active {
    background-color: var(--accent-hover);
    border-color: var(--accent-hover);
}

.fc .fc-button-primary:disabled {
    background-color: var(--border-secondary);
    border-color: var(--border-secondary);
    opacity: 0.6;
}

/* Day headers */
.fc .fc-col-header-cell {
    background: var(--bg-tertiary);
    padding: 0.75rem 0;
}

.fc .fc-col-header-cell-cushion {
    color: var(--text-primary);
    font-family: 'Merriweather', serif;
    font-weight: 600;
    text-decoration: none;
}

/* Day cells - Enhanced clickability */
.fc .fc-daygrid-day {
    background: var(--bg-secondary);
    transition: all 0.2s ease;
    min-height: 80px;
}

.fc .fc-daygrid-day.fc-day-clickable:hover {
    background: var(--bg-hover);
    box-shadow: inset 0 0 0 2px var(--accent-primary);
}

.fc .fc-daygrid-day-frame {
    min-height: 80px;
    cursor: pointer;
}

.fc .fc-daygrid-day-top {
    flex-direction: row;
    padding: 0.5rem;
}

.fc .fc-daygrid-day-number {
    color: var(--text-primary);
    font-family: 'Merriweather', serif;
    font-weight: 500;
    padding: 0.25rem 0.5rem;
    text-decoration: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.fc .fc-daygrid-day-number:hover {
    background: var(--accent-primary);
    color: var(--text-inverse);
}

/* Today highlight */
.fc .fc-day-today {
    background: var(--accent-lighter) !important;
}

.fc .fc-day-today .fc-daygrid-day-number {
    background: var(--accent-primary);
    color: var(--text-inverse);
    font-weight: 700;
}

/* Other month days */
.fc .fc-day-other {
    background: var(--bg-tertiary);
}

.fc .fc-day-other .fc-daygrid-day-number {
    color: var(--text-muted);
}

/* Events */
.fc .fc-event {
    border-radius: 4px;
    padding: 2px 6px;
    font-family: 'Merriweather', serif;
    font-size: 0.8rem;
    cursor: pointer;
    border: none;
    margin-bottom: 2px;
}

.fc .fc-event:hover {
    filter: brightness(1.1);
    transform: scale(1.02);
}

.fc .fc-event-title {
    font-weight: 600;
}

.fc .fc-daygrid-event-dot {
    border-color: currentColor;
}

/* Event colors by type */
.fc .fc-event.event-appointment {
    background-color: #3498db;
    border-color: #3498db;
}

.fc .fc-event.event-medication {
    background-color: #00875A;
    border-color: #00875A;
}

.fc .fc-event.event-health-event {
    background-color: #9b59b6;
    border-color: #9b59b6;
}

.fc .fc-event.event-reminder {
    background-color: #f39c12;
    border-color: #f39c12;
}

/* More events link */
.fc .fc-daygrid-more-link {
    color: var(--accent-primary);
    font-weight: 600;
    padding: 2px 4px;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.fc .fc-daygrid-more-link:hover {
    background: var(--accent-lighter);
}

/* Time grid (week/day view) */
.fc .fc-timegrid-slot {
    background: var(--bg-secondary);
    height: 3em;
}

.fc .fc-timegrid-slot-label-cushion {
    color: var(--text-muted);
    font-family: 'Merriweather', serif;
    font-size: 0.8rem;
}

.fc .fc-timegrid-axis-cushion {
    color: var(--text-muted);
}

/* Current time indicator */
.fc .fc-timegrid-now-indicator-line {
    border-color: var(--color-error);
    border-width: 2px;
}

.fc .fc-timegrid-now-indicator-arrow {
    border-color: var(--color-error);
    border-top-color: transparent;
    border-bottom-color: transparent;
}

/* List view */
.fc .fc-list {
    border-color: var(--border-primary);
}

.fc .fc-list-sticky .fc-list-day > * {
    background: var(--bg-tertiary);
}

.fc .fc-list-day-cushion {
    background: var(--bg-tertiary);
}

.fc .fc-list-day-text,
.fc .fc-list-day-side-text {
    color: var(--text-primary);
    font-family: 'Merriweather', serif;
}

.fc .fc-list-event:hover td {
    background: var(--bg-hover);
}

.fc .fc-list-event-title a {
    color: var(--text-primary);
}

.fc .fc-list-event-time {
    color: var(--text-muted);
}

/* ============================================
   DAY DETAIL PANEL
   ============================================ */

.day-detail-panel {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    width: 90%;
    max-width: 400px;
    background: var(--gradient-bg);
    border: 2px solid var(--accent-primary);
    border-radius: 16px;
    box-shadow: var(--shadow-xl);
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.day-detail-panel.active {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}

.day-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-primary);
}

.day-detail-date {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.day-detail-weekday {
    color: var(--accent-primary);
    font-family: 'Merriweather', serif;
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.day-detail-fulldate {
    color: var(--text-primary);
    font-family: 'Merriweather', serif;
    font-size: 1.25rem;
    font-weight: 700;
}

.day-detail-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.75rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: color 0.2s ease;
}

.day-detail-close:hover {
    color: var(--color-error);
}

.day-detail-content {
    padding: 1rem 1.5rem;
    max-height: 300px;
    overflow-y: auto;
}

.day-detail-events {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.day-detail-event {
    background: var(--bg-secondary);
    border-left: 4px solid var(--accent-primary);
    border-radius: 0 8px 8px 0;
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.day-detail-event:hover {
    background: var(--bg-hover);
    transform: translateX(4px);
}

.day-detail-event-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.day-detail-event-icon {
    font-size: 1rem;
}

.day-detail-event-title {
    color: var(--text-primary);
    font-family: 'Merriweather', serif;
    font-weight: 600;
    font-size: 0.95rem;
}

.day-detail-event-time {
    color: var(--text-muted);
    font-family: 'Merriweather', serif;
    font-size: 0.85rem;
}

.day-detail-event-location {
    color: var(--text-secondary);
    font-family: 'Merriweather', serif;
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

.day-detail-empty {
    text-align: center;
    padding: 2rem 1rem;
}

.day-detail-empty p {
    color: var(--text-muted);
    font-family: 'Merriweather', serif;
    font-size: 0.95rem;
    margin: 0;
}

.day-detail-footer {
    display: flex;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-primary);
}

.day-detail-add-btn,
.day-detail-view-btn {
    flex: 1;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-family: 'Merriweather', serif;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.day-detail-add-btn {
    background: var(--accent-primary);
    color: var(--text-inverse);
    border: none;
}

.day-detail-add-btn:hover {
    background: var(--accent-hover);
}

.day-detail-add-btn span {
    font-size: 1.2rem;
    font-weight: 700;
}

.day-detail-view-btn {
    background: transparent;
    color: var(--accent-primary);
    border: 2px solid var(--accent-primary);
}

.day-detail-view-btn:hover {
    background: var(--accent-lighter);
}

/* ============================================
   EVENT LEGEND
   ============================================ */

.calendar-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-primary);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-family: 'Merriweather', serif;
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

.legend-color.appointment {
    background-color: #3498db;
}

.legend-color.medication {
    background-color: #00875A;
}

.legend-color.health-event {
    background-color: #9b59b6;
}

.legend-color.reminder {
    background-color: #f39c12;
}

/* ============================================
   ADD EVENT MODAL
   ============================================ */

.calendar-modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-backdrop);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    padding: 2rem;
}

.calendar-modal-overlay.active {
    display: flex;
}

.calendar-modal {
    background: var(--gradient-bg);
    border: 2px solid var(--border-primary);
    border-radius: 16px;
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
}

.calendar-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-primary);
}

.calendar-modal-title {
    color: var(--accent-primary);
    font-size: 1.25rem;
    font-weight: 700;
    font-family: 'Merriweather', serif;
    margin: 0;
}

.calendar-modal-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
    transition: color 0.3s ease;
}

.calendar-modal-close:hover {
    color: var(--color-error);
}

.calendar-modal-body {
    padding: 1.5rem;
}

.calendar-form-group {
    margin-bottom: 1.25rem;
}

.calendar-form-label {
    display: block;
    color: var(--text-primary);
    font-family: 'Merriweather', serif;
    font-weight: 600;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.calendar-form-input,
.calendar-form-select,
.calendar-form-textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--input-bg);
    border: 2px solid var(--input-border);
    border-radius: 8px;
    color: var(--input-text);
    font-family: 'Merriweather', serif;
    font-size: 0.95rem;
    transition: border-color 0.3s ease;
}

.calendar-form-input:focus,
.calendar-form-select:focus,
.calendar-form-textarea:focus {
    outline: none;
    border-color: var(--input-border-focus);
}

.calendar-form-textarea {
    min-height: 100px;
    resize: vertical;
}

.calendar-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.calendar-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    padding: 1.5rem;
    border-top: 1px solid var(--border-primary);
}

.calendar-btn {
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-family: 'Merriweather', serif;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.calendar-btn-primary {
    background: var(--accent-primary);
    color: var(--text-inverse);
    border: none;
}

.calendar-btn-primary:hover {
    background: var(--accent-hover);
}

.calendar-btn-secondary {
    background: transparent;
    color: var(--text-muted);
    border: 2px solid var(--border-primary);
}

.calendar-btn-secondary:hover {
    border-color: var(--text-muted);
    color: var(--text-primary);
}

.calendar-btn-danger {
    background: transparent;
    color: var(--color-error);
    border: 2px solid var(--color-error);
}

.calendar-btn-danger:hover {
    background: var(--color-error-bg);
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    .health-calendar-container {
        padding: 1rem;
    }

    .health-calendar-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .health-calendar-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .fc .fc-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .fc .fc-toolbar-chunk {
        display: flex;
        justify-content: center;
    }

    .fc .fc-button {
        padding: 0.4rem 0.8rem;
        font-size: 0.85rem;
    }

    .fc .fc-daygrid-day {
        min-height: 60px;
    }

    .fc .fc-daygrid-day-frame {
        min-height: 60px;
    }

    .calendar-form-row {
        grid-template-columns: 1fr;
    }

    .calendar-modal {
        margin: 1rem;
        max-height: calc(100vh - 2rem);
    }

    .day-detail-panel {
        width: 95%;
        max-width: none;
    }

    .day-detail-footer {
        flex-direction: column;
    }
}

/* ============================================
   LARGE TEXT MODE SUPPORT
   ============================================ */

.large-text .health-calendar-title {
    font-size: var(--font-size-2xl);
}

.large-text .fc .fc-toolbar-title {
    font-size: var(--font-size-xl);
}

.large-text .fc .fc-button {
    font-size: var(--font-size-base);
    padding: 0.625rem 1.25rem;
}

.large-text .fc .fc-daygrid-day-number {
    font-size: var(--font-size-base);
}

.large-text .fc .fc-event {
    font-size: var(--font-size-sm);
}

.large-text .calendar-form-label {
    font-size: var(--font-size-base);
}

.large-text .calendar-form-input,
.large-text .calendar-form-select,
.large-text .calendar-form-textarea {
    font-size: var(--font-size-base);
}

.large-text .day-detail-fulldate {
    font-size: var(--font-size-xl);
}

.large-text .day-detail-event-title {
    font-size: var(--font-size-base);
}

/* ============================================
   HIGH CONTRAST MODE SUPPORT
   ============================================ */

.high-contrast .health-calendar-container {
    border-width: 3px;
}

.high-contrast .fc .fc-daygrid-day {
    border-width: 2px;
}

.high-contrast .fc .fc-event {
    border-width: 2px;
    font-weight: 700;
}

.high-contrast .fc .fc-button {
    border-width: 2px;
}

.high-contrast .day-detail-panel {
    border-width: 3px;
}

.high-contrast .day-detail-event {
    border-left-width: 6px;
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    .health-calendar-actions,
    .day-detail-panel,
    .calendar-modal-overlay {
        display: none !important;
    }

    .health-calendar-container {
        border: 1px solid #000;
        box-shadow: none;
    }

    .fc .fc-button {
        display: none;
    }
}
