/* Leaf Calendar — component styles (Gantt timeline + chrome).
   Tokens live in leaf-calendar-tokens.css and are scoped to .leaf-calendar. */

.leaf-calendar {
    display: flex; flex-direction: column;
    min-height: 100%;
    isolation: isolate;
}

/* ─── Date bar ─────────────────────────────────────────────────────── */
.leaf-calendar .lcdb {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 20px; gap: 20px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}
.leaf-calendar .lcdb-left,
.leaf-calendar .lcdb-right { display: flex; align-items: center; gap: 14px; }
.leaf-calendar .lcdb-nav-stack {
    display: flex; flex-direction: column;
    gap: 4px; align-items: flex-start;
}
.leaf-calendar .lcdb-nav-row { display: flex; align-items: center; gap: 6px; }
.leaf-calendar .lcdb-navgroup { display: flex; gap: 2px; }
.leaf-calendar .lcdb-arrow,
.leaf-calendar .lcdb-today {
    appearance: none; border: 1px solid var(--line); background: var(--surface);
    padding: 0 10px; min-width: 30px; height: 28px;
    border-radius: 6px; font-size: 12.5px; color: var(--ink-1); cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
}
.leaf-calendar .lcdb-today { font-weight: 600; padding: 0 14px; }
.leaf-calendar .lcdb-arrow:hover,
.leaf-calendar .lcdb-today:hover { background: var(--line-2); }

.leaf-calendar .lcdb-cycles {
    display: flex; padding: 2px;
    background: var(--surface-2); border: 1px solid var(--line);
    border-radius: 7px;
    align-self: flex-start;
}
.leaf-calendar .lcdb-cycle {
    appearance: none; border: 0; background: transparent;
    padding: 3px 9px; border-radius: 5px; cursor: pointer;
    display: flex; align-items: baseline; gap: 5px; line-height: 1.2;
    color: var(--ink-2);
}
.leaf-calendar .lcdb-cycle .lcdb-cycle-lbl { font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.leaf-calendar .lcdb-cycle .lcdb-cycle-sub { font-size: 9.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.leaf-calendar .lcdb-cycle.is-active {
    background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,.06);
    color: var(--ink-1);
}
.leaf-calendar .lcdb-cycle.is-active .lcdb-cycle-sub { color: var(--accent); }

.leaf-calendar .lcdb-group {
    display: flex; align-items: center; padding: 2px;
    background: var(--surface-2); border: 1px solid var(--line);
    border-radius: 8px;
}
.leaf-calendar .lcdb-group-lbl {
    font-size: 10.5px; color: var(--ink-3);
    padding: 0 8px 0 4px;
    text-transform: uppercase; letter-spacing: 0.06em;
    font-weight: 600;
}
.leaf-calendar .lcdb-group-btn {
    appearance: none; border: 0; background: transparent;
    padding: 5px 11px; border-radius: 6px; cursor: pointer;
    font-size: 12px; font-weight: 600; color: var(--ink-2);
    display: inline-flex; align-items: center; gap: 5px;
}
.leaf-calendar .lcdb-group-btn:hover { color: var(--ink-1); }
.leaf-calendar .lcdb-group-btn.is-active {
    background: var(--surface); color: var(--ink-1);
    box-shadow: 0 1px 2px rgba(0,0,0,.06);
}

/* Coverage-highlight toggles (Under / Over) — mirror the group toggle, independent on/off. */
.leaf-calendar .lcdb-hl {
    display: flex; align-items: center; padding: 2px;
    background: var(--surface-2); border: 1px solid var(--line);
    border-radius: 8px;
}
.leaf-calendar .lcdb-hl-btn {
    appearance: none; border: 0; background: transparent;
    padding: 5px 10px; border-radius: 6px; cursor: pointer;
    font-size: 12px; font-weight: 600; color: var(--ink-3);
    display: inline-flex; align-items: center; gap: 6px;
}
.leaf-calendar .lcdb-hl-btn:hover { color: var(--ink-1); }
.leaf-calendar .lcdb-hl-btn.is-active {
    background: var(--surface); color: var(--ink-1);
    box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.leaf-calendar .lcdb-hl-dot { width: 9px; height: 9px; border-radius: 3px; background: var(--line-2); }
.leaf-calendar .lcdb-hl--under .lcdb-hl-dot { background: rgba(214,158,46,0.9); }
.leaf-calendar .lcdb-hl--over .lcdb-hl-dot { background: rgba(120,80,170,0.85); }
.leaf-calendar .lcdb-hl-btn:not(.is-active) .lcdb-hl-dot { opacity: 0.35; }

.leaf-calendar .lcdb-primary {
    appearance: none; border: 0; background: var(--accent); color: #fff;
    padding: 6px 14px; border-radius: 7px; font-weight: 600; font-size: 12.5px; cursor: pointer;
    display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
    box-shadow: 0 1px 2px rgba(20,40,20,.18), inset 0 1px 0 rgba(255,255,255,.18);
}
.leaf-calendar .lcdb-primary:hover { filter: brightness(0.95); }
.leaf-calendar .lcdb-primary-plus { font-size: 16px; line-height: 0.5; transform: translateY(-1px); }

/* ─── Timeline wrap ────────────────────────────────────────────────── */
.leaf-calendar .htl-wrap {
    padding: 14px 20px 60px;
    overflow-x: auto;
    flex: 1;
}
.leaf-calendar .htl {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
    min-width: 1100px;
}

/* Day header */
.leaf-calendar .htl-head-row {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    border-bottom: 1px solid var(--line);
    background: var(--surface-2);
    position: relative;
}
.leaf-calendar .htl-head-day {
    border-right: 1px solid var(--line);
    padding: 9px 12px 6px;
    position: relative;
    min-width: 0;
}
.leaf-calendar .htl-head-day:last-child { border-right: 0; }
.leaf-calendar .htl-hd-top { display: flex; align-items: baseline; gap: 8px; }
.leaf-calendar .htl-hd-dow {
    font-size: 10.5px; color: var(--ink-3); text-transform: uppercase;
    letter-spacing: 0.06em; font-weight: 600;
}
.leaf-calendar .htl-hd-date {
    font-size: 13.5px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.leaf-calendar .htl-head-day.is-today { background: var(--accent-soft); }
.leaf-calendar .htl-head-day.is-today .htl-hd-dow,
.leaf-calendar .htl-head-day.is-today .htl-hd-date { color: var(--accent-ink); }
.leaf-calendar .htl-head-day.is-weekend { background: var(--surface-2); }
.leaf-calendar .htl-head-day.is-weekend .htl-hd-dow,
.leaf-calendar .htl-head-day.is-weekend .htl-hd-date { color: var(--ink-2); }
.leaf-calendar .htl-hd-pill {
    position: absolute; top: 8px; right: 10px;
    background: var(--accent); color: #fff; font-size: 9px; font-weight: 700;
    padding: 2px 6px; border-radius: 999px; letter-spacing: 0.06em; text-transform: uppercase;
}
.leaf-calendar .htl-hd-ticks {
    display: grid; grid-template-columns: repeat(4, 1fr) auto;
    font: 500 9px/1 "JetBrains Mono", ui-monospace, monospace;
    color: var(--ink-3);
    margin-top: 4px;
    opacity: 0.75;
}
.leaf-calendar .htl-hd-ticks > span { padding-right: 4px; }
.leaf-calendar .htl-hd-ticks > span:last-child { text-align: right; }

.leaf-calendar .htl-now-toplabel {
    position: absolute; top: 4px;
    transform: translateX(-50%);
    background: #d6443c; color: #fff;
    font: 700 9px/1 "JetBrains Mono", ui-monospace, monospace;
    padding: 3px 6px; border-radius: 3px;
    letter-spacing: 0.06em;
    z-index: 4;
    white-space: nowrap;
}

/* Body — stacked location panels */
.leaf-calendar .htl-body { background: var(--surface); }
.leaf-calendar .htl-loc { border-bottom: 1px solid var(--line); }
.leaf-calendar .htl-loc:last-child { border-bottom: 0; }

.leaf-calendar .htl-loc-head {
    display: grid;
    grid-template-columns: 22px minmax(0, 1.4fr) minmax(280px, 0.9fr);
    align-items: center;
    gap: 18px;
    padding: 10px 16px 9px;
    background: linear-gradient(180deg, #f5f2ea, #efece4);
}
.leaf-calendar .htl-loc-toggle {
    appearance: none; background: transparent; border: 0; padding: 4px 2px 0;
    color: var(--ink-2); cursor: pointer; line-height: 0;
}
.leaf-calendar .htl-loc-id { min-width: 0; }
.leaf-calendar .htl-loc-title {
    display: flex; align-items: center; gap: 7px;
    font-weight: 700; font-size: 13.5px; letter-spacing: -0.005em;
}
.leaf-calendar .htl-loc-addr { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.leaf-calendar .htl-loc-nick {
    margin-left: auto;
    font-size: 10.5px; color: var(--ink-3); font-weight: 500;
    background: var(--surface); border: 1px solid var(--line);
    padding: 1px 7px; border-radius: 999px;
}
.leaf-calendar .htl-loc-clients { font-size: 11.5px; color: var(--ink-2); margin-top: 2px; }
.leaf-calendar .htl-loc-sep { color: var(--ink-4); margin: 0 5px; }
.leaf-calendar .htl-loc-bar { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.leaf-calendar .htl-loc-bar .loc-bar { height: 4px; background: var(--line); border-radius: 999px; overflow: hidden; }
.leaf-calendar .htl-loc-bar .loc-bar-fill { height: 100%; border-radius: 999px; transition: width .3s; background: var(--accent); }
.leaf-calendar .htl-loc-bar .loc-totals-nums { display: flex; gap: 10px; flex-wrap: wrap; font-size: 11px; color: var(--ink-2); }
.leaf-calendar .htl-loc-bar .loc-totals-nums b { color: var(--ink-1); font-size: 12.5px; font-weight: 700; margin-right: 4px; }
.leaf-calendar .htl-loc-bar .loc-totals-nums i { font-style: normal; color: var(--ink-3); font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; }
.leaf-calendar .htl-loc-bar .loc-totals-nums .lcs-warn { color: var(--c-conf-fg); }

/* Canvas — the actual timeline grid + shifts */
.leaf-calendar .htl-canvas {
    position: relative;
    background: var(--surface);
    border-top: 1px solid var(--line-2);
}
.leaf-calendar .htl-grid {
    position: absolute; inset: 0;
    display: grid; grid-template-columns: repeat(7, 1fr);
    pointer-events: none;
}
.leaf-calendar .htl-day-cell {
    border-right: 1px solid var(--line-2);
    background-image: linear-gradient(to right,
        transparent 0, transparent calc(25% - 0.5px),
        var(--line-2) calc(25% - 0.5px), var(--line-2) 25%,
        transparent 25%, transparent calc(50% - 0.5px),
        var(--line) calc(50% - 0.5px), var(--line) 50%,
        transparent 50%, transparent calc(75% - 0.5px),
        var(--line-2) calc(75% - 0.5px), var(--line-2) 75%,
        transparent 75%);
}
.leaf-calendar .htl-day-cell:last-child { border-right: 0; }
.leaf-calendar .htl-day-cell.is-today { background-color: rgba(47,122,58,0.045); }
.leaf-calendar .htl-day-cell.is-weekend { background-color: var(--surface-2); }

/* NOW marker */
.leaf-calendar .htl-now {
    position: absolute; top: 0; bottom: 0; width: 0;
    border-left: 1.5px solid #d6443c;
    z-index: 4; pointer-events: none;
}
.leaf-calendar .htl-now::before {
    content: ""; position: absolute; left: -3px; top: -3px;
    width: 6px; height: 6px; border-radius: 50%; background: #d6443c;
    box-shadow: 0 0 0 2px rgba(214,68,60,0.18);
}

/* Needed-coverage gauge (quantity: needed vs scheduled hours, 1 lane = 8h).
   Solid fills + a dashed target line — deliberately distinct from the diagonal
   time-of-day gap hatch, and drawn behind the shift bars. */
.leaf-calendar .htl-need {
    position: absolute;
    z-index: 0;               /* behind gaps (z1), shifts (z2), now-marker (z4) */
    pointer-events: none;     /* decorative — let clicks reach the add-zone */
}

/* Drawer in-place edit panel */
.leaf-calendar .lcdr-edit { display: flex; flex-direction: column; gap: 10px; padding: 8px 0 2px; }

/* Click-to-add zone: one transparent layer per day, beneath the shift bars (z1 < shifts'
   z2) so clicking empty space adds a shift while clicking a shift still edits it. */
.leaf-calendar .htl-addzone {
    position: absolute; top: 0; bottom: 0;
    z-index: 1;
    cursor: pointer;
    background: transparent;
}
.leaf-calendar .htl-addzone:hover { background: rgba(47,122,58,0.04); }
/* Under-covered: needed > scheduled — faint amber, pinned to the bottom. */
.leaf-calendar .htl-need--under { background: rgba(214,158,46,0.09); border-radius: 4px 4px 0 0; }
.leaf-calendar .htl-need--under:hover { background: rgba(214,158,46,0.16); cursor: help; }
/* Over-covered: scheduled > needed — faint, pinned to the top. */
.leaf-calendar .htl-need--over { background: rgba(120,80,170,0.11); border-radius: 0 0 4px 4px; }
.leaf-calendar .htl-need--over:hover { background: rgba(120,80,170,0.18); cursor: help; }

/* Coverage gap */
.leaf-calendar .htl-gap {
    position: absolute; top: 2px;
    background:
        repeating-linear-gradient(45deg,
            rgba(214,68,60,0.08) 0 5px,
            rgba(214,68,60,0.14) 5px 10px);
    border: 1px dashed rgba(214,68,60,0.4);
    border-radius: 4px;
    z-index: 1;
    pointer-events: none;     /* decorative — clicking a gap adds a shift via the add-zone */
}

/* Shift bar */
.leaf-calendar .htlb {
    position: absolute;
    appearance: none; padding: 0; margin: 0;
    background: var(--pill-bg);
    color: var(--pill-fg);
    border: 1px solid var(--pill-bd);
    border-left: 4px solid var(--pill-fg);
    border-radius: 5px;
    display: flex; flex-direction: column;
    justify-content: center; align-items: stretch;
    gap: 1px;
    padding: 4px 8px 4px 9px;
    cursor: pointer;
    overflow: hidden;
    z-index: 2;
    transition: transform .12s, box-shadow .12s, filter .12s;
    box-shadow: 0 1px 0 rgba(0,0,0,.04);
    text-align: left;
    container-type: inline-size;
    container-name: htlb;
}
.leaf-calendar .htlb:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0,0,0,.10);
    filter: brightness(1.02);
    z-index: 5;
}
.leaf-calendar .htlb-bleedL {
    border-left-color: transparent;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}
.leaf-calendar .htlb-bleedL::before {
    content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
    background-image: linear-gradient(to bottom, var(--pill-fg) 0 3px, transparent 3px 6px);
    background-size: 3px 6px;
    opacity: 0.6;
}
.leaf-calendar .htlb-bleedR {
    border-right: 0;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}
.leaf-calendar .htlb-line {
    display: flex; align-items: center; gap: 5px;
    min-width: 0;
    line-height: 1.15;
    width: 100%;
}
.leaf-calendar .htlb-line-1 {
    font-size: 12px; font-weight: 700;
    color: var(--pill-fg);
}
.leaf-calendar .htlb-line-2 {
    font-size: 11px;
    font-weight: 600;
    color: var(--pill-fg);
    opacity: 0.85;
    margin-top: 1px;
}
.leaf-calendar .htlb-time {
    display: inline-flex; align-items: baseline; gap: 2px;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.leaf-calendar .htlb-dash { opacity: 0.5; padding: 0 1px; font-weight: 400; }
.leaf-calendar .htlb-cont { opacity: 0.7; padding-right: 2px; font-weight: 700; }
.leaf-calendar .htlb-recur { opacity: 0.65; padding-right: 2px; font-weight: 700; flex-shrink: 0; }
.leaf-calendar .htlb-sub {
    flex: 1; min-width: 0;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    letter-spacing: 0.04em;
}
.leaf-calendar .htlb-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--c-live-fg);
    margin-right: 1px;
    animation: leafCalendarLiveDotPulse 1.4s ease-in-out infinite;
    flex-shrink: 0;
}

/* Status-specific bar treatment */
.leaf-calendar .htlb.status-live      { animation: leafCalendarLivePulse 1.8s ease-in-out infinite; }
.leaf-calendar .htlb.status-conflict  { animation: leafCalendarConflictPulse 1.8s ease-in-out infinite; }
.leaf-calendar .htlb.status-completed { opacity: 0.78; }
.leaf-calendar .htlb.status-completed:hover { opacity: 1; }
.leaf-calendar .htlb.status-cancelled { opacity: 0.6; text-decoration: line-through; }
.leaf-calendar .htlb.status-open      { background: transparent; border-style: dashed; }

/* Container queries — degrade gracefully on narrow bars */
@container htlb (max-width: 110px) {
    .leaf-calendar .htlb-hrs { display: none; }
}
@container htlb (max-width: 72px) {
    .leaf-calendar .htlb-dash,
    .leaf-calendar .htlb-time :not(b):not(.htlb-cont) { display: none; }
}
@container htlb (max-width: 44px) {
    .leaf-calendar .htlb-sub { font-size: 9.5px; }
    .leaf-calendar .htlb-line-1 { font-size: 10px; }
}
@container htlb (max-width: 28px) {
    .leaf-calendar .htlb-line-2 { display: none; }
}

/* Duration chip rendered outside the bar */
.leaf-calendar .htlb-duration {
    position: absolute;
    transform: translateY(-50%);
    font: 700 11px/1 "JetBrains Mono", ui-monospace, monospace;
    color: var(--ink-2);
    pointer-events: none;
    white-space: nowrap;
    letter-spacing: -0.01em;
    z-index: 1;
    padding: 1px 5px;
    border-radius: 4px;
    background: rgba(0,0,0,0.04);
}

/* Drawer */
.leaf-calendar .lcdrawer-hd {
    display: flex; gap: 14px; align-items: flex-start;
    padding: 18px 18px 14px; border-bottom: 1px solid var(--line);
}
.leaf-calendar .lcdrawer-day {
    background: var(--accent-soft); color: var(--accent-ink);
    width: 50px; height: 50px; border-radius: 8px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.leaf-calendar .lcdrawer-day-dow { font-size: 9.5px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.leaf-calendar .lcdrawer-day-date { font-size: 20px; font-weight: 700; line-height: 1; }
.leaf-calendar .lcdrawer-title { flex: 1; min-width: 0; }
.leaf-calendar .lcdrawer-lbl { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.leaf-calendar .lcdrawer-sub { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.leaf-calendar .lcdrawer-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.leaf-calendar .lcdr-row {
    display: flex; justify-content: space-between; gap: 12px;
    font-size: 12.5px; padding: 6px 0; border-bottom: 1px dashed var(--line);
}
.leaf-calendar .lcdr-row > span:first-child { color: var(--ink-3); }
.leaf-calendar .lcdr-row > span:last-child { color: var(--ink-1); font-weight: 500; text-align: right; }
.leaf-calendar .lcdr-status-chip {
    text-transform: capitalize;
    padding: 2px 8px; border-radius: 999px;
    font-size: 11px; font-weight: 600;
}
.leaf-calendar .lcdrawer-actions { display: flex; gap: 8px; margin-top: 10px; }
