/* =========================================================
   XERION — CALENDAR (Phase 17)
   ---------------------------------------------------------
   File: web/frontend/css/calendar.css

   The Calendar view, its editor form, and the Integrations
   card's action row. Built only on the design tokens in
   global.css, so the dark theme comes for free.
========================================================= */

/* Sidebar item / buttons that are hidden until activated */
.sidebar-item[hidden],
.integration-actions [hidden],
#calendarNewEventButton[hidden] {
    display: none !important;
}


/* ---------- Integrations card actions ---------- */

.integration-actions {
    display: flex;
    gap: 8px;
}

.integration-actions .button {
    flex: 1;
}


/* ---------- Inactive state ---------- */

.calendar-inactive {
    padding: 28px;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    background: var(--surface-soft);
    text-align: center;
}

.calendar-inactive h3 {
    margin: 0 0 6px;
    font-size: 16px;
    color: var(--text);
}

.calendar-inactive p {
    margin: 0 0 16px;
    font-size: 13.5px;
    color: var(--muted);
}


/* ---------- Toolbar ---------- */

.calendar-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.calendar-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

.calendar-range-label {
    margin: 0 0 0 8px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

.calendar-view-switch {
    display: inline-flex;
    padding: 3px;
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
    background: var(--surface);
}

.calendar-view-tab {
    padding: 6px 14px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
}

.calendar-view-tab.is-active {
    background: var(--blue-light);
    color: var(--blue);
}


/* ---------- Layout ---------- */

.calendar-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 280px;
    gap: 16px;
    align-items: start;
}

.calendar-surface {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-xs);
    overflow-x: auto;
}


/* ---------- Event look (chips, blocks, list items) ---------- */

.cal-event {
    border: 0;
    border-left: 3px solid var(--blue);
    background: var(--blue-light);
    color: var(--blue);
    font: inherit;
    font-size: 11.5px;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
}

.cal-event.is-focus {
    border-left-color: var(--success);
    color: var(--success);
}

.cal-event.is-allday {
    background: var(--blue);
    border-left-color: var(--blue);
    color: var(--surface);
}

.cal-chip-time {
    font-weight: 500;
    opacity: 0.85;
}


/* ---------- Load error ---------- */

.cal-error {
    padding: 48px 24px;
    text-align: center;
}

.cal-error p {
    margin: 0 0 14px;
    font-size: 14px;
    color: var(--danger);
}


/* ---------- Month ---------- */

.cal-month {
    min-width: 560px;
}

.cal-month-head {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    border-bottom: 1px solid var(--border);
    background: var(--surface-soft);
}

.cal-month-head div {
    padding: 8px 10px;
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--muted);
}

.cal-month-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
}

.cal-cell {
    min-height: 108px;
    padding: 6px;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.cal-cell:nth-child(7n) {
    border-right: 0;
}

.cal-cell:nth-last-child(-n + 7) {
    border-bottom: 0;
}

.cal-cell.is-outside {
    background: var(--surface-soft);
}

.cal-cell.is-outside .cal-cell-number {
    color: var(--muted);
    opacity: 0.7;
}

.cal-cell-number {
    width: 26px;
    height: 26px;
    margin-bottom: 2px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    font: inherit;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
}

.cal-cell.is-today .cal-cell-number {
    background: var(--blue);
    color: var(--surface);
}

.cal-chip {
    display: block;
    width: 100%;
    margin-top: 3px;
    padding: 2px 6px;
    border-radius: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cal-more {
    margin-top: 3px;
    padding: 0 4px;
    border: 0;
    background: transparent;
    font: inherit;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
}


/* ---------- Week / Day (time grid) ---------- */

.cal-time-7 {
    min-width: 640px;
}

.cal-time-head,
.cal-allday-row,
.cal-time-body {
    display: grid;
}

.cal-time-7 .cal-time-head,
.cal-time-7 .cal-allday-row,
.cal-time-7 .cal-time-body {
    grid-template-columns: 52px repeat(7, minmax(0, 1fr));
}

.cal-time-1 .cal-time-head,
.cal-time-1 .cal-allday-row,
.cal-time-1 .cal-time-body {
    grid-template-columns: 52px minmax(0, 1fr);
}

.cal-time-head {
    border-bottom: 1px solid var(--border);
    background: var(--surface-soft);
}

.cal-gutter {
    padding: 6px 6px 0 0;
    font-size: 10.5px;
    text-align: right;
    color: var(--muted);
}

.cal-day-head button {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    width: 100%;
    padding: 8px 0;
    border: 0;
    background: transparent;
    font: inherit;
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--muted);
    cursor: pointer;
}

.cal-day-head button strong {
    font-size: 16px;
    letter-spacing: 0;
    color: var(--text);
}

.cal-day-head.is-today button strong {
    color: var(--blue);
}

.cal-allday-row {
    border-bottom: 1px solid var(--border);
}

.cal-allday-cell {
    min-height: 26px;
    padding: 3px;
    border-left: 1px solid var(--border);
}

.cal-time-scroll {
    max-height: 620px;
    overflow-y: auto;
}

.cal-time-body {
    position: relative;
}

.cal-hours .cal-hour {
    position: relative;
    padding: 0 6px 0 0;
    font-size: 10.5px;
    text-align: right;
    color: var(--muted);
    box-sizing: border-box;
}

.cal-hours .cal-hour::after {
    content: "";
}

.cal-col {
    position: relative;
    border-left: 1px solid var(--border);
    background-image: repeating-linear-gradient(
        to bottom,
        transparent 0,
        transparent 47px,
        var(--border) 47px,
        var(--border) 48px
    );
    cursor: pointer;
}

.cal-col.is-today {
    background-color: var(--blue-light);
}

.cal-block {
    position: absolute;
    display: block;
    padding: 2px 6px;
    border-radius: 6px;
    overflow: hidden;
    z-index: 1;
    line-height: 1.25;
}

.cal-now {
    position: absolute;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--danger);
    pointer-events: none;
    z-index: 2;
}


/* ---------- Upcoming ---------- */

.calendar-upcoming {
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-xs);
}

.calendar-upcoming h3 {
    margin: 0 0 10px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.cal-empty {
    margin: 0;
    font-size: 13px;
    color: var(--muted);
}

.cal-upcoming-day {
    margin: 12px 0 4px;
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--muted);
}

.cal-upcoming-day:first-child {
    margin-top: 0;
}

.cal-upcoming-item {
    display: grid;
    grid-template-columns: 56px minmax(0, 1fr);
    column-gap: 8px;
    width: 100%;
    padding: 7px 8px;
    border: 0;
    border-radius: var(--radius-small);
    background: transparent;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.cal-upcoming-item:hover {
    background: var(--surface-hover);
}

.cal-upcoming-time {
    font-size: 12px;
    font-weight: 600;
    color: var(--blue);
}

.cal-upcoming-item.is-focus .cal-upcoming-time {
    color: var(--success);
}

.cal-upcoming-title {
    font-size: 13px;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cal-upcoming-loc {
    grid-column: 2;
    font-size: 11.5px;
    color: var(--muted);
}


/* ---------- Editor form (inside the global modal) ---------- */

.cal-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.cal-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-soft);
}

.cal-field em {
    font-style: normal;
    font-weight: 400;
    color: var(--muted);
}

.cal-field input,
.cal-field textarea {
    width: 100%;
    box-sizing: border-box;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
    background: var(--surface);
    font: inherit;
    font-size: 13.5px;
    font-weight: 400;
    color: var(--text);
}

.cal-field input:focus,
.cal-field textarea:focus {
    outline: 2px solid var(--blue);
    outline-offset: -1px;
}

.cal-check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-soft);
}

.cal-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 10px;
}

.cal-row [hidden] {
    display: none;
}

.cal-form-error {
    margin: 0;
    font-size: 13px;
    color: var(--danger);
}

.cal-form-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.cal-spacer {
    flex: 1;
}

.cal-danger {
    color: var(--danger);
    border-color: var(--danger);
}


/* ---------- Narrow screens ---------- */

@media (max-width: 1100px) {
    .calendar-layout {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 700px) {
    /* All 7 columns must fit the screen (no sideways scrolling). */
    .cal-month {
        min-width: 0;
    }

    .cal-month-head div {
        padding: 6px 2px;
        font-size: 10px;
        text-align: center;
    }

    .cal-cell {
        min-height: 58px;
        padding: 3px 2px;
        text-align: center;
    }

    /* The week grid is too dense for a phone: Day is the agenda view
       there (calendar.js switches Week to Day on narrow screens). */
    .calendar-view-tab[data-calendar-view="week"] {
        display: none;
    }

    /* Month chips collapse to dots; tapping the day opens it. */
    .cal-month .cal-chip {
        display: inline-block;
        width: 7px;
        height: 7px;
        margin: 2px 1px 0;
        padding: 0;
        border: 0;
        border-radius: 50%;
        background: var(--blue);
        font-size: 0;
    }

    .cal-month .cal-chip.is-focus {
        background: var(--success);
    }

    .cal-more {
        font-size: 10px;
    }

    .calendar-range-label {
        font-size: 14px;
    }
}
