:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #0f1b2d;
  --muted: #5d6b7e;
  --line: #dde3ea;
  --accent: #1f6feb;
  --c-emerg: #e5383b;
  --c-mil: #f08c00;
  --c-int: #8b5cf6;
  --c-air: #1f6feb;
  --c-gnd: #8a94a3;
  --glass: rgba(255, 255, 255, 0.86);
  --shadow: 0 2px 10px rgba(15, 27, 45, 0.18);
  --tabs-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1320;
    --surface: #131d2c;
    --surface-2: #1a2638;
    --text: #e8eef6;
    --muted: #93a1b5;
    --line: #243246;
    --accent: #4c8dff;
    --c-air: #4c8dff;
    --c-gnd: #7d8898;
    --glass: rgba(19, 29, 44, 0.88);
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0b1320;
  --surface: #131d2c;
  --surface-2: #1a2638;
  --text: #e8eef6;
  --muted: #93a1b5;
  --line: #243246;
  --accent: #4c8dff;
  --c-air: #4c8dff;
  --c-gnd: #7d8898;
  --glass: rgba(19, 29, 44, 0.88);
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

body { overflow: hidden; }

button { font: inherit; color: inherit; cursor: pointer; }

main {
  position: fixed;
  inset: 0 0 calc(var(--tabs-h) + var(--safe-b)) 0;
}

.view { position: absolute; inset: 0; display: none; }
.view.active { display: block; }

/* ---------- Mapa ---------- */
#map { position: absolute; inset: 0; background: var(--surface-2); }

.leaflet-container { font: inherit; }
.leaflet-control-attribution {
  font-size: 10px;
  background: var(--glass) !important;
  color: var(--muted);
}
.leaflet-control-attribution a { color: var(--muted); }

.pill {
  position: absolute;
  top: calc(var(--safe-t) + 10px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  max-width: calc(100% - 32px);
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pill.error { color: var(--c-emerg); white-space: normal; text-align: center; }
.pill .spin {
  display: inline-block;
  width: 9px; height: 9px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 0.9s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.25; } }

.map-buttons {
  position: absolute;
  left: 12px;
  bottom: 22px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.round {
  width: 46px; height: 46px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}
.round svg, .icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.round.on { background: var(--accent); color: #fff; }

/* Znaczniki samolotów */
.ac-icon { background: none; border: 0; }
.ac {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: auto;
}
.ac svg {
  width: 26px; height: 26px;
  filter: drop-shadow(0 0 1.5px rgba(0, 0, 0, 0.7));
}
.ac.big svg { width: 32px; height: 32px; }
.ac.sel svg { filter: drop-shadow(0 0 3px #fff) drop-shadow(0 0 2px #000); }
.ac span {
  margin-top: 1px;
  padding: 0 5px;
  border-radius: 6px;
  background: var(--glass);
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
}
.no-labels .ac span { display: none; }
.ac.emerg svg { fill: var(--c-emerg); }
.ac.mil svg { fill: var(--c-mil); }
.ac.int svg { fill: var(--c-int); }
.ac.air svg { fill: var(--c-air); }
.ac.gnd svg { fill: var(--c-gnd); }

.me-dot {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #1f6feb;
  border: 3px solid #fff;
  box-shadow: 0 0 0 6px rgba(31, 111, 235, 0.22);
}

/* ---------- Lista ---------- */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-t) + 10px) 16px 6px;
}
.bar h1 { margin: 0; font-size: 26px; font-weight: 700; }

.icon-btn {
  border: 0;
  background: none;
  color: var(--accent);
  padding: 6px;
  display: grid;
  place-items: center;
}

.search-wrap { padding: 4px 16px 8px; }
#search {
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px;
}

#view-list { display: none; flex-direction: column; }
#view-list.active { display: flex; }

#list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
#list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
#list li:active { background: var(--surface-2); }
#list .ico svg { width: 26px; height: 26px; }
#list .ico.emerg svg { fill: var(--c-emerg); }
#list .ico.mil svg { fill: var(--c-mil); }
#list .ico.int svg { fill: var(--c-int); }
#list .ico.air svg { fill: var(--c-air); }
#list .ico.gnd svg { fill: var(--c-gnd); }
#list .main { flex: 1; min-width: 0; }
#list .t { font-weight: 650; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
#list .s { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#list .r { text-align: right; font-variant-numeric: tabular-nums; }
#list .r small { display: block; color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 40px 24px; }

.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.badge.emerg { color: var(--c-emerg); background: color-mix(in srgb, var(--c-emerg) 16%, transparent); }
.badge.mil { color: var(--c-mil); background: color-mix(in srgb, var(--c-mil) 16%, transparent); }
.badge.int { color: var(--c-int); background: color-mix(in srgb, var(--c-int) 16%, transparent); }
.badge.gnd { color: var(--c-gnd); background: color-mix(in srgb, var(--c-gnd) 18%, transparent); }

/* ---------- Ustawienia ---------- */
#view-settings { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.settings { padding: 0 16px 24px; }
fieldset {
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 0;
  border-radius: 12px;
  background: var(--surface);
}
legend {
  float: left;
  width: 100%;
  padding: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
fieldset > * + * { margin-top: 10px; }
fieldset label { display: block; }
fieldset label.check { display: flex; align-items: center; gap: 8px; }
select, input[type="password"], textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px;
}
textarea { font-family: ui-monospace, Menlo, monospace; font-size: 14px; resize: vertical; }
input[type="range"] { width: 100%; accent-color: var(--accent); margin-top: 6px; }
.note { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.center { text-align: center; }
button.link { border: 0; background: none; color: var(--accent); padding: 0; }
.legend { list-style: none; margin: 0; padding: 0; }
.legend li { display: flex; align-items: center; gap: 10px; padding: 3px 0; clear: both; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.dot.emerg { background: var(--c-emerg); }
.dot.mil { background: var(--c-mil); }
.dot.int { background: var(--c-int); }
.dot.air { background: var(--c-air); }
.dot.gnd { background: var(--c-gnd); }

/* ---------- Karta samolotu ---------- */
#sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.25);
}
#sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 1001;
  max-height: 82vh;
  max-height: 82dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.25);
  padding: 6px 16px calc(var(--safe-b) + 16px);
  transform: translateY(105%);
  transition: transform 0.25s ease;
}
#sheet.open { transform: none; }
@media (min-width: 700px) {
  #sheet { left: auto; width: 420px; right: 12px; bottom: 12px; border-radius: 16px; }
}
.grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }

.d-head { display: flex; align-items: center; gap: 10px; }
.d-head h2 { margin: 0; font-size: 22px; flex: 1; }
.d-close {
  border: 0;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--surface-2);
  font-size: 18px;
  line-height: 1;
}
.d-badges { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0 10px; }
.d-photo {
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface-2);
  min-height: 60px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
}
.d-photo img { width: 100%; display: block; }
.d-credit { font-size: 11px; color: var(--muted); margin: 4px 0 0; }
.d-credit a { color: inherit; }
.d-group {
  margin-top: 14px;
  background: var(--surface);
  border-radius: 12px;
  overflow: hidden;
}
.d-group h3 {
  margin: 0;
  padding: 10px 14px 4px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.d-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  border-top: 1px solid var(--line);
}
.d-row:first-of-type { border-top: 0; }
.d-row span:first-child { color: var(--muted); }
.d-row span:last-child { text-align: right; font-variant-numeric: tabular-nums; user-select: text; -webkit-user-select: text; }
.d-actions { display: grid; gap: 8px; margin-top: 14px; }
.d-actions a, .d-actions button {
  display: block;
  text-align: center;
  padding: 11px;
  border-radius: 10px;
  border: 0;
  background: var(--surface);
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

/* ---------- Zakładki ---------- */
.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 900;
  height: calc(var(--tabs-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex;
  background: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabs button {
  flex: 1;
  border: 0;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  color: var(--muted);
}
.tabs svg { width: 24px; height: 24px; fill: currentColor; }
.tabs button.active { color: var(--accent); }
