/* ─────────────────────────────────────────────────────────────────────────
   Leaf design system — the canonical shared layer.

   Tokens live on :root so every scope (the bespoke .care-review /
   .leaf-ledger / .leaf-calendar / .sv-scope / .gh blocks included) resolves
   the same warm-neutral palette. Primitives are prefixed .lf-* and scoped
   under .leaf-ds, which MainLayout puts on the app shell — so every page gets
   the type ramp + primitives.

   Where a bespoke sheet (schedule-visit.css, care-review.css, greenhouse.css)
   redefines a primitive it loads AFTER this file and wins at equal
   specificity. That is deliberate: those screens were designed first and stay
   pixel-stable.

   Fonts (Manrope, JetBrains Mono) load in App.razor.
   ───────────────────────────────────────────────────────────────────────── */

:root {
    /* Surfaces & ink (warm neutral) */
    --bg: #f7f6f3;
    --surface: #ffffff;
    --surface-2: #faf9f6;
    --surface-3: #f2f0ea;
    --ink-1: #1b1a17;
    --ink-2: #5b5953;
    --ink-3: #8a8881;
    --ink-4: #c8c5be;
    --line: #e9e6df;
    --line-2: #efece5;

    /* Brand */
    --accent: #2f7a3a;
    --accent-hover: #2a6e34;
    --accent-soft: #e6f0e3;
    --accent-ink: #1f4e2a;
    --warn: #c67a06;

    /* Status palette — the shared vocabulary */
    --c-sched-bg: #e8f1e6; --c-sched-fg: #1f4e2a; --c-sched-bd: #c6dec0;
    --c-live-bg:  #e0ecff; --c-live-fg:  #0a3d8a; --c-live-bd:  #b9d1f5;
    --c-done-bg:  #ececea; --c-done-fg:  #4d4a45; --c-done-bd:  #d8d6d2;
    --c-warn-bg:  #fbeed0; --c-warn-fg:  #7a4a06; --c-warn-bd:  #efd58a;
    --c-conf-bg:  #f9dfde; --c-conf-fg:  #8a1b1a; --c-conf-bd:  #ebbab8;
    --c-canc-bg:  #f0eeec; --c-canc-fg:  #807c75; --c-canc-bd:  #d8d4cd;

    /* Radii */
    --r-3: 6px; --r-4: 7px; --r-5: 8px; --r-6: 10px; --r-8: 12px; --r-pill: 999px;

    /* Elevation — soft and warm, never Material's blue-grey */
    --sh-1: 0 1px 2px rgba(20, 20, 15, 0.05);
    --sh-2: 0 2px 8px rgba(20, 20, 15, 0.07);
    --sh-3: 0 12px 32px rgba(20, 20, 15, 0.12);
    --sh-4: 0 24px 64px rgba(20, 20, 15, 0.22), 0 2px 6px rgba(20, 20, 15, 0.08);

    /* Type */
    --font-ui: "Manrope", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, monospace;
    --rv-font-ui: var(--font-ui);
    --rv-font-mono: var(--font-mono);
    --rv-deliv: #6f6c65;

    /* Focus */
    --focus-ring: 0 0 0 3px rgba(47, 122, 58, 0.16);
}

.leaf-ds {
    font-family: var(--font-ui);
    color: var(--ink-1);
    -webkit-font-smoothing: antialiased;
}
.leaf-ds *, .leaf-ds *::before, .leaf-ds *::after { box-sizing: border-box; }

/* Per-status token bundles. dot = flag/marker; bar = single-bar fill; ink = text;
   tint = wash/cell bg; line = border. (Cell bars override the fill — see ds-cellbar-fill.) */
.leaf-ds .ds-st-ok     { --st-dot: var(--line);      --st-bar: var(--rv-deliv);  --st-ink: var(--ink-2);     --st-tint: var(--surface-2); --st-line: var(--line); }
.leaf-ds .ds-st-under  { --st-dot: var(--ink-1);     --st-bar: var(--c-warn-fg); --st-ink: var(--c-warn-fg); --st-tint: var(--c-warn-bg); --st-line: var(--c-warn-bd); }
.leaf-ds .ds-st-missed { --st-dot: var(--c-warn-fg); --st-bar: var(--c-warn-fg); --st-ink: var(--c-warn-fg); --st-tint: var(--c-warn-bg); --st-line: var(--c-warn-bd); }
.leaf-ds .ds-st-over   { --st-dot: var(--c-conf-fg); --st-bar: var(--c-conf-fg); --st-ink: var(--c-conf-fg); --st-tint: var(--c-conf-bg); --st-line: var(--c-conf-bd); }
.leaf-ds .ds-st-none   { --st-dot: var(--line);      --st-bar: var(--ink-4);     --st-ink: var(--ink-3);     --st-tint: transparent;      --st-line: var(--line); }

/* ══ Text primitives ═══════════════════════════════════════════════════════ */
.leaf-ds .ds-eyebrow, .leaf-ds .lf-eyebrow { font-size: 10.5px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 4px; }
.leaf-ds .ds-title { font-size: 21px; font-weight: 700; letter-spacing: -0.01em; }
.leaf-ds .ds-subtitle { font-size: 12.5px; color: var(--ink-2); margin-top: 3px; }
.leaf-ds .ds-num, .leaf-ds .lf-num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.leaf-ds .lf-muted { color: var(--ink-3); }
.leaf-ds .lf-truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

/* ══ Status chip (legacy ds-chip; see .lf-tag for the general tone chip) ═════ */
.leaf-ds .ds-chip {
    display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
    background: var(--st-tint); color: var(--st-ink); border: 1px solid var(--st-line);
    padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* ══ Legend ════════════════════════════════════════════════════════════════ */
.leaf-ds .ds-legend { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.leaf-ds .ds-legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--ink-2); }
.leaf-ds .ds-legend-pill { width: 16px; height: 8px; border-radius: 999px; }
.leaf-ds .ds-legend-sq { width: 10px; height: 10px; border-radius: 3px; }
.leaf-ds .ds-legend-div { width: 1px; height: 14px; background: var(--line); }

/* ══ Cell bar (6px chain bar for the day matrix) ═══════════════════════════════
   Layer widths are set inline as percentages: clamp(v/max,0,1)*100%.
   The delivered fill is the neutral gray by default; rose only when over auth —
   the amber wash (not the fill) carries the under/missed shortfall. */
.leaf-ds .ds-cellbar { position: relative; height: 6px; width: 100%; }
.leaf-ds .ds-cellbar-track { position: absolute; left: 0; top: 0; height: 100%; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; box-sizing: border-box; }
.leaf-ds .ds-cellbar-wash { position: absolute; top: 0; height: 100%; background: var(--c-warn-bg); border: 1px solid var(--c-warn-bd); border-left: 0; border-radius: 0 999px 999px 0; box-sizing: border-box; }
.leaf-ds .ds-cellbar-wash--missed { background-image: repeating-linear-gradient(45deg, var(--c-warn-bg) 0 3px, rgba(198,122,6,0.20) 3px 6px); }
.leaf-ds .ds-cellbar-fill { position: absolute; left: 0; top: 0; height: 100%; background: var(--rv-deliv); border-radius: 999px; transition: width .3s; }
.leaf-ds .ds-cellbar-fill--over { background: var(--c-conf-fg); }
.leaf-ds .ds-cellbar-tick { position: absolute; top: -2px; height: 10px; width: 0; border-left: 1.5px dashed var(--ink-3); }

/* ══════════════════════════════════════════════════════════════════════════
   PAGE SCAFFOLD
   ══════════════════════════════════════════════════════════════════════════ */
.leaf-ds .lf-page { max-width: 1360px; margin: 0 auto; padding: 0 0 40px; }
.leaf-ds .lf-page.is-narrow { max-width: 920px; }
.leaf-ds .lf-page.is-wide { max-width: none; }

.leaf-ds .lf-page-head {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 24px; flex-wrap: wrap; margin-bottom: 20px;
}
.leaf-ds .lf-page-title { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.leaf-ds .lf-page-sub { font-size: 13px; color: var(--ink-2); margin-top: 5px; max-width: 68ch; }
.leaf-ds .lf-page-actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }

.leaf-ds .lf-back {
    display: inline-flex; align-items: center; gap: 5px; margin-bottom: 9px;
    font-size: 12px; font-weight: 600; color: var(--ink-3); text-decoration: none;
}
.leaf-ds .lf-back:hover { color: var(--ink-1); }

.leaf-ds .lf-section { margin-top: 26px; }
.leaf-ds .lf-section-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 11px; }
.leaf-ds .lf-section-title { font-size: 14px; font-weight: 700; letter-spacing: -0.01em; }
.leaf-ds .lf-section-sub { font-size: 11.5px; color: var(--ink-3); }
.leaf-ds .lf-rule { height: 1px; background: var(--line); border: 0; margin: 22px 0; }

/* ══════════════════════════════════════════════════════════════════════════
   CARD
   ══════════════════════════════════════════════════════════════════════════ */
.leaf-ds .lf-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-8); overflow: hidden; }
.leaf-ds .lf-card.is-flush { overflow: visible; }
.leaf-ds .lf-card + .lf-card { margin-top: 16px; }
.leaf-ds .lf-card-head {
    display: flex; align-items: center; justify-content: space-between; gap: 14px;
    padding: 13px 18px; border-bottom: 1px solid var(--line-2); background: var(--surface-2);
}
.leaf-ds .lf-card-title { font-size: 13.5px; font-weight: 700; letter-spacing: -0.005em; }
.leaf-ds .lf-card-sub { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; font-weight: 500; }
.leaf-ds .lf-card-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.leaf-ds .lf-card-body { padding: 18px; }
.leaf-ds .lf-card-body.is-tight { padding: 12px 14px; }
.leaf-ds .lf-card-foot {
    display: flex; align-items: center; justify-content: flex-end; gap: 10px;
    padding: 13px 18px; border-top: 1px solid var(--line-2); background: var(--surface-2);
}

.leaf-ds .lf-grid { display: grid; gap: 16px; align-items: start; }
.leaf-ds .lf-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.leaf-ds .lf-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.leaf-ds .lf-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .leaf-ds .lf-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .leaf-ds .lf-grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px)  { .leaf-ds .lf-grid-2, .leaf-ds .lf-grid-3, .leaf-ds .lf-grid-4 { grid-template-columns: minmax(0, 1fr); } }

/* ══════════════════════════════════════════════════════════════════════════
   STAT TILE
   ══════════════════════════════════════════════════════════════════════════ */
.leaf-ds .lf-stats { display: flex; gap: 10px; flex-wrap: wrap; }
.leaf-ds .lf-stat { min-width: 146px; padding: 11px 13px; border-radius: var(--r-6); background: var(--surface-2); border: 1px solid var(--line); }
.leaf-ds .lf-stat.is-flag { background: var(--st-tint); border-color: var(--st-line); }
.leaf-ds .lf-stat-label { font-size: 9.5px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.05em; }
.leaf-ds .lf-stat-value { font-size: 23px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.15; margin-top: 3px; color: var(--ink-1); }
.leaf-ds .lf-stat.is-flag .lf-stat-value { color: var(--st-ink); }
.leaf-ds .lf-stat-sub { font-size: 10px; color: var(--ink-3); margin-top: 1px; }

/* ══════════════════════════════════════════════════════════════════════════
   TOOLBAR / FILTER BAR
   ══════════════════════════════════════════════════════════════════════════ */
.leaf-ds .lf-toolbar {
    display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap;
    padding: 12px 14px; margin-bottom: 14px;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-6);
}
.leaf-ds .lf-toolbar.is-plain { background: transparent; border: 0; padding: 0; }
.leaf-ds .lf-toolbar-spacer { flex: 1 1 auto; }
.leaf-ds .lf-toolbar .lf-field { flex: 0 1 auto; }
.leaf-ds .lf-count { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.leaf-ds .lf-count b { color: var(--ink-1); font-weight: 700; }

/* ══════════════════════════════════════════════════════════════════════════
   BUTTONS
   ══════════════════════════════════════════════════════════════════════════ */
.leaf-ds .lf-btn {
    appearance: none; border: 1px solid transparent; cursor: pointer;
    height: 38px; padding: 0 16px; border-radius: var(--r-4);
    font: 600 12.5px/1 var(--font-ui); white-space: nowrap; text-decoration: none;
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    transition: background .12s, border-color .12s, color .12s, box-shadow .12s;
}
.leaf-ds .lf-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.leaf-ds .lf-btn.is-sm { height: 32px; padding: 0 12px; font-size: 12px; }
.leaf-ds .lf-btn.is-lg { height: 44px; padding: 0 22px; font-size: 13.5px; }
.leaf-ds .lf-btn.is-block { width: 100%; }
.leaf-ds .lf-btn:disabled, .leaf-ds .lf-btn.is-disabled { cursor: not-allowed; }

.leaf-ds .lf-btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); box-shadow: 0 1px 0 rgba(0,0,0,0.04); }
.leaf-ds .lf-btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.leaf-ds .lf-btn-primary:disabled { background: var(--ink-4); border-color: var(--ink-4); color: #fff; box-shadow: none; }

.leaf-ds .lf-btn-ghost { background: var(--surface); color: var(--ink-2); border-color: var(--line); }
.leaf-ds .lf-btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--ink-1); border-color: var(--ink-4); }
.leaf-ds .lf-btn-ghost:disabled { color: var(--ink-4); background: var(--surface-2); }

.leaf-ds .lf-btn-subtle { background: transparent; color: var(--ink-2); border-color: transparent; }
.leaf-ds .lf-btn-subtle:hover:not(:disabled) { background: var(--surface-3); color: var(--ink-1); }

.leaf-ds .lf-btn-danger { background: var(--surface); color: var(--c-conf-fg); border-color: var(--c-conf-bd); }
.leaf-ds .lf-btn-danger:hover:not(:disabled) { background: var(--c-conf-bg); }
.leaf-ds .lf-btn-danger-solid { background: var(--c-conf-fg); color: #fff; border-color: var(--c-conf-fg); }
.leaf-ds .lf-btn-danger-solid:hover:not(:disabled) { background: #741615; }

.leaf-ds .lf-btn-link { background: transparent; border: 0; padding: 0; height: auto; color: var(--accent-ink); font-weight: 600; text-decoration: none; }
.leaf-ds .lf-btn-link:hover { text-decoration: underline; }

.leaf-ds .lf-iconbtn {
    appearance: none; border: 1px solid var(--line); background: var(--surface);
    width: 34px; height: 34px; border-radius: var(--r-4); cursor: pointer;
    color: var(--ink-2); display: inline-flex; align-items: center; justify-content: center;
    flex: 0 0 auto; padding: 0; transition: background .12s, color .12s, border-color .12s;
}
.leaf-ds .lf-iconbtn:hover:not(:disabled) { background: var(--surface-2); color: var(--ink-1); border-color: var(--ink-4); }
.leaf-ds .lf-iconbtn:disabled { color: var(--ink-4); cursor: not-allowed; }
.leaf-ds .lf-iconbtn.is-sm { width: 28px; height: 28px; }
.leaf-ds .lf-iconbtn.is-bare { border-color: transparent; background: transparent; }
.leaf-ds .lf-iconbtn.is-bare:hover:not(:disabled) { background: var(--surface-3); border-color: transparent; }
.leaf-ds .lf-iconbtn.is-danger { color: var(--c-conf-fg); }
.leaf-ds .lf-iconbtn.is-danger:hover:not(:disabled) { background: var(--c-conf-bg); border-color: var(--c-conf-bd); }

.leaf-ds .lf-btngroup { display: inline-flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ══════════════════════════════════════════════════════════════════════════
   FORM FIELDS
   ══════════════════════════════════════════════════════════════════════════ */
.leaf-ds .lf-field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.leaf-ds .lf-label { font: 600 10.5px/1.2 var(--font-ui); color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.06em; }
.leaf-ds .lf-label .req { color: var(--accent); margin-left: 2px; }
.leaf-ds .lf-help { font-size: 11px; color: var(--ink-3); line-height: 1.35; }
.leaf-ds .lf-error { font-size: 11px; color: var(--c-conf-fg); font-weight: 600; line-height: 1.35; }

.leaf-ds .lf-control {
    appearance: none; -webkit-appearance: none;
    width: 100%; text-align: left;
    background: var(--surface); color: var(--ink-1);
    border: 1px solid var(--line); border-radius: var(--r-4);
    padding: 0 12px; height: 40px;
    font: 500 13px/1 var(--font-ui);
    transition: border-color .12s, box-shadow .12s, background .12s;
    font-variant-numeric: tabular-nums;
}
.leaf-ds div.lf-control, .leaf-ds button.lf-control, .leaf-ds a.lf-control { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.leaf-ds select.lf-control {
    cursor: pointer; padding-right: 32px;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238a8881' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center;
}
.leaf-ds textarea.lf-control { height: auto; min-height: 86px; padding: 10px 12px; line-height: 1.5; resize: vertical; }
.leaf-ds .lf-control::placeholder { color: var(--ink-3); }
.leaf-ds .lf-control:hover:not(:disabled) { border-color: var(--ink-4); }
.leaf-ds .lf-control:focus, .leaf-ds .lf-control.is-focus, .leaf-ds .lf-control:focus-within { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
.leaf-ds .lf-control:disabled, .leaf-ds .lf-control.is-disabled { background: var(--surface-2); color: var(--ink-3); cursor: not-allowed; }
.leaf-ds .lf-control.is-invalid { border-color: var(--c-conf-bd); background: #fffbfb; }
.leaf-ds .lf-control.is-invalid:focus { border-color: var(--c-conf-fg); box-shadow: 0 0 0 3px rgba(138,27,26,0.13); }
.leaf-ds input.lf-control::-webkit-calendar-picker-indicator { cursor: pointer; opacity: 0.5; }
.leaf-ds .lf-control .lf-ctl-val { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaf-ds .lf-control .lf-ctl-ph { color: var(--ink-3); }
.leaf-ds .lf-control .lf-chev, .leaf-ds .lf-control .lf-ctl-icon { color: var(--ink-3); flex: 0 0 auto; display: flex; }
.leaf-ds .lf-suffix { color: var(--ink-3); font-weight: 500; flex: 0 0 auto; }

/* Field grid — the standard 12-col form layout */
.leaf-ds .lf-fields { display: grid; gap: 14px; grid-template-columns: repeat(12, minmax(0, 1fr)); }
.leaf-ds .lf-fields > * { grid-column: span 12; }
.leaf-ds .lf-fields > .col-2 { grid-column: span 2; }
.leaf-ds .lf-fields > .col-3 { grid-column: span 3; }
.leaf-ds .lf-fields > .col-4 { grid-column: span 4; }
.leaf-ds .lf-fields > .col-5 { grid-column: span 5; }
.leaf-ds .lf-fields > .col-6 { grid-column: span 6; }
.leaf-ds .lf-fields > .col-7 { grid-column: span 7; }
.leaf-ds .lf-fields > .col-8 { grid-column: span 8; }
.leaf-ds .lf-fields > .col-9 { grid-column: span 9; }
.leaf-ds .lf-fields > .col-12 { grid-column: span 12; }
@media (max-width: 860px) { .leaf-ds .lf-fields > [class*="col-"] { grid-column: span 12; } }
.leaf-ds .lf-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Search */
.leaf-ds .lf-search {
    display: flex; align-items: center; gap: 8px;
    background: var(--surface-2); border: 1px solid var(--line);
    border-radius: var(--r-4); padding: 0 11px; height: 40px; min-width: 220px;
    transition: border-color .12s, box-shadow .12s, background .12s;
}
.leaf-ds .lf-search:focus-within { border-color: var(--accent); background: var(--surface); box-shadow: var(--focus-ring); }
.leaf-ds .lf-search svg { color: var(--ink-3); flex: 0 0 auto; }
.leaf-ds .lf-search input {
    appearance: none; border: 0; background: transparent; outline: none;
    flex: 1; min-width: 0; font: 500 13px/1 var(--font-ui); color: var(--ink-1);
}
.leaf-ds .lf-search input::placeholder { color: var(--ink-3); }

/* Checkbox + radio */
.leaf-ds .lf-check { display: inline-flex; align-items: flex-start; gap: 9px; cursor: pointer; font-size: 13px; font-weight: 500; color: var(--ink-1); line-height: 1.35; }
.leaf-ds .lf-check input { position: absolute; opacity: 0; width: 0; height: 0; }
.leaf-ds .lf-check-box {
    flex: 0 0 auto; width: 17px; height: 17px; margin-top: 1px; border-radius: 4px;
    border: 1.6px solid var(--ink-4); background: var(--surface);
    display: flex; align-items: center; justify-content: center;
    transition: background .12s, border-color .12s;
}
.leaf-ds .lf-check-box svg { opacity: 0; color: #fff; }
.leaf-ds .lf-check:hover .lf-check-box { border-color: var(--accent); }
.leaf-ds .lf-check input:checked + .lf-check-box { background: var(--accent); border-color: var(--accent); }
.leaf-ds .lf-check input:checked + .lf-check-box svg { opacity: 1; }
.leaf-ds .lf-check input:focus-visible + .lf-check-box { box-shadow: var(--focus-ring); }
.leaf-ds .lf-check input:disabled + .lf-check-box { background: var(--surface-2); border-color: var(--line); }
.leaf-ds .lf-check.is-disabled { cursor: not-allowed; color: var(--ink-3); }
.leaf-ds .lf-check-radio { border-radius: 50%; }
.leaf-ds .lf-check input:checked + .lf-check-radio { background: var(--accent); box-shadow: inset 0 0 0 3px var(--surface); }

/* Switch */
.leaf-ds .lf-switch { position: relative; width: 38px; height: 22px; border-radius: 999px; flex: 0 0 auto; border: 0; cursor: pointer; background: var(--ink-4); transition: background .15s; padding: 0; }
.leaf-ds .lf-switch.is-on { background: var(--accent); }
.leaf-ds .lf-switch:disabled { opacity: 0.5; cursor: not-allowed; }
.leaf-ds .lf-switch .lf-knob { position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 999px; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: left .15s; }
.leaf-ds .lf-switch.is-on .lf-knob { left: 18px; }
.leaf-ds .lf-switch-row { display: flex; align-items: center; gap: 10px; }
.leaf-ds .lf-switch-label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }

/* ══════════════════════════════════════════════════════════════════════════
   TAGS / CHIPS / AVATARS
   ══════════════════════════════════════════════════════════════════════════ */
.leaf-ds .lf-tag {
    display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
    padding: 2px 8px; border-radius: var(--r-pill);
    font: 700 11px/1.5 var(--font-ui); font-variant-numeric: tabular-nums;
    background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
}
.leaf-ds .lf-tag.is-sq { border-radius: var(--r-3); }
.leaf-ds .lf-tag.tone-neutral { background: var(--surface-2); color: var(--ink-2); border-color: var(--line); }
.leaf-ds .lf-tag.tone-ok      { background: var(--c-sched-bg); color: var(--c-sched-fg); border-color: var(--c-sched-bd); }
.leaf-ds .lf-tag.tone-accent  { background: var(--accent-soft); color: var(--accent-ink); border-color: var(--c-sched-bd); }
.leaf-ds .lf-tag.tone-info    { background: var(--c-live-bg); color: var(--c-live-fg); border-color: var(--c-live-bd); }
.leaf-ds .lf-tag.tone-warn    { background: var(--c-warn-bg); color: var(--c-warn-fg); border-color: var(--c-warn-bd); }
.leaf-ds .lf-tag.tone-danger  { background: var(--c-conf-bg); color: var(--c-conf-fg); border-color: var(--c-conf-bd); }
.leaf-ds .lf-tag.tone-muted   { background: var(--c-canc-bg); color: var(--c-canc-fg); border-color: var(--c-canc-bd); }
.leaf-ds .lf-tag.tone-done    { background: var(--c-done-bg); color: var(--c-done-fg); border-color: var(--c-done-bd); }
.leaf-ds .lf-tag-dot { width: 6px; height: 6px; border-radius: 999px; background: currentColor; flex: 0 0 auto; }

.leaf-ds .lf-chip {
    appearance: none; cursor: pointer;
    background: var(--surface); border: 1px solid var(--line); color: var(--ink-2);
    border-radius: var(--r-pill); height: 30px; padding: 0 12px;
    font: 600 12px/1 var(--font-ui);
    display: inline-flex; align-items: center; gap: 6px;
    transition: background .12s, border-color .12s, color .12s;
}
.leaf-ds .lf-chip:hover { border-color: var(--ink-4); color: var(--ink-1); }
.leaf-ds .lf-chip.is-on { background: var(--accent-soft); border-color: var(--c-sched-bd); color: var(--accent-ink); }
.leaf-ds .lf-chips { display: flex; flex-wrap: wrap; gap: 6px; }

.leaf-ds .lf-avatar {
    flex: 0 0 auto; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
    font: 700 10.5px/1 var(--font-ui); letter-spacing: 0.01em;
    width: 28px; height: 28px; background: var(--accent-soft); color: var(--accent-ink);
    border: 1px solid var(--c-sched-bd);
}
.leaf-ds .lf-avatar.sz-sm { width: 22px; height: 22px; font-size: 9px; }
.leaf-ds .lf-avatar.sz-lg { width: 38px; height: 38px; font-size: 13px; }

/* ══════════════════════════════════════════════════════════════════════════
   SEGMENTED CONTROL / TABS
   ══════════════════════════════════════════════════════════════════════════ */
.leaf-ds .lf-seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-5); padding: 3px; gap: 3px; }
.leaf-ds .lf-seg-btn { cursor: pointer; border: 0; border-radius: var(--r-3); padding: 6px 14px; font: 600 12.5px/1 var(--font-ui); white-space: nowrap; background: transparent; color: var(--ink-3); transition: background .12s, color .12s; }
.leaf-ds .lf-seg-btn:hover { color: var(--ink-1); }
.leaf-ds .lf-seg-btn.is-on { background: var(--surface); color: var(--ink-1); box-shadow: 0 1px 2px rgba(0,0,0,.06); }

.leaf-ds .lf-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
.leaf-ds .lf-tab {
    appearance: none; background: transparent; border: 0; border-bottom: 2px solid transparent;
    cursor: pointer; padding: 10px 14px; margin-bottom: -1px; white-space: nowrap;
    font: 600 13px/1 var(--font-ui); color: var(--ink-3);
    display: inline-flex; align-items: center; gap: 7px;
    transition: color .12s, border-color .12s;
}
.leaf-ds .lf-tab:hover { color: var(--ink-1); }
.leaf-ds .lf-tab.is-on { color: var(--accent-ink); border-bottom-color: var(--accent); }
.leaf-ds .lf-tab-count { font-size: 10.5px; font-weight: 700; font-variant-numeric: tabular-nums; background: var(--surface-3); color: var(--ink-2); border-radius: 999px; padding: 1px 6px; }
.leaf-ds .lf-tab.is-on .lf-tab-count { background: var(--accent-soft); color: var(--accent-ink); }

/* ══════════════════════════════════════════════════════════════════════════
   TABLE
   ══════════════════════════════════════════════════════════════════════════ */
.leaf-ds .lf-tablewrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-8); overflow: hidden; }
.leaf-ds .lf-tablescroll { overflow-x: auto; }
.leaf-ds .lf-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.leaf-ds .lf-table thead th {
    position: sticky; top: 0; z-index: 2;
    text-align: left; white-space: nowrap; vertical-align: middle;
    padding: 9px 14px; background: var(--surface-2);
    border-bottom: 1px solid var(--line);
    font: 700 10px/1.4 var(--font-ui); color: var(--ink-3);
    text-transform: uppercase; letter-spacing: 0.06em;
}
.leaf-ds .lf-table thead th.is-sortable { cursor: pointer; user-select: none; }
.leaf-ds .lf-table thead th.is-sortable:hover { color: var(--ink-1); background: var(--surface-3); }
.leaf-ds .lf-table thead th.is-sorted { color: var(--ink-1); }
.leaf-ds .lf-sortarrow { display: inline-flex; margin-left: 5px; vertical-align: -1px; opacity: 0; transition: opacity .12s, transform .12s; }
.leaf-ds .lf-table thead th.is-sortable:hover .lf-sortarrow { opacity: 0.45; }
.leaf-ds .lf-table thead th.is-sorted .lf-sortarrow { opacity: 1; }
.leaf-ds .lf-table thead th.is-sorted.is-desc .lf-sortarrow { transform: rotate(180deg); }
.leaf-ds .lf-table tbody td { padding: 10px 14px; border-bottom: 1px solid var(--line-2); color: var(--ink-1); vertical-align: middle; }
.leaf-ds .lf-table tbody tr:last-child td { border-bottom: 0; }
.leaf-ds .lf-table tbody tr.is-clickable { cursor: pointer; }
.leaf-ds .lf-table tbody tr:hover td { background: var(--surface-2); }
.leaf-ds .lf-table tbody tr.is-selected td { background: var(--accent-soft); }
.leaf-ds .lf-table tbody tr.is-muted td { color: var(--ink-3); }
/* Numeric columns are right-aligned everywhere but only monospaced in the body —
   a mono uppercase header reads as a different type system. */
.leaf-ds .lf-table .is-num { text-align: right; }
.leaf-ds .lf-table tbody td.is-num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 12.5px; }
.leaf-ds .lf-table .is-center { text-align: center; }
.leaf-ds .lf-table .is-tight { width: 1%; white-space: nowrap; }
.leaf-ds .lf-table.is-dense tbody td { padding: 7px 12px; }
.leaf-ds .lf-table.is-dense thead th { padding: 7px 12px; }

/* The primary cell of a row — name + supporting meta; the whole row navigates */
.leaf-ds .lf-cell-primary { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.leaf-ds .lf-cell-name { font-size: 13px; font-weight: 700; letter-spacing: -0.005em; color: var(--ink-1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.leaf-ds .lf-cell-meta { font-size: 10.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.leaf-ds .lf-table tbody tr.is-clickable:hover .lf-cell-name { color: var(--accent-ink); text-decoration: underline; text-underline-offset: 2px; }
.leaf-ds .lf-rowarrow { color: var(--ink-4); display: flex; }
.leaf-ds .lf-table tbody tr:hover .lf-rowarrow { color: var(--ink-2); }
.leaf-ds .lf-rowactions { display: flex; align-items: center; gap: 4px; justify-content: flex-end; }

.leaf-ds .lf-tablefoot {
    display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
    padding: 8px 14px; border-top: 1px solid var(--line); background: var(--surface-2);
    font-size: 11.5px; color: var(--ink-3);
}
.leaf-ds .lf-pager { display: flex; align-items: center; gap: 6px; }
.leaf-ds .lf-pager-info { font-variant-numeric: tabular-nums; }

.leaf-ds a.lf-link { color: var(--accent-ink); font-weight: 600; text-decoration: none; }
.leaf-ds a.lf-link:hover { text-decoration: underline; }

/* ══════════════════════════════════════════════════════════════════════════
   EMPTY / LOADING / ALERT
   ══════════════════════════════════════════════════════════════════════════ */
.leaf-ds .lf-empty { padding: 44px 22px; text-align: center; color: var(--ink-3); display: flex; flex-direction: column; align-items: center; gap: 7px; }
.leaf-ds .lf-empty-icon { color: var(--ink-4); }
.leaf-ds .lf-empty-title { font-size: 14px; font-weight: 700; color: var(--ink-2); }
.leaf-ds .lf-empty-text { font-size: 12.5px; color: var(--ink-3); max-width: 46ch; line-height: 1.5; }

.leaf-ds .lf-loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 44px 0; color: var(--ink-3); font-size: 12.5px; font-weight: 600; }
.leaf-ds .lf-spinner { width: 18px; height: 18px; border-radius: 50%; flex: 0 0 auto; border: 2px solid var(--line); border-top-color: var(--accent); animation: lf-spin .7s linear infinite; }
.leaf-ds .lf-spinner.is-sm { width: 13px; height: 13px; border-width: 1.6px; }
.leaf-ds .lf-spinner.is-onaccent { border-color: rgba(255,255,255,0.35); border-top-color: #fff; }
@keyframes lf-spin { to { transform: rotate(360deg); } }

.leaf-ds .lf-skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: lf-shimmer 1.3s ease infinite; border-radius: var(--r-3); }
@keyframes lf-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

.leaf-ds .lf-alert {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 11px 14px; border-radius: var(--r-5); font-size: 12.5px; line-height: 1.5;
    background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
}
.leaf-ds .lf-alert-icon { flex: 0 0 auto; margin-top: 1px; }
.leaf-ds .lf-alert-body { flex: 1; min-width: 0; }
.leaf-ds .lf-alert-title { font-weight: 700; color: inherit; margin-bottom: 2px; }
.leaf-ds .lf-alert.tone-info   { background: var(--c-live-bg); color: var(--c-live-fg); border-color: var(--c-live-bd); }
.leaf-ds .lf-alert.tone-ok     { background: var(--accent-soft); color: var(--accent-ink); border-color: var(--c-sched-bd); }
.leaf-ds .lf-alert.tone-warn   { background: var(--c-warn-bg); color: var(--c-warn-fg); border-color: var(--c-warn-bd); }
.leaf-ds .lf-alert.tone-danger { background: var(--c-conf-bg); color: var(--c-conf-fg); border-color: var(--c-conf-bd); }

/* ══════════════════════════════════════════════════════════════════════════
   DIALOG  (bare-DOM modal; .sv-scope overrides these for the visit dialog)
   ══════════════════════════════════════════════════════════════════════════ */
.lf-overlay {
    position: fixed; inset: 0; z-index: 1300;
    background: rgba(20, 20, 15, 0.34);
    -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
    display: flex; align-items: flex-start; justify-content: center;
    padding: 46px 24px 40px; overflow-y: auto;
    font-family: var(--font-ui); color: var(--ink-1);
}
.lf-overlay *, .lf-overlay *::before, .lf-overlay *::after { box-sizing: border-box; }
.lf-overlay .lf-dialog {
    background: var(--surface); border-radius: var(--r-6); box-shadow: var(--sh-4);
    width: 520px; max-width: 100%; display: flex; flex-direction: column; overflow: hidden;
    animation: lf-dialog-in .18s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.lf-overlay .lf-dialog.sz-sm { width: 420px; }
.lf-overlay .lf-dialog.sz-lg { width: 720px; }
.lf-overlay .lf-dialog.sz-xl { width: 960px; }
@keyframes lf-dialog-in { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }
.lf-overlay .lf-dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 18px 22px 14px; }
.lf-overlay .lf-dlg-title { font: 700 17px/1.2 var(--font-ui); letter-spacing: -0.01em; }
.lf-overlay .lf-dlg-sub { font: 500 10.5px/1.3 var(--font-ui); color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.07em; margin-top: 3px; }
.lf-overlay .lf-dlg-body { padding: 4px 22px 12px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; }
.lf-overlay .lf-dlg-foot { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 14px 22px 18px; border-top: 1px solid var(--line-2); margin-top: 4px; }
.leaf-ds .lf-x, .lf-overlay .lf-x {
    appearance: none; border: 1px solid var(--line); background: var(--surface-2);
    width: 30px; height: 30px; border-radius: var(--r-4); cursor: pointer; padding: 0;
    color: var(--ink-2); display: flex; align-items: center; justify-content: center; flex: 0 0 auto;
    transition: background .12s, color .12s, border-color .12s;
}
.leaf-ds .lf-x:hover, .lf-overlay .lf-x:hover { background: var(--bg); color: var(--ink-1); border-color: var(--ink-4); }

/* ══════════════════════════════════════════════════════════════════════════
   MISC
   ══════════════════════════════════════════════════════════════════════════ */
.leaf-ds .lf-kv { display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: 7px 18px; font-size: 13px; align-items: baseline; margin: 0; }
.leaf-ds .lf-kv dt { font-size: 10.5px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.05em; }
.leaf-ds .lf-kv dd { margin: 0; color: var(--ink-1); font-weight: 500; }

.leaf-ds .lf-inline { display: inline-flex; align-items: center; gap: 6px; }
.leaf-ds .lf-stack { display: flex; flex-direction: column; gap: 14px; }
.leaf-ds .lf-stack.is-tight { gap: 8px; }
.leaf-ds .lf-vrule { width: 1px; align-self: stretch; background: var(--line); }

.leaf-ds .lf-scroll-y { overflow-y: auto; }
.leaf-ds .lf-scroll-y::-webkit-scrollbar, .leaf-ds .lf-tablescroll::-webkit-scrollbar { width: 10px; height: 10px; }
.leaf-ds .lf-scroll-y::-webkit-scrollbar-thumb, .leaf-ds .lf-tablescroll::-webkit-scrollbar-thumb { background: var(--ink-4); border-radius: 999px; border: 3px solid var(--surface); }
.leaf-ds .lf-scroll-y::-webkit-scrollbar-track, .leaf-ds .lf-tablescroll::-webkit-scrollbar-track { background: transparent; }
.leaf-ds .lf-report-error { margin-bottom: 14px; }
.leaf-ds .lf-table tbody tr.is-flagged td { box-shadow: inset 3px 0 0 -1px var(--c-warn-bd); }

/* Compliance grid — row labels in the gutter column, cells centred + tabular. */
.leaf-ds .lf-compliance th:first-child, .leaf-ds .lf-compliance td:first-child { position: sticky; left: 0; background: var(--surface); z-index: 1; }
.leaf-ds .lf-compliance thead th:first-child { background: var(--surface-2); }
.leaf-ds .lf-compliance-row { font-size: 11px; font-weight: 700; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap; }
.leaf-ds .lf-compliance th.is-center { min-width: 58px; }

/* Registration code — meant to be read aloud / typed on a tablet, so it gets
   the largest monospace treatment in the app. */
.leaf-ds .lf-regcode { background: var(--c-live-bg); border: 1px solid var(--c-live-bd); border-radius: var(--r-6); padding: 16px; text-align: center; }
.leaf-ds .lf-regcode-value { font-family: var(--font-mono); font-size: 34px; font-weight: 600; letter-spacing: 0.28em; color: var(--c-live-fg); text-indent: 0.28em; }
.leaf-ds .lf-regcode-meta { font-size: 11.5px; color: var(--c-live-fg); opacity: 0.85; margin-top: 6px; }

/* ══ Autocomplete ══════════════════════════════════════════════════════════ */
.leaf-ds .lf-ac { position: relative; }
.leaf-ds .lf-ac-pop {
    position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 50;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-5);
    box-shadow: var(--sh-3); padding: 4px; max-height: 280px; overflow-y: auto;
}
.leaf-ds .lf-ac-opt {
    display: block; width: 100%; text-align: left; cursor: pointer;
    background: transparent; border: 0; border-radius: var(--r-3); padding: 8px 10px;
    font: 500 12.5px/1.4 var(--font-ui); color: var(--ink-1);
}
.leaf-ds .lf-ac-opt:hover { background: var(--surface-2); }
.leaf-ds .lf-ac-empty { padding: 10px; font-size: 12px; color: var(--ink-3); text-align: center; }

/* File upload — the native input covers the styled button so the whole
   control is the hit target, while keeping real <input type=file> semantics. */
.leaf-ds .lf-upload { position: relative; display: inline-flex; cursor: pointer; }
.leaf-ds .lf-upload input[type=file] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.leaf-ds .lf-upload input[type=file]:disabled { cursor: not-allowed; }
.leaf-ds .lf-upload input[type=file]:focus-visible + .lf-btn { box-shadow: var(--focus-ring); }
.leaf-ds .lf-upload .lf-btn { pointer-events: none; }

/* Photo preview + its remove affordance */
.leaf-ds .lf-photo { width: 132px; height: 132px; border-radius: var(--r-6); object-fit: cover; border: 1px solid var(--line); display: block; }
.leaf-ds .lf-photo-row { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; }

/* ══ Dual-list transfer (care plan task assignment) ════════════════════════ */
.leaf-ds .lf-transfer { display: grid; grid-template-columns: minmax(0,1fr) auto minmax(0,1fr); gap: 14px; align-items: start; }
@media (max-width: 940px) {
    .leaf-ds .lf-transfer { grid-template-columns: minmax(0,1fr); }
    .leaf-ds .lf-transfer-controls { flex-direction: row; flex-wrap: wrap; justify-content: center; padding: 0; }
    .leaf-ds .lf-transfer-divider { width: 100%; height: 0; border: 0; }
}
.leaf-ds .lf-transfer-controls { display: flex; flex-direction: column; gap: 8px; padding-top: 78px; }
.leaf-ds .lf-transfer-divider { height: 1px; background: var(--line); margin: 4px 0; }
.leaf-ds .lf-transfer-search { padding: 10px 12px; border-bottom: 1px solid var(--line-2); }
.leaf-ds .lf-transfer-list { max-height: 380px; padding: 6px; }
.leaf-ds .lf-transfer-row { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: var(--r-3); cursor: pointer; }
.leaf-ds .lf-transfer-row:hover { background: var(--surface-2); }
.leaf-ds .lf-transfer-name { flex: 1; min-width: 0; font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.leaf-ds .lf-transfer-empty { padding: 24px 12px; text-align: center; font-size: 12px; color: var(--ink-3); }

/* Thin indeterminate bar for "reloading in place" (date changes on the care
   review screens) — feedback without collapsing the content underneath. */
.lf-topprogress { height: 3px; margin-bottom: 1px; overflow: hidden; }
.lf-topprogress-bar { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, transparent, var(--accent), transparent); animation: lf-slide 1.1s ease-in-out infinite; }
@keyframes lf-slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }

/* ══ Comment feed ══════════════════════════════════════════════════════════ */
.leaf-ds .lf-comments { display: flex; flex-direction: column; gap: 2px; margin-bottom: 16px; }
.leaf-ds .lf-comment { display: flex; gap: 10px; padding: 9px 10px; border-radius: var(--r-4); }
.leaf-ds .lf-comment:hover { background: var(--surface-2); }
.leaf-ds .lf-comment-body { flex: 1; min-width: 0; }
.leaf-ds .lf-comment-meta { display: flex; align-items: baseline; gap: 8px; font-size: 10.5px; color: var(--ink-3); flex-wrap: wrap; }
.leaf-ds .lf-comment-meta b { font-size: 12px; font-weight: 700; color: var(--ink-1); }
.leaf-ds .lf-comment-text { font-size: 13px; line-height: 1.5; margin-top: 3px; white-space: pre-wrap; }

/* ══ Threaded comments (employee notes) ════════════════════════════════════ */
.leaf-ds .lf-thread-list { display: flex; flex-direction: column; gap: 6px; }
.leaf-ds .lf-thread { border: 1px solid var(--line-2); border-radius: var(--r-5); background: var(--surface); overflow: hidden; }
.leaf-ds .lf-thread.is-open { border-color: var(--line); box-shadow: var(--sh-1); }
.leaf-ds .lf-thread-head { display: flex; align-items: center; justify-content: flex-start; gap: 9px; width: 100%; padding: 10px 12px; background: transparent; border: 0; cursor: pointer; text-align: left; }
.leaf-ds .lf-thread-head:hover { background: var(--surface-2); }
.leaf-ds .lf-thread-chev { color: var(--ink-4); display: flex; flex: 0 0 auto; transition: transform .18s; }
.leaf-ds .lf-thread.is-open .lf-thread-chev { transform: rotate(90deg); }
.leaf-ds .lf-thread-summary { flex: 1; min-width: 0; font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.leaf-ds .lf-thread-meta { font-size: 10.5px; color: var(--ink-3); white-space: nowrap; flex: 0 0 auto; }
.leaf-ds .lf-thread-body { padding: 4px 14px 14px 34px; border-top: 1px solid var(--line-2); }
.leaf-ds .lf-thread-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding-top: 10px; }
.leaf-ds .lf-reply { margin-top: 10px; padding: 10px 12px; border-left: 2px solid var(--accent-soft); background: var(--surface-2); border-radius: 0 var(--r-4) var(--r-4) 0; }
@media (max-width: 700px) { .leaf-ds .lf-thread-meta { display: none; } }

/* House schedule summary — client band spans its PCS/PCA pair, and the pair
   is visually grouped by a divider on the left edge of each client group. */
.leaf-ds .lf-hsched thead tr:first-child th { border-bottom: 0; }
.leaf-ds .lf-hsched-client { background: var(--accent-soft) !important; color: var(--accent-ink) !important; border-left: 1px solid var(--line); }
.leaf-ds .lf-hsched tbody td { border-right: 1px solid var(--line-2); }
.leaf-ds .lf-hsched tbody td:last-child, .leaf-ds .lf-hsched thead th:last-child { border-right: 0; }

/* ══ House schedule editor (drag-drop day grid + task palette) ═════════════ */
.leaf-ds .hs-editor { display: grid; grid-template-columns: minmax(0, 420px) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1000px) { .leaf-ds .hs-editor { grid-template-columns: minmax(0, 1fr); } }
.leaf-ds .hs-grid-scroll { max-height: 70vh; overflow-y: auto; }
.leaf-ds .hs-grid th.hs-half { background: var(--surface-3) !important; color: var(--ink-1) !important; }
.leaf-ds .hs-grid .hs-timecol { width: 58px; }
.leaf-ds .hs-grid .hs-taskcol { min-width: 150px; }
.leaf-ds .hs-grid td { border-right: 1px solid var(--line-2); }
.leaf-ds .hs-grid td:last-child { border-right: 0; }
.leaf-ds .hs-time { text-align: right; white-space: nowrap; font-family: var(--font-mono); font-size: 11px; color: var(--ink-3); }
.leaf-ds .hs-drop { min-width: 150px; height: 26px; padding: 2px 5px !important; }
.leaf-ds .hs-drop:hover { background: var(--accent-soft); }
.leaf-ds .hs-palettecell { padding: 3px !important; }
.leaf-ds .hs-clienthead { padding: 7px 12px !important; }
.leaf-ds .hs-chip {
    display: inline-block; padding: 2px 7px; border-radius: var(--r-3);
    font-size: 11px; font-weight: 600; white-space: nowrap; user-select: none;
    cursor: grab; margin-bottom: 1px; line-height: 1.5;
}
.leaf-ds .hs-chip:active { cursor: grabbing; }

/* ══ Right-side drawer (calendar shift detail) ═════════════════════════════ */
.lf-drawer-scrim { position: fixed; inset: 0; z-index: 1200; background: rgba(20, 20, 15, 0.30); }
.lf-drawer {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 1201;
    width: 380px; max-width: 100%;
    background: var(--surface); border-left: 1px solid var(--line);
    box-shadow: var(--sh-3); overflow-y: auto;
    animation: lf-drawer-in .18s cubic-bezier(0.2, 0.7, 0.2, 1);
}
@keyframes lf-drawer-in { from { transform: translateX(16px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Double-chevron (jump a week) — the second glyph tucks in tight. */
.leaf-ds .lf-dbl, .leaf-calendar .lf-dbl { margin-left: -6px; }

/* Resource list (help page) — icon, label, trailing status. */
.leaf-ds .lf-resource-list { display: flex; flex-direction: column; gap: 2px; }
.leaf-ds .lf-resource { display: flex; align-items: center; gap: 10px; padding: 9px 8px; border-radius: var(--r-3); }
.leaf-ds .lf-resource:hover { background: var(--surface-2); }
.leaf-ds .lf-resource-icon { color: var(--ink-3); display: flex; flex: 0 0 auto; }
.leaf-ds .lf-resource-name { flex: 1; min-width: 0; font-size: 13px; font-weight: 600; }

/* QR pairing card */
.leaf-ds .lf-qr { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.leaf-ds .lf-qr-code svg { display: block; width: 190px; height: 190px; }
.leaf-ds .lf-qr-link { display: flex; align-items: center; gap: 6px; max-width: 100%; }
.leaf-ds .lf-qr-link code { font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-2); word-break: break-all; }

/* ══ Menu (dropdown) ═══════════════════════════════════════════════════════ */
.leaf-ds .lf-menu, .leaf-ledger .lf-menu { position: relative; display: inline-flex; }
.leaf-ds .lf-menu-activator, .leaf-ledger .lf-menu-activator {
    display: inline-flex; align-items: center; justify-content: flex-start; gap: 6px; cursor: pointer;
    background: transparent; border: 0; padding: 0; color: inherit; font: inherit; text-align: left;
}
.leaf-ds .lf-menu-chev, .leaf-ledger .lf-menu-chev { color: var(--ink-3); display: flex; transition: transform .15s; }
.leaf-ds .lf-menu.is-open .lf-menu-chev, .leaf-ledger .lf-menu.is-open .lf-menu-chev { transform: rotate(180deg); }
.lf-menu-backdrop { position: fixed; inset: 0; z-index: 55; }
.leaf-ds .lf-menu-pop, .leaf-ledger .lf-menu-pop {
    position: absolute; top: calc(100% + 6px); left: 0; z-index: 56;
    min-width: 220px; max-height: 340px; overflow-y: auto;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-6);
    box-shadow: var(--sh-3); padding: 5px;
}
.leaf-ds .lf-menu-pop.is-end, .leaf-ledger .lf-menu-pop.is-end { left: auto; right: 0; }
.leaf-ledger .lf-menuitem {
    display: flex; align-items: center; gap: 10px; width: 100%;
    padding: 8px 10px; border-radius: var(--r-3); text-decoration: none;
    font: 600 12.5px/1.3 var(--font-ui); color: var(--ink-1);
    background: transparent; border: 0; cursor: pointer; text-align: left;
}
.leaf-ledger .lf-menuitem:hover, .leaf-ds .lf-menuitem:hover { background: var(--surface-2); }
.leaf-ds .lf-menuitem.is-selected, .leaf-ledger .lf-menuitem.is-selected { background: var(--accent-soft); color: var(--accent-ink); }
.leaf-ds .lf-menuitem:disabled { color: var(--ink-4); cursor: not-allowed; }

/* ══ Disclosure (collapsible panel) ════════════════════════════════════════ */
.leaf-ds .lf-disclosure { border: 1px solid var(--line); border-radius: var(--r-6); background: var(--surface); overflow: hidden; }
.leaf-ds .lf-disclosure + .lf-disclosure { margin-top: 8px; }
.leaf-ds .lf-disclosure.is-open { box-shadow: var(--sh-1); }
.leaf-ds .lf-disclosure-head {
    display: flex; align-items: center; justify-content: flex-start; gap: 9px; width: 100%;
    padding: 12px 14px; background: transparent; border: 0; cursor: pointer; text-align: left;
}
.leaf-ds .lf-disclosure-title { flex: 0 0 auto; }
.leaf-ds .lf-disclosure-sub { flex: 1; min-width: 0; }
.leaf-ds .lf-disclosure-head:hover { background: var(--surface-2); }
.leaf-ds .lf-disclosure.is-open .lf-disclosure-head { background: var(--surface-2); border-bottom: 1px solid var(--line-2); }
.leaf-ds .lf-disclosure-chev { color: var(--ink-4); display: flex; flex: 0 0 auto; transition: transform .18s; }
.leaf-ds .lf-disclosure.is-open .lf-disclosure-chev { transform: rotate(90deg); }
.leaf-ds .lf-disclosure-title { font-size: 13px; font-weight: 700; }
.leaf-ds .lf-disclosure-sub { font-size: 11.5px; color: var(--ink-3); }
.leaf-ds .lf-disclosure-body { padding: 16px 14px; }

/* A scheduled (future) stay is tinted so it reads apart from history. */
.leaf-ds .lf-table tbody tr.is-scheduled td { background: var(--c-warn-bg); }
.leaf-ds .lf-table tbody tr.is-scheduled:hover td { background: #f8e7c4; }

/* Colour field — native swatch + hex text side by side. */
.leaf-ds .lf-colorfield { display: flex; align-items: center; gap: 8px; }
.leaf-ds .lf-colorswatch {
    appearance: none; -webkit-appearance: none; flex: 0 0 auto;
    width: 40px; height: 40px; padding: 3px; cursor: pointer;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-4);
}
.leaf-ds .lf-colorswatch::-webkit-color-swatch-wrapper { padding: 0; }
.leaf-ds .lf-colorswatch::-webkit-color-swatch { border: 0; border-radius: 4px; }
.leaf-ds .lf-colorhex { flex: 1; min-width: 0; font-family: var(--font-mono); text-transform: uppercase; }

.leaf-ds .lf-logo-preview { max-height: 80px; max-width: 300px; object-fit: contain; border: 1px solid var(--line); border-radius: var(--r-4); padding: 6px; background: var(--surface); }

/* ══ Date / time pickers ═══════════════════════════════════════════════════
   Our own popups rather than <input type=date|time>. The native ones are
   browser chrome — their selection highlight is the OS accent blue and no CSS
   reaches it — so selection here uses the same soft green as .lf-chip.is-on. */
.leaf-ds .lf-picker { position: relative; }
.leaf-ds .lf-picker .lf-control { padding-right: 4px; }
.leaf-ds .lf-picker-input {
    flex: 1; min-width: 0; border: 0; background: transparent; outline: none;
    font: inherit; color: inherit; padding: 0; height: 100%;
    font-variant-numeric: tabular-nums;
}
.leaf-ds .lf-picker-input::placeholder { color: var(--ink-3); }
.leaf-ds .lf-picker-btn {
    flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center;
    width: 28px; height: 28px; border: 0; border-radius: var(--r-3);
    background: transparent; color: var(--ink-3); cursor: pointer;
}
.leaf-ds .lf-picker-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--ink-1); }
.leaf-ds .lf-picker-btn:disabled { color: var(--ink-4); cursor: not-allowed; }

.lf-picker-backdrop { position: fixed; inset: 0; z-index: 58; }
.leaf-ds .lf-picker-pop {
    position: absolute; top: calc(100% + 5px); left: 0; z-index: 59;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-6);
    box-shadow: var(--sh-3); padding: 5px;
}

/* Time slots */
.leaf-ds .lf-slotlist { width: 148px; max-height: 260px; overflow-y: auto; }
.leaf-ds .lf-slot {
    display: block; width: 100%; text-align: left; cursor: pointer;
    background: transparent; border: 0; border-radius: var(--r-3);
    padding: 6px 10px; font: 600 12.5px/1.4 var(--font-ui);
    color: var(--ink-1); font-variant-numeric: tabular-nums;
}
.leaf-ds .lf-slot:hover { background: var(--surface-2); }
.leaf-ds .lf-slot.is-on { background: var(--accent-soft); color: var(--accent-ink); }

/* Month calendar */
.leaf-ds .lf-cal { width: 252px; padding: 8px; }
.leaf-ds .lf-cal-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 2px 2px 8px; }
.leaf-ds .lf-cal-month { font-size: 13px; font-weight: 700; }
.leaf-ds .lf-cal-dow { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; margin-bottom: 3px; }
.leaf-ds .lf-cal-dow span { text-align: center; font-size: 9.5px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; }
.leaf-ds .lf-cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.leaf-ds .lf-cal-day {
    aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
    border: 1px solid transparent; border-radius: var(--r-3); cursor: pointer;
    background: transparent; color: var(--ink-1);
    font: 600 12px/1 var(--font-ui); font-variant-numeric: tabular-nums;
}
.leaf-ds .lf-cal-day:hover:not(:disabled) { background: var(--surface-2); }
.leaf-ds .lf-cal-day.is-out { color: var(--ink-4); }
.leaf-ds .lf-cal-day.is-today { border-color: var(--ink-4); }
.leaf-ds .lf-cal-day.is-on { background: var(--accent-soft); border-color: var(--c-sched-bd); color: var(--accent-ink); font-weight: 700; }
.leaf-ds .lf-cal-day:disabled { color: var(--ink-4); cursor: not-allowed; opacity: .5; }
.leaf-ds .lf-cal-foot { display: flex; gap: 6px; justify-content: flex-end; padding-top: 7px; margin-top: 5px; border-top: 1px solid var(--line-2); }

/* Any native pickers still around (browser-rendered) at least follow the brand. */
.leaf-ds input, .leaf-ds select, .leaf-ds textarea { accent-color: var(--accent); }

/* A card clips its children so a full-bleed table gets rounded corners — but that
   also clips any popup opened inside it. Cards that actually contain one opt out. */
.leaf-ds .lf-card:has(.lf-picker), .leaf-ds .lf-card:has(.lf-ac), .leaf-ds .lf-card:has(.lf-menu) { overflow: visible; }
.leaf-ds .lf-card:has(.lf-picker) .lf-card-head { border-radius: var(--r-8) var(--r-8) 0 0; }

/* Permission grid — two/three columns of checkboxes that stay readable at any width. */
.leaf-ds .lf-permgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px 18px; }

/* A chip set disabled by an "all" switch: dimmed, but still legible so the prior
   selection is visible rather than wiped. */
.leaf-ds .lf-chips.is-disabled { opacity: .5; }
.leaf-ds .lf-chip:disabled { cursor: not-allowed; }
