/* LeeCal calendar theme. Dark, high-contrast, color-forward.
   Custody is the cell background tint (whose day it is); events are vivid chips/bands on top. */

:root {
    --bg: #0c0d12;
    --surface: #16181f;
    --surface-2: #1e212a;
    --cell: #191c24;
    --cell-out: #121419;       /* leading/trailing days, dimmed */
    --text: #e8eaed;
    --text-dim: #8a8f98;
    --text-faint: #5b606b;
    --border: #2a2d37;
    --border-soft: #23262f;

    /* People (custody owners + tags) */
    --sean: #2E6DE6;
    --lindsay: #E0529C;
    --amanda: #18A999;
    --patrick: #E8590C;

    --today: #f5c518;
    --nc: #8E5BD9;             /* "Sean in NC" rail - violet, distinct from every person color */
    --sync-pending: #ffb020;   /* amber: painted locally, not in Apple yet */
    --sync-differs: #e5484d;   /* red: differs from Apple / feeds conflict */
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* ---- App shell ---- */
.app-shell { min-height: 100vh; }

.app-bar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.7rem 1.1rem;
    background: rgba(12, 13, 18, 0.85);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border-soft);
}

.app-bar-brand {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: 0.5px;
    color: var(--text);
    text-decoration: none;
}

.app-bar-user { display: flex; align-items: center; gap: 0.75rem; }
.app-bar-name { color: var(--text-dim); font-size: 0.9rem; }
.app-bar-logout-form { margin: 0; }
.app-bar-logout {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 0.3rem 0.7rem;
    border-radius: 7px;
    font-size: 0.85rem;
    cursor: pointer;
}
.app-bar-logout:hover { color: var(--text); border-color: var(--text-dim); }

.app-main { padding: 1.1rem; max-width: 1400px; margin: 0 auto; }

.cal-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.8rem;
    gap: 0.6rem;
}

/* ---- Toolbar: mode switch + view controls on one space-efficient row ---- */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem 0.8rem;
    margin-bottom: 0.8rem;
}
.view-controls {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.tool-btn {
    background: var(--surface);
    border: 1px solid var(--border-soft);
    color: var(--text-dim);
    min-height: 2.2rem;
    padding: 0.35rem 0.7rem;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
}
.tool-btn:hover { color: var(--text); }
.tool-btn.active { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--border); }
.tool-btn:disabled { opacity: 0.5; cursor: default; }
.apple-inline { font-size: 0.78rem; color: var(--text-dim); }

.mode-switch {
    display: inline-flex;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: 10px;
    padding: 3px;
    gap: 2px;
}
.mode-switch button {
    background: transparent;
    border: none;
    color: var(--text-dim);
    min-height: 2.2rem;
    padding: 0.35rem 0.8rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
}
.mode-switch button.active {
    background: var(--surface-2);
    color: var(--text);
    box-shadow: inset 0 0 0 1px var(--border);
}

/* ---- Month layout: user-selected columns (phones always stack to one) ---- */
.month-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.1rem;
}
@media (min-width: 760px) {
    .month-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
    .month-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
    .month-grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
}

/* ---- Month card ---- */
.month-card {
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: 16px;
    padding: 1rem 1rem 1.1rem;
}

.month-head { margin-bottom: 0.7rem; }
.month-title {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.month-title .m-name { font-size: 1.5rem; font-weight: 800; line-height: 1; }
.month-title .m-year { font-size: 1.5rem; font-weight: 800; color: var(--text-faint); line-height: 1; }
.month-summary {
    margin-top: 0.35rem;
    font-size: 0.78rem;
    color: var(--text-dim);
    line-height: 1.35;
}

/* ---- Weekday header ---- */
.weekday-row {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin-bottom: 4px;
}
.weekday-row.with-gutter { grid-template-columns: 1.4rem repeat(7, 1fr); }
.weekday {
    text-align: center;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.6px;
    color: var(--text-faint);
    padding: 2px 0;
}

/* ---- Day grid ---- */
.week-row {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin-bottom: 4px;
}
.week-row.with-gutter { grid-template-columns: 1.4rem repeat(7, 1fr); }

/* Custody mode: per-row paint button in the left gutter. */
.week-btn {
    align-self: stretch;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-dim);
    border-radius: 6px;
    padding: 0;
    font-size: 0.7rem;
    cursor: pointer;
    touch-action: manipulation;
}
.week-btn:hover { color: var(--text); border-color: var(--text-dim); }

.day-cell {
    position: relative;
    aspect-ratio: 1 / 1;
    border-radius: 9px;
    background: var(--cell);
    border: 1px solid transparent;
    padding: 3px 4px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-width: 0;
    /* Paint modes involve rapid tapping: suppress double-tap zoom and text selection. */
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}
.day-cell.out-of-month { background: var(--cell-out); }
.day-cell.out-of-month .day-num { color: var(--text-faint); }
.day-cell.today { box-shadow: inset 0 0 0 2px var(--today); }

/* Custody background tint: --owner / --owner2 set inline per cell */
.day-cell.custody {
    background: color-mix(in srgb, var(--owner) 26%, var(--cell));
}
.day-cell.custody.split {
    background: linear-gradient(135deg,
        color-mix(in srgb, var(--owner) 30%, var(--cell)) 0 50%,
        color-mix(in srgb, var(--owner2) 30%, var(--cell)) 50% 100%);
}

/* Day-flag edge rails: NC pins to the top edge, Patrick to the bottom. The cell's
   overflow:hidden clips them to the rounded corners. */
.rail {
    position: absolute;
    left: 0;
    right: 0;
    height: 4px;
    pointer-events: none;
}
.rail-nc { top: 0; background: var(--nc); }
.rail-patrick { bottom: 0; background: var(--patrick); }

/* Apple sync markers: a dashed inset ring, visually distinct from the solid gold today ring.
   pointer-events:none keeps taps landing on the cell. */
.sync-ring {
    position: absolute;
    inset: 1px;
    border-radius: 8px;
    border: 1.5px dashed var(--sync-pending);
    pointer-events: none;
}
.day-cell.sync-differs .sync-ring { border-color: var(--sync-differs); }
.day-cell.sync-conflict .sync-ring { border-style: solid; border-color: var(--sync-differs); }
.day-cell.today .sync-ring { inset: 4px; border-radius: 5px; }   /* nest inside the gold ring */

.day-num {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
    margin-bottom: 2px;
}

.exchange-tag {
    font-size: 0.55rem;
    color: var(--text-dim);
    line-height: 1;
    margin-bottom: 2px;
}

/* ---- Event chips ---- */
.chips { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

.chip {
    --chip: var(--patrick);
    background: var(--chip);
    color: #fff;
    font-size: 0.58rem;
    font-weight: 600;
    line-height: 1.15;
    padding: 1px 4px;
    border-radius: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* Travel / multi-day band: square the interior edges so adjacent days read continuous. */
.chip.band { border-radius: 0; }
.chip.band.start { border-top-left-radius: 4px; border-bottom-left-radius: 4px; }
.chip.band.end   { border-top-right-radius: 4px; border-bottom-right-radius: 4px; }
.chip.band:not(.start) { color: transparent; }   /* label only on the first day */

.chip.tentative {
    background: transparent;
    border: 1px dashed var(--chip);
    color: var(--text);
}

.chip.apple { opacity: 0.85; }   /* read-only Apple feed event, not ours */

.chip-more { font-size: 0.55rem; color: var(--text-dim); padding: 0 3px; }

/* ---- Legend ---- */
.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem 1rem;
    align-items: center;
    margin-bottom: 1.1rem;
    padding: 0.6rem 0.8rem;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: 12px;
    font-size: 0.78rem;
    color: var(--text-dim);
}
.legend-item { display: inline-flex; align-items: center; gap: 0.4rem; }
.legend-swatch { width: 13px; height: 13px; border-radius: 4px; display: inline-block; }
.legend-swatch.split {
    background: linear-gradient(135deg, var(--sean) 0 50%, var(--lindsay) 50% 100%);
}
.legend-swatch.tentative { background: transparent; border: 1px dashed currentColor; }
.legend-swatch.rail-swatch { width: 16px; height: 5px; border-radius: 2px; }
.legend-swatch.sync-pending { background: transparent; border: 1.5px dashed var(--sync-pending); }
.legend-swatch.sync-differs { background: transparent; border: 1.5px dashed var(--sync-differs); }
.legend-swatch.sync-conflict { background: transparent; border: 1.5px solid var(--sync-differs); }

/* ---- Apple sync panel ---- */
.apple-panel {
    margin-bottom: 1.1rem;
    padding: 0.6rem 0.8rem;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: 12px;
    font-size: 0.82rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.apple-status { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; }
.apple-warn {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.6rem;
    padding: 0.45rem 0.6rem;
    border-radius: 8px;
    background: color-mix(in srgb, var(--sync-pending) 16%, var(--surface));
    color: var(--text);
}
.apple-warn-x {
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.8rem;
}
.nudge-head { font-weight: 700; color: var(--text); }
.nudge-list { display: flex; flex-direction: column; gap: 0.35rem; }
.nudge-row { display: flex; align-items: center; gap: 0.5rem; color: var(--text); }
.nudge-pill {
    font-size: 0.66rem;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 999px;
    letter-spacing: 0.3px;
}
.nudge-pill.add { background: color-mix(in srgb, var(--sync-pending) 25%, var(--surface)); color: var(--sync-pending); }
.nudge-pill.change { background: color-mix(in srgb, var(--sync-differs) 22%, var(--surface)); color: var(--sync-differs); }
.nudge-pill.conflict { background: var(--sync-differs); color: #fff; }
.nudge-past { font-size: 0.75rem; }
.nudge-send { display: flex; align-items: center; flex-wrap: wrap; gap: 0.8rem; margin-top: 0.2rem; }
.nudge-recip { display: inline-flex; align-items: center; gap: 0.35rem; color: var(--text); cursor: pointer; }
.nudge-send-btn {
    background: var(--sean);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 0.4rem 0.9rem;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
}
.nudge-send-btn:disabled { opacity: 0.5; cursor: default; }
.apple-panel .muted { color: var(--text-dim); }

/* ---- Login ---- */
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.login-card {
    width: 100%;
    max-width: 360px;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: 16px;
    padding: 2rem 1.6rem;
    text-align: center;
}
.login-brand { font-size: 2rem; font-weight: 800; margin: 0 0 1rem; letter-spacing: 0.5px; }
.login-lead { color: var(--text-dim); font-size: 0.92rem; margin-bottom: 1.2rem; }
.login-form { display: flex; flex-direction: column; gap: 0.7rem; }
.login-input {
    background: var(--cell);
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 0.7rem 0.8rem;
    color: var(--text);
    font-size: 1rem;
}
.login-input:focus { outline: none; border-color: var(--sean); }
.login-btn {
    background: var(--sean);
    color: #fff;
    border: none;
    border-radius: 9px;
    padding: 0.7rem 0.8rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}
.login-btn:hover { filter: brightness(1.08); }
.login-msg { font-size: 0.9rem; line-height: 1.4; padding: 0.6rem; border-radius: 9px; }
.login-msg-ok { background: color-mix(in srgb, var(--amanda) 20%, var(--surface)); color: var(--text); }
.login-msg-err { background: color-mix(in srgb, #c0392b 22%, var(--surface)); color: var(--text); margin-bottom: 1rem; }

.placeholder { padding: 2rem; }
