:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1c2530;
  --muted: #6b7785;
  --border: #dfe4ea;
  --accent: #1565c0;
  --accent-dark: #0d47a1;
  --danger: #c62828;
  --success: #2e7d32;
  --warn: #f9a825;
}

* { box-sizing: border-box; }

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

a { color: var(--accent); }

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: #14202e;
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1rem;
  gap: 0.25rem;
}
.sidebar .brand { font-weight: 700; font-size: 1.1rem; margin-bottom: 1.5rem; }
.sidebar a {
  color: #cfd8e3;
  text-decoration: none;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
}
.sidebar a:hover { background: rgba(255,255,255,0.08); color: #fff; }
.logout-form { margin-top: auto; }
.logout-form button {
  width: 100%;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.25);
  color: #cfd8e3;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
}
.logout-form button:hover { background: rgba(255,255,255,0.08); }

.content { flex: 1; padding: 2rem; max-width: 1100px; }
.content.full { display: flex; align-items: center; justify-content: center; min-height: 100vh; max-width: none; }

h1 { margin-top: 0; }

.muted { color: var(--muted); }

.flash {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.95rem;
}
.flash-success { background: #e6f4ea; color: var(--success); }
.flash-error { background: #fdecea; color: var(--danger); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
}

.cards { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.stat { min-width: 140px; display: flex; flex-direction: column; gap: 0.25rem; }
.stat-label { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.stat-value { font-size: 1.5rem; font-weight: 700; }

.map { height: 360px; border-radius: 10px; margin-bottom: 1.5rem; border: 1px solid var(--border); }
.map-small { height: 260px; }
.map-large { height: 600px; }

.table { width: 100%; border-collapse: collapse; margin-bottom: 1.5rem; background: var(--card); border-radius: 10px; overflow: hidden; }
.table th, .table td { text-align: left; padding: 0.6rem 0.9rem; border-bottom: 1px solid var(--border); font-size: 0.92rem; }
.table th { background: #eef1f5; font-weight: 600; }
.table th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.table th.sortable:hover { background: #e3e8ee; }

.bar { display: inline-block; width: 100px; height: 8px; background: #e3e7eb; border-radius: 4px; overflow: hidden; vertical-align: middle; margin-right: 0.5rem; }
.bar-fill { display: block; height: 100%; background: var(--accent); } /* block: it is a <span> in some lists */

.badge { display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.78rem; font-weight: 600; }
.badge-pending { background: #fff3cd; color: #8a6512; }
.badge-approved { background: #e6f4ea; color: var(--success); }
.badge-rejected { background: #fdecea; color: var(--danger); }
.badge-active { background: #e6f4ea; color: var(--success); }
.badge-disabled { background: #eee; color: #666; }

.form { display: flex; flex-direction: column; gap: 0.9rem; max-width: 480px; margin-bottom: 2rem; }
.form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; font-weight: 600; }
.form input, .form select, .form textarea {
  font: inherit;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}
.form fieldset { border: 1px solid var(--border); border-radius: 8px; display: flex; gap: 1rem; }
.form fieldset label { flex: 1; }
.form button, button {
  font: inherit;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.6rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  align-self: flex-start;
}
.form button:hover, button:hover { background: var(--accent-dark); }
button.danger { background: var(--danger); }
button.danger:hover { background: #8e1c1c; }

.auth-box { max-width: 380px; margin: 0 auto; }

.report { margin-bottom: 1rem; }
.report-head { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.4rem; }
.photo-strip { display: flex; gap: 0.5rem; flex-wrap: wrap; margin: 0.5rem 0; }
.photo-strip img { width: 110px; height: 110px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }
.report-actions { display: flex; gap: 0.6rem; align-items: center; margin-top: 0.5rem; }
.reject-form { display: flex; gap: 0.4rem; }
.reject-form input { padding: 0.4rem 0.5rem; border: 1px solid var(--border); border-radius: 6px; }

.stage-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; }
.stage-dot-open { background: #dfe4ea; }
.stage-dot-checked { background: var(--warn); }
.stage-dot-approved { background: var(--success); }
.stage-dot-rejected { background: var(--danger); }

.stage-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stage-panel { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 1rem; display: flex; flex-direction: column; gap: 0.6rem; }
.stage-panel-title { font-weight: 700; font-size: 0.85rem; text-align: center; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; margin: 0; }
.stage-panel label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.82rem; font-weight: 600; }
.stage-panel input, .stage-panel select, .stage-panel textarea {
  font: inherit;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}
.stage-billing { border-top: 1px dashed var(--border); padding-top: 0.5rem; display: flex; flex-direction: column; gap: 0.6rem; }

.expand-cell { background: var(--bg); padding: 1rem !important; }
.expand-content .progress-form-status { margin-left: 0.75rem; }

.content.wide { max-width: none; }

/* Houses: map on the left, search + list on the right. */
.houses-layout { display: grid; grid-template-columns: minmax(300px, 2fr) 3fr; gap: 1.25rem; align-items: start; }
.houses-map-pane { position: sticky; top: 1rem; min-width: 0; }
.houses-map { height: calc(100vh - 11rem); min-height: 360px; border-radius: 10px; border: 1px solid var(--border); }
.houses-list-pane { min-width: 0; container-type: inline-size; }
/* The wide table scrolls inside this wrapper (it is the only scroll container,
   so the sticky edit panel below tracks it). */
#house-results { overflow-x: auto; border-radius: 10px; }
#house-results .table { min-width: 720px; overflow: visible; }
.expand-content { position: sticky; left: 0; width: calc(100cqw - 2rem); }

@media (max-width: 1100px) {
  .houses-layout { grid-template-columns: minmax(0, 1fr); }
  .houses-map-pane { position: static; }
  .houses-map { height: 40vh; min-height: 260px; }
}

.nav-toggle { display: none; }
/* Refresh button (Zinier update popup): a menu entry under the name on
   desktop, an icon left of the menu button on phones. */
.nav-refresh {
  display: flex; align-items: center; gap: 0.6rem;
  margin: -0.75rem 0 0.75rem; padding: 0.55rem 0.75rem;
  color: #cfd8e3; background: transparent; border: 1px solid rgba(255,255,255,0.2); border-radius: 6px;
  font: inherit; text-align: left; cursor: pointer;
}
.nav-refresh:hover { background: rgba(255,255,255,0.08); }
.zinier-dialog { width: min(640px, calc(100vw - 2rem)); height: min(720px, calc(100vh - 2rem)); padding: 0; border: 0; border-radius: 10px; box-shadow: 0 10px 40px rgba(0,0,0,.35); overflow: hidden; }
.zinier-dialog[open] { display: flex; flex-direction: column; }
.zinier-dialog::backdrop { background: rgba(0,0,0,.45); }
.zinier-dialog-bar { display: flex; align-items: center; justify-content: space-between; padding: 0.5rem 0.5rem 0.5rem 1rem; border-bottom: 1px solid var(--border); }
.zinier-dialog-bar button { min-width: 40px; min-height: 40px; padding: 0; font-size: 1.6rem; line-height: 1; background: transparent; color: inherit; border: 0; cursor: pointer; }
.zinier-dialog iframe { flex: 1; width: 100%; border: 0; }
/* The page inside the popup: no menu, no back link. */
html.embedded .sidebar, html.embedded .content > p:first-child > a[href="/oxg-import"] { display: none; }
html.embedded .shell { display: block; min-height: 0; }
html.embedded body { overflow-wrap: anywhere; }

/* ---- Phone / small tablet ---------------------------------------------- */
@media (max-width: 900px) {
  .shell { flex-direction: column; min-height: 100vh; }

  /* Sidebar becomes a sticky top bar; links collapse behind the menu button. */
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2000; /* above Leaflet panes/controls (up to 1000) */
    width: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    padding: 0.5rem 1rem;
    gap: 0;
  }
  .sidebar .brand { margin: 0; }
  .sidebar .nav-refresh { justify-content: center; margin: 0 0.5rem 0 auto; padding: 0; width: 44px; height: 44px; color: #fff; border-color: rgba(255,255,255,0.25); }
  .nav-refresh-label { display: none; }
  .sidebar .nav-refresh + .nav-toggle { margin-left: 0; }
  .sidebar .nav-toggle {
    display: block;
    margin-left: auto;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    font-size: 1.4rem;
    line-height: 1;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 6px;
    align-self: center;
  }
  .sidebar .nav-toggle:hover { background: rgba(255,255,255,0.08); }
  .sidebar > a,
  .sidebar > .logout-form { display: none; flex: 1 0 100%; }
  .sidebar.open > a { display: block; padding: 0.85rem 0.75rem; }
  .sidebar.open > .logout-form { display: block; margin-top: 0.5rem; padding-bottom: 0.5rem; }
  .logout-form button { min-height: 44px; }

  .content { padding: 1rem; min-width: 0; max-width: 100%; }
  .content.full { min-height: 100vh; padding: 1rem; }
  @supports (height: 100dvh) {
    .content.full { min-height: 100dvh; }
  }
  h1 { font-size: 1.5rem; }

  /* Stat cards: two per row instead of fixed-width wrapping. */
  .cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
  .cards .card-wide { grid-column: 1 / -1; } /* e.g. the Zinier dates on the house page */
  .stat { min-width: 0; }
  .stat-value { font-size: 1.25rem; }

  /* Maps */
  .map { height: 300px; }
  .map-small { height: 240px; }
  .map-large { height: 65vh; min-height: 320px; }

  /* Tables scroll sideways inside themselves rather than widening the page. */
  .table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table th, .table td { white-space: nowrap; }
  .table th.sortable { padding: 0.8rem 0.9rem; }
  .table .expand-cell { white-space: normal; }
  /* The houses table scrolls in #house-results instead (see above). */
  #house-results .table { display: table; overflow: visible; }

  /* Simple data tables become stacked label/value cards. */
  .table-stack { overflow: visible; background: transparent; }
  .table-stack thead {
    position: absolute; width: 1px; height: 1px; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
  .table-stack tbody, .table-stack tr, .table-stack td { display: block; }
  .table-stack tr {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.25rem 0.9rem;
    margin-bottom: 0.75rem;
  }
  .table-stack td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.55rem 0;
    text-align: right;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .table-stack td:last-child { border-bottom: none; }
  .table-stack td::before {
    content: attr(data-label);
    flex-shrink: 0;
    font-weight: 600;
    color: var(--muted);
    text-align: left;
  }
  .table-stack td[data-label=""]::before { content: none; }
  .table-stack td[data-label=""] { justify-content: flex-end; }
  .table-stack td[colspan] { display: block; text-align: left; }
  .table-stack td[colspan]::before { content: none; }

  /* Forms: full width, 16px text (stops iOS zooming on focus), 44px targets. */
  .form { max-width: 560px; }
  .form label, .form input, .form select, .form textarea { min-width: 0; }
  .form input, .form select, .form textarea { width: 100%; }
  .form fieldset { min-width: 0; gap: 0.75rem; }
  .content input, .content select, .content textarea { font-size: 16px; }
  .content input[type="checkbox"] { width: 22px; height: 22px; }
  .content input:not([type="checkbox"]):not([type="file"]),
  .content select { min-height: 44px; }
  button, .form button { min-height: 44px; padding: 0.6rem 1.1rem; }
  .form > button { align-self: stretch; }

  /* Segment report cards */
  .report-head { flex-wrap: wrap; }
  .report-actions { flex-direction: column; align-items: stretch; }
  .report-actions button { width: 100%; }
  .reject-form { flex-direction: column; }
  .reject-form input { width: 100%; }
  .photo-strip img { width: 96px; height: 96px; }

  .auth-box { width: 100%; }
}

/* --- Houses: types, step status, detail page --------------------------- */
.small { font-size: 0.8rem; }
.warn-text { color: #b26a00; font-size: 0.85rem; }
.inline-form { display: inline-flex; gap: 0.4rem; align-items: center; margin: 0; }
.link-button { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; font-size: 0.8rem; }
.link-button:hover { background: none; }

.filter-bar { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 1rem; }
.filter-bar input[type="text"] { flex: 1; min-width: 220px; max-width: 420px; }
.filter-bar input, .filter-bar select { padding: 0.45rem 0.6rem; border: 1px solid var(--border); border-radius: 6px; }

.type-badge { display: inline-block; padding: 0.1rem 0.45rem; border-radius: 4px; font-size: 0.75rem; font-weight: 600; vertical-align: middle; }
.type-HC { background: #e3f2fd; color: var(--accent-dark); }
.type-HP_PLUS { background: #f3e5f5; color: #6a1b9a; }

.step-chip { display: inline-block; padding: 0.1rem 0.45rem; border-radius: 999px; font-size: 0.72rem; white-space: nowrap; border: 1px solid transparent; }
.step-OPEN { background: #f1f3f5; color: var(--muted); border-color: var(--border); }
.step-BUILT { background: #fff8e1; color: #8a6100; }
.step-OFFICE_CHECKED { background: #e3f2fd; color: var(--accent-dark); }
.step-OXG_APPROVED { background: #e8f5e9; color: var(--success); }
.step-INVOICED { background: var(--success); color: #fff; }
.step-REJECTED { background: #ffebee; color: var(--danger); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.2rem 0.8rem; margin: 0.3rem 0; font-size: 0.9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.step-card { margin-bottom: 1rem; }
.step-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; margin-bottom: 0.4rem; }
.step-card details { margin-top: 0.6rem; }
.step-card summary { cursor: pointer; color: var(--accent); }
.step-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.75rem; padding-top: 0.75rem; border-top: 1px solid var(--border); }
.step-actions input { padding: 0.35rem 0.5rem; border: 1px solid var(--border); border-radius: 6px; }
.photo-strip figure { margin: 0; text-align: center; }
.photo-strip figcaption { font-size: 0.75rem; color: var(--muted); }
.type-change { margin: 1rem 0; }
.type-change summary { cursor: pointer; }
.history { font-size: 0.85rem; margin: 0.5rem 0 0; padding-left: 1.2rem; }

.tabs { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-bottom: 1rem; border-bottom: 1px solid var(--border); }
.tab { padding: 0.45rem 0.8rem; text-decoration: none; border-bottom: 2px solid transparent; }
.tab.active { border-bottom-color: var(--accent); font-weight: 600; }
.bulk-bar { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: flex-end; margin-bottom: 1rem; }
.bulk-bar label { display: flex; flex-direction: column; font-size: 0.85rem; gap: 0.2rem; }
.bulk-bar input, .bulk-bar select { padding: 0.4rem 0.5rem; border: 1px solid var(--border); border-radius: 6px; }


/* --- LV: spreadsheet grid ------------------------------------------------ */
.lv-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; margin-bottom: 0.5rem; position: sticky; top: 0; z-index: 3; background: var(--bg); padding: 0.5rem 0; }
.lv-toolbar label { display: flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; }
.lv-toolbar select, .lv-toolbar input[type="search"] { padding: 0.4rem 0.55rem; border: 1px solid var(--border); border-radius: 6px; }
.lv-toolbar input[type="search"] { width: 240px; }
.lv-spacer { flex: 1; }
.lv-legend { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.8rem; color: var(--muted); }
.lv-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-left: 0.4rem; }
.lv-swatch-cost { background: #90b4e0; }
.lv-swatch-margin { background: #66bb6a; }
.lv-swatch-loss { background: var(--danger); }
#lv-dirty { font-size: 0.85rem; color: #b26a00; }

.lv-grid-wrap { overflow: auto; max-height: calc(100vh - 210px); border: 1px solid #c9d1da; border-radius: 4px; background: var(--card); }
.lv-grid { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 900px; font-size: 13px; table-layout: fixed; }
.lv-grid col.c-pos { width: 118px; }
.lv-grid col.c-title { width: auto; }
.lv-grid col.c-unit { width: 88px; }
.lv-grid col.c-num { width: 104px; }
.lv-grid col.c-pct { width: 60px; }
.lv-grid col.c-bar { width: 180px; }
.lv-grid th, .lv-grid td { border-right: 1px solid #e3e8ee; border-bottom: 1px solid #e3e8ee; padding: 0 8px; height: 28px; vertical-align: middle; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lv-grid th { position: sticky; top: 0; z-index: 2; background: #eef1f5; font-weight: 600; text-align: left; color: #3a4654; border-bottom: 2px solid #c9d1da; }
.lv-grid th.num, .lv-grid td.num { text-align: right; font-variant-numeric: tabular-nums; }
.lv-grid td.pos { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; position: sticky; left: 0; background: inherit; }
.lv-grid tbody tr.lv-row { background: var(--card); }
.lv-grid tbody tr.lv-row:nth-child(even) { background: #fafbfc; }
.lv-grid tbody tr.lv-row:hover { background: #f1f6fd; }
.lv-grid .lv-section td { background: #14202e; color: #fff; font-weight: 700; letter-spacing: 0.03em; height: 30px; position: sticky; top: 30px; z-index: 1; }
.lv-grid .lv-group td { background: #e8edf3; font-weight: 600; color: #3a4654; }
/* Heading rows span the full width; keep their label in view when scrolling sideways. */
.lv-grid .lv-section td, .lv-grid .lv-group td { overflow: visible; }
.lv-grid .lv-heading { display: inline-block; position: sticky; left: 8px; }
.lv-grid td.unit { color: var(--muted); }
.lv-grid td.margin, .lv-grid td.pct { color: var(--success); }
.lv-grid tr.loss td.margin, .lv-grid tr.loss td.pct { color: var(--danger); font-weight: 600; }

.lv-grid td.title { cursor: default; }
.lv-grid .lv-title { overflow: hidden; text-overflow: ellipsis; }
.lv-grid .lv-desc { display: none; }
.lv-grid td.title:has(.lv-desc) { cursor: pointer; }
.lv-grid td.title:has(.lv-desc) .lv-title::after { content: " ▸"; color: var(--muted); }
.lv-grid tr.expanded td { white-space: normal; height: auto; vertical-align: top; padding-top: 5px; padding-bottom: 5px; }
.lv-grid tr.expanded .lv-title::after { content: " ▾"; }
.lv-grid tr.expanded .lv-desc { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; white-space: pre-line; }

.lv-auto { display: inline-block; font-family: inherit; font-size: 10px; padding: 0 4px; border-radius: 3px; background: #e3f2fd; color: var(--accent-dark); vertical-align: 1px; }

/* Editable cell: looks like a spreadsheet cell, not a form field. */
.lv-grid td.cell-input { padding: 0; background: #fffdf2; }
.lv-grid td.cell-input input { width: 100%; height: 27px; border: 0; margin: 0; padding: 0 8px; background: transparent; text-align: right; font: inherit; font-variant-numeric: tabular-nums; border-radius: 0; }
.lv-grid td.cell-input input:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: #fff; }
.lv-grid td.cell-input input.invalid { outline: 2px solid var(--danger); outline-offset: -2px; }
.lv-grid td.cell-input.dirty { background: #fff3c4; }

.lv-grid td.bar-cell { padding: 0 10px; }
.lv-bar { display: flex; height: 10px; border-radius: 2px; background: #edf0f3; overflow: hidden; }
.lv-bar-cost { background: #90b4e0; }
.lv-bar-margin { background: #66bb6a; }
.lv-grid tr.loss .lv-bar-cost { background: var(--danger); }

@media (max-width: 700px) {
  .lv-toolbar input[type="search"] { width: 100%; }
  .lv-grid-wrap { max-height: none; }
}
.total-row td { border-top: 2px solid var(--border); }

/* Houses list: one overview line per house, expands to the full details. */
.house-list { display: flex; flex-direction: column; gap: 0.4rem; }
.house-item { background: var(--card); border: 1px solid var(--border); border-radius: 8px; }
.house-item[open] { border-color: var(--accent); }
.house-item summary {
  display: grid; grid-template-columns: 1fr auto 150px 80px; gap: 0.8rem; align-items: center;
  padding: 0.6rem 0.9rem; cursor: pointer; list-style: none;
}
.house-item summary::-webkit-details-marker { display: none; }
.house-item summary:hover { background: #f5f7fa; }
.house-addr { display: flex; flex-direction: column; min-width: 0; }
.house-progress { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem; }
.house-detail { padding: 0.2rem 0.9rem 0.9rem; border-top: 1px solid var(--border); }
.house-detail h4 { margin: 0.9rem 0 0.4rem; font-size: 0.85rem; }
.house-detail ul { margin: 0; padding-left: 1.2rem; }
.house-facts { display: grid; grid-template-columns: max-content 1fr; gap: 0.25rem 1rem; margin: 0.8rem 0 0; }
.house-facts dt { color: var(--muted); }
.house-facts dd { margin: 0; }
.house-steps { display: flex; flex-wrap: wrap; gap: 0.4rem; }
@media (max-width: 600px) {
  .house-item summary { grid-template-columns: 1fr auto; }
  .house-progress { grid-column: 1; }
}

/* PDP area labels on the houses map. */
.leaflet-tooltip.pdp-label { background: transparent; border: 0; box-shadow: none; color: #4527a0; font-weight: 700; font-size: 11px; }
.hide-pdp-labels .pdp-label { display: none; }

/* Map tab: the map fills everything next to (or below) the nav, with the
   search bar floating at the bottom. */
/* The page itself never scrolls here: on phones 100vh is taller than the
   visible screen, and once scrolled the map swallows every swipe back up. */
html:has(.map-page), body:has(.map-page) { height: 100%; overflow: hidden; }
.shell:has(.map-page) { height: 100vh; height: 100dvh; min-height: 0; }
.content.map-page { position: relative; padding: 0; max-width: none; min-height: 0; overflow: hidden; }
.map-page #map { position: absolute; inset: 0; }
.map-search {
  position: absolute; z-index: 1000; right: 0.8rem; bottom: 1.5rem; /* above the map attribution */
  width: min(420px, calc(100% - 1.6rem)); background: var(--card); border-radius: 10px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.25); padding: 0.6rem 0.7rem; display: flex; flex-direction: column; gap: 0.35rem;
}
.map-search-row { display: flex; gap: 0.5rem; }
.map-search input { flex: 1; min-width: 0; padding: 0.55rem 0.65rem; border: 1px solid var(--border); border-radius: 6px; font-size: 1rem; }
.map-search button { background: var(--accent); color: #fff; border: 0; border-radius: 6px; padding: 0 1rem; cursor: pointer; }
@media (max-width: 900px) {
  .shell:has(.map-page) { min-height: 0; }
  .shell:has(.map-page) .sidebar { position: static; }
  .content.map-page { flex: 1; }
}

/* Tagesbericht */
a.button { display: inline-block; background: var(--accent); color: #fff; text-decoration: none; padding: 0.55rem 1rem; border-radius: 6px; font-weight: 600; }
a.button:hover { background: var(--accent-dark); }
.daily-layout { display: grid; grid-template-columns: 3fr 2fr; gap: 1.25rem; align-items: start; }
.daily-map-pane { position: sticky; top: 1rem; min-width: 0; }
.daily-map { height: calc(100vh - 14rem); min-height: 360px; border-radius: 10px; border: 1px solid var(--border); }
.daily-tools { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 0.4rem; }
.daily-tools button { padding: 0.5rem 0.8rem; min-height: 40px; }
.daily-tools button.secondary { background: #eef1f5; color: var(--text, #1d2733); border: 1px solid var(--border); }
.daily-tools button.secondary:hover { background: #e3e8ee; }
.seg { display: inline-flex; border: 1px solid var(--accent); border-radius: 6px; overflow: hidden; }
.seg button { border-radius: 0; background: #fff; color: var(--accent); border: 0; }
.seg button.active { background: var(--accent); color: #fff; }
.legend-row { display: flex; flex-wrap: wrap; gap: 0.3rem 0.9rem; align-items: center; }
.legend-row .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: -0.5rem; }
.daily-form { max-width: none; }
/* One position per row: name left, amount + unit right. `.form fieldset`
   is a flex row elsewhere, hence the extra specificity. */
.daily-form fieldset.qty-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 0 1.5rem;
  padding: 0.3rem 0.9rem 0.6rem; min-width: 0; margin: 0;
}
.daily-form .qty-grid legend { font-weight: 700; padding: 0 0.3rem; }
.daily-form label.qty-row {
  flex-direction: row; align-items: center; justify-content: space-between; gap: 0.8rem;
  padding: 0.5rem 0; border-bottom: 1px solid var(--border); font-weight: 500;
}
.qty-name { flex: 1; min-width: 0; line-height: 1.3; }
.qty-input { display: flex; align-items: center; gap: 0.4rem; flex-shrink: 0; }
.daily-form .qty-input input { width: 5.5rem; text-align: right; padding: 0.5rem 0.6rem; font-size: 1rem; }
.qty-unit { width: 2.6rem; color: var(--muted); font-size: 0.9rem; }
.daily-form details > summary { cursor: pointer; padding: 0.4rem 0; color: var(--accent); }
.daily-form ul { margin: 0.3rem 0 0; padding-left: 1.2rem; }
@media (max-width: 900px) {
  .daily-layout { grid-template-columns: minmax(0, 1fr); }
  .daily-map-pane { position: static; }
  .daily-map { height: 55vh; min-height: 300px; }
}
.legend-row .line { display: inline-block; width: 16px; height: 4px; border-radius: 2px; margin-right: -0.5rem; }
.legend-row .dot.marked { width: 12px; height: 12px; box-shadow: 0 0 0 2px #000; }
.leaflet-marker-icon.mfg-label { background: none; border: 0; }
.leaflet-marker-icon.house-symbols { background: none; border: 0; }
.leaflet-marker-icon.pdp-point { background: none; border: 0; filter: drop-shadow(0 1px 1px rgba(0,0,0,.4)); }
/* Duct bundle/pipe icon (square + circle) centred on the house (over the HP+ cross). */
.house-symbols .duct-icon { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); line-height: 0; filter: drop-shadow(0 0 1.5px #fff) drop-shadow(0 1px 1px rgba(0,0,0,.35)); }
.popup-contact { margin-top: 0.4rem; }
.mfg-label span {
  position: absolute; transform: translate(-50%, -50%);
  color: #1a237e; font-weight: 800; font-size: 14px; white-space: nowrap;
  /* white halo instead of a box, so it stays readable over the map */
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff;
}
.hide-mfg-labels .mfg-label { display: none; }

/* Map tab: grips and restore buttons for the swipe-away panels. */
/* Thin grey pill. The selector beats `.map-search button` (the blue Search
   button) and the phone rule that makes every button 44px tall. */
.map-search button.map-grip {
  align-self: center; width: 40px; height: 4px; min-height: 0; padding: 0; margin: -0.1rem 0 0.15rem;
  border: 0; border-radius: 2px; background: #c5ccd6; cursor: pointer; position: relative;
}
.map-search button.map-grip::before { content: ""; position: absolute; inset: -10px -12px; } /* bigger tap target */
.map-search button.map-grip:hover, .map-search button.map-grip:active { background: #9aa5b3; }
.leaflet-control-layers { position: relative; padding-left: 1.6rem; }
.map-grip-side {
  position: absolute; left: 0; top: 0; bottom: 0; width: 1.4rem; padding: 0; border: 0;
  border-right: 1px solid var(--border); background: #f5f7fa; color: var(--muted); font-size: 1.1rem; cursor: pointer;
}
.map-grip-side:hover { background: #e3e8ee; }
.map-legend { position: relative; padding-right: 1.9rem !important; } /* !important: the inline padding */
.map-grip-side.map-grip-left { left: auto; right: 0; border-right: 0; border-left: 1px solid var(--border); }
.map-restore {
  background: #fff; color: var(--accent); border: 0; border-radius: 6px; padding: 0.45rem 0.8rem;
  box-shadow: 0 1px 6px rgba(0,0,0,0.3); font-weight: 600; cursor: pointer;
}
.map-restore:hover { background: #f5f7fa; }
.map-restore-search { position: absolute; z-index: 1000; right: 0.8rem; bottom: 1.5rem; }

/* OXG Import */
.import-card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 1rem 1.2rem; margin: 1rem 0; max-width: 720px; }
.import-card h2 { margin: 0 0 0.4rem; font-size: 1.1rem; }
.import-card .form { margin-bottom: 0; }

/* OXG task phases (Zinier Task Planung) */
.phase-row { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.8rem; }
.phase-chip { display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.78rem; font-weight: 600; white-space: nowrap; background: #eef1f5; color: #455a64; }
.phase-OPEN { background: #eef1f5; color: #455a64; }
.phase-SCHEDULED { background: #e3f2fd; color: #1565c0; }
.phase-IN_REVIEW { background: #fff3cd; color: #8a6512; }
.phase-RETURNED { background: #fde2e1; color: #b71c1c; }
.phase-AT_OXG { background: #f3e5f5; color: #6a1b9a; }
.phase-DONE { background: #e6f4ea; color: #1e7e34; }
.phase-CANCELLED { background: #f1f1f1; color: #9e9e9e; text-decoration: line-through; }
.oxg-task { margin: 0.3rem 0; font-size: 0.85rem; }
.oxg-task .note { color: #b71c1c; }
.step-line { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 0.25rem; margin-right: 0.4rem; }

/* Houses list: one pill per applicable step, green once it is built. */
.step-pill { padding: 0.1rem 0.45rem; border: 1px solid var(--border); border-radius: 4px; background: #fff; font-size: 0.75rem; white-space: nowrap; }
.step-filters { display: flex; flex-wrap: wrap; gap: 0.4rem; width: 100%; }
.step-toggle { padding: 0.3rem 0.7rem; border: 1px solid var(--border); border-radius: 4px; background: #fff; color: inherit; font-size: 0.85rem; cursor: pointer; }
/* On the map, beat `.map-search button` (the blue Search button). */
.map-step-filters { margin: 0.4rem 0; }
.map-search .step-toggle { min-height: 0; padding: 0.25rem 0.55rem; border: 1px solid var(--border); border-radius: 4px; background: #fff; color: inherit; font-size: 0.8rem; }
.map-search .step-toggle:hover { background: #f0f3f6; }
.step-toggle.step-has, .map-search .step-toggle.step-has { background: #2e7d32; border-color: #2e7d32; color: #fff; }
.step-toggle.step-built, .map-search .step-toggle.step-built { background: #f9a825; border-color: #f9a825; color: #000; }
.step-toggle.step-not, .map-search .step-toggle.step-not { background: #c62828; border-color: #c62828; color: #fff; }
.step-toggle:hover { background: #f0f3f6; }
.step-toggle.step-has:hover, .map-search .step-toggle.step-has:hover { background: #1b5e20; }
.step-toggle.step-built:hover, .map-search .step-toggle.step-built:hover { background: #f57f17; }
.step-toggle.step-not:hover, .map-search .step-toggle.step-not:hover { background: #8e1c1c; }
.step-pill.step-built { background: #f9a825; border-color: #f9a825; color: #000; }
.step-pill.step-done { background: #2e7d32; border-color: #2e7d32; color: #fff; }

.form label.checkbox-row { flex-direction: row; align-items: center; gap: 0.5rem; font-weight: normal; }
.form label.checkbox-row input { width: auto; min-height: 0; }

/* Collapsible groups in the map's layer box (Areas, DQS). */
.layer-group-head { display: flex; align-items: center; justify-content: space-between; gap: 0.4rem; }
.layer-group-head label { margin: 0; }
.leaflet-control-layers .layer-group-toggle { background: none; border: 0; padding: 0 0.3rem; min-height: 0; color: inherit; font-size: 13px; cursor: pointer; line-height: 1; }
.layer-group-item { display: block; padding-left: 1.2rem; }
.layer-subgroup { padding-left: 1.2rem; }
.layer-subgroup .layer-group-head label { font-weight: 600; }
.layer-group-info { padding-left: 1.2rem; font-size: 11px; color: var(--muted); margin: 2px 0 4px; }
.layer-group-info:empty { display: none; }

/* Duct contents along Netwin duct bundle routes (zoomed in). */
.leaflet-marker-icon.duct-label { background: none; border: 0; }
.duct-label span { position: absolute; left: 0; top: 0; white-space: nowrap; transform-origin: 0 0; font-size: 11px; font-weight: 600; color: #e65100; text-shadow: 0 0 2px #fff, 0 0 2px #fff, 0 0 3px #fff; pointer-events: none; }

/* "bundle - pipe" (Netwin) under a house's address, as coloured chips. */
.duct-line { display: inline-flex; align-items: center; gap: 0.25rem; font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.duct-chip { display: inline-block; padding: 0.05rem 0.45rem; border-radius: 999px; border: 1px solid rgba(0, 0, 0, 0.25); line-height: 1.4; }
/* House popup: "Duct:" / "Pipe:" before each colour chip. */
.duct-part-label { font-size: 0.8rem; color: var(--muted); font-weight: normal; }
.popup-steps { margin-top: 0.35rem; }
p.duct-para { margin: -0.4rem 0 0.5rem; }

/* Objects on the map: Kabelschacht box (as in DQS); duct pills can be hidden. */
.leaflet-marker-icon.schacht-point { background: none; border: 0; }
.schacht-point span, .schacht-swatch { display: inline-block; padding: 0 3px; font: italic 600 9px/12px sans-serif; color: #000; background: #fff; border: 1.5px solid #000; transform: skewX(-8deg); }
.schacht-point span { box-shadow: 0 1px 2px rgba(0,0,0,.35); }
.hide-duct-pills .duct-icon { display: none; }

/* Map: "my location" button and dot */
.map-locate { font-size: 1.25rem; line-height: 30px; text-align: center; color: #1a73e8 !important; }
.me-dot { background: #1a73e8; border: 3px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25), 0 1px 4px rgba(0, 0, 0, 0.4); }

/* Partnerportal: positions per PDP (scrolls sideways, PDP column stays put) */
.pos-matrix-wrap { overflow-x: auto; border-radius: 10px; margin-bottom: 1.5rem; -webkit-overflow-scrolling: touch; }
.pos-matrix { border-collapse: collapse; background: var(--card); font-size: 0.88rem; }
.pos-matrix th, .pos-matrix td { padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.pos-matrix thead th { background: #eef1f5; font-weight: 600; min-width: 7.5rem; max-width: 10rem; text-align: right; }
.pos-matrix tfoot th { background: #eef1f5; }
.pos-matrix .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos-matrix .pdp { position: sticky; left: 0; background: var(--card); text-align: left; white-space: nowrap; z-index: 1; }
.pos-matrix thead .pdp, .pos-matrix tfoot .pdp { background: #eef1f5; }
.pos-matrix tbody tr:hover td { background: #f5f7fa; }
a.card.stat { text-decoration: none; color: inherit; }
a.card.stat:hover { border-color: var(--accent); }

/* Partnerportal status tabs (pills above the view tabs) */
.status-tabs { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.5rem 0 0.75rem; }
.status-tab { padding: 0.4rem 0.85rem; border-radius: 999px; border: 1px solid var(--border); background: var(--card); text-decoration: none; color: inherit; font-weight: 600; font-size: 0.9rem; }
.status-tab .count { font-weight: 400; color: var(--muted); margin-left: 0.2rem; }
.status-tab.active { background: #263238; border-color: #263238; color: #fff; }
.status-tab.active .count { color: #cfd8dc; }
.status-tab.status-badge-approved.active { background: var(--success); border-color: var(--success); }
.status-tab.status-badge-rejected.active { background: var(--danger); border-color: var(--danger); }
.status-tab.status-badge-pending.active { background: #b7791f; border-color: #b7791f; }
.pos-matrix .group-row th { text-align: center; border-bottom: 0; padding-bottom: 0.1rem; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.pos-matrix .group-row .group { border-left: 2px solid #c9d1da; }
.pos-matrix td.plan, .pos-matrix th.plan { background: #f3f8f2; }
.pos-matrix thead th.plan { background: #e3efe1; }
.pos-matrix th.group.plan { background: #e3efe1; color: #2e5d2a; }
.pos-matrix tbody tr:hover td.plan { background: #e8f1e6; }
.pos-matrix tr > :nth-child(3) { border-left: 2px solid #c9d1da; }

/* Secondary (outline) link button, e.g. the Excel downloads */
a.button.button-secondary { background: var(--card); color: var(--accent); border: 1px solid var(--accent); padding: 0.45rem 0.9rem; }
a.button.button-secondary:hover { background: #eef4fb; }
a.button.button-small { padding: 0.2rem 0.65rem; font-size: 0.85rem; }


/* Map layer box: calendar under "Highlight day / week" (DQS). Marked = scans
   that day / week, yellow = picked, outline = today. */
.dqs-cal { margin: 0.2rem 0 0.4rem 1.6rem; font-size: 0.8rem; }
.dqs-cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.2rem; }
.dqs-cal-head button { min-width: 32px; min-height: 28px; padding: 0; font-size: 1.1rem; background: none; border: 1px solid var(--border); border-radius: 4px; cursor: pointer; color: inherit; }
.dqs-cal table { border-collapse: collapse; width: 100%; }
.dqs-cal th { font-weight: 600; color: var(--muted); padding: 0 0 0.15rem; text-align: center; }
.dqs-cal td { padding: 1px; text-align: center; }
.dqs-cal td button { width: 100%; min-width: 26px; min-height: 26px; padding: 0; background: none; border: 1px solid transparent; border-radius: 4px; font: inherit; color: #9aa4b1; cursor: pointer; }
.dqs-cal td button.has { color: #1b5e20; background: #e8f5e9; font-weight: 700; }
.dqs-cal td button.out { opacity: 0.45; }
.dqs-cal td button.today { border-color: #212121; }
.dqs-cal td button.on { background: #ffea00; color: #212121; border-color: #212121; }
.dqs-cal td button.kw { color: var(--muted); font-size: 0.7rem; }
.dqs-cal td button.kw.has { color: #1b5e20; }
.dqs-cal td button.kw.on { color: #212121; }
.dqs-cal-info { margin-top: 0.2rem; }
