/* ============ Dronetjenesten Lightmeter ============ */

:root {
  --bg: #0d1117;
  --surface: rgba(18, 23, 31, 0.86);
  --surface-solid: #161b24;
  --line: rgba(240, 246, 252, 0.12);
  --text: #f0f6fc;
  --text-dim: rgba(240, 246, 252, 0.62);
  --accent: #ffb347;
  --accent-ink: #201404;
  --danger: #ff6b6b;
  --ok: #4cd97b;
  --radius: 16px;
  --sheet-max: 560px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }

[hidden] { display: none !important; }

/* ============ Desktop gate ============ */

.gate {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  padding: 32px;
}
.gate-logo { border-radius: 22px; }
.gate h1 { font-size: 26px; margin: 8px 0 0; }
.gate p { margin: 4px 0; color: var(--text-dim); max-width: 46ch; }
.gate-url {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 18px;
  color: var(--accent) !important;
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 18px;
  user-select: all;
  -webkit-user-select: all;
}
.gate-hint { font-size: 14px; }

/* ============ Meter screen ============ */

#screen-meter { position: fixed; inset: 0; }

#viewfinder {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

/* dark vignettes so controls stay readable over any feed */
#screen-meter::before,
#screen-meter::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  pointer-events: none;
  z-index: 1;
}
#screen-meter::before { top: 0; height: 140px; background: linear-gradient(rgba(5,8,12,.82), transparent); }
#screen-meter::after { bottom: 0; height: 45%; background: linear-gradient(transparent, rgba(5,8,12,.55)); }

/* ---- top bar ---- */

.topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 3;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) calc(env(safe-area-inset-right, 0px) + 12px) 0 calc(env(safe-area-inset-left, 0px) + 12px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.topbar-row { display: flex; align-items: center; gap: 8px; }
.topbar-spacer { flex: 1; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  max-width: 60vw;
}
.chip span { overflow: hidden; text-overflow: ellipsis; }
.chip-drone { color: var(--accent); }
.chip-icon { padding: 9px; }

.segmented {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.segment {
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
}
.segment.is-active { background: var(--text); color: #10151c; }
.segmented-wide { width: 100%; }
.segmented-wide .segment { flex: 1; text-align: center; }

/* ---- reticle ---- */

.reticle {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 2;
}
.reticle-ring {
  width: 84px;
  height: 84px;
  border: 1.5px solid rgba(240, 246, 252, 0.75);
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0,0,0,.25), inset 0 0 0 1px rgba(0,0,0,.25);
  position: relative;
}
.reticle-ring::before, .reticle-ring::after {
  content: "";
  position: absolute;
  background: rgba(240, 246, 252, 0.75);
}
.reticle-ring::before { left: 50%; top: 50%; width: 14px; height: 1.5px; transform: translate(-50%, -50%); }
.reticle-ring::after { left: 50%; top: 50%; width: 1.5px; height: 14px; transform: translate(-50%, -50%); }

/* ---- camera overlay ---- */

.camera-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(5, 8, 12, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.camera-overlay-card {
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}
.camera-overlay-card p { margin: 0; color: var(--text-dim); line-height: 1.45; }

/* ---- bottom sheet ---- */

.sheet {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  z-index: 3;
  width: min(100%, var(--sheet-max));
  padding: 10px 14px calc(env(safe-area-inset-bottom, 0px) + 14px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sheet-handlebar {
  width: 40px; height: 4px;
  border-radius: 2px;
  background: var(--line);
  margin: 0 auto;
}

.reading-row { display: flex; align-items: center; gap: 12px; }
.reading-main { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.reading-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 8px;
}
.reading-value { font-variant-numeric: tabular-nums; font-size: 34px; font-weight: 700; line-height: 1.05; display: flex; align-items: baseline; gap: 4px; }
.reading-value small { font-size: 15px; font-weight: 600; color: var(--text-dim); }
.reading-lux { font-size: 13px; font-weight: 500; color: var(--text-dim); margin-left: 10px; }

.badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 2px 7px;
  border-radius: 6px;
}
.badge-live { background: rgba(76, 217, 123, 0.16); color: var(--ok); }
.badge-est { background: rgba(255, 179, 71, 0.16); color: var(--accent); }
.badge-hold { background: rgba(240, 246, 252, 0.16); color: var(--text); }

.btn-hold {
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: rgba(240, 246, 252, 0.07);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  flex: none;
}
.btn-hold[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ---- manual mode ---- */

.manual-row { display: flex; flex-direction: column; gap: 8px; }
.manual-slider { display: flex; align-items: center; gap: 10px; }
.manual-slider input[type="range"] { flex: 1; }
.btn-measure {
  width: 44px; height: 44px;
  flex: none;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: rgba(240, 246, 252, 0.07);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}
.manual-chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.manual-chips::-webkit-scrollbar { display: none; }
.scene-chip {
  flex: none;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(240, 246, 252, 0.07);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
}
.scene-chip.is-active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  height: 30px;
  margin: 0;
  touch-action: pan-x;
}

/* ---- results ---- */

.results { display: flex; gap: 6px; }
.result-tile {
  flex: 1;
  min-width: 0;
  background: rgba(240, 246, 252, 0.06);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 4px 9px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  text-align: center;
}
.result-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-dim);
  white-space: nowrap;
}
.result-value {
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.result-sub {
  font-size: 10px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  min-height: 12px;
}
.result-tile-nd .result-value { color: var(--accent); }
.result-tile.is-warn { border-color: rgba(255, 107, 107, 0.55); }
.result-tile.is-warn .result-value { color: var(--danger); }

.result-note { margin: 0; font-size: 13px; line-height: 1.4; color: var(--accent); }
.result-note.is-error { color: var(--danger); }

/* ---- buttons ---- */

.btn {
  padding: 12px 18px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 15px;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: rgba(240, 246, 252, 0.08); color: var(--text); border: 1px solid var(--line); }

.btn-close {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: rgba(240, 246, 252, 0.08);
  color: var(--text-dim);
  font-size: 15px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============ Modals ============ */

.modal { position: fixed; inset: 0; z-index: 10; }
.modal-scrim { position: absolute; inset: 0; background: rgba(2, 4, 7, 0.6); }
.modal-card {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: min(100%, var(--sheet-max));
  max-height: 78%;
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 16px 16px calc(env(safe-area-inset-bottom, 0px) + 16px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  position: sticky;
  top: -16px;
  background: var(--surface-solid);
  padding: 4px 0 8px;
  z-index: 1;
}
.modal-head h2 { margin: 0; font-size: 18px; }

.drone-list, .option-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.drone-item, .option-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 13px 14px;
  border-radius: 12px;
  background: rgba(240, 246, 252, 0.05);
  border: 1px solid var(--line);
  text-align: left;
}
.drone-item.is-active, .option-item.is-active { border-color: var(--accent); background: rgba(255, 179, 71, 0.1); }
.drone-item b, .option-item b { font-size: 15px; }
.drone-item small, .option-item small { display: block; color: var(--text-dim); font-size: 12px; margin-top: 2px; }
.drone-check { color: var(--accent); font-weight: 700; }

/* ============ Settings ============ */

.setting-block { padding: 14px 2px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.setting-block:first-of-type { border-top: 0; }
.setting-label { font-size: 14px; font-weight: 700; display: flex; justify-content: space-between; }
.setting-label b { color: var(--accent); font-variant-numeric: tabular-nums; }
.setting-help { margin: 0; font-size: 13px; line-height: 1.45; color: var(--text-dim); }
.setting-help a { color: var(--accent); }

/* ============ Install banner ============ */

.banner {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  z-index: 20;
  width: min(calc(100% - 20px), 480px);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.banner img { border-radius: 10px; }
.banner-text { flex: 1; display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.banner-text span { color: var(--text-dim); line-height: 1.4; }
.banner-text svg { vertical-align: -2px; color: var(--accent); }

/* ============ Landscape / tablets ============ */

@media (min-width: 600px) and (orientation: landscape) {
  .sheet {
    left: auto;
    right: calc(env(safe-area-inset-right, 0px) + 16px);
    transform: none;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
    border-radius: var(--radius);
    border-bottom: 1px solid var(--line);
    width: 380px;
  }
  .modal-card {
    bottom: 50%;
    transform: translate(-50%, 50%);
    border-radius: var(--radius);
    border-bottom: 1px solid var(--line);
    max-height: 84%;
  }
}
