/* ==========================================
   Calendar Container
   ========================================== */
.calendar-wrap {
    flex: 1;
    overflow: auto;
    display: flex;
    flex-direction: column;
    background: var(--surface-solid);
    transition: flex 0.3s ease, width 0.3s ease, opacity 0.3s ease;
}

/* ==========================================
   CSS Grid Calendar — Named Grid Lines
   ========================================== */
.calendar {
    display: grid;
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
    position: relative;
    background: var(--surface-solid);

    grid-template-rows:
        [header] 52px
        [time-0600] repeat(15,1fr) [time-0615] repeat(15,1fr)
        [time-0630] repeat(15,1fr) [time-0645] repeat(15,1fr)
        [time-0700] repeat(15,1fr) [time-0715] repeat(15,1fr)
        [time-0730] repeat(15,1fr) [time-0745] repeat(15,1fr)
        [time-0800] repeat(15,1fr) [time-0815] repeat(15,1fr)
        [time-0830] repeat(15,1fr) [time-0845] repeat(15,1fr)
        [time-0900] repeat(15,1fr) [time-0915] repeat(15,1fr)
        [time-0930] repeat(15,1fr) [time-0945] repeat(15,1fr)
        [time-1000] repeat(15,1fr) [time-1015] repeat(15,1fr)
        [time-1030] repeat(15,1fr) [time-1045] repeat(15,1fr)
        [time-1100] repeat(15,1fr) [time-1115] repeat(15,1fr)
        [time-1130] repeat(15,1fr) [time-1145] repeat(15,1fr)
        [time-1200] repeat(15,1fr) [time-1215] repeat(15,1fr)
        [time-1230] repeat(15,1fr) [time-1245] repeat(15,1fr)
        [time-1300] repeat(15,1fr) [time-1315] repeat(15,1fr)
        [time-1330] repeat(15,1fr) [time-1345] repeat(15,1fr)
        [time-1400] repeat(15,1fr) [time-1415] repeat(15,1fr)
        [time-1430] repeat(15,1fr) [time-1445] repeat(15,1fr)
        [time-1500] repeat(15,1fr) [time-1515] repeat(15,1fr)
        [time-1530] repeat(15,1fr) [time-1545] repeat(15,1fr)
        [time-1600] repeat(15,1fr) [time-1615] repeat(15,1fr)
        [time-1630] repeat(15,1fr) [time-1645] repeat(15,1fr)
        [time-1700] repeat(15,1fr) [time-1715] repeat(15,1fr)
        [time-1730] repeat(15,1fr) [time-1745] repeat(15,1fr)
        [time-1800] repeat(15,1fr) [time-1815] repeat(15,1fr)
        [time-1830] repeat(15,1fr) [time-1845] repeat(15,1fr)
        [time-1900] repeat(15,1fr) [time-1915] repeat(15,1fr)
        [time-1930] repeat(15,1fr) [time-1945] repeat(15,1fr)
        [time-2000] repeat(15,1fr) [time-2015] repeat(15,1fr)
        [time-2030] repeat(15,1fr) [time-2045] repeat(15,1fr)
        [time-2100] repeat(15,1fr) [time-2115] repeat(15,1fr)
        [time-2130] repeat(15,1fr) [time-2145] repeat(15,1fr)
        [time-end];
}

/* Week: minimum 120px per day so columns never get crushed */
.week-view {
    grid-template-columns: 52px repeat(7, minmax(120px, 1fr));
    min-width: max(100%, 900px);
}

/* Day: full width, no squeeze */
.day-view {
    grid-template-columns: 52px 1fr;
    min-width: 100%;
}

.cell {
    min-height: 40px;
    /* Each cell spans 2 rows (2 x 15min = 30min) */
}

/* ==========================================
   Corner
   ========================================== */
.corner {
    grid-column: 1;
    grid-row: header;
    position: sticky;
    top: 0;
    left: 0;
    z-index: 25;
    background: var(--surface-solid);
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
}

/* ==========================================
   Day Headers — frosted sticky
   ========================================== */
.day-header {
    grid-row: header;
    position: sticky;
    top: 0;
    z-index: 15;
    background: var(--surface);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    user-select: none;
}

.day-name {
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.day-num {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text);
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    letter-spacing: -0.02em;
}

.day-header.is-today .day-num {
    background: var(--accent);
    color: #fff;
}

.day-header.is-today .day-name {
    color: var(--accent);
}

/* ==========================================
   Time Labels — sticky left
   ========================================== */
.time-label {
    grid-column: 1;
    color: var(--text-tertiary);
    font-size: 0.65rem;
    font-weight: 500;
    text-align: right;
    padding: 0 8px 0 0;
    border-right: 1px solid var(--border);
    position: sticky;
    left: 0;
    z-index: 5;
    background: var(--surface-solid);
    display: flex;
    align-items: start;
    justify-content: flex-end;
    margin-top: -6px;
    user-select: none;
    letter-spacing: 0.01em;
}

/* ==========================================
   Grid Cells
   ========================================== */
.cell {
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s ease;
}

.cell-hour {
    border-bottom-color: var(--border-strong);
}

.cell:hover {
    background: rgba(0, 0, 0, 0.015);
}

/* ==========================================
   Events — polished cards
   ========================================== */
.event {
    border-radius: 6px;
    padding: 5px 8px;
    font-size: 0.75rem;
    line-height: 1.35;
    color: #fff;
    overflow: hidden;
    cursor: pointer;
    margin: 1px 3px;
    z-index: 5;
    display: flex;
    flex-direction: column;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    position: relative;
}

.event::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 6px;
    background: linear-gradient(180deg, rgba(255,255,255,0.12) 0%, transparent 50%);
    pointer-events: none;
}

.event:hover {
    transform: scale(1.01);
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.15);
    z-index: 6;
}

.event.resizing {
    z-index: 20;
    opacity: 0.85;
    transition: none;
    user-select: none;
}

.event.resizing:hover {
    transform: none;
}

.event.ghost {
    opacity: 0.5;
    border: 2px dashed rgba(255, 255, 255, 0.6);
    animation: ghost-pulse 1.5s ease-in-out infinite;
    pointer-events: none;
    z-index: 4;
}

.event.ghost.ready {
    opacity: 0.75;
    border: 2px solid rgba(255, 255, 255, 0.8);
    animation: none;
}

@keyframes ghost-pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 0.6; }
}

.event-title {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.01em;
}

.event-time {
    font-size: 0.68rem;
    opacity: 0.8;
}

.event-patient {
    font-size: 0.68rem;
    opacity: 0.8;
    margin-top: 1px;
}

.event-sms {
    position: absolute;
    top: 4px;
    right: 6px;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 0.6rem;
    font-weight: 600;
    opacity: 0.7;
    background: rgba(255,255,255,0.25);
    padding: 1px 5px;
    border-radius: 8px;
}

/* ==========================================
   Current Time Line
   ========================================== */
.now-line {
    grid-column: 1 / -1;
    height: 2px;
    background: var(--red);
    z-index: 10;
    pointer-events: none;
    position: relative;
}

.now-line::before {
    content: "";
    width: 10px;
    height: 10px;
    background: var(--red);
    border-radius: 50%;
    position: absolute;
    left: 48px;
    top: -4px;
    box-shadow: 0 0 6px rgba(255, 59, 48, 0.4);
}

/* ==========================================
   MOBILE RESPONSIVE
   ========================================== */
@media (max-width: 768px) {
    /* Hide sidebar, show toggle */
    .app-layout {
        flex-direction: column;
        position: relative;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 300px;
        z-index: 60;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: none;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 20px 0 60px rgba(0, 0, 0, 0.15);
    }

    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.25);
        z-index: 55;
    }

    .sidebar-backdrop.open {
        display: block;
    }

    /* Navbar adjustments */
    .navbar {
        padding: 10px 12px;
        gap: 8px;
    }

    .nav-title {
        min-width: 0;
        font-size: 0.82rem;
    }

    .logo {
        font-size: 1rem;
    }

    /* Week view: scroll horizontally, min column width */
    .week-view {
        grid-template-columns: 44px repeat(7, minmax(100px, 1fr));
        min-width: 750px;
    }

    .calendar-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Smaller time labels */
    .time-label {
        font-size: 0.6rem;
        padding: 0 4px 0 0;
    }

    .corner {
        min-width: 44px;
    }

    /* Day view fills screen */
    .day-view {
        grid-template-columns: 44px 1fr;
        min-width: 100%;
    }

    /* Smaller events */
    .event {
        padding: 3px 6px;
        font-size: 0.7rem;
        margin: 1px 2px;
    }

    .event-time,
    .event-patient {
        font-size: 0.62rem;
    }

    /* Modal full-width */
    .modal {
        width: calc(100vw - 32px);
        max-width: 400px;
        padding: 20px;
    }

    .form-row {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .form-row .form-group:first-child {
        grid-column: 1 / -1;
    }

    /* Right panel — overlay on mobile */
    .panel-right {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: 0 !important;
        z-index: 60;
        transition: width 0.25s ease;
        box-shadow: none;
    }

    .panel-right.open {
        width: 300px !important;
        box-shadow: -20px 0 60px rgba(0, 0, 0, 0.15);
    }

    /* View toggle compact */
    .view-btn {
        padding: 5px 10px;
        font-size: 0.75rem;
    }
}

/* Tiny screens (< 480px) — force day view feel */
@media (max-width: 480px) {
    .navbar {
        padding: 8px 10px;
        gap: 6px;
    }

    .nav-btn {
        width: 28px;
        height: 28px;
        font-size: 0.85rem;
    }

    .nav-title {
        font-size: 0.78rem;
    }

    .week-view {
        grid-template-columns: 40px repeat(7, minmax(80px, 1fr));
        min-width: 620px;
    }

    .day-header .day-name {
        font-size: 0.58rem;
    }

    .day-header .day-num {
        font-size: 0.9rem;
        width: 26px;
        height: 26px;
    }

    .cell {
        min-height: 36px;
    }

    .sidebar {
        width: 280px;
    }

    .modal {
        width: calc(100vw - 20px);
        border-radius: var(--radius);
        padding: 16px;
    }
}

/* ==========================================
   Scrollbar — minimal
   ========================================== */
.calendar::-webkit-scrollbar,
.calendar-wrap::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.calendar::-webkit-scrollbar-track,
.calendar-wrap::-webkit-scrollbar-track {
    background: transparent;
}

.calendar::-webkit-scrollbar-thumb,
.calendar-wrap::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.12);
    border-radius: 3px;
}

.calendar::-webkit-scrollbar-thumb:hover,
.calendar-wrap::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.2);
}

.sidebar::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 2px;
}

.patient-list::-webkit-scrollbar {
    width: 4px;
}

.patient-list::-webkit-scrollbar-track {
    background: transparent;
}

.patient-list::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.08);
    border-radius: 2px;
}
