:root {
  --green: #1f3a2b;
  --green-2: #2e5640;
  --ember: #d9622b;
  --ember-soft: #fbe9df;
  --bg: #f4f2ed;
  --card: #ffffff;
  --ink: #1b1d1c;
  --muted: #6a6f6b;
  --line: #dcd8cf;
  --ok: #2f7d4a;
  --warn: #b7791f;
  --danger: #b3261e;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { min-height: 100vh; padding-bottom: calc(24px + var(--safe-bottom)); }
button, input, select, textarea { font: inherit; color: inherit; }

/* Top bar */
#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: var(--green); color: #fff;
}
#titleWrap { flex: 1; min-width: 0; }
#title { font-size: 19px; margin: 0; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#subtitle { font-size: 13px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#topActions { display: flex; gap: 8px; }
.icon-btn { background: none; border: 0; color: #fff; font-size: 34px; line-height: 1; padding: 0 8px 4px 0; cursor: pointer; }
.top-btn { background: rgba(255,255,255,.14); color: #fff; border: 0; border-radius: 10px; padding: 8px 12px; font-weight: 600; cursor: pointer; }
.top-btn.primary { background: var(--ember); }

/* Tabs */
#tabs {
  position: sticky; top: calc(56px + var(--safe-top)); z-index: 19;
  display: flex; gap: 4px; overflow-x: auto; padding: 8px 12px;
  background: var(--green-2); scrollbar-width: none;
}
#tabs::-webkit-scrollbar { display: none; }
#tabs button {
  flex: 0 0 auto; border: 0; border-radius: 999px; padding: 8px 14px;
  background: transparent; color: #dfe9e2; font-weight: 600; cursor: pointer;
}
#tabs button.active { background: #fff; color: var(--green); }
#tabs .badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px; background: var(--ember); color: #fff; font-size: 12px; }

main { max-width: 980px; margin: 0 auto; padding: 16px; }
h2 { font-size: 17px; margin: 22px 0 8px; color: var(--green); }
h2:first-child { margin-top: 4px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card.tap { cursor: pointer; }
.card.tap:active { background: #faf8f4; }
.row { display: flex; gap: 12px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eee9df; color: #4a4f4b; }
.pill.ember { background: var(--ember-soft); color: #9a3f14; }
.pill.ok { background: #e2f1e6; color: var(--ok); }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px 14px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field.full { grid-column: 1 / -1; }
.field > span { font-size: 13px; font-weight: 600; color: #3f4541; }
.field > span em { font-weight: 400; font-style: normal; color: var(--muted); }
input[type=text], input[type=number], input[type=date], input[type=time], select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; background: #fff;
  padding: 11px 12px; font-size: 16px; min-height: 46px;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--ember); outline-offset: -1px; border-color: transparent; }
.inline-input { display: flex; gap: 8px; }
.inline-input > * { flex: 1; }
.inline-input > button { flex: 0 0 auto; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 10px 12px; min-height: 44px; cursor: pointer; font-weight: 500; }
.seg button.on { background: var(--green); color: #fff; border-color: var(--green); }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.check { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; min-height: 46px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--green); }

.btn { border: 0; border-radius: 10px; padding: 12px 16px; min-height: 46px; font-weight: 600; cursor: pointer; background: #e8e3d8; color: var(--ink); }
.btn.primary { background: var(--green); color: #fff; }
.btn.ember { background: var(--ember); color: #fff; }
.btn.danger { background: #f6dedc; color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.fab { position: fixed; right: 20px; bottom: calc(20px + var(--safe-bottom)); z-index: 15; border: 0; border-radius: 999px; padding: 16px 22px; background: var(--ember); color: #fff; font-weight: 700; font-size: 16px; box-shadow: 0 6px 18px rgba(0,0,0,.25); cursor: pointer; }

/* Photos */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.photo-tile { position: relative; border-radius: 10px; overflow: hidden; background: #ddd; aspect-ratio: 4/3; cursor: pointer; border: 0; padding: 0; }
.photo-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-tile .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 4px 6px; font-size: 12px; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.75)); text-align: left; }
.photo-tile .num { position: absolute; top: 6px; left: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; border-radius: 6px; padding: 1px 6px; }
.photo-tile .warn { position: absolute; top: 6px; right: 6px; background: var(--warn); color: #fff; font-size: 11px; border-radius: 6px; padding: 1px 6px; }
.preview-img { width: 100%; border-radius: 10px; display: block; }

/* Map */
#siteMap { height: 62vh; min-height: 360px; border-radius: var(--radius); border: 1px solid var(--line); }
.map-label { background: rgba(0,0,0,.65); color: #fff; border: 0; border-radius: 6px; padding: 2px 6px; font-size: 12px; font-weight: 600; box-shadow: none; }
.map-label::before { display: none; }

/* Checklist */
.cl-item { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid #eee9df; }
.cl-item:last-child { border-bottom: 0; }
.cl-dot { flex: 0 0 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; color: #fff; background: #c9c3b6; }
.cl-dot.ok { background: var(--ok); }
.cl-dot.warn { background: var(--warn); }

/* Sheet (modal) */
.sheet { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet-panel { width: 100%; max-width: 760px; max-height: 92vh; overflow-y: auto; background: var(--bg); border-radius: 18px 18px 0 0; padding: 16px 16px calc(20px + var(--safe-bottom)); }
@media (min-width: 768px) { .sheet { align-items: center; } .sheet-panel { border-radius: 18px; max-height: 88vh; } }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.sheet-head h3 { flex: 1; margin: 0; font-size: 18px; }

#toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translateX(-50%); z-index: 60; background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 15px; max-width: 90vw; text-align: center; }

.cam-open #toast { bottom: auto; top: 38%; }

/* Camera */
#camera { position: fixed; inset: 0; z-index: 50; background: #000; color: #fff; }
#camVideo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#camHud { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between; pointer-events: none; }
#camHud > * { pointer-events: auto; }
.hud-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: calc(12px + var(--safe-top)) 16px 12px; background: linear-gradient(rgba(0,0,0,.65), transparent); }
.hud-bearing { display: flex; align-items: baseline; gap: 10px; text-shadow: 0 1px 3px #000; }
#hudCard { font-size: 40px; font-weight: 800; }
#hudDeg { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.hud-meta { text-align: right; font-size: 14px; line-height: 1.5; text-shadow: 0 1px 3px #000; font-variant-numeric: tabular-nums; }
#hudLevel { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
#hudHorizon { position: absolute; left: -20%; right: -20%; top: 50%; height: 0; border-top: 2px dashed rgba(255,255,255,.6); }
.hud-cross { position: absolute; left: 50%; top: 50%; width: 44px; height: 44px; margin: -22px 0 0 -22px; border: 2px solid rgba(255,255,255,.9); border-radius: 50%; }
.hud-cross::before, .hud-cross::after { content: ""; position: absolute; background: rgba(255,255,255,.9); }
.hud-cross::before { left: 50%; top: -14px; bottom: -14px; width: 2px; margin-left: -1px; }
.hud-cross::after { top: 50%; left: -14px; right: -14px; height: 2px; margin-top: -1px; }
#clinoReadout { position: absolute; left: 0; right: 0; top: 58%; text-align: center; text-shadow: 0 1px 4px #000; pointer-events: none; }
#clinoDeg { font-size: 54px; font-weight: 800; font-variant-numeric: tabular-nums; }
#clinoHint { font-size: 14px; opacity: .9; padding: 0 30px; }
.hud-bottom { padding: 12px 16px calc(16px + var(--safe-bottom)); background: linear-gradient(transparent, rgba(0,0,0,.75) 30%); display: flex; flex-direction: column; gap: 10px; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { flex: 0 0 auto; border: 1px solid rgba(255,255,255,.5); background: rgba(0,0,0,.35); color: #fff; border-radius: 999px; padding: 8px 12px; font-weight: 600; cursor: pointer; }
.chips button.on { background: var(--ember); border-color: var(--ember); }
#camCaption { background: rgba(0,0,0,.45); border: 1px solid rgba(255,255,255,.4); color: #fff; }
#camCaption::placeholder { color: rgba(255,255,255,.7); }
.cam-controls { display: flex; align-items: center; justify-content: space-between; }
.cam-btn { min-width: 84px; text-align: center; border: 0; background: rgba(255,255,255,.18); color: #fff; padding: 10px 14px; border-radius: 10px; font-weight: 600; cursor: pointer; }
#camShutter { width: 76px; height: 76px; border-radius: 50%; border: 5px solid #fff; background: var(--ember); cursor: pointer; }
#camShutter:active { transform: scale(.94); }
#camShutter.clino { background: var(--green-2); }
#camCount { text-align: center; font-size: 13px; opacity: .85; }
.flash { animation: flash .25s; }
@keyframes flash { from { background: #fff; } to { background: #000; } }
