/* The Lease Builder's styling: the Leases page, template picker, lease hub, State lease library, paper preview and
   Quick Fill. Moved out of index.html byte-identical (split #6); linked where these rules used to sit. */
  /* ── LEASES PAGE ── */
  #page-leases { background: var(--bg2); }
  #page-leases .topbar {
    height: auto;
    min-height: 62px;
    padding-top: 12px;
    padding-bottom: 12px;
    flex-wrap: wrap;
    gap: 8px;
    row-gap: 8px;
    align-items: center;
  }
  #page-leases .topbar-left {
    flex: 0 0 auto;
    gap: 0;
  }
  #page-leases .topbar-left .page-title {
    flex-shrink: 0;
    white-space: nowrap;
  }
  #page-leases .topbar-right {
    flex: 1 1 auto;
    justify-content: flex-end;
    gap: 6px;
    flex-wrap: wrap;
  }
  .lease-tpl-group {
    display: inline-flex; align-items: center; gap: 4px;
    height: 32px;
  }

  /* Lease Template Picker — glass-style centered popup (mirrors .tasks-drawer) */
  .lz-picker-overlay {
    position:fixed; inset:0;
    background:radial-gradient(ellipse at center, rgba(20,40,90,0.35) 0%, rgba(5,10,30,0.55) 100%);
    z-index:2500; display:none; opacity:0; transition:opacity 0.2s;
    backdrop-filter:blur(4px); -webkit-backdrop-filter:blur(4px);
  }
  .lz-picker-overlay.open { display:block; opacity:1; }
  .lz-picker {
    position:fixed; top:50%; left:50%; width:680px; max-width:94vw; height:580px; max-height:86vh;
    transform:translate(-50%, -50%) scale(0.92); opacity:0;
    /* Light mode is the white sheet shared with the New task drawer; the blue
       glass is restated below for dark mode only. */
    background:rgba(255,255,255,0.70);
    backdrop-filter:blur(32px) saturate(1.6);
    -webkit-backdrop-filter:blur(32px) saturate(1.6);
    z-index:2501; border-radius:22px;
    box-shadow:
      0 20px 60px rgba(20,50,140,0.35),
      0 8px 24px rgba(30,70,160,0.22),
      0 1px 3px rgba(0,0,0,0.12),
      inset 0 1px 0 rgba(255,255,255,0.7),
      inset 0 -1px 0 rgba(80,130,210,0.18),
      inset 1px 0 0 rgba(255,255,255,0.35),
      inset -1px 0 0 rgba(80,130,210,0.10);
    border:1px solid rgba(200,220,255,0.55);
    transition:transform 0.28s cubic-bezier(.4,0,.2,1), opacity 0.22s ease;
    display:flex; flex-direction:column; pointer-events:none;
    overflow:hidden;
  }
  .lz-picker::before {
    content:""; position:absolute; inset:0; pointer-events:none; border-radius:inherit;
    background:linear-gradient(180deg, rgba(255,255,255,0.35) 0%, rgba(255,255,255,0) 35%, rgba(255,255,255,0) 100%);
    z-index:0;
  }
  .lz-picker > * { position:relative; z-index:1; }
  /* Dark mode keeps the original blue glass, restated verbatim — the white
     sheet above is a light-mode change only. backdrop-filter is repeated
     because the light rule sets its own. */
  [data-theme="dark"] .lz-picker {
    background:
      linear-gradient(160deg,
        rgba(230,241,255,0.92) 0%,
        rgba(213,231,255,0.88) 22%,
        rgba(196,219,252,0.86) 48%,
        rgba(180,208,250,0.88) 75%,
        rgba(175,209,247,0.92) 100%),
      radial-gradient(circle at 12% 8%, rgba(255,255,255,0.65) 0%, transparent 45%),
      radial-gradient(circle at 92% 96%, rgba(110,165,235,0.30) 0%, transparent 55%);
    background-blend-mode:normal, screen, normal;
    backdrop-filter:blur(28px) saturate(1.9) brightness(1.05);
    -webkit-backdrop-filter:blur(28px) saturate(1.9) brightness(1.05);
  }
  .lz-picker.open { transform:translate(-50%, -50%) scale(1); opacity:1; pointer-events:auto; }
  .lz-picker-head {
    padding:18px 24px; border-bottom:1px solid rgba(200,220,255,0.4);
    display:flex; align-items:center; justify-content:space-between;
    border-radius:22px 22px 0 0;
    background:linear-gradient(180deg, rgba(255,255,255,0.25) 0%, rgba(255,255,255,0) 100%);
  }
  .lz-picker-head h3 { margin:0; font-size:17px; font-weight:600; color:#1a3370; letter-spacing:-0.2px; }
  .lz-picker-head .btn { background:rgba(255,255,255,0.4); border:1px solid rgba(200,220,255,0.5); border-radius:8px; backdrop-filter:blur(6px); }
  .lz-picker-head .btn:hover { background:rgba(255,255,255,0.6); }
  .lz-picker-search {
    padding:14px 24px 0;
  }
  .lz-picker-search input {
    width:100%; box-sizing:border-box;
    background:rgba(255,255,255,0.55); border:1px solid rgba(180,210,255,0.6); border-radius:10px;
    padding:9px 12px; font-size:13px; color:#1a2f5c;
    backdrop-filter:blur(8px); -webkit-backdrop-filter:blur(8px);
    box-shadow:inset 0 1px 0 rgba(255,255,255,0.5), 0 1px 2px rgba(40,80,160,0.05);
    transition:border-color 0.15s, background 0.15s, box-shadow 0.15s;
  }
  .lz-picker-search input:focus {
    outline:none; border-color:rgba(80,130,235,0.8); background:rgba(255,255,255,0.75);
    box-shadow:inset 0 1px 0 rgba(255,255,255,0.5), 0 0 0 3px rgba(100,160,255,0.25);
  }
  .lz-picker-cats {
    padding:12px 24px; display:flex; flex-wrap:wrap; gap:6px;
    border-bottom:1px solid rgba(200,220,255,0.4);
  }
  .lz-cat-pill {
    padding:6px 12px; border:1px solid rgba(180,210,255,0.6); border-radius:16px;
    font-size:12px; background:rgba(255,255,255,0.5); color:#1a2f5c; cursor:pointer;
    display:inline-flex; align-items:center; gap:5px;
    backdrop-filter:blur(6px); transition:all 0.15s; white-space:nowrap;
    box-shadow:inset 0 1px 0 rgba(255,255,255,0.5);
  }
  .lz-cat-pill:hover { background:rgba(255,255,255,0.75); }
  .lz-cat-pill.active {
    border-color:rgba(40,90,210,0.8);
    background:linear-gradient(135deg, #5a90f0, #2a60d0); color:#fff;
    box-shadow:0 2px 8px rgba(40,90,210,0.35), inset 0 1px 0 rgba(255,255,255,0.3);
  }
  .lz-cat-pill .lz-cat-count {
    background:rgba(255,255,255,0.55); color:#1a3370;
    border-radius:10px; padding:0 6px; font-size:11px; font-weight:600;
    min-width:18px; text-align:center;
  }
  .lz-cat-pill.active .lz-cat-count { background:rgba(255,255,255,0.85); color:#1a3370; }
  .lz-picker-body {
    overflow-y:auto; padding:16px 24px; flex:1; min-height:0;
  }
  .lz-tpl-grid {
    display:grid; grid-template-columns:1fr 1fr; gap:10px;
  }
  .lz-tpl-card {
    text-align:left; cursor:pointer;
    padding:12px 14px; border-radius:12px;
    border:1px solid rgba(200,220,255,0.55);
    background:rgba(255,255,255,0.55);
    backdrop-filter:blur(8px); -webkit-backdrop-filter:blur(8px);
    box-shadow:inset 0 1px 0 rgba(255,255,255,0.5), 0 2px 6px rgba(40,80,160,0.06);
    transition:all 0.15s;
    display:flex; flex-direction:column; gap:6px; min-width:0;
  }
  .lz-tpl-card:hover {
    background:rgba(255,255,255,0.78);
    border-color:rgba(80,130,235,0.55);
    transform:translateY(-1px);
    box-shadow:0 6px 16px rgba(40,90,210,0.18), inset 0 1px 0 rgba(255,255,255,0.6);
  }
  .lz-tpl-card.selected {
    border-color:rgba(40,90,210,0.8);
    background:linear-gradient(135deg, rgba(255,255,255,0.85), rgba(220,235,255,0.85));
    box-shadow:0 4px 12px rgba(40,90,210,0.25), inset 0 1px 0 rgba(255,255,255,0.6);
  }
  .lz-tpl-card .name {
    font-size:13px; font-weight:600; color:#1a2f5c;
    overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
  }
  .lz-tpl-card .meta {
    font-size:11px; color:#3a5a95; display:flex; gap:6px; align-items:center; flex-wrap:wrap;
  }
  .lz-tpl-card .meta .chip {
    background:rgba(80,130,235,0.15); color:#1a3370;
    padding:2px 8px; border-radius:10px; font-weight:500; font-size:11px;
  }
  .lz-tpl-card { position:relative; }
  .lz-card-actions {
    position:absolute; top:7px; right:8px;
    display:flex; gap:4px;
    opacity:0; transition:opacity 0.15s;
    pointer-events:none;
  }
  .lz-tpl-card:hover .lz-card-actions { opacity:1; pointer-events:auto; }
  .lz-card-act-btn {
    padding:3px 5px; border-radius:6px;
    border:1px solid rgba(180,210,255,0.7);
    background:rgba(255,255,255,0.92);
    cursor:pointer; display:flex; align-items:center; justify-content:center;
    color:#3a5a95; transition:all 0.12s; line-height:1;
  }
  .lz-card-act-btn:hover { background:#fff; color:#1a3370; border-color:rgba(80,130,235,0.6); }
  .lz-card-act-btn.del { color:#dc2626; }
  .lz-card-act-btn.del:hover { background:#fee2e2; border-color:#fca5a5; }
  .lz-card-act-btn i { width:12px; height:12px; display:block; }
  .lz-picker-empty {
    text-align:center; padding:40px 16px;
    color:#3a5a95;
  }
  .lz-picker-empty .te-icon { font-size:32px; opacity:0.5; margin-bottom:8px; color:#5a90f0; }
  .lz-picker-foot {
    padding:14px 24px; border-top:1px solid rgba(200,220,255,0.4);
    display:flex; gap:10px; justify-content:space-between; align-items:center;
    border-radius:0 0 22px 22px;
    background:linear-gradient(0deg, rgba(255,255,255,0.2) 0%, rgba(255,255,255,0) 100%);
  }
  .lz-picker-foot .btn {
    background:rgba(255,255,255,0.55); border:1px solid rgba(180,210,255,0.6); border-radius:9px;
    padding:8px 14px; font-size:13px; backdrop-filter:blur(6px);
    box-shadow:inset 0 1px 0 rgba(255,255,255,0.5), 0 1px 2px rgba(40,80,160,0.06);
    transition:all 0.15s;
  }
  .lz-picker-foot .btn:hover { background:rgba(255,255,255,0.75); }
  .lz-picker-foot .btn-primary {
    background:linear-gradient(135deg, #4a85f0 0%, #2560d8 100%); color:#fff; border-color:rgba(40,90,210,0.6);
    box-shadow:0 4px 12px rgba(40,90,210,0.35), inset 0 1px 0 rgba(255,255,255,0.3);
  }
  .lz-picker-foot .btn-primary:hover { background:linear-gradient(135deg, #5a95ff 0%, #2f6ce8 100%); }
  @media (max-width: 640px) {
    .lz-picker { width:96vw; max-height:94vh; border-radius:16px; }
    .lz-tpl-grid { grid-template-columns:1fr; }
  }
  #page-leases .topbar #lz-template-picker-btn {
    height: 32px; font-size: 13px;
    min-width: 160px; max-width: 200px;
    margin-right: 2px;
    display: inline-flex; align-items: center; gap: 8px;
    justify-content: flex-start;
    padding: 0 10px;
  }
  #page-leases .topbar #lz-template-picker-btn #lz-template-picker-label {
    flex: 1; min-width: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    text-align: left;
    color: var(--text);
  }
  #page-leases .topbar #lz-template-picker-btn.is-empty #lz-template-picker-label {
    color: var(--text3);
    font-style: italic;
  }
  #page-leases .topbar .btn {
    height: 32px;
    padding: 0 10px;
    font-size: 13px;
    white-space: nowrap;
  }
  #page-leases .topbar .btn.icon-only {
    padding: 0; width: 32px;
    justify-content: center;
  }
  #page-leases .topbar .btn.icon-only i { margin: 0; }

  /* === Lease Builder toolbar: equal-size action buttons ===
     Width sized to fit "Auto-fill from Report" (the longest label) so the
     five top-level action buttons match. Scoped via #page-leases so this
     only affects the Lease Builder toolbar. */
  #page-leases .topbar-right > .btn,
  #page-leases .topbar-right > .lease-tpl-group > #lz-template-picker-btn {
    width: 180px;
    justify-content: center;
  }
  /* "Pick a template": drop the older min/max-width so the unified width
     applies, and stop the label from claiming all leftover space so the
     icon + label + chevron stay grouped and centered together. */
  #page-leases .topbar-right > .lease-tpl-group > #lz-template-picker-btn {
    min-width: 0;
    max-width: none;
  }
  #page-leases .topbar-right > .lease-tpl-group > #lz-template-picker-btn > #lz-template-picker-label {
    flex: 0 1 auto;
    max-width: 110px;
  }
  /* Mobile: the global mobile rule compacts .topbar-right .btn.btn-primary
     into a 34px icon-only square (Apps/Tasks "Add" pattern). For the Lease
     Builder we want Download PDF to stay the same width as the other four,
     so opt this button out of that compaction. */
  @media (max-width: 768px) {
    #page-leases .topbar-right > .btn.btn-primary {
      width: 180px !important;
      height: auto !important;
      min-height: 44px !important;
      padding: 0 10px !important;
      border-radius: var(--radius) !important;
    }
    #page-leases .topbar-right > .btn.btn-primary i {
      width: 14px !important;
      height: 14px !important;
    }
  }

  .lease-tb-divider {
    width: 1px; height: 22px;
    background: var(--border);
    margin: 0 4px;
    flex-shrink: 0;
  }
  .lease-layout {
    flex:1; display:grid; grid-template-columns:380px 1fr; gap:20px;
    padding:22px; overflow:auto; min-height:0;
    align-items:start;
  }
  @media (max-width: 980px) { .lease-layout { grid-template-columns: 1fr; } }
  /* No template yet: the page is ONE column holding the centred empty state, and the empty editor card takes no
     space. This used to be set only afterwards by leaseRender() (inline), so the empty state painted in the right
     column beside a blank 380px card and then jumped to the centre. Keyed on the empty state's own visibility
     (leaseRender() hides it with an inline display:none once a template loads), so first paint is the final layout. */
  #page-leases .lease-layout:has(#lz-blank-state:not([style*="none"])) { grid-template-columns: 1fr; padding-bottom: 20px; }
  #page-leases .lease-layout:has(#lz-blank-state:not([style*="none"])) .lease-editor { display: none; }
  #page-leases .lease-layout:has(#lz-blank-state:not([style*="none"])) .lease-preview-wrap { max-height: none; padding-bottom: 0; overflow-y: hidden; }
  .lease-editor {
    background:var(--bg); border:1px solid var(--border); border-radius:var(--radius-lg);
    padding:16px 18px; overflow-y:auto; max-height:calc(100vh - 120px);
    box-shadow:var(--shadow-md), inset 0 1px 0 rgba(255,255,255,0.04);
  }
  .lease-editor h3 {
    font-family:var(--font-display); font-size:11px; text-transform:uppercase;
    letter-spacing:1px; font-weight:500; color:var(--text2);
    margin:18px 0 8px; padding-bottom:6px; border-bottom:1px solid var(--gold-soft);
  }
  .lease-editor h3:first-child { margin-top:4px; }
  .lease-row { display:grid; grid-template-columns:1fr 1fr; gap:8px; margin-bottom:10px; }
  .lease-row.full { grid-template-columns:1fr; }
  .lease-row label { font-size:11px; color:var(--text2); display:block; margin-bottom:3px; }
  .lease-row .form-input { font-size:13px; padding:6px 8px; height:32px; width:100%; min-width:0; max-width:100%; }
  .lease-row textarea.form-input { height:auto; min-height:60px; }
  .lease-add-block {
    background:var(--bg2); border:1px dashed var(--border2); border-radius:6px;
    padding:10px 12px; margin-bottom:10px; position:relative;
  }
  .lease-add-block .lab-head {
    display:flex; align-items:center; justify-content:space-between; margin-bottom:8px;
    font-size:11px; font-weight:700; color:var(--text2); text-transform:uppercase; letter-spacing:0.4px;
  }
  .lease-add-block .lab-remove {
    background:transparent; border:none; color:#dc2626; cursor:pointer; font-size:12px; padding:2px 6px;
  }
  .lease-add-block .lab-remove:hover { background:rgba(220,38,38,0.08); border-radius:4px; }
  .lease-add-btn {
    width:100%; padding:8px; border:1px dashed var(--border2); background:transparent;
    color:var(--text2); border-radius:6px; cursor:pointer; font-size:12px;
    display:inline-flex; align-items:center; justify-content:center; gap:6px;
    margin-bottom:14px; transition:all 0.12s;
  }
  .lease-add-btn:hover { border-color:var(--accent); color:var(--accent); }

  .lease-preview-wrap { overflow-y:auto; max-height:calc(100vh - 120px); padding-bottom:20px; }
  #lz-blank-state {
    display:flex; flex-direction:column; align-items:center; justify-content:flex-start;
    text-align:center; height:calc(100vh - 110px); padding:40px; box-sizing:border-box; overflow-y:auto;
    background:var(--bg); border-radius:var(--radius-lg);
    border:1.5px dashed var(--border2); width:100%; max-width:none; margin:0;
  }
  .lz-blank-icon { color:var(--text3); margin-bottom:16px; }
  .lz-blank-icon svg { width:48px; height:48px; }
  .lz-blank-title { font-size:16px; font-weight:600; color:var(--text); margin-bottom:8px; }
  .lz-blank-sub { font-size:13px; color:var(--text2); max-width:300px; line-height:1.6; margin-bottom:24px; }
  .lz-blank-actions { display:flex; gap:10px; flex-wrap:wrap; justify-content:center; }
  /* ── Leases home (UI fix #47, 26 Nov 2026): a clear title, New lease, and the recent leases and templates on the
     page itself. Top-aligned so the lists filling in never move the call to action. Theme tokens only. */
  .lz-blank-pagetitle { display:none; }
  .lz-blank-icon { margin-top:24px; }
  .lz-blank-title { font-family:var(--font-display); font-size:20px; }
  .lz-blank-more { display:flex; gap:8px; flex-wrap:wrap; justify-content:center; margin-top:12px; }
  .lz-blank-more .btn { display:inline-flex; align-items:center; gap:6px; }
  .lz-blank-more .btn svg { width:15px; height:15px; }
  .lz-blank-lists { display:grid; grid-template-columns:repeat(2, minmax(0, 1fr)); gap:16px; width:100%; max-width:880px; margin-top:32px; text-align:left; }
  .lz-blank-list { background:var(--bg); border:1px solid var(--border2); border-radius:var(--radius-xl); box-shadow:var(--shadow-xs); padding:14px 14px 8px; min-width:0; }
  .lz-blank-list-head { display:flex; align-items:center; justify-content:space-between; gap:8px; margin-bottom:6px; }
  .lz-blank-list-head h3 { margin:0; font-family:var(--font-display); font-size:15px; font-weight:600; color:var(--text); }
  .lz-blank-all { border:0; background:none; padding:4px 6px; border-radius:8px; font:inherit; font-size:13px; font-weight:600; color:var(--accent); cursor:pointer; }
  .lz-blank-all:hover { background:var(--accent-soft); }
  .lz-blank-row { display:flex; align-items:center; gap:10px; width:100%; min-height:48px; padding:8px; border:0; border-radius:10px; background:none; text-align:left; font:inherit; color:var(--text); cursor:pointer; }
  .lz-blank-row:hover, .lz-blank-row:focus-visible { background:var(--bg2); outline:none; }
  .lz-blank-row svg { width:18px; height:18px; flex:none; color:var(--text3); }
  .lz-blank-row-text { display:flex; flex-direction:column; min-width:0; }
  .lz-blank-row-title { font-size:14px; font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
  .lz-blank-row-sub { font-size:12.5px; color:var(--text2); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
  .lz-blank-none { font-size:13px; color:var(--text3); padding:10px 8px 12px; line-height:1.5; }
  /* Search and actions (Reuven, 26 Nov 2026): one row the width of the lists, every control the same height, so the
     top of the page reads as one toolbar instead of a stack of odd-sized buttons. */
  .lz-home-tools { display:flex; align-items:center; gap:8px; width:100%; max-width:880px; margin-top:4px; }
  .lz-home-search { position:relative; flex:1 1 auto; min-width:0; display:block; }
  .lz-home-search svg { position:absolute; left:12px; top:50%; transform:translateY(-50%); width:16px; height:16px; color:var(--text3); pointer-events:none; }
  .lz-home-search .form-input { width:100%; height:38px; padding-left:36px; box-sizing:border-box; margin:0; }
  .lz-home-tools .lz-blank-actions, .lz-home-tools .lz-blank-more { display:flex; flex-wrap:nowrap; gap:8px; margin:0; flex:none; }
  .lz-home-tools .btn { height:38px; min-height:38px; padding:0 14px; display:inline-flex; align-items:center; justify-content:center; gap:6px; white-space:nowrap; box-sizing:border-box; font-size:13px; }
  .lz-home-tools .btn svg { width:15px; height:15px; flex:none; }
  #lz-blank-state .lz-blank-icon { margin-top:8px; margin-bottom:10px; }
  #lz-blank-state .lz-blank-icon svg { width:36px; height:36px; }
  #lz-blank-state .lz-blank-sub { margin-bottom:18px; }
  #lz-blank-state .lz-blank-lists { margin-top:20px; }
  @media (max-width: 768px) {
    /* Review fix: on a phone the page is not a dashed card. The large "Leases" title sits at the top of the page,
       like Tasks, and the rest flows on the page below it. */
    #page-leases .lease-layout:has(#lz-blank-state:not([style*="none"])) { padding:4px 16px 20px; }
    #lz-blank-state { padding:0 0 32px; border:0; background:transparent; border-radius:0; height:auto; min-height:0; overflow:visible; }
    .lz-blank-pagetitle { display:block; align-self:stretch; text-align:left; font-size:30px; font-weight:800; letter-spacing:-.6px; line-height:1.1; color:var(--text); margin-bottom:4px; }
    .lz-blank-lists { grid-template-columns:1fr; margin-top:24px; }
    /* Phone: the title, one short line, then the tools. The big icon and the second heading go, so the search and
       New lease sit near the top; every control is 44px, the two smaller actions share a row at equal widths. */
    #lz-blank-state .lz-blank-icon, #lz-blank-state .lz-blank-title { display:none; }
    #lz-blank-state .lz-blank-sub { align-self:stretch; text-align:left; max-width:none; margin:2px 0 14px; font-size:14px; line-height:1.45; }
    .lz-home-tools { display:grid; grid-template-columns:1fr 1fr; gap:8px; margin-top:0; }
    .lz-home-search, .lz-home-tools .lz-blank-actions { grid-column:1 / -1; }
    .lz-home-tools .lz-blank-more { display:contents; }
    .lz-home-search .form-input, .lz-home-tools .btn { height:44px; min-height:44px; font-size:15px; }
    .lz-home-tools .lz-blank-actions .btn { width:100%; }
    .lz-home-tools .lz-blank-more .btn { width:100%; padding:0 8px; }
    #lz-blank-state .lz-blank-lists { margin-top:18px; }
  }
  /* Same quiet white glass button on desktop as on the phone */
  #lz-blank-state .lz-blank-actions .btn-primary { background: rgba(255,255,255,.92) !important; border: 1px solid rgba(180,210,255,.8) !important; box-shadow: 0 2px 10px rgba(26,51,112,.08) !important; color: #1a3370 !important; display:inline-flex; align-items:center; gap:8px; font-weight:600; }
  .lz-section-card {
    background:var(--bg2); border:1px solid var(--border);
    border-radius:var(--radius); padding:10px 12px 4px; margin-bottom:12px;
  }
  .lz-section-card h3 { margin-top:0; }
  .lease-editor h3.lz-section-h3-icon { display:flex; align-items:center; gap:6px; }
  .lease-editor h3.lz-section-h3-icon svg { width:13px; height:13px; flex-shrink:0; }
  .lease-paper {
    background:#fff; color:#111; max-width:850px; margin:0 auto;
    padding:50px 60px; box-shadow:var(--shadow-lg); border-radius:4px;
    font-family: 'Times New Roman', Times, serif; font-size:11pt; line-height:1.45;
    position: relative;  /* containing block for absolute .lp-page-marker overlays */
  }
  .lease-paper h1 {
    font-size:14pt; font-weight:bold; text-align:left; margin:0 0 12px;
    text-transform:uppercase;
  }
  .lease-paper h2 {
    font-size:11pt; font-weight:bold; margin:18px 0 8px; text-transform:uppercase;
  }
  .lease-paper p { margin:0 0 10px; }
  .lease-paper ul { margin:6px 0 12px 24px; padding:0; }
  .lease-paper ul li { margin:3px 0; list-style:disc; }
  .lease-paper .lp-meta { margin:4px 0; }
  .lease-paper .lp-tenant-block { margin:8px 0 12px 0; }
  .lease-paper .lp-tenant-block .lp-tn { font-weight:600; margin-bottom:2px; }
  .lease-paper .lp-sig-line {
    border-bottom:1px solid #111; margin:30px 0 4px; min-height:18px;
  }
  .lease-paper .lp-sig-label { font-size:10pt; font-weight:bold; }
  .lease-paper .lp-empty { color:#cbd5e1; font-style:italic; }
  .lease-paper .lp-broker {
    border-top:1px solid #111; border-bottom:1px solid #111; padding:8px 0; margin:6px 0; font-size:10.5pt;
  }
  .lease-paper .lp-broker div { padding:3px 0; border-bottom:1px solid #e5e7eb; }
  .lease-paper .lp-broker div:last-child { border-bottom:none; }
  .lease-paper .lp-page-break { page-break-before:always; height:0; }

  /* Visible page-boundary markers in the live preview — show the user
     exactly where each PDF page will end. Pure visual indicator, doesn't
     break the contenteditable region. */
  .lease-paper .lp-page-marker {
    /* Absolute overlay so the marker contributes zero vertical space to the
       document — pressing Enter near a page boundary no longer causes layout
       jumps when the marker is recreated at a new y-position. JS sets `top`
       inline based on the page-break y. left/right span past .lease-paper's
       horizontal padding for the full-width line. */
    position: absolute;
    left: 0; right: 0;
    height: 22px;
    /* Two thin gray lines with a small gap — evokes the boundary between two
       pages of a paginated document. */
    background: linear-gradient(
      to bottom,
      transparent 0,
      transparent 9px,
      #d4d4d8 9px,
      #d4d4d8 10px,
      transparent 10px,
      transparent 12px,
      #d4d4d8 12px,
      #d4d4d8 13px,
      transparent 13px,
      transparent 22px
    );
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
  }
  .lease-paper .lp-page-marker::before {
    content: attr(data-page-label);
    position: absolute;
    left: 50%; top: 50%;
    transform: translate(-50%, -50%);
    background: #ffffff;
    color: #6b7280;
    font-family: var(--font-display, 'DM Sans', sans-serif);
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    padding: 3px 12px;
    border: 1px solid #d4d4d8;
    border-radius: 999px;
    white-space: nowrap;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  }
  .lease-paper .lp-page-marker { display: block; }
  .lease-paper.pdf-exporting .lp-page-marker { display: none; }
  /* Visible breathing room above the first element of each new PDF page.
     The padding lives on the break-start element itself, not on the
     marker, so when typing changes which element starts the page the
     padding moves with it — net document height stays constant, no
     "stretch" on Enter. */
  .lease-paper .lp-page-start { padding-top: 36px; }
  .lease-paper.pdf-exporting .lp-page-start { padding-top: 0; }
  /* During PDF export, the markers are hidden so they don't appear in the
     captured canvas. Pagination is forced by real <div class="html2pdf__page-break">
     elements (leaseApplyExportBreaks), placed at boundaries computed in html2pdf's
     true export frame by leaseComputePageBreakPoints. */

  /* Editable preview: when lz-paper is contenteditable, show a subtle
     focus ring so the user knows clicks will edit. */
  #lz-paper[contenteditable="true"] { outline: none; cursor: text; }
  #lz-paper[contenteditable="true"]:focus { box-shadow: var(--shadow-lg), 0 0 0 2px rgba(99, 102, 241, 0.18); }
  /* The lp-empty placeholder shouldn't accept clicks as "edit here". */
  #lz-paper[contenteditable="true"] .lp-empty { cursor: default; }

  /* Toolbar that sits above lz-paper. Reuses the existing .lz-toolbar/.lz-tb
     styling defined for the template editor. */
  .lz-paper-toolbar {
    position: sticky; top: 0; z-index: 5;
    margin: 0 auto 14px; max-width: 850px;
    display: flex; align-items: center; gap: 4px;
    padding: 8px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
  }
  .lz-paper-toolbar .lz-tb { background: transparent; }
  .lz-paper-toolbar .lz-paper-toolbar-hint {
    margin-left: auto; font-size: 11px; color: var(--text3);
    display: flex; align-items: center; gap: 6px;
  }
  .lz-paper-toolbar .lz-paper-toolbar-hint i { width: 12px; height: 12px; }

  /* ── Saved Leases modal ── */
  /* ── LEASE HUB PANEL (unified template picker + saved leases) ── */
  .lz-drafts-search-wrap {
    position: relative; padding: 12px 24px;
    border-bottom: 1px solid rgba(200,220,255,0.4); flex-shrink: 0;
  }
  .lz-drafts-search-icon {
    position: absolute; left: 36px; top: 50%; transform: translateY(-50%);
    width: 15px; height: 15px; color: #3a5a95; pointer-events: none;
  }
  .lz-drafts-search-input {
    width: 100%; height: 36px; padding: 0 12px 0 36px; font-size: 13px;
    background: rgba(255,255,255,0.55); border: 1px solid rgba(180,210,255,0.6);
    border-radius: 10px; color: #1a2f5c; box-sizing: border-box;
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  }
  .lz-drafts-search-input:focus {
    outline: none; background: rgba(255,255,255,0.75);
    border-color: rgba(80,130,235,0.8); box-shadow: 0 0 0 3px rgba(100,160,255,0.2);
  }
  .lz-drafts-body { flex: 1 1 auto; overflow-y: auto; overflow-x: auto; -webkit-overflow-scrolling: touch; padding: 0; min-height: 0; }
  .lz-drafts-table { width: 100%; border-collapse: collapse; display: none; }
  /* Saved Leases only: let the table exceed the body so it scrolls horizontally INSIDE the
     fixed frame instead of dragging the whole modal. Scoped by id so the shared Invoices
     tables (#inv-list-table / #inv-saved-table) keep width:100%. */
  #lz-drafts-table { width: max-content; min-width: 100%; }
  .lz-drafts-table thead th {
    position: sticky; top: 0; z-index: 2; text-align: left;
    font-size: 11px; color: #3a5a95; text-transform: uppercase;
    letter-spacing: 0.4px; font-weight: 500; padding: 10px 16px;
    border-bottom: 1px solid rgba(200,220,255,0.45);
    background: rgba(210,228,255,0.6);
    box-shadow: 0 1px 0 rgba(200,220,255,0.4);
    backdrop-filter: blur(8px);
  }
  .lz-drafts-table tbody tr { border-bottom: 1px solid rgba(200,220,255,0.3); transition: background 0.1s; }
  .lz-drafts-table tbody tr:hover { background: rgba(255,255,255,0.45); }
  .lz-drafts-table tbody tr.lz-hidden { display: none; }
  .lz-drafts-table td { padding: 12px 16px; font-size: 13px; vertical-align: top; color: #1a2f5c; }
  .lz-drafts-table td.col-status { font-size: 12px; color: #3a5a95; white-space: nowrap; }
  .lz-drafts-table td.col-updated { font-size: 12px; color: #5a7ab5; white-space: nowrap; }
  .lz-drafts-table td.col-actions { text-align: right; white-space: nowrap; }
  .lz-drafts-row-title { font-weight: 500; color: #1a2f5c; }
  .lz-drafts-row-sub { font-size: 11px; color: #3a5a95; margin-top: 2px; }
  .lz-drafts-table .btn {
    background: rgba(255,255,255,0.6); border: 1px solid rgba(180,210,255,0.6);
    color: #1a3370; font-size: 12px; padding: 4px 12px; border-radius: 8px;
  }
  .lz-drafts-table .btn:hover { background: rgba(255,255,255,0.85); }
  /* Hub view shells */
  .lz-hub-view { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow-x: hidden; }
  /* Home menu */
  .lz-hub-menu {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px;
    padding: 20px 24px 24px; align-content: start;
  }
  .lz-hub-option {
    display: flex; flex-direction: column; align-items: flex-start;
    aspect-ratio: 1; padding: 20px 18px 18px;
    border-radius: 16px; cursor: pointer; text-align: left;
    background: rgba(255,255,255,0.52); border: 1px solid rgba(200,220,255,0.55);
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.6), 0 2px 6px rgba(40,80,160,0.06);
    transition: all 0.18s;
  }
  .lz-hub-option:hover {
    background: rgba(255,255,255,0.82); border-color: rgba(80,130,235,0.6);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(40,90,210,0.2), inset 0 1px 0 rgba(255,255,255,0.7);
  }
  .lz-hub-opt-icon { width: 28px; height: 28px; color: #2a60d0; flex-shrink: 0; margin-bottom: auto; }
  .lz-hub-opt-text { margin-top: 14px; }
  .lz-hub-opt-title { font-size: 13px; font-weight: 700; color: #1a2f5c; line-height: 1.2; }
  .lz-hub-opt-sub { font-size: 11px; color: #3a5a95; margin-top: 4px; line-height: 1.4; }
  .lz-hub-opt-arrow { display: none; }
  .lz-picker.at-home { height: auto; max-height: 86vh; }
  /* Mobile: the 3 square hub cards shrink to ~97px and clip their subtitles.
     Stack them as full-width icon+text rows instead. */
  @media (max-width: 768px) {
    .lz-hub-menu { grid-template-columns: 1fr; gap: 10px; padding: 16px; }
    .lz-hub-option { aspect-ratio: auto; flex-direction: row; align-items: center; gap: 14px; padding: 16px 18px; }
    .lz-hub-opt-icon { margin-bottom: 0; }
    .lz-hub-opt-text { margin-top: 0; }
  }
  /* Hub back button */
  .lz-hub-back {
    background: rgba(255,255,255,0.4); border: 1px solid rgba(200,220,255,0.5);
    border-radius: 8px; backdrop-filter: blur(6px); padding: 4px 10px;
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 12px; color: #1a3370; cursor: pointer; transition: background 0.15s;
  }
  .lz-hub-back:hover { background: rgba(255,255,255,0.65); }
  .lz-hub-back i { width: 13px; height: 13px; }

  /* ── State lease library (inside the lease hub panel) ─────────────────────────────
     Greys only. Glass cards. The views swap inside #lz-picker (Back returns), so the
     preview is a panel view, never a stacked dialog. Phone is declared in full below:
     nothing here is inherited from the desktop-only rules. */
  .lzl-home { grid-column: 1 / -1; aspect-ratio: auto; flex-direction: row; align-items: center; gap: 14px; padding: 14px 18px; }
  .lzl-home .lz-hub-opt-icon { margin-bottom: 0; }
  .lzl-home .lz-hub-opt-text { margin-top: 0; }
  .lz-picker.lzl { width: 720px; height: min(660px, 90vh); }
  .lzl-intro { margin: 0; padding: 8px 24px 0; font-size: 12px; line-height: 1.45; color: var(--text2); }
  .lzl-body { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; padding: 12px 24px 16px; scrollbar-width: thin; scrollbar-color: var(--border2) transparent; }
  .lzl-state { background: rgba(255,255,255,0.52); border: 1px solid var(--border2); border-radius: 12px; margin-bottom: 8px; overflow: hidden; box-shadow: 0 2px 12px rgba(24,24,27,0.07); }
  .lzl-state-h, .lzl-row { display: flex; align-items: center; gap: 12px; width: 100%; box-sizing: border-box; text-align: left; cursor: pointer; font-family: inherit; color: var(--text); background: transparent; border: 0; margin: 0; }
  .lzl-state .lzl-state-h { min-height: 56px; padding: 8px 16px; }
  .lzl-state-h:hover, .lzl-row:hover { background: rgba(68,64,60,0.05); }
  .lzl-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
  .lzl-name { font-size: 13px; font-weight: 600; line-height: 1.3; color: var(--text); }
  .lzl-code { font-size: 10px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text2); margin-left: 8px; }
  .lzl-sub { font-size: 11px; line-height: 1.35; color: var(--text2); }
  .lzl-chev { width: 14px; height: 14px; flex-shrink: 0; color: var(--text2); transition: transform 0.18s; }
  .lzl-state.open .lzl-state-h .lzl-chev { transform: rotate(180deg); }
  .lzl-rows { display: none; border-top: 1px solid var(--border2); }
  .lzl-state.open .lzl-rows { display: block; }
  .lzl-state .lzl-row { min-height: 56px; padding: 8px 16px; border-top: 1px solid var(--border); }
  .lzl-row:first-child { border-top: 0; }
  .lzl-chip { display: inline-flex; align-items: center; flex-shrink: 0; font-size: 10px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; line-height: 1; color: var(--text2); background: rgba(68,64,60,0.07); border-radius: 4px; padding: 3px 6px; }
  .lzl-empty { padding: 32px 16px; text-align: center; font-size: 12px; line-height: 1.5; color: var(--text2); }
  .lzl-empty b { display: block; font-size: 13px; color: var(--text); margin-bottom: 4px; }
  .lzl-empty .btn { margin-top: 12px; }
  .lzl-pv-meta { display: flex; flex-direction: column; gap: 4px; padding: 12px 24px 0; }
  .lzl-pv-title { font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.3; }
  .lzl-pv-line { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--text2); }
  .lzl-pv-scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; padding: 12px 24px 16px; scrollbar-width: thin; scrollbar-color: var(--border2) transparent; }
  .lease-paper.lzl-paper { max-width: none; margin: 0; padding: 24px 28px; border: 1px solid var(--border2); box-shadow: none; border-radius: 12px; font-size: 10pt; overflow-wrap: anywhere; }
  .lease-paper.lzl-paper hr { border: 0; border-top: 1px solid rgba(68,64,60,0.18); margin: 12px 0; }
  .lzl-ph { background: rgba(68,64,60,0.09); border-radius: 4px; padding: 0 4px; font-family: inherit; font-size: 0.92em; color: #57534e; white-space: normal; }
  .lzl-foot-note { font-size: 11px; color: var(--text2); }
  [data-theme="dark"] .lzl-state { background: rgba(255,255,255,0.05); border-color: var(--border2); box-shadow: none; }
  [data-theme="dark"] .lzl-state-h:hover, [data-theme="dark"] .lzl-row:hover { background: rgba(255,255,255,0.06); }
  [data-theme="dark"] .lzl-chip { background: rgba(255,255,255,0.08); color: var(--text2); }
  [data-theme="dark"] .lzl-ph { background: rgba(255,255,255,0.10); color: var(--text2); }
  [data-theme="dark"] .lease-paper.lzl-paper:not(.pdf-exporting) hr { border-top-color: rgba(255,255,255,0.18); }
  @media (max-width: 768px) {
    .lz-picker.lzl {
      top: calc(var(--safe-top, 0px) + 54px); left: 50%; width: calc(100vw - 16px); max-width: none;
      height: calc(100dvh - var(--safe-top, 0px) - 54px - var(--tabbar-space, 0px) - 8px); max-height: none;
      transform: translate(-50%, 0) scale(0.96); border-radius: 22px;
    }
    .lz-picker.lzl.open { transform: translate(-50%, 0) scale(1); }
    .lzl-intro { padding: 8px 16px 0; }
    .lz-picker.lzl .lz-picker-search { padding: 12px 16px 0; }
    .lz-picker.lzl .lz-picker-search input { min-height: 44px; font-size: 13px !important; }
    .lz-picker.lzl .lz-picker-head { padding-left: 16px; padding-right: 16px; }
    .lz-picker.lzl .lz-hub-back { min-height: 44px; min-width: 44px; justify-content: center; }
    .lz-picker.lzl .lz-picker-head .btn { min-height: 44px; min-width: 44px; display: inline-flex; align-items: center; justify-content: center; }
    .lzl-body { padding: 12px 16px 16px; }
    .lzl-state .lzl-state-h, .lzl-state .lzl-row { min-height: 56px; padding: 8px 16px; font-size: 13px; }
    .lzl-pv-meta { padding: 12px 16px 0; }
    .lzl-pv-scroll { padding: 12px 16px 16px; }
    .lease-paper.lzl-paper { padding: 16px; }
    .lz-picker.lzl .lz-picker-foot { padding: 12px 16px; }
    .lz-picker.lzl .lz-picker-foot .btn { min-height: 44px; }
  }

  /* PDF / print page-break behavior: keep paragraphs, list items, headings,
     tenant blocks, signature lines, and the broker box atomic so html2pdf's
     canvas-slicer cannot cut through the middle of a line of text. */
  .lease-paper.pdf-exporting p,
  .lease-paper.pdf-exporting li,
  .lease-paper.pdf-exporting h1,
  .lease-paper.pdf-exporting h2,
  .lease-paper.pdf-exporting h3,
  .lease-paper.pdf-exporting h4,
  .lease-paper.pdf-exporting h5,
  .lease-paper.pdf-exporting h6,
  .lease-paper.pdf-exporting tr,
  .lease-paper.pdf-exporting .lp-tenant-block,
  .lease-paper.pdf-exporting .lp-broker,
  .lease-paper.pdf-exporting .lp-sig-line {
    page-break-inside: avoid;
    break-inside: avoid;
  }
  /* Clean page breaks are injected just before export as real
     <div class="html2pdf__page-break"> elements (see leaseApplyExportBreaks),
     at the SAME safe element boundaries the live preview shows as page markers
     — so the canvas is sliced between paragraphs, never through a line of text. */
  .lease-paper.pdf-exporting h1,
  .lease-paper.pdf-exporting h2,
  .lease-paper.pdf-exporting h3 {
    page-break-after: avoid;
    break-after: avoid;
  }
  @media print {
    /* Hide everything except the lease paper — modeled on the invoice
       @media print block above. Native browser print produces a clean
       vector PDF, no html2pdf canvas rasterization. */
    body * { visibility: hidden !important; }
    #lz-paper, #lz-paper * { visibility: visible !important; }
    #lz-paper {
      position: absolute; left: 0; top: 0;
      margin: 0; max-width: none;
      padding: 0.5in;
      /* Repeat the padding on every printed page fragment, not just the
         first/last. Without clone, pages 2+ start with content flush
         against the top edge. */
      box-decoration-break: clone;
      -webkit-box-decoration-break: clone;
      box-shadow: none; border-radius: 0;
    }
    .lp-page-marker, .lz-paper-toolbar { display: none !important; }
    /* margin:0 on @page eliminates the browser's auto-injected header
       (date / title) and footer (URL / page number) by leaving no space
       for them. The per-page margins are provided by #lz-paper's padding,
       which repeats on every fragment via box-decoration-break: clone. */
    @page { size: letter; margin: 0; }

    .lease-paper p,
    .lease-paper li,
    .lease-paper h1,
    .lease-paper h2,
    .lease-paper h3,
    .lease-paper .lp-tenant-block,
    .lease-paper .lp-broker,
    .lease-paper .lp-sig-line {
      page-break-inside: avoid;
      break-inside: avoid;
    }
    .lease-paper h1,
    .lease-paper h2,
    .lease-paper h3 {
      page-break-after: avoid;
      break-after: avoid;
    }
    .lease-paper p { orphans: 3; widows: 3; }
  }

  @media (max-width: 640px) {
    .lease-paper { padding:24px 18px; font-size:10pt; }
  }
  .lease-paper code, .lease-paper kbd { font-family:'SFMono-Regular',Consolas,monospace; font-size:90%; background:#f3f4f6; padding:1px 4px; border-radius:3px; }

  /* Dark-mode preview only — PDF/print revert to white paper via .pdf-exporting class */
  [data-theme="dark"] .lease-paper:not(.pdf-exporting) {
    background:#1a2236; color:#f0f2f6;
    box-shadow:var(--shadow-lg), inset 0 1px 0 rgba(255,255,255,0.04);
  }
  [data-theme="dark"] .lease-paper:not(.pdf-exporting) .lp-sig-line { border-bottom-color:rgba(255,255,255,0.35); }
  [data-theme="dark"] .lease-paper:not(.pdf-exporting) .lp-broker { border-top-color:rgba(255,255,255,0.35); border-bottom-color:rgba(255,255,255,0.35); }
  [data-theme="dark"] .lease-paper:not(.pdf-exporting) .lp-broker div { border-bottom-color:rgba(255,255,255,0.10); }
  [data-theme="dark"] .lease-paper:not(.pdf-exporting) .lp-empty { color:#6b7383; }
  [data-theme="dark"] .lease-paper:not(.pdf-exporting) code,
  [data-theme="dark"] .lease-paper:not(.pdf-exporting) kbd { background:rgba(255,255,255,0.06); color:#f0f2f6; }

  /* ── Lease Builder searchable Quick Fill ── */
  .lz-search-list {
    position: fixed; z-index: 50;
    background: var(--bg); border: 1px solid var(--border2);
    border-radius: var(--radius); box-shadow: var(--shadow-lg);
    max-height: 240px; overflow-y: auto;
  }
  .lz-search-item {
    padding: 8px 12px; font-size: 13px; cursor: pointer;
    border-bottom: 1px solid var(--border);
  }
  .lz-search-item:last-child { border-bottom: none; }
  .lz-search-item:hover, .lz-search-item.active { background: var(--bg3); }
  .lz-search-item .name { font-weight: 500; color: var(--text); }
  .lz-search-item .meta { font-size: 11px; color: var(--text3); margin-top: 2px; }
  .lz-search-empty {
    padding: 14px 12px; font-size: 12px; color: var(--text3); text-align: center;
  }
