/* ================= PLANNER ================= */
.planner-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 40px;
    align-items: start;
}

.calendar-card {
    border: 1px solid var(--border);
    padding: 24px;
}

.calendar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
}

.calendar-head .nav-arrow {
    background: none;
    border: 1.5px solid var(--border-strong);
    border-radius: 2px;
    width: 30px;
    height: 30px;
    cursor: pointer;
    color: var(--text);
}

.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
}

.cal-dow {
    text-align: center;
    font-size: .66rem;
    color: var(--text-muted);
    font-weight: 700;
    padding: 6px 0;
    background: var(--bg);
    font-family: 'IBM Plex Mono', monospace;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.day-cell {
    min-height: 96px;
    padding: 6px;
    font-size: .82rem;
    position: relative;
    color: var(--text-muted);
    background: var(--bg);
    font-family: 'IBM Plex Mono', monospace;
}

.day-cell.pad {
    background: var(--bg-sunken);
}

.day-cell.in-month {
    color: var(--text);
    cursor: pointer;
}

.day-cell.in-month:hover {
    background: var(--bg-raised);
}

.day-cell.today {
    background: var(--bg-raised);
    box-shadow: inset 0 0 0 2px var(--accent);
    font-weight: 700;
}

.day-cell.drag-over {
    background: var(--gold-soft);
    box-shadow: inset 0 0 0 2px var(--gold);
}

.day-events {
    position: absolute;
    left: 5px;
    right: 5px;
    bottom: 5px;
    top: 22px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
}

.event-chip {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: .62rem;
    line-height: 1.5;
    padding: 1px 5px;
    border-radius: 2px;
    border-left: 2.5px solid;
    cursor: grab;
    font-weight: 600;
    font-family: 'Public Sans', sans-serif;
}

.event-chip:active {
    cursor: grabbing;
    opacity: .6;
}

.event-chip[data-type="lesson"] {
    background: var(--bg-sunken);
    color: var(--text);
    border-left-color: var(--text-muted);
}

.event-chip[data-type="review"] {
    background: var(--success-soft);
    color: var(--success);
    border-left-color: var(--success);
}

.event-chip[data-type="mock"] {
    background: var(--danger-soft);
    color: var(--danger);
    border-left-color: var(--danger);
}

.event-chip[data-type="flashcards"] {
    background: var(--gold-soft);
    color: var(--gold);
    border-left-color: var(--gold);
}

.event-chip[data-type="custom"] {
    background: var(--bg-sunken);
    color: var(--text-muted);
    border-left-color: var(--text-muted);
    font-style: italic;
}

.chip-check {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    border: 1.5px solid currentColor;
    flex: none;
    cursor: pointer;
}

.chip-check.done {
    background: currentColor;
}

.chip-time {
    font-family: 'IBM Plex Mono', monospace;
    font-size: .58rem;
    opacity: .75;
    flex: none;
}

.event-chip.done .chip-time {
    opacity: .5;
}

.chip-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.event-chip.done .chip-title {
    text-decoration: line-through;
    opacity: .65;
}

.event-more {
    font-size: .6rem;
    color: var(--text-muted);
    font-family: 'IBM Plex Mono', monospace;
    padding: 1px 5px;
    cursor: pointer;
}

.event-more:hover {
    color: var(--text);
    text-decoration: underline;
}

.cal-popover {
    display: none;
    position: fixed;
    z-index: 100;
    width: 272px;
    background: var(--bg);
    border: 1.5px solid var(--text);
    box-shadow: var(--shadow);
    border-radius: 4px;
    padding: 16px;
}

.cal-popover.active {
    display: block;
}

.cal-popover-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    gap: 8px;
}

.cal-popover-head h4 {
    margin: 0;
    font-size: .72rem;
    font-family: 'IBM Plex Mono', monospace;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .05em;
}

.cal-popover input[type="text"],
.cal-popover input[type="date"],
.cal-popover input[type="time"],
.cal-popover select {
    width: 100%;
    padding: 8px 9px;
    border: 1.5px solid var(--border-strong);
    background: var(--bg);
    color: var(--text);
    font-family: 'Public Sans', sans-serif;
    font-size: .86rem;
    border-radius: 2px;
    margin-bottom: 10px;
    box-sizing: border-box;
}

/* optional time: a dashed placeholder that swaps in a real field, and swaps back out again.
   --tf-h keeps the placeholder, the input and the clear button the same height as their neighbours */
.time-field {
    --tf-h: 34px;
    display: inline-flex;
    align-items: center;
    flex: none;
}

.time-field[data-has="false"] .time-row {
    display: none;
}

.time-field[data-has="true"] .time-add-btn {
    display: none;
}

/* reads as an empty slot waiting to be filled, not as a link */
.time-add-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: var(--tf-h);
    padding: 0 11px;
    background: none;
    border: 1.5px dashed var(--border-strong);
    border-radius: 2px;
    cursor: pointer;
    font-family: 'IBM Plex Mono', monospace;
    font-size: .66rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    white-space: nowrap;
}

.time-add-btn:hover {
    border-style: solid;
    border-color: var(--accent);
    color: var(--accent);
}

.time-row {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

/* a bordered square the same height as the input, so it pairs with it instead of
   floating between two fields the way a bare x did */
.time-clear-btn {
    width: var(--tf-h);
    height: var(--tf-h);
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: var(--bg);
    border: 1.5px solid var(--border-strong);
    border-radius: 2px;
    cursor: pointer;
    color: var(--text-muted);
}

.time-clear-btn:hover {
    color: var(--danger);
    border-color: var(--danger);
    background: var(--danger-soft);
}

/* the create and edit popovers use the same labelled-field grammar as the list editor,
   so a session looks the same wherever it is opened from */
.pop-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 14px;
}

.cal-popover .pop-form input[type="text"],
.cal-popover .pop-form input[type="date"],
.cal-popover .pop-form select,
.cal-popover .pop-form .time-field,
.cal-popover .pop-form .cal-popover-types {
    margin-bottom: 0;
}

/* the title is what the session is, so it carries a little more weight than its fields */
.cal-popover input.pop-title-input {
    font-size: .95rem;
    font-weight: 600;
    padding: 9px 10px;
}

.pop-hint {
    font-family: 'IBM Plex Mono', monospace;
    font-size: .62rem;
    letter-spacing: .04em;
    color: var(--text-muted);
}

.pop-hint kbd {
    font-family: inherit;
    font-size: inherit;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 2px;
    padding: 1px 4px;
    background: var(--bg);
}

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

.cal-popover .time-field {
    --tf-h: 36px;
    margin-bottom: 10px;
}

/* sized to its own content: never stretches a neighbour, never clips the AM/PM or clock icon */
.cal-popover .time-row input[type="time"] {
    width: auto;
    height: var(--tf-h);
    flex: none;
    padding-top: 0;
    padding-bottom: 0;
    margin-bottom: 0;
}

.cal-day-time {
    font-family: 'IBM Plex Mono', monospace;
    font-size: .68rem;
    color: var(--text-muted);
    flex: none;
}

.cal-day-row.done .cal-day-time {
    opacity: .6;
}

.cal-popover-types {
    display: flex;
    gap: 7px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.cal-type-swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    padding: 0;
}

.cal-type-swatch[data-active="true"] {
    border-color: var(--text);
}

.cal-type-dot {
    width: 15px;
    height: 15px;
    border-radius: 50%;
    display: block;
}

.cal-type-dot[data-type="lesson"] {
    background: var(--text-muted);
}

.cal-type-dot[data-type="review"] {
    background: var(--success);
}

.cal-type-dot[data-type="mock"] {
    background: var(--danger);
}

.cal-type-dot[data-type="flashcards"] {
    background: var(--gold);
}

.cal-type-dot[data-type="custom"] {
    background: var(--border-strong);
}

.cal-popover-foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.cal-popover-view-title {
    font-size: .98rem;
    font-weight: 700;
    margin: 0;
}

.cal-popover-view-title.done {
    text-decoration: line-through;
    color: var(--text-muted);
}

.cal-popover-done {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-bottom: 10px;
}

.cal-popover-done input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    flex: none;
    cursor: pointer;
    margin: 0;
}

.cal-del-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    display: flex;
    align-items: center;
    gap: 5px;
    font-family: 'Public Sans', sans-serif;
    font-size: .8rem;
}

.cal-del-btn:hover {
    color: var(--danger);
}

.cal-popover-day-list {
    max-height: 220px;
    overflow-y: auto;
    margin-bottom: 10px;
}

.cal-day-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    font-size: .82rem;
}

.cal-day-row:last-child {
    border-bottom: none;
}

.cal-day-row input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--accent);
    flex: none;
    cursor: pointer;
    margin: 0;
}

.cal-day-row .cal-type-dot {
    flex: none;
    width: 9px;
    height: 9px;
}

.cal-day-row .cal-day-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}

.cal-day-row .cal-day-title:hover {
    text-decoration: underline;
}

.cal-day-row.done .cal-day-title {
    text-decoration: line-through;
    color: var(--text-muted);
}

.cal-day-row button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 3px;
    display: flex;
    flex: none;
}

.cal-day-row button:hover {
    color: var(--danger);
}

.countdown-ticket {
    background: var(--bg-raised);
    border: 1.5px solid var(--text);
    position: relative;
    margin-bottom: 22px;
    padding: 22px 20px;
    overflow: hidden;
}

.countdown-ticket::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 60%;
    border-top: 2px dashed var(--border-strong);
}

.countdown-ticket .c-label {
    display: block;
    padding-right: 22px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: .68rem;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.countdown-ticket .days {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 2.6rem;
    display: block;
    line-height: 1;
    margin: .15em 0;
}

.countdown-ticket .c-sub {
    font-size: .82rem;
    color: var(--text-muted);
    display: block;
    padding-top: 14px;
}

.countdown-edit-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    display: flex;
    z-index: 1;
}

.countdown-edit-btn:hover {
    color: var(--text);
}

.countdown-ticket.compact {
    flex: none;
    width: 220px;
    margin-bottom: 0;
    padding: 12px 14px;
}

.countdown-ticket.compact::before {
    display: none;
}

.countdown-ticket.compact .c-label {
    font-size: .6rem;
}

.countdown-ticket.compact .days {
    font-size: 1.6rem;
    margin: .1em 0;
}

.countdown-ticket.compact .c-sub {
    font-size: .7rem;
    padding-top: 6px;
}

.countdown-ticket.compact .countdown-edit-btn {
    top: 8px;
    right: 8px;
}

.todo-card {
    border: 1px solid var(--border);
    padding: 22px;
}

.plan-session-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 0;
    border-bottom: 1px solid var(--border);
    font-size: .88rem;
}

.plan-session-row:last-child {
    border-bottom: none;
}

.plan-session-row input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    flex: none;
    cursor: pointer;
}

.plan-session-date {
    font-family: 'IBM Plex Mono', monospace;
    font-size: .72rem;
    color: var(--text-muted);
    width: 66px;
    flex: none;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.plan-session-time {
    font-size: .64rem;
    opacity: .85;
}

.plan-session-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.plan-session-row.done .plan-session-title {
    text-decoration: line-through;
    color: var(--text-muted);
}

.plan-session-row.done .plan-session-date {
    opacity: .6;
}

.plan-session-row.done .tag {
    opacity: .6;
}

.plan-session-actions {
    display: flex;
    gap: 2px;
    flex: none;
}

.plan-session-actions button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 5px;
    display: flex;
}

.plan-session-actions button:hover {
    color: var(--text);
}

.plan-session-actions .del-btn:hover {
    color: var(--danger);
}

/* editing lifts the row out of the list into its own card, so it is obvious
   which session is open and where the edit begins and ends */
.plan-session-edit {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 8px 0;
    padding: 14px 16px;
    background: var(--bg-raised);
    border: 1.5px solid var(--border-strong);
    border-left: 3px solid var(--accent);
    border-radius: 3px;
}

.edit-fields {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 10px 12px;
}

/* every control carries its own label, stacked, so nothing has to be guessed at */
.edit-field {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex: none;
    min-width: 0;
}

.edit-field-grow {
    flex: 1 1 200px;
}

.edit-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: .6rem;
    text-transform: uppercase;
    letter-spacing: .09em;
    color: var(--text-muted);
    line-height: 1;
}

.plan-session-edit input[type="text"],
.plan-session-edit input[type="date"],
.plan-session-edit input[type="time"],
.plan-session-edit select {
    height: 34px;
    width: auto;
    padding: 0 9px;
    border: 1.5px solid var(--border-strong);
    background: var(--bg);
    color: var(--text);
    font-family: 'Public Sans', sans-serif;
    font-size: .82rem;
    border-radius: 2px;
}

/* only the title grows; the rest are sized to their own content so the date and
   time never get clipped and never shove the title around */
.plan-session-edit input[type="text"] {
    width: 100%;
    min-width: 0;
}

.plan-session-edit input:focus,
.plan-session-edit select:focus {
    border-color: var(--accent);
    outline: none;
}

.plan-session-edit .is-invalid {
    border-color: var(--danger);
    background: var(--danger-soft);
}

.edit-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding-top: 11px;
    border-top: 1px dashed var(--border);
}

.edit-hint {
    margin-right: auto;
    font-family: 'IBM Plex Mono', monospace;
    font-size: .62rem;
    letter-spacing: .04em;
    color: var(--text-muted);
}

.edit-hint kbd {
    font-family: inherit;
    font-size: inherit;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 2px;
    padding: 1px 4px;
    background: var(--bg);
}

@media (max-width: 560px) {
    .edit-field-grow {
        flex-basis: 100%;
    }

    .edit-hint {
        display: none;
    }
}

.plan-empty {
    color: var(--text-muted);
    font-size: .86rem;
    padding: 6px 0;
}


@media (max-width: 900px) {
    .planner-layout {
        grid-template-columns: 1fr;
    }

    /* a grid item's min-width defaults to its content; the nowrap session
       titles would otherwise push the card past the viewport */
    .planner-layout>* {
        min-width: 0;
    }
}

@media (max-width: 720px) {
    .calendar-card {
        padding: 14px 12px;
    }

    .countdown-ticket.compact {
        width: 100%;
    }

    .countdown-edit-btn {
        padding: 10px;
        top: 2px;
        right: 2px;
    }

    .calendar-head .nav-arrow {
        width: 40px;
        height: 40px;
    }

    .cal-dow {
        font-size: .6rem;
        letter-spacing: 0;
    }

    /* a phone month shows *that* a day is booked, not what: type-coloured bars,
       and the whole cell is the tap target (it opens the day's agenda) */
    .day-cell {
        min-height: 54px;
        padding: 5px 4px;
        font-size: .74rem;
    }

    .day-events {
        top: auto;
        left: 4px;
        right: 4px;
        bottom: 5px;
        gap: 2px;
        pointer-events: none;
    }

    .event-chip {
        height: 4px;
        padding: 0;
        border-left: none;
        border-radius: 1px;
        font-size: 0;
        background: currentColor !important;
    }

    .event-chip[data-type="lesson"] {
        color: var(--text-muted);
    }

    .event-chip.done {
        opacity: .35;
    }

    .chip-check,
    .chip-time,
    .chip-title {
        display: none;
    }

    .event-more {
        padding: 0;
        font-size: .54rem;
        line-height: 1;
    }

    /* popovers become a bottom sheet over a dimmed page */
    .cal-popover {
        left: 0 !important;
        right: 0;
        top: auto !important;
        bottom: 0;
        width: auto;
        max-height: 82vh;
        overflow-y: auto;
        border-width: 1.5px 0 0;
        border-radius: 10px 10px 0 0;
        padding: 20px 18px calc(20px + var(--safe-b));
        box-shadow: 0 0 0 100vmax rgba(20, 17, 10, 0.55);
        z-index: 110;
    }

    .cal-popover::before {
        content: '';
        display: block;
        width: 36px;
        height: 4px;
        margin: -8px auto 14px;
        border-radius: 2px;
        background: var(--border-strong);
    }

    .cal-popover input[type="text"],
    .cal-popover input[type="date"],
    .cal-popover input[type="time"],
    .cal-popover select {
        font-size: 16px;
        min-height: 44px;
    }

    .cal-popover .pop-hint {
        display: none;
    }

    .cal-day-row {
        min-height: 48px;
    }

    .todo-card {
        padding: 16px 14px;
    }

    /* session rows: title gets the full line, tag and date sit beneath it */
    .plan-session-row {
        display: grid;
        grid-template-columns: auto 1fr auto;
        grid-template-areas:
            "check title actions"
            "check meta  actions";
        column-gap: 12px;
        row-gap: 4px;
        align-items: center;
    }

    .plan-session-row input[type="checkbox"] {
        grid-area: check;
        width: 20px;
        height: 20px;
    }

    .plan-session-title {
        grid-area: title;
        white-space: normal;
    }

    .plan-session-date {
        grid-area: meta;
        justify-self: start;
        width: auto;
        flex-direction: row;
        gap: 6px;
        align-items: baseline;
    }

    .plan-session-row>.tag {
        grid-area: meta;
        justify-self: end;
    }

    .plan-session-actions {
        grid-area: actions;
    }

    .plan-session-actions button {
        padding: 10px;
    }
}
