/* P1B Floor Plans — one stylesheet for the pages and the editor. Mobile-first, big touch
   targets, high contrast for bright sunlight on site. Navy + white; orange = "check". */
:root {
  --navy: #14213d; --navy2: #1f3160; --ink: #1b1f27; --muted: #5b6475; --line: #d5dbe5;
  --bg: #f3f5f9; --card: #ffffff; --accent: #e07a00; --check: #d98200; --low: #c62828;
  --good: #1b7a3a; --blue: #1e63d6; --tap: 44px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); font-size: 16px; line-height: 1.4; }
a { color: var(--blue); }
h1 { font-size: 1.4rem; margin: 0 0 .6rem; }
h2 { font-size: 1.15rem; margin: 0 0 .6rem; }
h3 { font-size: 1.05rem; margin: .4rem 0; }
h4 { font-size: .95rem; margin: .8rem 0 .3rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, Consolas, monospace; }
.breakall { word-break: break-all; }
.good { color: var(--good); }
.warn { color: var(--check); }
[hidden] { display: none !important; }

/* top bar */
.topbar { background: var(--navy); color: #fff; display: flex; align-items: center; gap: 12px; padding: 8px 16px;
  padding-top: max(8px, env(safe-area-inset-top)); flex-wrap: wrap; }
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.1rem; display: flex; align-items: center; gap: 8px; }
.brand-mark { background: var(--accent); color: #fff; border-radius: 6px; padding: 2px 6px; font-size: .9rem; }
.topnav { display: flex; gap: 4px; align-items: center; margin-left: auto; flex-wrap: wrap; }
.topnav a, .linkbtn { color: #fff; text-decoration: none; padding: 8px 10px; border-radius: 6px; min-height: 40px;
  display: inline-flex; align-items: center; background: none; border: 0; font: inherit; cursor: pointer; }
.topnav a:hover, .linkbtn:hover { background: var(--navy2); }
form.inline { display: inline; margin: 0; }
.wrap { max-width: 980px; margin: 0 auto; padding: 16px; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 16px; }

/* cards / forms */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 14px; }
.card.narrow { max-width: 460px; margin-left: auto; margin-right: auto; }
label { display: block; margin: 0 0 12px; font-weight: 600; font-size: .9rem; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; font: inherit; font-weight: 400; padding: 10px 12px;
  border: 1px solid #aab3c2; border-radius: 8px; background: #fff; color: var(--ink); min-height: var(--tap); }
input[type=checkbox] { width: auto; min-height: 0; display: inline; margin: 0 8px 0 0; }
input[type=range] { padding: 0; }
textarea { min-height: 60px; }
.btn, button { font: inherit; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--tap); padding: 8px 16px;
  border-radius: 8px; border: 1px solid #aab3c2; background: #fff; color: var(--ink); text-decoration: none; cursor: pointer; font-weight: 600; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.big { min-height: 54px; font-size: 1.05rem; padding: 10px 20px; }
.btn.small { min-height: 36px; padding: 4px 10px; font-size: .85rem; }
.msg { padding: 10px 12px; border-radius: 8px; margin: 0 0 12px; border: 1px solid; }
.msg-info { background: #eef3ff; border-color: #b9ccf5; }
.msg-good { background: #eaf7ee; border-color: #9fd3b0; }
.msg-bad { background: #fdeaea; border-color: #eba5a5; color: #7a1414; }
.secret { font-size: 1.15rem; letter-spacing: .05em; background: #f4f4f4; padding: 8px; border-radius: 6px; user-select: all; }
.qr { background: #fff; padding: 8px; display: inline-block; border: 1px solid var(--line); border-radius: 8px; }
.tag { display: inline-block; background: #e8edf7; color: var(--navy); border-radius: 999px; padding: 1px 8px; font-size: .75rem; font-weight: 600; }
.conf { display: inline-block; border-radius: 999px; padding: 0 8px; font-size: .75rem; font-weight: 700; text-transform: uppercase; }
.conf-high { background: #e7f4ea; color: var(--good); }
.conf-check { background: #fff0d6; color: #8a5200; border: 1px dashed var(--check); }
.conf-low { background: #fde0e0; color: var(--low); border: 1px dotted var(--low); }

/* home */
.search { display: flex; gap: 8px; }
.search input { margin: 0; }
.actions { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-start; margin-bottom: 14px; }
.actions > * { flex: 1 1 220px; }
.newplan { padding: 0; margin: 0; border: 0; background: none; }
.newplan summary { list-style: none; width: 100%; }
.newplan summary::-webkit-details-marker { display: none; }
.newplan[open] form { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-top: 8px; }
ul.plans, ul.caps { list-style: none; margin: 0; padding: 0; }
.planrow { display: grid; grid-template-columns: 1fr; gap: 2px; padding: 12px 8px; border-bottom: 1px solid var(--line);
  text-decoration: none; color: var(--ink); min-height: var(--tap); }
.planrow:hover { background: #f6f8fc; }
.planrow .job { font-weight: 700; color: var(--navy); }
.planrow .meta { color: var(--muted); font-size: .85rem; }
ul.caps li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.capform { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.capform input { flex: 1 1 140px; margin: 0; }
@media (min-width: 700px) { .planrow { grid-template-columns: 160px 1fr auto; align-items: center; } }

/* tables */
.tablewrap { overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
table.grid, table.qt, table.wt { border-collapse: collapse; width: 100%; font-size: .9rem; }
.grid th, .grid td, .qt th, .qt td, .wt th, .wt td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.grid td:not(:first-child), .qt td:not(:first-child) { font-variant-numeric: tabular-nums; }
tr.tot td { font-weight: 700; border-top: 2px solid var(--ink); }
tr.on td { background: #eaf1ff; }
tr.badrow td { background: #fde0e0; }
td.acts { display: flex; gap: 6px; flex-wrap: wrap; }
td.acts form { margin: 0; }

/* print */
.plansvg svg { max-width: 100%; height: auto; }
.printbar { display: flex; gap: 8px; margin-bottom: 12px; }
@media print {
  .topbar, .foot, .noprint { display: none !important; }
  body, .wrap { background: #fff; padding: 0; max-width: none; }
  table { page-break-inside: auto; } tr { page-break-inside: avoid; }
  .tablewrap { overflow: visible; }
}

/* ============================== editor ============================== */
body.editor { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; background: #fff; }
body.editor #app { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.etop { display: flex; align-items: center; gap: 6px; background: var(--navy); color: #fff; padding: 6px 8px;
  padding-top: max(6px, env(safe-area-inset-top)); }
.ebtn { min-width: var(--tap); min-height: var(--tap); border: 0; border-radius: 8px; background: var(--navy2); color: #fff;
  font-size: 1.25rem; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; cursor: pointer; padding: 0 10px; }
.ebtn:disabled { opacity: .35; }
.ebtn.save { background: var(--accent); font-size: 1rem; font-weight: 700; padding: 0 16px; }
.etitle { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.elabel { opacity: .8; margin-left: 4px; }
.badge { display: inline-block; font-size: .75rem; background: rgba(255,255,255,.18); border-radius: 999px; padding: 1px 8px; margin-left: 4px; }
.badge.warn { background: var(--accent); }
.toolbar { display: flex; gap: 6px; overflow-x: auto; padding: 6px; background: #eef1f6; border-bottom: 1px solid var(--line);
  -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
.tbtn { flex: 0 0 auto; min-height: 40px; padding: 0 12px; border: 1px solid #aab3c2; border-radius: 8px; background: #fff; color: var(--ink);
  font-weight: 600; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; font-size: .92rem; }
.tbtn.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.tbtn:disabled { opacity: .4; }
.ebody { flex: 1; display: flex; min-height: 0; position: relative; }
#canvasWrap { flex: 1; position: relative; min-width: 0; background: #f7f8fa; overflow: hidden; }
#cv { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; cursor: crosshair; }
#cv .grid { stroke: #e3e7ee; stroke-width: 1; pointer-events: none; }
#cv .grid.g5 { stroke: #cfd6e2; }
#cv .rfill { stroke: none; }
#cv .rfill.rsel { fill: #eaf1ff; }
#cv .hit { stroke: transparent; fill: transparent; pointer-events: all; cursor: pointer; }
#cv .corner { fill: #fff; stroke: var(--blue); stroke-width: 2.5; pointer-events: none; }
#cv .corner.con { fill: var(--blue); }
#cv .dim { font-size: 11px; text-anchor: middle; dominant-baseline: middle; pointer-events: none; paint-order: stroke;
  stroke: #fff; stroke-width: 3px; font-variant-numeric: tabular-nums; }
#cv .dim.dimbad { fill: var(--low) !important; font-weight: 700; }
#cv .rname { font-size: 13px; font-weight: 700; text-anchor: middle; pointer-events: none; paint-order: stroke; stroke: #fff; stroke-width: 3px; }
#cv .rarea { font-size: 11px; text-anchor: middle; pointer-events: none; paint-order: stroke; stroke: #fff; stroke-width: 3px; }
#cv .rconf { font-size: 10px; font-weight: 700; text-anchor: middle; pointer-events: none; paint-order: stroke; stroke: #fff; stroke-width: 3px; }
#cv .preview { fill: rgba(30,99,214,.08); stroke: var(--blue); stroke-width: 2; stroke-dasharray: 6 4; pointer-events: none; }
#cv .trace { fill: none; stroke: var(--accent); stroke-width: 2.5; pointer-events: none; }
#cv .tpt { fill: var(--accent); stroke: #fff; stroke-width: 2; pointer-events: none; }
#cv .tpt.tfirst { fill: #fff; stroke: var(--accent); stroke-width: 3; }
.ebanner { position: absolute; top: 8px; left: 8px; right: 8px; background: #fff7e6; border: 1px solid var(--check); border-radius: 8px;
  padding: 8px 10px; z-index: 4; font-size: .9rem; }
.ebanner button, .modebar button, .dimbox button { min-height: 38px; padding: 0 12px; margin-left: 6px; border-radius: 8px;
  border: 1px solid #aab3c2; background: #fff; font-weight: 600; cursor: pointer; }
.ebanner button.primary, .modebar button.primary, .dimbox button.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.dimbox button.danger { color: var(--low); border-color: var(--low); }
.modebar { position: absolute; top: 8px; left: 8px; right: 8px; background: var(--navy); color: #fff; border-radius: 8px; padding: 8px 10px;
  z-index: 4; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: .9rem; }
.modebar span { flex: 1 1 200px; }
/* on the navy bar every control is a real white button; Finish is the orange call to action */
.modebar button { margin-left: 0; color: var(--ink); background: #fff; border: 1px solid #fff; min-width: 64px; }
.modebar button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.modebar button:hover { filter: brightness(.95); }
#cv .smark circle { fill: #7b2cbf; stroke: #fff; stroke-width: 1.5; }
#cv .smark text { font-size: 11px; font-weight: 700; fill: #5a189a; paint-order: stroke; stroke: #fff; stroke-width: 3px; }
.dimbox { position: absolute; left: 8px; right: 8px; bottom: 8px; background: #fff; border: 2px solid var(--navy); border-radius: 10px;
  padding: 8px 10px; z-index: 3; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; box-shadow: 0 2px 10px rgba(0,0,0,.15); }
.dimbox input { width: 110px; display: inline-block; margin: 0; font-size: 1.1rem; font-weight: 700; }
.dimbox .muted { font-size: .85rem; }
.zoombtns { position: absolute; right: 10px; top: 60px; display: flex; flex-direction: column; gap: 6px; z-index: 2; }
.zoombtns button { width: var(--tap); height: var(--tap); border-radius: 50%; border: 1px solid #aab3c2; background: #fff; font-size: 1.4rem; cursor: pointer; }

#panel { width: 390px; border-left: 1px solid var(--line); background: #fff; display: flex; flex-direction: column; min-height: 0; }
.ptabs { display: flex; overflow-x: auto; border-bottom: 1px solid var(--line); background: #f7f8fa; flex: 0 0 auto; }
.ptabs button { flex: 0 0 auto; min-height: var(--tap); padding: 0 12px; border: 0; background: none; font-weight: 600; color: var(--muted);
  border-bottom: 3px solid transparent; cursor: pointer; }
.ptabs button.on { color: var(--navy); border-bottom-color: var(--accent); }
.ptabs .pclose { margin-left: auto; font-size: 1.4rem; }
.count { background: var(--check); color: #fff; border-radius: 999px; padding: 0 6px; font-size: .75rem; }
.count:empty { display: none; }
.pbody { flex: 1; overflow-y: auto; padding: 12px; -webkit-overflow-scrolling: touch; }
.prow { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.prow button, .pbody button[data-p] { min-height: 40px; padding: 0 12px; border-radius: 8px; border: 1px solid #aab3c2; background: #fff;
  font-weight: 600; cursor: pointer; }
.prow button.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.pbody button.danger { color: var(--low); border-color: var(--low); }
.pbody button.small { min-height: 32px; font-size: .8rem; }
.fgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.fgrid label { font-size: .82rem; margin-bottom: 8px; }
.plabel { font-size: .82rem; }
.subcard { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin: 10px 0; background: #fbfcfe; }
.subcard summary { font-weight: 700; cursor: pointer; min-height: 32px; }
fieldset.opf { border: 1px solid var(--line); border-radius: 8px; margin: 8px 0; padding: 8px; }
fieldset.opf.on { border-color: var(--blue); background: #f2f6ff; }
fieldset.opf legend { font-weight: 700; font-size: .85rem; }
ul.rlist, ul.dlist, ul.clist, ul.vlist, ul.dq, ul.errs { list-style: none; margin: 0; padding: 0; }
ul.rlist li button { width: 100%; display: grid; grid-template-columns: 1fr auto auto; grid-template-rows: auto auto; gap: 0 8px; text-align: left;
  padding: 8px; border: 0; border-bottom: 1px solid var(--line); background: none; min-height: 52px; cursor: pointer; }
ul.rlist li.on button { background: #eaf1ff; }
ul.rlist .rn { font-weight: 700; } ul.rlist .muted { grid-column: 1; font-size: .8rem; }
ul.rlist .ra { grid-row: 1; grid-column: 2; font-variant-numeric: tabular-nums; }
ul.rlist .conf { grid-row: 1 / span 2; grid-column: 3; align-self: center; }
ul.dlist li, ul.vlist li { display: flex; gap: 8px; align-items: flex-start; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); }
ul.vlist li a, ul.vlist li button { min-height: 38px; display: inline-flex; align-items: center; }
.calc { font-size: .85rem; font-variant-numeric: tabular-nums; }
ul.clist li button { width: 100%; text-align: left; border: 0; border-left: 4px dashed var(--check); background: #fff8eb; padding: 10px; margin: 4px 0;
  border-radius: 4px; cursor: pointer; font: inherit; min-height: var(--tap); }
ul.clist li.bad button { border-left: 4px solid var(--low); background: #fdecec; }
ul.errs li { padding: 6px 8px; margin: 4px 0; background: #fdecec; border-left: 4px solid var(--low); border-radius: 4px; font-size: .9rem; }
ul.dq li { padding: 4px 0; font-size: .88rem; border-bottom: 1px solid var(--line); }
.chk { font-weight: 400; display: flex; align-items: center; }
.calrow { display: grid; grid-template-columns: 1.2fr 1.2fr 1fr; gap: 6px; margin-bottom: 6px; }
.calrow select, .calrow input { margin: 0; }

dialog { border: 0; border-radius: 12px; padding: 0; width: min(440px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); box-shadow: 0 8px 40px rgba(0,0,0,.35); }
dialog.wide { width: min(640px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(10,18,40,.45); }
dialog form { padding: 16px; margin: 0; display: flex; flex-direction: column; max-height: calc(100dvh - 24px); }
.dlgbody { overflow-y: auto; flex: 1; }
.dlgbtns { display: flex; flex-direction: row-reverse; gap: 8px; margin-top: 12px; }
.dlgbtns button { min-height: var(--tap); padding: 0 18px; border-radius: 8px; border: 1px solid #aab3c2; background: #fff; font-weight: 700; cursor: pointer; }
.dlgbtns button.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 10px 16px;
  border-radius: 8px; z-index: 50; max-width: calc(100vw - 32px); box-shadow: 0 4px 16px rgba(0,0,0,.3); }
.toast.bad { background: var(--low); }
/* editor: the toast lives at the top of the canvas (editor.js sets `top` below any banner/trace bar),
   never over the phone's bottom sheet or the dimension box; it never takes a tap either */
body.editor .toast { position: absolute; bottom: auto; top: 8px; z-index: 7; pointer-events: none; }
.phone-only { display: none !important; }

@media (max-width: 899px) {
  .phone-only { display: inline-flex !important; }
  #panel { position: absolute; left: 0; right: 0; bottom: 0; width: auto; height: 58%; border-left: 0; border-top: 3px solid var(--navy);
    transform: translateY(105%); transition: transform .2s ease; z-index: 6; box-shadow: 0 -6px 20px rgba(0,0,0,.2);
    border-radius: 14px 14px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  #panel.open { transform: none; }
  .elabel { display: none; }
  .fgrid { grid-template-columns: 1fr 1fr; }
}
