/* =================================================================
 *  CALENDAR VIEW  (month grid + day modal)
 * ================================================================= */
#view-calendar {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 16px 32px;
}

.cal-nav {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 12px 0 14px;
}
.cal-nav-btn {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    width: 44px; height: 44px;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
}
.cal-nav-btn:hover { background: var(--bg-hover-soft); border-color: var(--accent); }
.cal-today-btn {
    margin-left: auto;
    padding: 10px 16px;
    border: 1px solid var(--accent);
    background: var(--bg-surface);
    color: var(--accent);
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
    min-height: 44px;
}
.cal-today-btn:hover { background: var(--accent); color: var(--text-on-accent); }

.cal-month-heading {
    flex: 1;
    margin: 0;
    text-align: center;
    font-size: 1.5rem;
    color: var(--text-heading);
    font-weight: 600;
}

.cal-grid-host { width: 100%; }
.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 4px;
    background: var(--border-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}
.cal-weekday {
    background: var(--bg-surface-alt);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 8px 6px;
    text-align: center;
}

.cal-cell {
    background: var(--bg-surface);
    min-height: 110px;
    padding: 6px 8px;
    cursor: default;
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: background 0.1s;
    overflow: hidden;
}
.cal-cell-pad {
    background: var(--bg-surface-alt);
    opacity: 0.4;
    cursor: default;
    min-height: 110px;
}
.cal-cell-has { cursor: pointer; }
.cal-cell-has:hover { background: var(--bg-result-hover); }
.cal-cell-today {
    background: var(--bg-hover-soft);
    box-shadow: inset 0 0 0 2px var(--accent);
    position: relative;
}
.cal-cell-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
}
.cal-day-num {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
}
.cal-cell-today .cal-day-num {
    color: var(--accent);
    font-weight: 700;
}
.cal-dec-dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--text-faint);
    opacity: 0.55;
}
.cal-cell-names {
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
}
.cal-name {
    font-size: 0.78rem;
    line-height: 1.2;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 1px 4px;
    border-radius: 3px;
    background: var(--bg-hover-soft);
}
.cal-cell-today .cal-name {
    background: var(--bg-surface);
}
.cal-more {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-style: italic;
    padding: 0 4px;
}

.cal-empty {
    padding: 28px;
    text-align: center;
    color: var(--text-muted);
    background: var(--bg-surface);
    border: 1px dashed var(--border-color);
    border-radius: 8px;
}

/* ----- Modal ----- */
.cal-modal {
    position: fixed; inset: 0;
    z-index: 400;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.cal-modal.hidden { display: none; }
.cal-modal-backdrop {
    position: absolute; inset: 0;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(2px);
}
.cal-modal-card {
    position: relative;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: min(620px, 100%);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
    overflow: hidden;
}
.cal-modal-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-surface-alt);
}
.cal-modal-header h3 {
    margin: 0;
    flex: 1;
    color: var(--text-heading);
    font-size: 1.1rem;
}
.cal-modal-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 6px;
    min-width: 44px;
    min-height: 44px;
}
.cal-modal-close:hover { background: var(--bg-hover-soft); color: var(--text-primary); }

.cal-modal-body {
    overflow-y: auto;
    padding: 12px 18px 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.cal-modal-empty {
    color: var(--text-muted);
    text-align: center;
    padding: 32px 12px;
    font-style: italic;
}

.cal-modal-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-surface);
}
.cal-modal-row.is-deceased {
    background: var(--bg-surface-alt);
    opacity: 0.85;
}
.cal-modal-row-main { flex: 1; min-width: 0; }
.cal-modal-row-name {
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}
.cal-modal-link {
    color: inherit;
    cursor: pointer;
    text-decoration: none;
}
.cal-modal-link:hover { color: var(--accent); text-decoration: underline; }
.cal-modal-row-meta {
    margin-top: 3px;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.cal-age {
    margin-left: 8px;
    color: var(--accent);
    font-weight: 600;
}
.cal-age-dec {
    color: var(--text-faint);
    font-weight: 500;
}
.cal-dec-badge {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    background: var(--bg-hover-soft);
    padding: 1px 6px;
    border-radius: 4px;
}
.cal-add-btns {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
}
.cal-ics-btn,
.cal-gcal-btn {
    padding: 7px 12px;
    border-radius: 6px;
    font-size: 0.82rem;
    cursor: pointer;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
    white-space: nowrap;
    text-align: center;
    border: 1px solid var(--accent);
    background: var(--bg-surface);
    color: var(--accent);
    font-weight: 500;
}
.cal-ics-btn:hover,
.cal-gcal-btn:hover { background: var(--accent); color: var(--text-on-accent); }

/* Google Calendar gets Google-ish blue trim to make it visually distinct. */
.cal-gcal-btn {
    border-color: #1a73e8;
    color: #1a73e8;
}
.cal-gcal-btn:hover {
    background: #1a73e8;
    color: #fff;
    border-color: #1a73e8;
}
:root[data-theme="dark"] .cal-gcal-btn {
    border-color: #8ab4f8;
    color: #8ab4f8;
}
:root[data-theme="dark"] .cal-gcal-btn:hover {
    background: #8ab4f8;
    color: #0b1220;
    border-color: #8ab4f8;
}

/* Show-deceased toggle (compact switch) */
.cal-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.cal-toggle input { display: none; }
.cal-toggle-slider {
    width: 34px; height: 18px;
    border-radius: 999px;
    background: var(--border-color);
    position: relative;
    transition: background 0.15s;
}
.cal-toggle-slider::after {
    content: '';
    position: absolute;
    top: 2px; left: 2px;
    width: 14px; height: 14px;
    border-radius: 50%;
    background: #fff;
    transition: transform 0.15s;
}
.cal-toggle input:checked + .cal-toggle-slider {
    background: var(--accent);
}
.cal-toggle input:checked + .cal-toggle-slider::after {
    transform: translateX(16px);
}

@media (max-width: 820px) {
    .cal-cell { min-height: 86px; padding: 4px 5px; }
    .cal-cell-pad { min-height: 86px; }
    .cal-name { font-size: 0.7rem; }
    .cal-day-num { font-size: 0.8rem; }
    .cal-weekday { font-size: 0.68rem; padding: 6px 2px; }
}
@media (max-width: 560px) {
    .cal-modal-row {
        flex-direction: column;
        align-items: stretch;
    }
    .cal-add-btns {
        flex-direction: row;
        gap: 10px;
    }
    .cal-ics-btn, .cal-gcal-btn { flex: 1; min-height: 44px; }
}
@media (max-width: 480px) {
    /* Phones: shrink cells so the full month fits closer to one viewport,
       and only show the day number + a dot/count rather than truncated names. */
    .cal-cell { min-height: 54px; padding: 3px 4px; gap: 2px; }
    .cal-cell-pad { min-height: 54px; }
    .cal-name { font-size: 0.62rem; padding: 0 2px; }
    .cal-cell-names { gap: 1px; }
    .cal-day-num { font-size: 0.78rem; }
    .cal-weekday { font-size: 0.6rem; padding: 4px 1px; letter-spacing: 0.02em; }
    .cal-grid { gap: 2px; }
    .cal-nav { gap: 6px; }
    .cal-month-heading { font-size: 1.1rem; }
}
