/* ================= Homebuilder frame — base idioms =================
   Shared building blocks for every homes screen. Tokens come from the
   shell (public/app/app.css :root); everything here is prefixed hm- and
   only applies inside the homes frame. Screen files add what is specific
   to their screen. Touch targets are 44px on phone. */

body.homes-app {
  --hm-bg: #f5f6f8;
  --hm-rail: 228px;
  --hm-pane: 320px;
  --hm-gap: 16px;
  --hm-radius: 12px;
  --hm-ink: var(--app-ink);
  --hm-text: var(--app-text-primary);
  --hm-muted: var(--app-text-muted);
  --hm-faint: var(--app-text-placeholder);
  --hm-line: var(--app-border);
  --hm-line-strong: var(--app-border-strong);
}
body.homes-app .main-content { background: var(--hm-bg); font-feature-settings: "cv11", "ss01"; }

/* ---- page scaffolding ---- */
.hm-page { padding: 4px 16px 28px; color: var(--hm-text); }
.hm-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 14px 0 12px; }
.hm-head-text { min-width: 0; }
.hm-title { margin: 0; font-size: 22px; font-weight: 700; line-height: 1.2; letter-spacing: -.01em; color: var(--app-navy); overflow-wrap: anywhere; }
.hm-sub { margin: 3px 0 0; font-size: 14px; line-height: 1.4; color: var(--hm-muted); }
.hm-eyebrow { margin: 0 0 2px; font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--hm-muted); }
.hm-section-title { display: flex; align-items: center; gap: 8px; margin: 22px 0 10px; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--hm-muted); }
.hm-section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hm-section-head .hm-section-title { margin-bottom: 10px; }
.hm-count { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 6px; font-size: 11.5px; font-weight: 650; letter-spacing: 0; color: var(--hm-muted); background: var(--app-surface-3); border-radius: var(--radius-pill); }
.hm-muted-line { margin: 4px 0; font-size: 13.5px; color: var(--hm-muted); }
.hm-footnote { margin: 8px 2px 0; font-size: 12px; color: var(--hm-faint); }
.hm-spacer { flex: 1; }
.hm-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.hm-back { display: inline-flex; align-items: center; gap: 2px; min-height: 44px; padding: 0 6px 0 0; font: inherit; font-size: 14px; font-weight: 600; color: var(--app-accent); background: none; border: 0; text-decoration: none; cursor: pointer; }
.hm-back .hm-ic { width: 18px; height: 18px; }
.hm-back-row { margin: 2px 0 -6px; }

/* ---- icons ---- */
.hm-ic { display: inline-block; width: 18px; height: 18px; flex: none; vertical-align: -3px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---- cards, rows, lists ---- */
.hm-card { display: block; background: var(--app-surface); border: 1px solid var(--hm-line); border-radius: var(--hm-radius); box-shadow: var(--shadow-1); color: inherit; text-decoration: none; }
.hm-list { display: grid; gap: 8px; }
.hm-list-flush { gap: 0; overflow: hidden; }
.hm-row { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 10px 14px; font: inherit; text-align: left; color: inherit; text-decoration: none; background: var(--app-surface); border: 1px solid var(--hm-line); border-radius: var(--hm-radius); transition: background var(--motion-fast); }
.hm-list-flush .hm-row { border-width: 0 0 1px; border-radius: 0; }
.hm-list-flush .hm-row:last-child { border-bottom: 0; }
a.hm-row, button.hm-row { cursor: pointer; }
a.hm-row:hover, button.hm-row:hover { background: var(--app-surface-2); }
.hm-row-lead { display: grid; place-items: center; width: 36px; height: 36px; flex: none; color: var(--app-accent); background: var(--app-accent-soft); border-radius: 10px; }
.hm-row-main { flex: 1; min-width: 0; }
.hm-row-main b { display: block; font-size: 15px; font-weight: 600; line-height: 1.3; color: var(--hm-ink); overflow-wrap: anywhere; }
.hm-row-main small { display: block; margin-top: 2px; font-size: 12.5px; line-height: 1.35; color: var(--hm-muted); overflow-wrap: anywhere; }
.hm-row-trail { display: flex; flex: none; align-items: center; gap: 8px; color: var(--hm-faint); }
.hm-stripe { flex: none; align-self: stretch; width: 4px; min-height: 32px; border-radius: 2px; }

/* ---- pills ---- */
.hm-pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; font-size: 11.5px; font-weight: 650; line-height: 1.45; white-space: nowrap; color: var(--hm-muted); background: var(--app-surface-3); border-radius: var(--radius-pill); }
.hm-pill-ok { color: var(--app-ok); background: var(--app-ok-bg); }
.hm-pill-warn { color: var(--app-warn); background: var(--app-warn-bg); }
.hm-pill-danger { color: var(--app-danger); background: var(--app-danger-bg); }
.hm-pill-info { color: var(--app-info); background: var(--app-info-bg); }
.hm-pill-accent { color: var(--app-navy); background: var(--app-accent-soft); }
.hm-pill-muted { color: var(--hm-muted); background: var(--app-surface-3); }

/* ---- buttons ---- */
.hm-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px; font: inherit; font-size: 14px; font-weight: 600; color: var(--hm-text); background: var(--app-surface); border: 1px solid var(--hm-line-strong); border-radius: var(--radius-sm); cursor: pointer; text-decoration: none; transition: background var(--motion-fast), border-color var(--motion-fast), opacity var(--motion-fast); }
.hm-btn:hover { background: var(--app-surface-2); }
.hm-btn:active { opacity: .85; }
.hm-btn[disabled] { opacity: .5; cursor: default; }
.hm-btn .hm-ic { width: 16px; height: 16px; }
.hm-btn-primary { color: #fff; background: var(--app-accent); border-color: var(--app-accent); }
.hm-btn-primary:hover { background: var(--app-accent); opacity: .92; }
.hm-btn-ghost { color: var(--app-accent); background: transparent; border-color: transparent; }
.hm-btn-ghost:hover { background: var(--app-accent-soft); }
.hm-btn-danger { color: var(--app-danger); background: transparent; border-color: transparent; }
.hm-btn-danger:hover { background: var(--app-danger-bg); }
.hm-btn-danger-solid { color: #fff; background: var(--app-danger); border-color: var(--app-danger); }
.hm-btn-danger-solid:hover { background: var(--app-danger); opacity: .92; }
.hm-btn-sm { min-height: 34px; padding: 5px 11px; font-size: 13px; }
.hm-btn-icon, .hm-btn-icon-sq { width: 40px; min-height: 40px; padding: 0; color: var(--hm-muted); }
.hm-btn-icon { background: transparent; border-color: transparent; border-radius: 10px; }
.hm-btn-icon:hover { color: var(--hm-text); background: var(--app-surface-3); }
.hm-btn-quiet-danger:hover { color: var(--app-danger); background: var(--app-danger-bg); }
.hm-btn:focus-visible, .hm-row:focus-visible, .hm-tab:focus-visible, .hm-seg-btn:focus-visible, a:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--app-accent) 35%, white); outline-offset: 2px;
}

/* ---- segmented control & tabs ---- */
.hm-seg { display: flex; gap: 2px; padding: 3px; background: var(--app-surface-3); border-radius: 11px; overflow-x: auto; scrollbar-width: none; }
.hm-seg::-webkit-scrollbar { display: none; }
.hm-seg[hidden] { display: none; }
.hm-seg-btn { display: inline-flex; flex: 1 0 auto; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 6px 12px; font: inherit; font-size: 13.5px; font-weight: 600; white-space: nowrap; color: var(--hm-muted); background: transparent; border: 0; border-radius: 9px; cursor: pointer; }
.hm-seg-btn.active { color: var(--app-navy); background: var(--app-surface); box-shadow: var(--shadow-1); }
.hm-seg-inline { display: inline-flex; }
.hm-tabs { display: flex; gap: 4px; margin-top: 14px; border-bottom: 1px solid var(--hm-line); overflow-x: auto; scrollbar-width: none; }
.hm-tabs::-webkit-scrollbar { display: none; }
.hm-tab { flex: none; display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px; font-size: 14px; font-weight: 600; color: var(--hm-muted); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.hm-tab:hover { color: var(--hm-text); }
.hm-tab.is-active { color: var(--app-navy); border-bottom-color: var(--app-navy); }

/* ---- forms ---- */
.hm-search { position: relative; display: flex; align-items: center; }
.hm-search .hm-ic { position: absolute; left: 12px; width: 17px; height: 17px; color: var(--hm-faint); pointer-events: none; }
.hm-search input { width: 100%; min-height: 42px; padding: 9px 12px 9px 38px; font: inherit; font-size: 15px; color: var(--hm-ink); background: var(--app-surface); border: 1px solid var(--hm-line-strong); border-radius: 10px; outline: none; -webkit-appearance: none; }
.hm-search input:focus, .hm-select:focus { border-color: var(--app-accent); box-shadow: 0 0 0 3px var(--app-accent-soft); }
.hm-search input::placeholder { color: var(--hm-faint); }
.hm-select { min-height: 40px; padding: 8px 32px 8px 12px; font: inherit; font-size: 14px; color: var(--hm-text); background: var(--app-surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center / 16px; border: 1px solid var(--hm-line-strong); border-radius: 10px; outline: none; -webkit-appearance: none; appearance: none; }
.hm-select-sm { min-height: 36px; font-size: 13.5px; }
.hm-toggle, .hm-check { display: inline-flex; align-items: center; gap: 8px; min-height: 36px; font-size: 13.5px; color: var(--hm-muted); cursor: pointer; }
.hm-toggle input, .hm-check input { width: 18px; height: 18px; margin: 0; accent-color: var(--app-accent); }
.hm-filter-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 12px; }
.hm-form { display: grid; gap: 14px; }
.hm-field { display: grid; gap: 6px; min-width: 0; }
.hm-field > span { font-size: 12.5px; font-weight: 650; color: var(--hm-muted); }
.hm-field > span em { font-style: normal; font-weight: 500; color: var(--hm-faint); }
.hm-field input, .hm-field select, .hm-field textarea { width: 100%; min-height: 44px; padding: 10px 12px; font: inherit; font-size: 15px; color: var(--hm-ink); background: var(--app-surface); border: 1px solid var(--hm-line-strong); border-radius: var(--radius-sm); outline: none; -webkit-appearance: none; appearance: none; }
.hm-field select { padding-right: 32px; background: var(--app-surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center / 16px; }
.hm-field textarea { min-height: 64px; resize: vertical; line-height: 1.45; }
.hm-field input:focus, .hm-field select:focus, .hm-field textarea:focus { border-color: var(--app-accent); box-shadow: 0 0 0 3px var(--app-accent-soft); }
.hm-field input:disabled { color: var(--hm-muted); background: var(--app-surface-2); }
.hm-field-help { font-size: 12px; color: var(--hm-muted); }
.hm-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hm-field-row[hidden] { display: none; }
.hm-form-error { margin: 0; padding: 10px 12px; font-size: 13.5px; font-weight: 600; color: var(--app-danger); background: var(--app-danger-bg); border-radius: var(--radius-sm); }
.hm-form-error[hidden] { display: none; }
@media (max-width: 480px) { .hm-field-row { grid-template-columns: 1fr; } }

/* ---- states ---- */
.hm-empty { display: grid; justify-items: center; gap: 6px; margin: 8px 0; padding: 28px 20px; text-align: center; color: var(--hm-muted); background: var(--app-surface); border: 1px dashed var(--hm-line-strong); border-radius: var(--hm-radius); }
.hm-empty-ic { display: grid; place-items: center; width: 44px; height: 44px; margin-bottom: 4px; color: var(--app-accent); background: var(--app-accent-soft); border-radius: 50%; }
.hm-empty-ic .hm-ic { width: 22px; height: 22px; }
.hm-empty b { font-size: 15px; color: var(--hm-text); }
.hm-empty p { max-width: 380px; margin: 0; font-size: 13.5px; line-height: 1.5; }
.hm-empty .hm-btn { margin-top: 8px; }
.hm-error { display: flex; align-items: center; gap: 10px; margin: 8px 0; padding: 12px 14px; font-size: 14px; color: var(--app-danger); background: var(--app-danger-bg); border-radius: var(--hm-radius); }
.hm-error > span { flex: 1; min-width: 0; }
.hm-error .hm-btn { flex: none; }
.hm-banner { display: flex; align-items: flex-start; gap: 10px; margin: 0 0 12px; padding: 12px 14px; font-size: 13.5px; line-height: 1.45; border: 1px solid; border-radius: var(--hm-radius); }
.hm-banner > .hm-ic { margin-top: 1px; }
.hm-banner > span { flex: 1; min-width: 0; }
.hm-banner .hm-btn { flex: none; margin: -4px 0; }
.hm-banner-info { color: #1e3a8a; background: #eff6ff; border-color: #bfdbfe; }
.hm-banner-warn { color: #78350f; background: #fffbeb; border-color: #fde68a; }

.hm-skeleton { display: grid; gap: 8px; margin: 8px 0; }
.hm-skeleton > div { height: 60px; border-radius: var(--hm-radius); background: linear-gradient(90deg, #eceff3 25%, #f5f7f9 50%, #eceff3 75%); background-size: 200% 100%; animation: hm-shimmer 1.2s linear infinite; }
.hm-skeleton-head > div { width: 46%; height: 30px; margin: 16px 0 6px; }
.hm-skeleton-line > div { height: 40px; }
.hm-skeleton-tiles > div { height: 84px; }
.hm-skeleton-cal > div { height: 380px; }
.hm-skeleton-compact > div { height: 28px; }
@keyframes hm-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---- progress bar ---- */
.hm-progress { display: block; width: 100%; height: 6px; overflow: hidden; background: var(--app-surface-3); border-radius: var(--radius-pill); }
.hm-progress > span { display: block; height: 100%; background: var(--app-accent); border-radius: inherit; transition: width var(--motion-base) ease; }

/* ---- stat tiles & facts ---- */
.hm-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.hm-tile { display: grid; gap: 2px; padding: 12px 14px; background: var(--app-surface); border: 1px solid var(--hm-line); border-radius: var(--hm-radius); }
.hm-tile > span { font-size: 12px; font-weight: 600; color: var(--hm-muted); }
.hm-tile > b { font-size: 20px; font-weight: 700; letter-spacing: -.01em; color: var(--hm-ink); font-variant-numeric: tabular-nums; }
.hm-tile > small { font-size: 12px; color: var(--hm-muted); }
.hm-tile.is-over > b, .hm-tile.is-over > span { color: var(--app-danger); }
.hm-facts { display: flex; flex-wrap: wrap; gap: 10px 28px; margin: 12px 0 0; }
.hm-facts > div { min-width: 0; }
.hm-facts dt { font-size: 11.5px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase; color: var(--hm-faint); }
.hm-facts dd { margin: 2px 0 0; font-size: 14px; font-weight: 550; color: var(--hm-text); overflow-wrap: anywhere; }

/* ---- tables (desktop); phone restyles rows as cards per screen ---- */
.hm-table-wrap { overflow-x: auto; background: var(--app-surface); border: 1px solid var(--hm-line); border-radius: var(--hm-radius); box-shadow: var(--shadow-1); }
.hm-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.hm-table th, .hm-table td { padding: 11px 14px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--hm-line); }
.hm-table thead th { position: sticky; top: 0; z-index: 1; font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; white-space: nowrap; color: var(--hm-muted); background: var(--app-surface-2); }
.hm-table tbody th { font-weight: 600; color: var(--hm-ink); }
.hm-table tbody tr:last-child > * { border-bottom: 0; }
.hm-table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---- files ---- */
.hm-files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.hm-file-link { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; min-height: 36px; padding: 6px 11px; font-size: 13px; font-weight: 600; color: var(--app-accent); background: var(--app-surface); border: 1px solid var(--hm-line-strong); border-radius: 8px; text-decoration: none; }
.hm-file-link span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hm-file-link small { font-weight: 500; color: var(--hm-muted); }
.hm-file-link:hover { background: var(--app-surface-2); }
.hm-file-link .hm-ic { width: 15px; height: 15px; }

/* ---- toast ---- */
.hm-toast { position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 1300; display: flex; align-items: center; gap: 8px; max-width: min(92vw, 440px); padding: 11px 16px; font-size: 14px; font-weight: 600; color: #fff; background: #0f172a; border-radius: 12px; box-shadow: var(--shadow-2); opacity: 0; transform: translate(-50%, 8px); pointer-events: none; transition: opacity var(--motion-base), transform var(--motion-base); }
.hm-toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.hm-toast.is-error { background: var(--app-danger); }
.hm-toast .hm-ic { width: 17px; height: 17px; }

/* ---- sheet (bottom sheet on phone, dialog on desktop) ---- */
.hm-sheet-wrap { position: fixed; inset: 0 0 auto; z-index: 1200; display: flex; align-items: flex-end; justify-content: center; height: var(--app-visible-height, 100dvh); padding-top: env(safe-area-inset-top); }
.hm-sheet-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, .42); animation: hm-fade var(--motion-base) ease-out; }
.hm-sheet { position: relative; display: flex; flex-direction: column; width: 100%; max-width: 560px; max-height: 92%; background: var(--app-surface); border-radius: 16px 16px 0 0; box-shadow: var(--shadow-sheet); overflow: hidden; outline: none; animation: hm-sheet-in var(--motion-base) ease-out; }
.hm-sheet-wide { max-width: 760px; }
.hm-sheet-grip { flex: none; width: 36px; height: 4px; margin: 8px auto 0; border-radius: 2px; background: var(--hm-line-strong); }
.hm-sheet-head { display: flex; flex: none; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px 12px; border-bottom: 1px solid var(--hm-line); }
.hm-sheet-head b { display: block; font-size: 16px; color: var(--app-navy); }
.hm-sheet-head small { display: block; margin-top: 1px; font-size: 12.5px; color: var(--hm-muted); }
.hm-sheet-close { display: grid; place-items: center; width: 40px; height: 40px; flex: none; padding: 0; color: var(--hm-muted); background: var(--app-surface-3); border: 0; border-radius: 50%; cursor: pointer; }
.hm-sheet-body { flex: 1; min-height: 0; padding: 16px; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.hm-sheet-body:last-child { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
.hm-sheet-text { margin: 0; font-size: 14.5px; line-height: 1.5; color: var(--hm-text); }
.hm-sheet-foot { display: flex; flex: none; justify-content: flex-end; gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--hm-line); }
.hm-sheet-foot .hm-btn-danger { margin-right: auto; }
.keyboard-open .hm-sheet-foot { padding-bottom: 12px; }
@keyframes hm-sheet-in { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes hm-fade { from { opacity: 0; } to { opacity: 1; } }
@media (min-width: 720px) {
  .hm-sheet-wrap { align-items: center; padding: 24px; }
  .hm-sheet { max-height: 86%; border-radius: 16px; }
  .hm-sheet-grip { display: none; }
  .hm-sheet-head { padding-top: 14px; }
  .hm-sheet-foot { padding-bottom: 12px; }
}

/* ---- phone / desktop visibility helpers ---- */
@media (min-width: 1024px) {
  .hm-only-phone { display: none !important; }
  .hm-toast { bottom: 28px; }
}
