﻿/* =========================================================
   GLOBAL LAYOUT
========================================================= */

body {
    margin: 0;
    padding: 0;
    background: #eef2f7;
    font-family: 'Segoe UI', Roboto, Arial, sans-serif;
    overflow-x: hidden;
}

#calendar-container {
    position: relative;
    max-width: 1200px;
    margin: 20px auto;
    padding-bottom: 60px; /* space for footer */
}

#calendar {
    background: #ffffff;
    padding: 20px;
    border-radius: 16px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.08);
    min-height: 500px;
    margin-top: 10px;
}


/* =========================================================
   STICKY HEADER SYSTEM (FILTERS + CALENDAR TOOLBAR)
========================================================= */

/* Filter bar (top layer) */
#calendar-filters {
    position: sticky;
    top: 0;
    z-index: 1000;

    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;

    padding: 10px 12px;

    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(6px);
    border-bottom: 1px solid #e2e8f0;
}

/* Calendar toolbar (second sticky layer) */



/* =========================================================
   FILTERS + SEARCH
========================================================= */

#calendar-filters label {
    background: #f1f5f9;
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s ease;
}

#calendar-filters input[type="checkbox"] {
    accent-color: #4f46e5;
}

#search-box {
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid #cbd5f5;
    font-size: 13px;
    outline: none;
    min-width: 200px;
}

#search-box:focus {
    border-color: #4f46e5;
    box-shadow: 0 0 0 2px rgba(79,70,229,0.15);
}

.filter-active { color: #3b82f6; }
.filter-accepted { color: #16a34a; }
.filter-cancelled { color: #f59e0b; }
.filter-rejected { color: #ef4444; }


/* =========================================================
   FULLCALENDAR BUTTON STYLING
========================================================= */

.fc .fc-button-group {
    display: flex;
    gap: 6px;
}

.fc .fc-button {
    background: #f1f5f9 !important;
    border: none !important;
    color: #334155 !important;
    padding: 6px 12px !important;
    border-radius: 10px !important;
    font-size: 13px !important;
    font-weight: 500;
    transition: all 0.2s ease;
}

.fc .fc-button:hover {
    background: #e2e8f0 !important;
}

.fc .fc-button-active {
    background: #4f46e5 !important;
    color: #ffffff !important;
}

.fc .fc-today-button {
    background: #e0f2fe !important;
    color: #0369a1 !important;
}

.fc .fc-prev-button,
.fc .fc-next-button {
    border-radius: 50% !important;
    width: 34px;
    height: 34px;
    padding: 0 !important;
}

/* Replace default arrows */
.fc .fc-prev-button span,
.fc .fc-next-button span {
    display: none;
}

.fc .fc-prev-button::after {
    content: "\2039";
    font-size: 18px;
}

.fc .fc-next-button::after {
    content: "\203A";
    font-size: 18px;
}


/* =========================================================
   FOOTER (STATUS BAR)
========================================================= */

#calendar-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 999;

    padding: 12px 20px;
    display: flex;
    justify-content: space-around;

    font-size: 13px;
    color: #64748b;

    background: #ffffff;
    border-top: 1px solid #e2e8f0;
    box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.05);
}

#countdown {
    font-weight: bold;
    color: #4f46e5;
}

.footer-label {
    font-weight: 600;
}

#last-updated-text {
    margin-left: 6px;
    color: #16a34a;
    font-size: 12px;
}

#sync-status {
    margin-left: 8px;
    font-size: 12px;
    color: #f59e0b;
}

.footer-counts {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.count-accepted { color: #16a34a; }
.count-active { color: #3b82f6; }
.count-cancelled { color: #f59e0b; }
.count-rejected { color: #ef4444; }

.footer-server {
    display: flex;
    align-items: center;
    gap: 8px;
}

#server-latency,
#build-meta {
    font-size: 12px;
    color: #64748b;
}


/* =========================================================
   SERVER STATUS INDICATOR
========================================================= */

#server-status-dot {
    width: 10px;
    height: 10px;
    background-color: #22c55e;
    border-radius: 50%;
    position: relative;
    flex-shrink: 0;
}

/* Pulse effect */
#server-status-dot::after {
    content: "";
    position: absolute;
    top: -4px;
    left: -4px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(34, 197, 94, 0.4);
    animation: heartbeat 1.5s infinite;
}

/* Offline state */
#server-status-dot.offline {
    background-color: #ef4444;
}

#server-status-dot.offline::after {
    background: rgba(239, 68, 68, 0.4);
}


/* =========================================================
   MODAL
========================================================= */

#event-modal {
    display: none;
    position: fixed;
    z-index: 1001;
    inset: 0;

    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);

    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    padding: 25px;
    border-radius: 15px;
    width: 85%;
    max-width: 450px;
    position: relative;

    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    animation: fadeIn 0.2s ease;
}

.modal-header {
    border-bottom: 1px solid #f1f5f9;
    padding-bottom: 12px;
    margin-bottom: 15px;
}

.modal-body p {
    margin: 10px 0;
    color: #334155;
    font-size: 14px;
    line-height: 1.6;
}

.close-btn {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 28px;
    cursor: pointer;
    color: #94a3b8;
}

.modal-title {
    margin: 0;
    color: #1e293b;
    font-size: 18px;
}


/* =========================================================
   LOADER
========================================================= */

#loader-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.7);

    display: none;
    align-items: center;
    justify-content: center;

    z-index: 100;
    border-radius: 16px;
}

.spinner {
    width: 40px;
    height: 40px;

    border: 4px solid #f3f3f3;
    border-top: 4px solid #4f46e5;

    border-radius: 50%;
    animation: spin 1s linear infinite;
}


/* =========================================================
   ANIMATIONS
========================================================= */

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes fadeIn {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@keyframes heartbeat {
    0% { transform: scale(0.8); opacity: 0.7; }
    70% { transform: scale(1.8); opacity: 0; }
    100% { opacity: 0; }
}


/* ===== CLEAN 2-LINE HEADER ===== */

.fc .fc-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

/* -------- LINE 1 -------- */
.fc .fc-toolbar-chunk:nth-child(1) {
    order: 1;
    width: 33%;
    display: flex;
    justify-content: flex-start;
}

.fc .fc-toolbar-chunk:nth-child(2) {
    order: 1;
    width: 34%;
    display: flex;
    justify-content: center;
}

.fc .fc-toolbar-chunk:nth-child(3) {
    order: 1;
    width: 33%;
    display: flex;
    justify-content: flex-end;
}

/* -------- LINE 2 -------- */

/* Title (left half) */
.fc .fc-toolbar-title {
    order: 2;
    width: 50%;
    text-align: left;
}

/* Right side controls */
.fc .fc-toolbar-chunk:nth-child(3) {
    flex-wrap: wrap;
}

/* Move buttons to second line */
.fc .fc-button-group,
.fc .fc-today-button {
    order: 3;
}

/* Force second row */
.fc .fc-toolbar > *:nth-child(n+4) {
    width: 50%;
}

/* Right align buttons */
.fc .fc-button-group {
    margin-left: auto;
}

/* =========================================================
   CUSTOM HEADER (REPLACES FULLCALENDAR HEADER)
========================================================= */

#custom-header {
    position: sticky;
    top: 60px; /* below filter bar */
    z-index: 900;

    background: #ffffff;
    border-bottom: 1px solid #e2e8f0;

    padding: 10px 12px;
}

/* ---------- Line 1 ---------- */
.ch-line1 {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.ch-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ch-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ---------- Line 2 ---------- */
.ch-line2 {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* ---------- Title ---------- */
.ch-title {
    font-size: 18px;
    font-weight: 600;
    color: #1e293b;
}

/* ---------- Buttons ---------- */
.ch-btn {
    background: #f1f5f9;
    border: none;
    padding: 6px 12px;
    border-radius: 10px;
    font-size: 13px;
    cursor: pointer;
}

.ch-btn.active {
    background: #4f46e5;
    color: #ffffff;
}

.ch-btn:hover {
    background: #e2e8f0;
}

/* Circle buttons (prev/next) */
.ch-btn-circle {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: #f1f5f9;
    font-size: 18px;
    cursor: pointer;
}

/* Today button */
.ch-btn-pill {
    padding: 5px 14px;
    border-radius: 20px;
    border: none;
    background: #e0f2fe;
    color: #0369a1;
    font-size: 13px;
    cursor: pointer;
}

.ch-btn-logout {
    padding: 5px 14px;
    border-radius: 20px;
    border: none;
    background: #fee2e2;
    color: #b91c1c;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

.ch-btn-logout:hover {
    background: #fecaca;
}

.ch-btn-report {
    padding: 5px 14px;
    border-radius: 20px;
    border: none;
    background: #e0f2fe;
    color: #0c4a6e;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

.ch-btn-report:hover {
    background: #bae6fd;
}

/* View group */
.ch-views {
    display: flex;
    gap: 6px;
}

.ch-secondary {
    display: flex;
    align-items: center;
    gap: 8px;
}

.fc-header-toolbar {
    display: none !important;
}

.day-event-count {
    margin-left: 6px;
    padding: 1px 6px;
    border-radius: 999px;
    background: #dbeafe;
    color: #1e40af;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.4;
    box-shadow: 0 2px 6px rgba(30, 64, 175, 0.2);
    animation: countPop 280ms ease-out;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#day-view-type-summary {
    display: none;
    position: sticky;
    top: 136px;
    z-index: 880;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin: 10px 0 2px;
    padding: 10px 12px;
    background: linear-gradient(135deg, #eef2ff 0%, #f8fafc 100%);
    border: 1px solid #c7d2fe;
    border-radius: 12px;
    box-shadow: 0 8px 18px rgba(79, 70, 229, 0.12);
    animation: daySummaryEnter 260ms ease-out;
}

.day-summary-total {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
    border-radius: 999px;
    background: linear-gradient(135deg, #4338ca 0%, #3730a3 100%);
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
    box-shadow: 0 6px 12px rgba(67, 56, 202, 0.28);
    animation: dayChipPop 280ms ease-out;
}

.day-summary-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: 100%;
    padding: 4px 10px;
    border-radius: 999px;
    background: #ffffff;
    color: #1e3a8a;
    border: 1px solid #bfdbfe;
    font-size: 10px;
    font-weight: 600;
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow: 0 4px 10px rgba(30, 64, 175, 0.12);
    animation: dayChipPop 300ms ease-out;
    transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.day-summary-chip:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 14px rgba(30, 64, 175, 0.18);
}

.day-summary-label {
    letter-spacing: 0.2px;
    color: inherit;
    opacity: 0.95;
}

.day-summary-value {
    min-width: 20px;
    text-align: center;
    padding: 1px 7px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.78);
    color: #1e3a8a;
    font-weight: 800;
    border: 1px solid rgba(191, 219, 254, 0.8);
}

.day-summary-total .day-summary-value {
    background: rgba(255, 255, 255, 0.24);
    border-color: rgba(255, 255, 255, 0.38);
    color: #ffffff;
}

.day-summary-empty {
    font-size: 12px;
    font-weight: 600;
    color: #475569;
    padding: 4px 2px;
}

.day-event-count:hover {
    transform: translateY(-1px) scale(1.03);
    box-shadow: 0 4px 10px rgba(30, 64, 175, 0.28);
}

@keyframes countPop {
    0% {
        transform: scale(0.72);
        opacity: 0.3;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes daySummaryEnter {
    0% {
        opacity: 0;
        transform: translateY(-4px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes dayChipPop {
    0% {
        opacity: 0;
        transform: scale(0.9);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@media (max-width: 768px) {
    .day-event-count {
        font-size: 10px;
        padding: 1px 5px;
    }

    #day-view-type-summary {
        top: 146px;
        margin-top: 6px;
        gap: 4px;
        padding: 8px 8px;
    }

    .day-summary-total {
        font-size: 10px;
        padding: 1px 6px;
    }

    .day-summary-chip {
        font-size: 9px;
        padding: 2px 7px;
        gap: 6px;
    }

    #calendar-container {
        margin: 0;
        width: 100%;
        padding-bottom: 170px;
    }

    #calendar {
        border-radius: 0;
        padding: 6px;
        box-shadow: none;
        margin-top: 0;
    }

    #calendar-filters {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        justify-content: stretch;
        align-items: stretch;
        gap: 6px;
        padding: 8px;
    }

    #calendar-filters label {
        box-sizing: border-box;
        grid-column: span 1;
        width: 100%;
        max-width: none;
        min-width: 0;
        justify-content: center;
        white-space: nowrap;
        gap: 4px;
        font-size: 11px;
        padding: 4px 8px;
        overflow: hidden;
    }

    #search-box {
        grid-column: 1 / -1 !important;
        width: 100%;
        min-width: 0;
        font-size: 12px;
        padding: 8px 10px;
        border-radius: 10px;
        margin-top: 2px;
    }

    #custom-header {
        top: 54px;
        padding: 8px;
        text-align: center;
    }

    #custom-header .ch-line1 {
        width: 100%;
        display: grid !important;
        grid-template-columns: auto 1fr;
        align-items: center;
        gap: 6px;
        margin-bottom: 8px;
    }

    #custom-header .ch-line2 {
        display: flex !important;
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
        width: 100%;
    }

    #custom-header .ch-title {
        flex: 1 1 auto;
        font-size: 14px;
        margin-left: auto;
        white-space: nowrap;
        text-align: right !important;
        justify-self: end;
    }

    #custom-header .ch-nav {
        flex: 0 0 auto;
        gap: 4px;
        justify-content: flex-start !important;
        justify-self: start;
    }

    #custom-header .ch-views {
        display: grid !important;
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
        gap: 4px;
        width: 100%;
    }

    #custom-header .ch-views .ch-btn {
        width: 100% !important;
        text-align: center;
    }

    #custom-header .ch-secondary {
        gap: 4px;
        width: 100%;
        justify-content: flex-end;
    }

    .ch-btn {
        font-size: 11px;
        padding: 5px 8px;
    }

    .ch-btn-pill,
    .ch-btn-report,
    .ch-btn-logout {
        font-size: 11px;
        padding: 5px 8px;
    }

    .ch-btn-circle {
        width: 30px;
        height: 30px;
        font-size: 16px;
    }

    #calendar-filters input[type="checkbox"] {
        transform: scale(1);
        margin: 0;
    }

    #calendar-footer {
        display: grid;
        grid-template-columns: 1fr;
        gap: 6px;
        align-items: center !important;
        justify-items: center !important;
        font-size: 12px;
        line-height: 1.35;
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
        box-sizing: border-box;
        max-height: 40vh;
        overflow-y: auto;
        text-align: center !important;
    }

    #calendar-footer > div {
        width: 100%;
        min-width: 0;
        text-align: center !important;
    }

    .footer-sync,
    .footer-counts,
    .footer-server {
        display: flex;
        align-items: center;
        justify-content: center !important;
        gap: 8px;
        flex-wrap: wrap;
    }

    .footer-counts span,
    .footer-sync span,
    .footer-server span {
        white-space: nowrap;
    }

    #build-meta {
        white-space: normal;
        word-break: break-word;
    }
}
