:root {
  --navy: #0F2A4A; --blue: #2B7DB3; --bg: #EEF3F8; --soft: #E1EEF8; --hl: #0F2A4A; --card: #FFFFFF; --text: #1F2A37;
  --muted: #5B6778; --line: #D5DEE8; --danger: #B42318; --ok: #1E7F4F;
  --radius: 14px; --tap: 48px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-family: 'Open Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; font-size: 16px; line-height: 1.45;
  -webkit-tap-highlight-color: transparent; padding-bottom: calc(76px + var(--safe-b)); }
h1, h2, h3, .btn, .tab, .area-btn .name, .shape-btn .name, .total { font-family: 'Montserrat', system-ui, sans-serif; }
h1 { font-size: 1.45rem; margin: 0; } h2 { font-size: 1.15rem; margin: 0 0 .5rem; } h3 { font-size: 1rem; margin: 0; }
p { margin: .25rem 0 .75rem; }
.muted { color: var(--muted); font-size: .9rem; }
#app { max-width: 560px; margin: 0 auto; padding: 0 16px 24px; }

/* Header */
.topbar { position: sticky; top: 0; z-index: 5; margin: 0 -16px 16px; padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 10px;
  background: var(--navy); color: #fff; display: flex; align-items: center; gap: 8px; min-height: 60px; }
.topbar h1 { font-size: 1.1rem; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .sub { display: block; font-family: 'Open Sans', sans-serif; font-size: .78rem; font-weight: 400; opacity: .8; }
.icon-btn { min-width: var(--tap); min-height: var(--tap); border: 0; border-radius: 12px; background: rgba(255,255,255,.12); color: #fff;
  font-size: 1.35rem; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.brand { margin: 0 -16px 16px; padding: calc(18px + env(safe-area-inset-top, 0px)) 16px 18px; background: #fff; text-align: center; border-bottom: 4px solid var(--navy); }
.brand img { max-width: 240px; width: 70%; height: auto; display: block; margin: 0 auto 6px; }
.brand .tagline { font-family: 'Montserrat', sans-serif; font-weight: 700; color: var(--blue); letter-spacing: .04em; font-size: .9rem; }

/* Cards, buttons */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: 0 1px 3px rgba(15,42,74,.08); margin-bottom: 12px; }
.btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 52px; padding: 12px 16px; border: 0; border-radius: 12px;
  font-weight: 700; font-size: 1rem; cursor: pointer; text-decoration: none; }
.btn-primary { background: var(--navy); color: #fff; }
.btn-secondary { background: var(--blue); color: #fff; }
.btn-ghost { background: #fff; color: var(--navy); border: 2px solid var(--line); }
.btn-danger { background: #fff; color: var(--danger); border: 2px solid #f1c3bf; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn + .btn, .stack > * + * { margin-top: 10px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-2 .btn + .btn { margin-top: 0; }

label.field { display: block; font-weight: 600; margin-bottom: 14px; }
label.field span.hint { display: block; font-weight: 400; color: var(--muted); font-size: .85rem; }
input[type=text], select { width: 100%; min-height: var(--tap); margin-top: 6px; padding: 10px 12px; font: inherit; color: var(--text);
  border: 2px solid var(--line); border-radius: 10px; background: #fff; }
input[type=text]:focus, select:focus { outline: none; border-color: var(--blue); }
select.required-missing { border-color: var(--danger); }

/* Project list */
.proj { display: block; width: 100%; text-align: left; border: 0; font: inherit; color: inherit; cursor: pointer; min-height: var(--tap); }
.proj .meta { color: var(--muted); font-size: .85rem; }
.proj .tot { font-family: 'Montserrat', sans-serif; font-weight: 700; color: var(--navy); }

/* Area & shape pickers */
.area-btn { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 92px; padding: 16px; margin-bottom: 12px; border: 2px solid transparent;
  border-radius: var(--radius); background: #fff; box-shadow: 0 1px 3px rgba(15,42,74,.08); cursor: pointer; text-align: left; font: inherit; color: inherit; }
.area-btn:active, .shape-btn:active { border-color: var(--blue); }
.area-btn .ico { width: 54px; height: 54px; border-radius: 12px; background: var(--bg); display: flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.area-btn .ico svg { width: 34px; height: 34px; }
.area-btn .name { font-size: 1.25rem; font-weight: 800; color: var(--navy); display: block; }
.area-btn .sum { color: var(--muted); font-size: .9rem; }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; margin-left: 6px; vertical-align: middle; font-family: 'Open Sans', sans-serif; }
.badge-done { background: #DDF3E7; color: var(--ok); }
.badge-wip { background: var(--soft); color: var(--blue); }
.shape-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.shape-btn { min-height: 120px; border: 2px solid transparent; border-radius: var(--radius); background: #fff; box-shadow: 0 1px 3px rgba(15,42,74,.08);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; cursor: pointer; font: inherit; color: var(--navy); }
.shape-btn .shape-icon { width: 56px; height: 56px; }
.shape-btn .name { font-weight: 700; }

/* Measure screen */
.diagram { width: 100%; height: auto; display: block; background: #fff; border-radius: var(--radius); }
.meas-row { display: flex; align-items: center; justify-content: space-between; width: 100%; min-height: 60px; padding: 12px 14px; margin-bottom: 10px;
  border: 2px solid var(--line); border-radius: 12px; background: #fff; font: inherit; color: inherit; cursor: pointer; text-align: left; }
.meas-row .lbl { font-weight: 700; }
.meas-row .val { font-family: 'Montserrat', sans-serif; font-weight: 700; color: var(--navy); }
.meas-row .val.empty { color: var(--blue); font-family: 'Open Sans', sans-serif; font-weight: 600; }
.meas-row.err { border-color: var(--danger); }
.preview { display: flex; justify-content: space-between; align-items: center; background: var(--navy); color: #fff; border-radius: 12px; padding: 14px 16px; margin: 6px 0 14px; }
.preview .total { font-size: 1.4rem; font-weight: 800; }
.error-text { color: var(--danger); font-size: .9rem; font-weight: 600; margin: 4px 0 10px; }
.helper-link { margin: 0 0 12px; }

/* Notepad */
.group-h { display: flex; justify-content: space-between; align-items: baseline; margin: 18px 0 8px; }
.group-h h2 { margin: 0; color: var(--navy); }
.shape-item { display: flex; gap: 10px; align-items: flex-start; }
.shape-item .info { flex: 1; min-width: 0; }
.shape-item .m { color: var(--muted); font-size: .88rem; white-space: pre-line; }
.shape-item .sq { font-family: 'Montserrat', sans-serif; font-weight: 800; color: var(--navy); white-space: nowrap; }
.shape-item .actions { display: flex; gap: 8px; margin-top: 10px; }
.small-btn { min-height: 44px; min-width: 44px; padding: 8px 14px; border-radius: 10px; border: 2px solid var(--line); background: #fff; font: 600 .9rem 'Open Sans', sans-serif; color: var(--navy); cursor: pointer; }
.small-btn.danger { color: var(--danger); border-color: #f1c3bf; }
.subtotal { display: flex; justify-content: space-between; padding: 10px 14px; background: #fff; border-left: 4px solid var(--blue); border-radius: 8px; font-weight: 700; }
.grand { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; padding: 16px; background: var(--navy); color: #fff; border-radius: var(--radius); }
.grand .total { font-size: 1.35rem; font-weight: 800; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }

/* Bottom tabs */
[hidden] { display: none !important; }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: grid; grid-template-columns: repeat(4, 1fr); background: #fff;
  border-top: 1px solid var(--line); padding-bottom: var(--safe-b); box-shadow: 0 -2px 10px rgba(15,42,74,.06); }
.tab { min-height: 60px; border: 0; background: none; font-size: .75rem; font-weight: 700; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer; }
.tab .ti { font-size: 1.3rem; line-height: 1; }
.tab[aria-current="page"] { color: var(--navy); box-shadow: inset 0 3px 0 var(--blue); }

/* Keypad sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(15,42,74,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; background: #fff; border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + var(--safe-b)); }
.sheet h3 { color: var(--navy); margin-bottom: 4px; }
.kp-display { font-family: 'Montserrat', sans-serif; font-size: 1.9rem; font-weight: 800; color: var(--navy); background: var(--bg); border-radius: 12px; padding: 10px 14px; min-height: 60px; margin: 8px 0 4px; word-break: break-all; }
.kp-conv { min-height: 22px; color: var(--muted); font-size: .9rem; }
.keypad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.key { min-height: 56px; border: 0; border-radius: 12px; background: var(--bg); font: 700 1.35rem 'Montserrat', sans-serif; color: var(--text); cursor: pointer; }
.key:active { background: #d9e5f1; }
.key.alt { background: var(--soft); color: var(--blue); }
.key.done { background: var(--navy); color: #fff; font-size: 1.05rem; }
.key.wide { grid-column: span 2; }

/* Confirm dialog */
.dialog { background: #fff; border-radius: 16px; padding: 20px; margin: 16px; max-width: 420px; width: 100%; align-self: center; }

.toast { position: fixed; left: 50%; bottom: calc(84px + var(--safe-b)); transform: translateX(-50%); background: var(--text); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 60; font-weight: 600; max-width: 90vw; }
.pyth-result { text-align: center; background: var(--navy); color: #fff; border-radius: var(--radius); padding: 16px; margin: 6px 0 14px; }
.pyth-result .total { font-size: 1.8rem; font-weight: 800; }
.formula { text-align: center; font-family: 'Montserrat', sans-serif; font-weight: 700; color: var(--blue); margin: 4px 0 12px; }

/* x2 identical-shapes toggle */
.pair-toggle { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 60px; padding: 12px 14px; margin: 4px 0 10px;
  border: 2px dashed var(--blue); border-radius: 12px; background: #fff; font: inherit; color: var(--text); text-align: left; cursor: pointer; }
.pair-toggle[aria-pressed="true"] { border-style: solid; background: var(--soft); }
.pair-toggle .pt-box { flex: 0 0 28px; height: 28px; border-radius: 7px; border: 2px solid var(--blue); display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: #fff; background: #fff; }
.pair-toggle[aria-pressed="true"] .pt-box { background: var(--blue); }
.pair-toggle .pt-sub { display: block; font-size: .82rem; }
.pt-calc { font-size: .85rem; font-weight: 600; opacity: .85; }

/* Long-press on project cards */
.proj { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; transition: transform .15s, box-shadow .15s; touch-action: manipulation; }
.proj.pressing { transform: scale(.98); box-shadow: 0 0 0 3px var(--blue); }

/* Interactive measuring diagram */
.diagram-card { padding: 6px 4px 8px; }
.mdiagram { background: transparent; touch-action: manipulation; }
.diagram-hint { text-align: center; margin: 2px 0 0; font-size: .85rem; }
/* odd number of shapes: last button spans the full row */
.shape-grid > .shape-btn:last-child:nth-child(odd) { grid-column: 1 / -1; min-height: 96px; flex-direction: row; gap: 14px; }

/* Area notes */
.notes-card { padding: 4px 12px; }
.notes-toggle { display: flex; justify-content: space-between; align-items: center; width: 100%; min-height: 52px; border: 0; background: none;
  font: 700 1rem 'Montserrat', sans-serif; color: var(--navy); cursor: pointer; padding: 0 2px; text-align: left; }
.note-list { list-style: none; margin: 0 0 4px; padding: 0; }
.note-list li { display: flex; align-items: flex-start; gap: 8px; border-top: 1px solid var(--line); }
.note-list .bullet { color: var(--blue); font-size: 1.4rem; line-height: 1; width: 14px; text-align: center; padding-top: 12px; }
.note-list textarea { flex: 1; min-height: 48px; margin: 0; border: 0; border-radius: 0; padding: 12px 4px; background: transparent; font: inherit; color: var(--text); resize: none; overflow: hidden; line-height: 1.4; display: block; }
.note-list textarea:focus { outline: none; background: #F4F8FC; border-color: transparent; }
.note-hint { font-size: .8rem; margin: 6px 0 10px; }
.notes-view ul { margin: 6px 0 0; padding-left: 20px; } .notes-view li { margin: 2px 0; }

.notes-head { font: 700 1rem 'Montserrat', sans-serif; color: var(--navy); padding: 12px 2px 8px; }

/* Folders */
.folder-card { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 64px; border: 0; font: inherit; color: inherit; text-align: left; cursor: pointer; }
.folder-card .fi { font-size: 1.6rem; }
.folder-card .fn { flex: 1; font-family: 'Montserrat', sans-serif; font-weight: 700; color: var(--navy); }
.folder-card .fc { color: var(--muted); font-size: .85rem; }
.folder-pick { justify-content: flex-start; }

/* Area photos */
.photos-card { padding: 4px 12px 12px; }
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 10px; }
.photo-grid:empty { display: none; }
.ph-thumb { aspect-ratio: 1; min-height: 44px; padding: 0; border: 0; border-radius: 8px; overflow: hidden; background: var(--bg); cursor: pointer; }
.ph-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
[data-ph-status]:not(:empty) { font-weight: 600; color: var(--navy); margin: 0 0 10px; }
.photo-sheet { max-height: 92vh; overflow: auto; }
.ph-full { width: 100%; height: auto; max-height: 64vh; object-fit: contain; display: block; border-radius: 10px; background: #000; }
.np-photos { display: flex; justify-content: space-between; align-items: center; width: 100%; min-height: 52px; border: 0; font: 700 1rem 'Montserrat', sans-serif; color: var(--navy); cursor: pointer; text-align: left; }
.legacy-card { border-left: 4px solid var(--hl); }
.ph-thumb { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; touch-action: manipulation; transition: transform .15s, box-shadow .15s; }
.ph-thumb img { pointer-events: none; -webkit-user-drag: none; }
.ph-thumb.pressing { transform: scale(.95); box-shadow: 0 0 0 3px var(--danger); }
.wall-sub { display: flex; justify-content: space-between; margin: -4px 0 8px 18px; padding: 6px 12px; font-size: .9rem; color: var(--muted); border-left: 2px solid var(--line); }

/* JobNimbus (Freedom only) */
.jn-card { margin-top: 14px; }
.jn-card input[type=text] { margin-top: 0; }
.jn-job { padding: 10px 12px; background: var(--bg); border-radius: 10px; margin-bottom: 8px; }
.jn-sent { margin-bottom: 4px; }
.jn-status { margin-bottom: 8px; font-weight: 600; }
.jn-sheet { max-height: 88vh; display: flex; flex-direction: column; }
.jn-sheet input[type=text] { margin: 8px 0; }
.jn-results { overflow: auto; flex: 1; min-height: 120px; margin-bottom: 10px; }
.jn-result { display: block; width: 100%; min-height: 56px; text-align: left; padding: 10px 12px; margin-bottom: 8px; border: 2px solid var(--line); border-radius: 10px; background: #fff; font: inherit; color: var(--text); cursor: pointer; }
.jn-result .muted { display: block; font-size: .85rem; }
.jn-status-tag { display: inline-block; margin-top: 4px; font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--soft); color: var(--blue); }
