/* Sello: mist ground, deep navy, one turquoise tint, a seal as the only ornament.
   Layout follows each phone: iOS bars and large titles, Android app bar and FAB. */
@font-face { font-family: Karla; src: url(fonts/Karla-Regular.ttf) format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: Karla; src: url(fonts/Karla-Bold.ttf) format("truetype"); font-weight: 700; font-display: swap; }

:root {
  --ground: #f2f4fa; --surface: #ffffff; --ink: #14255c; --text: #1c2340; --muted: #5d6585; --hairline: #e0e5f0;
  --navy: #14255c; --on-navy: #ffffff; --on-navy-soft: #c3cde8; --tint: #006683; --edge: #7f88a3; --turquoise: #009dca; --tint-soft: #e0f2f8;
  --warn: #8a5a00; --warn-soft: #fff1d2; --bad: #b3261e; --bad-soft: #fde7e4; --good: #0b7349; --good-soft: #dcf3e6;
  --bar: rgb(242 244 250 / 0.82);
  --top: max(env(safe-area-inset-top, 0px), var(--safe-area-inset-top, 0px));
  --bottom: max(env(safe-area-inset-bottom, 0px), var(--safe-area-inset-bottom, 0px));
  --radius: 10px; --bar-h: max(48px, 2.8rem); --tab-h: max(56px, 3.6rem);
  --ui: system-ui, -apple-system, "SF Pro Text", Roboto, sans-serif;
  --brand: Karla, var(--ui);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ground: #0b1022; --surface: #161d36; --ink: #eef1fb; --text: #e6eaf6; --muted: #a0a9c8; --hairline: #2a3353;
    --navy: #1b2f73; --on-navy-soft: #c8d2ee; --tint: #5fcdee; --edge: #6f7aa0; --tint-soft: #123449;
    --warn: #f1c465; --warn-soft: #3b2f12; --bad: #ff9c91; --bad-soft: #431c18; --good: #74dfaa; --good-soft: #123b2a;
    --bar: rgb(11 16 34 / 0.82);
    color-scheme: dark;
  }
}
html[data-os="ios"] { font: -apple-system-body; }
html[data-os="android"] { font-size: 16px; --radius: 12px; --bar-h: max(64px, 3.6rem); --tab-h: max(80px, 4.8rem); }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
::selection { background: var(--tint-soft); }
body { margin: 0; background: var(--ground); color: var(--text); font-family: var(--ui); line-height: 1.38; font-variant-numeric: tabular-nums; -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%; caret-color: var(--tint); }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
.sprite { position: absolute; width: 0; height: 0; }
.icon { width: 1.4em; height: 1.4em; min-width: 24px; min-height: 24px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--tint); outline-offset: 2px; }

a.row:active, .primary:active, .secondary:active, .frame:active, .chip:active, .tabbar a:active { filter: brightness(0.92); }

/* Bars */
.bar { position: fixed; inset: 0 0 auto 0; z-index: 5; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; height: calc(var(--top) + var(--bar-h)); padding: var(--top) 8px 0; background: var(--bar); -webkit-backdrop-filter: saturate(180%) blur(18px); backdrop-filter: saturate(180%) blur(18px); color: var(--ink); }
html[data-os="android"] .bar { background: var(--ground); -webkit-backdrop-filter: none; backdrop-filter: none; }
.bar.on-field { background: var(--navy); color: var(--on-navy); -webkit-backdrop-filter: none; backdrop-filter: none; }
.bar-side { display: inline-flex; align-items: center; min-height: 44px; min-width: 44px; justify-self: start; border: 0; background: none; color: var(--tint); padding: 0 4px; }
.bar.on-field .bar-side { color: var(--on-navy); }
.bar-side.end { justify-self: end; }
.bar-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 52vw; }
.bar.on-field .bar-title { visibility: hidden; }
#back-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 30vw; }
html[data-os="ios"] .bar.has-large:not(.scrolled) .bar-title { opacity: 0; }
html[data-os="ios"] .bar-title { transition: opacity 160ms ease-out; }
html[data-os="android"] .bar { grid-template-columns: auto 1fr auto; gap: 4px; }
html[data-os="android"] .bar-title { font: 400 1.375rem var(--brand); justify-self: start; }
html[data-os="android"] #back-label { display: none; }
html[data-os="android"] .bar-side { min-width: 48px; min-height: 48px; justify-content: center; color: inherit; }

main { padding: calc(var(--top) + var(--bar-h)) 0 calc(var(--bottom) + var(--tab-h) + 32px); }
.view { max-width: 40rem; margin: 0 auto; padding: 0 16px; }
.large { font: 700 2.125rem/1.12 var(--brand); color: var(--ink); margin: 4px 0 18px; letter-spacing: -0.01em; }
html[data-os="android"] .large { display: none; }
html[data-os="android"] .view:not(#view-dossier) { padding-top: 8px; }

.group-title { font: 700 1.25rem var(--brand); color: var(--ink); margin: 30px 2px 10px; }
.foot { font-size: 0.8125rem; color: var(--muted); margin: 8px 2px 0; }
.group { background: var(--surface); border-radius: var(--radius); }
.group:not(.list):not(.chain):not(.fields) { padding: 14px 16px; }

/* Lists */
.row { display: flex; align-items: center; gap: 10px; min-height: 64px; padding: 10px 10px 10px 16px; color: var(--text); }
.row + .row { background: linear-gradient(var(--hairline), var(--hairline)) no-repeat 16px 0 / calc(100% - 16px) 1px; }
.row > .icon { color: var(--muted); width: 18px; height: 18px; }
.row-text { display: grid; gap: 2px; min-width: 0; flex: 1; text-align: left; }
.row-title { font-weight: 600; overflow-wrap: anywhere; }
.row-sub { font-size: 0.875rem; color: var(--muted); }
.row-sub.warn { color: var(--warn); }
.row-end { color: var(--muted); }
.row-action { color: var(--tint); font-size: 0.9375rem; font-weight: 600; }

/* Empty */
.empty { display: grid; gap: 16px; padding: 18px 0; }
.empty p { color: var(--muted); margin: 0; }
.blank-frames { display: grid; grid-template-columns: repeat(4, 48px); gap: 12px; }
.blank-frames i { height: 48px; border-radius: 4px; box-shadow: inset 0 0 0 1.5px var(--edge); }

/* Controls */
.primary, .secondary { display: block; width: 100%; min-height: 56px; border: 0; border-radius: var(--radius); font-weight: 600; font-size: 1.0625rem; }
.primary { background: var(--navy); color: var(--on-navy); }
.secondary { background: var(--tint-soft); color: var(--tint); }
#calc-save, .next { position: sticky; bottom: calc(var(--bottom) + 12px); margin-top: 18px; box-shadow: 0 4px 14px rgb(9 14 34 / 0.35); }
.primary:disabled { opacity: 0.45; }
#view-calc.in-dossier .hint { display: none; }
.text-btn { border: 0; background: none; color: var(--tint); min-height: 44px; padding: 0 4px; }
.text-btn.strong { font-weight: 700; }
html[data-os="android"] .primary, html[data-os="android"] .secondary { border-radius: 999px; }

.fab { display: none; position: fixed; right: 16px; bottom: calc(var(--bottom) + var(--tab-h) + 16px); z-index: 4; width: 56px; height: 56px; border: 0; border-radius: 16px; background: var(--navy); color: var(--on-navy); place-items: center; box-shadow: 0 3px 8px rgb(20 37 92 / 0.32); }
html[data-os="android"] .fab:not([hidden]) { display: grid; }
html[data-os="ios"] .fab:not([hidden]) { display: grid; top: calc(var(--top) + 2px); right: 8px; bottom: auto; width: 44px; height: 44px; background: none; color: var(--tint); box-shadow: none; z-index: 6; }

/* Segmented */
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px; background: var(--hairline); padding: 2px; border-radius: 10px; margin-bottom: 14px; }
.segmented button { min-height: 44px; border: 0; border-radius: 8px; background: none; font-weight: 600; font-size: 0.875rem; color: var(--muted); }
.segmented button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgb(20 37 92 / 0.18); }

/* Forms */
.forms form { background: var(--surface); border-radius: var(--radius); padding: 16px; display: grid; gap: 14px; }
#pricing { display: grid; gap: 14px; }
.form-title { font-size: 1.0625rem; font-weight: 600; color: var(--ink); margin: 0; text-wrap: balance; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: end; }
label { display: flex; flex-direction: column; justify-content: flex-end; gap: 5px; font-size: 0.875rem; color: var(--muted); min-width: 0; }
.unit { white-space: nowrap; }
input, select { font: inherit; font-size: 1.0625rem; width: 100%; min-height: 48px; padding: 8px 12px; border: 0; border-radius: 10px; background: var(--ground); color: var(--text); box-shadow: inset 0 0 0 1px var(--edge); }
input::placeholder { color: var(--muted); }
input[type="checkbox"] { width: 26px; min-height: 26px; flex: none; accent-color: var(--tint); }
.check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); min-height: 48px; }
fieldset { border: 0; border-radius: 10px; padding: 0; margin: 0; display: grid; gap: 10px; }
legend { font-size: 0.875rem; color: var(--muted); padding: 0 0 8px; }
@media (max-width: 360px) { .grid2 { grid-template-columns: 1fr; } }
.formulas summary { min-height: 44px; display: flex; align-items: center; font-weight: 600; color: var(--tint); }
.formulas dl { margin-top: 8px; }
#warnings { margin: 0 0 10px; }
.element { display: grid; grid-template-columns: 1fr 1fr 1fr 44px; gap: 8px; align-items: end; }
.remove { border: 0; background: none; color: var(--muted); height: 48px; font-size: 1.25rem; }
button[data-add] { justify-self: start; border: 0; background: none; color: var(--tint); font-weight: 600; min-height: 44px; padding: 0; }
.hint { font-size: 0.8125rem; color: var(--muted); margin: 0; }
.fields input, .fields select { box-shadow: none; background: var(--surface); border-radius: 0; min-height: 52px; padding: 8px 16px; }
.fields > * + * { background-image: linear-gradient(var(--hairline), var(--hairline)); background-repeat: no-repeat; background-position: 16px 0; background-size: calc(100% - 16px) 1px; }
.fields { overflow: hidden; }

/* Result */
.result { position: sticky; top: calc(var(--top) + var(--bar-h) + 6px); z-index: 2; background: var(--navy); color: var(--on-navy); border-radius: var(--radius); padding: 14px 18px; display: grid; gap: 1px; margin-bottom: 14px; }
.result-label { color: var(--on-navy-soft); font-size: 0.875rem; }
.result .kwh { font: 700 2.5rem/1.1 var(--brand); }
.result .kwh small { font: 400 1.0625rem var(--brand); }
.result .meta { color: var(--on-navy-soft); font-size: 0.8125rem; overflow-wrap: anywhere; }
.result.error { background: var(--bad-soft); color: var(--bad); }
.result.error .kwh { font-size: 1.1875rem; line-height: 1.3; }
.result.error .result-label, .result.error .meta { color: inherit; }

dl { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: 9px 14px; }
dt { color: var(--muted); min-width: 0; }
dd { margin: 0; text-align: right; }
dd.total { font-weight: 700; color: var(--tint); }
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pills:not(:empty) { margin-top: 10px; }
.pill { font-size: 0.8125rem; padding: 3px 10px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.muted { background: var(--ground); color: var(--muted); }
.err { background: var(--bad-soft); color: var(--bad); border-radius: 10px; padding: 10px 12px; }
.err code { font-size: 0.8125rem; display: block; margin-top: 2px; overflow-wrap: anywhere; }
.trace { font-size: 0.75rem; color: var(--muted); overflow-wrap: anywhere; margin: 0; }
.report { margin-top: 12px; }
.report-top { display: flex; justify-content: space-between; align-items: center; }

/* Dossier: the logbook. Newest photo on a plate, then every frame in chain order. */
#view-dossier { padding-top: 0; }
.plate { position: relative; margin: 0 -16px; background: var(--navy); color: var(--on-navy); }
.plate-photo { display: block; width: 100%; padding: 0; border: 0; background: none; }
.plate-photo img { display: block; width: 100%; height: 44vh; object-fit: cover; }
.plate.empty-plate { padding-top: 28px; }
.plate-empty { margin: 0; padding: 40px 16px 8px; color: var(--on-navy-soft); }
.plate-caption { padding: 12px 16px 14px; }
.plate-caption h1 { font: 700 1.375rem/1.15 var(--brand); margin: 0; overflow-wrap: anywhere; }
.plate-caption p { margin: 2px 0 0; color: var(--on-navy-soft); font-size: 0.875rem; }
.plate .seal { position: absolute; right: 14px; bottom: 56px; filter: drop-shadow(0 3px 6px rgb(9 14 34 / 0.4)); }
.plate .seal.pressed { animation: press 240ms cubic-bezier(0.16, 1, 0.3, 1) both; }
@keyframes press { from { transform: scale(1.08); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .plate .seal.pressed { animation: none; } }

.ledger { display: grid; grid-template-columns: 1fr 1fr; margin: 0 -16px; background: var(--surface); }
.ledger-cell { display: grid; align-content: center; gap: 1px; min-height: 68px; padding: 10px 16px; }
.ledger-cell + .ledger-cell { box-shadow: inset 1px 0 0 var(--hairline); }
.ledger-cell strong { font: 700 1.125rem/1.2 var(--brand); color: var(--ink); }
.ledger-cell strong.todo { color: var(--tint); font-size: 1.0625rem; }
.ledger-cell small { font: 400 0.875rem var(--brand); }
.ledger-cell span { font-size: 0.8125rem; color: var(--muted); }

.chips { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px; padding: 14px 16px 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border: 0; border-radius: 6px; background: var(--surface); color: var(--text); font-size: 0.9375rem; box-shadow: inset 0 0 0 1px var(--hairline); }
.chip b { font: 700 0.9375rem var(--brand); color: var(--muted); }
.chip.missing { box-shadow: inset 0 0 0 1px var(--warn); }
.chip[aria-checked="true"] { background: var(--navy); color: var(--on-navy); box-shadow: none; }
.chip[aria-checked="true"] b { color: var(--on-navy-soft); }

.contact { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; margin: 0 -16px; }
.frame { position: relative; display: block; padding: 0; border: 0; background: var(--hairline); aspect-ratio: 4 / 3; overflow: hidden; }
.frame img { display: block; width: 100%; height: 100%; object-fit: cover; }
.frame-no { position: absolute; left: 0; bottom: 0; padding: 1px 6px; background: rgb(9 14 34 / 0.72); color: #fff; font: 700 0.75rem var(--brand); }
.next-row { display: flex; gap: 8px; align-items: stretch; box-shadow: none; }
.next-row .primary { flex: 1; min-width: 0; box-shadow: 0 4px 14px rgb(9 14 34 / 0.35); }
.gallery-btn { flex: none; display: grid; place-items: center; width: 56px; border: 0; border-radius: var(--radius); background: var(--surface); color: var(--tint); box-shadow: 0 4px 14px rgb(9 14 34 / 0.35), inset 0 0 0 1px var(--edge); }
.text-btn.danger { color: #ff9c91; align-self: center; }
.verify { display: block; margin: 16px 0 0; font-weight: 600; }

.marks { display: inline-flex; gap: 4px; }
.marks i { width: 12px; height: 12px; border-radius: 3px; box-shadow: inset 0 0 0 1.5px var(--edge); }
.marks i.on { background: var(--turquoise); box-shadow: none; }

.seal polygon { fill: var(--turquoise); }
.seal-ring { fill: none; stroke: rgb(255 255 255 / 0.7); stroke-width: 2.5; }
.seal-tick { fill: none; stroke: #fff; stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; }

.sheet { width: 100%; max-width: 40rem; margin: auto auto 0; border: 0; padding: 12px 16px calc(var(--bottom) + 24px); background: var(--ground); color: var(--text); border-radius: 16px 16px 0 0; }
.sheet::backdrop { background: rgb(9 14 34 / 0.45); }
.sheet-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; margin-bottom: 12px; }
.sheet-head h2 { font-size: 1.0625rem; margin: 0; color: var(--ink); }
.sheet-head .strong { justify-self: end; }
.sheet-head .text-btn:first-child { justify-self: start; }

.sheet.viewer { position: fixed; inset: 0; width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: calc(var(--top) + 6px) 12px calc(var(--bottom) + 12px); border-radius: 0; background: #000; color: #fff; }
.sheet.viewer[open] { display: flex; flex-direction: column; gap: 8px; }
.viewer-head { display: flex; justify-content: space-between; align-items: center; }
.viewer-head .text-btn { color: #fff; }
.viewer-meta { margin: 0; color: #d5dbee; font-size: 0.875rem; }
.viewer-frame { position: relative; flex: 1; min-height: 0; display: flex; }
.viewer img { flex: 1; min-height: 0; width: 100%; object-fit: contain; }
.compass-badge { position: absolute; left: 10px; bottom: 10px; display: flex; align-items: center; gap: 8px; padding: 6px 10px 6px 6px; border-radius: 999px; background: rgba(0, 0, 0, 0.55); color: #fff; font-size: 0.8125rem; font-variant-numeric: tabular-nums; pointer-events: none; }
.compass-badge.unreliable { background: rgba(140, 40, 30, 0.7); }
.compass-needle { position: relative; width: 26px; height: 26px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.85); }
.compass-needle::before { content: ""; position: absolute; left: 50%; top: 2px; width: 0; height: 0; margin-left: -4px; border-left: 4px solid transparent; border-right: 4px solid transparent; border-bottom: 10px solid #4fc3f7; }
@media (prefers-contrast: more) { :root { --muted: var(--text); --hairline: var(--edge); } }

.toast { position: fixed; left: 16px; right: 16px; bottom: calc(var(--bottom) + var(--tab-h) + 14px); z-index: 7; background: var(--navy); color: var(--on-navy); padding: 13px 16px; border-radius: 12px; }

/* Tab bar */
.tabbar { position: fixed; inset: auto 0 0 0; z-index: 5; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; height: calc(var(--bottom) + var(--tab-h)); padding-bottom: var(--bottom); background: var(--bar); -webkit-backdrop-filter: saturate(180%) blur(18px); backdrop-filter: saturate(180%) blur(18px); box-shadow: 0 -1px 0 var(--hairline); }
.tabbar a { display: grid; justify-items: center; align-content: center; gap: 2px; color: var(--muted); font-size: 0.6875rem; font-weight: 500; min-height: 48px; }
.tabbar a[aria-current="page"] { color: var(--tint); }
html[data-os="android"] .tabbar { background: var(--surface); box-shadow: none; }
html[data-os="android"] .tabbar a { font-size: 0.75rem; gap: 4px; }
html[data-os="android"] .tabbar .icon { box-sizing: content-box; padding: 4px 20px; border-radius: 16px; }
html[data-os="android"] .tabbar a[aria-current="page"] { color: var(--ink); }
html[data-os="android"] .tabbar a[aria-current="page"] .icon { background: var(--tint-soft); }


.proof-actions { display: flex; justify-content: space-between; margin-top: 8px; }
.proof-warn { color: var(--bad); font-size: 0.875rem; margin: 10px 0 0; }
.qr { background: #fff; border-radius: var(--radius); padding: 16px; }
.qr svg { display: block; width: 100%; height: auto; }

/* Team: invitations, devices, pairing a computer. Shared by the phone and admin.html. */
.lede { color: var(--muted); margin: -4px 0 16px; }
.team-actions { display: grid; gap: 10px; margin: 0 0 20px; }
.team-actions .primary, .team-actions .secondary, .sheet .primary { display: flex; align-items: center; justify-content: center; gap: 8px; }
.primary.danger { background: var(--bad); color: #fff; }
.secondary.danger { background: var(--bad-soft); color: var(--bad); margin-top: 24px; }
.row .text-btn.danger { color: var(--bad); flex: none; }
.row .pill { margin-left: 8px; vertical-align: 1px; }
label.row.check-row { flex-direction: row; justify-content: flex-start; align-items: center; gap: 14px; font-size: inherit; color: var(--text); cursor: pointer; }
.check-row .row-title { font-weight: 600; }
.check-row input[type="checkbox"] { flex: none; width: 22px; height: 22px; margin: 0; accent-color: var(--tint); }
.check-row input[type="checkbox"]:disabled { opacity: 0.5; }
.sheet-text { margin: 4px 0 16px; color: var(--text); }
.sheet-actions { display: grid; gap: 10px; margin: 16px 0 8px; }
.sheet .qr { max-width: 18rem; margin: 0 auto; }
.check-digits { font-family: var(--brand); font-size: clamp(2.2rem, 9vw, 3rem); font-weight: 700; letter-spacing: 0.12em; color: var(--ink); text-align: center; margin: 8px 0 20px; font-variant-numeric: tabular-nums; }
.notice { padding: 14px 16px; border-radius: var(--radius); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.notice p { margin: 0 0 8px; }
.pair-code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: clamp(2rem, 9vw, 2.6rem); font-weight: 700; letter-spacing: 0.08em; color: var(--ink); text-align: center; margin: 12px 0 8px; user-select: all; }
.countdown { text-align: center; }
.sheet .pair-code + .foot { text-align: center; }
