/* ── Annual Planner – planner.css  v1.1.1 ───────────────────── */
:root {
    --ap-primary:   #2563EB;
    --ap-primary-d: #1D4ED8;
    --ap-border:    #E2E8F0;
    --ap-bg:        #F8FAFC;
    --ap-card:      #FFFFFF;
    --ap-text:      #1E293B;
    --ap-muted:     #64748B;
    --ap-q1:        #EFF6FF;
    --ap-q2:        #F0FDF4;
    --ap-q3:        #FFFBEB;
    --ap-q4:        #FDF4FF;
    --ap-radius:    10px;
    --ap-shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
    --ap-trans:     .15s ease;
}

/* ── Visibility helpers (used by JS instead of [hidden] to avoid theme conflicts) ── */
#ap-modal,
#ap-popout-modal,
#ap-overlay,
#ap-event-editor {
    display: none;   /* hidden by default; JS adds .ap-is-open to reveal */
}
#ap-modal.ap-is-open        { display: block; }
#ap-overlay.ap-is-open      { display: block; }
#ap-event-editor.ap-is-open { display: block; }
#ap-popout-modal.ap-is-open { display: flex; flex-direction: column; }

#ap-wrap * { box-sizing: border-box; }

#ap-wrap {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: var(--ap-text);
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem 1rem 3rem;
}

/* ── Toolbar ── */
.ap-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    gap: 1rem;
}
.ap-year-title {
    font-size: 1.4rem;
    font-weight: 700;
    margin: 0;
    color: var(--ap-text);
}

/* ── Buttons ── */
.ap-btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .45rem 1rem;
    border: 1px solid var(--ap-border);
    border-radius: 6px;
    background: var(--ap-card);
    color: var(--ap-text);
    font-size: .85rem;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--ap-trans), border-color var(--ap-trans);
    text-decoration: none;
}
.ap-btn:hover { background: var(--ap-bg); border-color: #CBD5E1; }
.ap-btn-primary {
    background: var(--ap-primary);
    border-color: var(--ap-primary);
    color: #fff;
}
.ap-btn-primary:hover { background: var(--ap-primary-d); border-color: var(--ap-primary-d); }
.ap-btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Global Goal ── */
.ap-global-wrap {
    background: var(--ap-card);
    border: 1px solid var(--ap-border);
    border-radius: var(--ap-radius);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--ap-shadow);
}
.ap-label {
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--ap-muted);
    margin-bottom: .4rem;
}
.ap-global-goal {
    font-size: 1.15rem;
    font-weight: 600;
    min-height: 2rem;
    line-height: 1.5;
}

/* ── Quarter grid ── */
.ap-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}
@media (max-width: 900px) { .ap-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 550px) { .ap-grid { grid-template-columns: 1fr; } }

.ap-quarter-col { display: flex; flex-direction: column; gap: .75rem; }

.ap-card {
    background: var(--ap-card);
    border: 1px solid var(--ap-border);
    border-radius: var(--ap-radius);
    padding: 1rem 1.1rem;
    box-shadow: var(--ap-shadow);
}

/* Quarter colours */
.ap-quarter-col:nth-child(1) .ap-quarter-card { background: var(--ap-q1); border-color: #BFDBFE; }
.ap-quarter-col:nth-child(2) .ap-quarter-card { background: var(--ap-q2); border-color: #BBF7D0; }
.ap-quarter-col:nth-child(3) .ap-quarter-card { background: var(--ap-q3); border-color: #FDE68A; }
.ap-quarter-col:nth-child(4) .ap-quarter-card { background: var(--ap-q4); border-color: #E9D5FF; }

/* ── Month card ── */
.ap-month-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: .5rem;
}
.ap-month-header-btns {
    display: flex;
    align-items: center;
    gap: 2px;
}
.ap-month-name {
    font-size: .8rem;
    font-weight: 700;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--ap-muted);
}
.ap-cal-btn,
.ap-popout-btn {
    background: none;
    border: none;
    padding: 2px 4px;
    cursor: pointer;
    color: var(--ap-muted);
    border-radius: 4px;
    transition: background var(--ap-trans), color var(--ap-trans);
    line-height: 1;
}
.ap-cal-btn:hover    { background: var(--ap-bg); color: var(--ap-primary); }
.ap-popout-btn:hover { background: var(--ap-bg); color: var(--ap-primary); }

/* ── Editable fields ── */
.ap-editable {
    min-height: 3.5rem;
    outline: none;
    border-radius: 6px;
    padding: .3rem .4rem;
    font-size: .9rem;
    line-height: 1.55;
    color: var(--ap-text);
    transition: background var(--ap-trans), box-shadow var(--ap-trans);
    word-break: break-word;
}
.ap-editable[contenteditable="true"] {
    background: #F0F7FF;
    box-shadow: 0 0 0 2px var(--ap-primary);
    cursor: text;
}
.ap-editable[contenteditable="true"]:focus { outline: none; }

/* ── Actions bar ── */
.ap-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1.25rem;
}
.ap-save-status {
    font-size: .82rem;
    color: var(--ap-muted);
    opacity: 0;
    transition: opacity .3s;
}
.ap-save-status.visible { opacity: 1; }

/* ── Overlay ── */
.ap-overlay {
    position: fixed; inset: 0;
    background: rgba(15,23,42,.4);
    z-index: 9998;
}

/* ── Modal base (shared by calendar + pop-out) ── */
.ap-modal {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    z-index: 9999;
    background: var(--ap-card);
    border-radius: 14px;
    box-shadow: 0 20px 60px rgba(0,0,0,.22);
    width: min(520px, 95vw);
    max-height: 90vh;
    overflow-y: auto;
    padding: 1.5rem 1.75rem 2rem;
}
.ap-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}
.ap-modal-header h3 { margin: 0; font-size: 1.1rem; font-weight: 700; }
.ap-modal-close {
    background: none; border: none;
    font-size: 1.5rem; line-height: 1;
    cursor: pointer; color: var(--ap-muted);
    border-radius: 50%; padding: 0 5px;
    transition: color var(--ap-trans);
}
.ap-modal-close:hover { color: var(--ap-text); }

/* ── In-modal calendar nav ── */
.ap-cal-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: .75rem;
    font-weight: 600;
    font-size: .95rem;
}
.ap-cal-nav button {
    background: none; border: 1px solid var(--ap-border);
    border-radius: 6px; padding: .3rem .7rem;
    cursor: pointer; color: var(--ap-text);
    font-size: .9rem;
    transition: background var(--ap-trans);
}
.ap-cal-nav button:hover { background: var(--ap-bg); }

/* ── Calendar grid ── */
.ap-calendar { width: 100%; }
.ap-cal-dow {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    text-align: center;
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--ap-muted);
    margin-bottom: .25rem;
}
.ap-cal-days {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 3px;
}
.ap-day {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 4px 2px 2px;
    border-radius: 6px;
    font-size: .82rem;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background var(--ap-trans), border-color var(--ap-trans);
    min-height: 36px;
    position: relative;
}
.ap-day:hover { background: var(--ap-bg); border-color: var(--ap-border); }
.ap-day.today { background: #EFF6FF; border-color: #BFDBFE; font-weight: 700; color: var(--ap-primary); }
.ap-day.has-note:after {
    content: '';
    display: block;
    width: 5px; height: 5px;
    border-radius: 50%;
    background: var(--ap-primary);
    margin-top: 2px;
}
.ap-day.other-month { color: #CBD5E1; }
.ap-day.selected { background: var(--ap-primary); color: #fff; border-color: var(--ap-primary); }
.ap-day.selected:after { background: #fff; }

/* ── Day-note event editor (inside calendar modal) ── */
.ap-event-editor {
    margin-top: 1rem;
    background: var(--ap-bg);
    border: 1px solid var(--ap-border);
    border-radius: var(--ap-radius);
    padding: 1rem;
}
.ap-event-editor strong { display: block; margin-bottom: .5rem; font-size: .9rem; }
.ap-event-editor textarea {
    width: 100%;
    border: 1px solid var(--ap-border);
    border-radius: 6px;
    padding: .5rem .75rem;
    font-size: .88rem;
    font-family: inherit;
    resize: vertical;
    outline: none;
    transition: box-shadow var(--ap-trans);
}
.ap-event-editor textarea:focus { box-shadow: 0 0 0 2px var(--ap-primary); }
.ap-event-btns { display: flex; gap: .5rem; margin-top: .6rem; }

/* ── Pop-out month editor modal ── */
#ap-popout-modal {
    width: min(680px, 95vw);
    max-height: 80vh;
    overflow: hidden;   /* body scrolls internally */
}
.ap-popout-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: .75rem;
    overflow: hidden;
    min-height: 0;      /* allow flex children to shrink below content size */
}
.ap-popout-editor {
    flex: 1;
    min-height: 200px;
    max-height: 52vh;
    overflow-y: auto;
    font-size: 1.15rem;
    line-height: 1.7;
    border: 1px solid var(--ap-border);
    border-radius: 8px;
    padding: .75rem 1rem;
    background: var(--ap-bg);
    word-break: break-word;
}
.ap-popout-editor[contenteditable="true"] {
    background: #F0F7FF;
    box-shadow: 0 0 0 2px var(--ap-primary);
    cursor: text;
}
.ap-popout-editor[contenteditable="true"]:focus { outline: none; }
.ap-popout-hint {
    font-size: .8rem;
    color: var(--ap-muted);
    margin: 0;
    text-align: center;
}
.ap-popout-actions {
    display: flex;
    justify-content: flex-end;
    gap: .6rem;
}

/* ── Editing mode highlight ── */
#ap-wrap.editing .ap-editable { cursor: text; }
#ap-wrap.editing .ap-editable:hover:not(:focus) {
    background: #F8FAFC;
    box-shadow: 0 0 0 1.5px #CBD5E1;
}
