/* FlightTracker — Material 3, layout A. Jasny i ciemny motyw przez zmienne. */
:root {
  --primary: #2B5EA7;
  --on-primary: #FFFFFF;
  --primary-container: #D6E3FF;
  --on-primary-container: #001B3E;
  --surface: #F8F9FF;
  --surface-low: #F2F3F9;
  --surface-container: #ECEEF4;
  --card: #FFFFFF;
  --on-surface: #191C20;
  --on-surface-variant: #43474E;
  --outline: #73777F;
  --outline-variant: #C3C6CF;
  --photo-bg: #DCE3EE;
  --photo-fg: #A9B4C4;
  --ok: #1F7A35;
  --error: #BA1A1A;
  --warn: #7A5900;
  --scrim: rgba(0, 0, 0, .32);
  --shadow: 0 1px 2px rgba(0,0,0,.12), 0 1px 3px 1px rgba(0,0,0,.08);
  --chip-cruise-bg: #D6E3FF; --chip-cruise-fg: #0F3266;
  --chip-approach-bg: #FFDBC8; --chip-approach-fg: #5C1A00;
  --chip-taxi-bg: #FCE186; --chip-taxi-fg: #3A3000;
  --chip-landed-bg: #B9F0B8; --chip-landed-fg: #002106;
  --chip-idle-bg: #E1E2E8; --chip-idle-fg: #43474E;
  --chip-lost-bg: #FFDAD6; --chip-lost-fg: #410002;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --primary: #A8C8FF;
    --on-primary: #00305F;
    --primary-container: #284777;
    --on-primary-container: #D6E3FF;
    --surface: #111318;
    --surface-low: #191C20;
    --surface-container: #1D2024;
    --card: #1D2024;
    --on-surface: #E2E2E9;
    --on-surface-variant: #C3C6CF;
    --outline: #8D9199;
    --outline-variant: #43474E;
    --photo-bg: #2B3038;
    --photo-fg: #5B6472;
    --ok: #7DDB8B;
    --error: #FFB4AB;
    --warn: #E9C349;
    --shadow: 0 1px 3px rgba(0,0,0,.5);
    --chip-cruise-bg: #284777; --chip-cruise-fg: #D6E3FF;
    --chip-approach-bg: #6E2E07; --chip-approach-fg: #FFDBC8;
    --chip-taxi-bg: #544600; --chip-taxi-fg: #FCE186;
    --chip-landed-bg: #1E5128; --chip-landed-fg: #B9F0B8;
    --chip-idle-bg: #33353A; --chip-idle-fg: #C3C6CF;
    --chip-lost-bg: #93000A; --chip-lost-fg: #FFDAD6;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 14px/1.45 Roboto, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--surface);
  color: var(--on-surface);
  padding-bottom: env(safe-area-inset-bottom);
}
[hidden] { display: none !important; }
a { color: var(--primary); }
code, .mono { font-family: "Roboto Mono", ui-monospace, SFMono-Regular, Menlo, monospace; }
code { background: var(--surface-container); padding: 0 4px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--on-surface-variant); }
svg { flex: none; }

/* ---------- pasek aplikacji ---------- */
.app-bar {
  position: sticky; top: 0; z-index: 500;
  display: flex; align-items: center; gap: 8px 16px; flex-wrap: wrap;
  padding: calc(8px + env(safe-area-inset-top)) 8px 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--outline-variant);
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand h1 { margin: 0; font-size: 22px; font-weight: 400; }
.brand-icon { width: 26px; height: 26px; fill: var(--primary); transform: rotate(45deg); }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px;
  border-radius: 8px; border: 1px solid var(--outline-variant); font-size: 13px; color: var(--on-surface-variant); white-space: nowrap;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.chip.err { color: var(--error); border-color: var(--error); }
.chip.err .dot { background: var(--error); }
.icon-btn {
  position: relative; width: 48px; height: 48px; border-radius: 50%; border: 0; background: transparent;
  display: grid; place-items: center; cursor: pointer; color: var(--on-surface-variant);
}
.icon-btn:hover { background: var(--surface-container); }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.bell-dot { position: absolute; top: 10px; right: 10px; width: 8px; height: 8px; border-radius: 50%; background: var(--error); }
.bar-actions { display: flex; }

/* Komputer (mockup A): jedna etykieta stanu, sam dzwonek, tytuł 500. */
@media (min-width: 720px) {
  .app-bar { padding: 12px 24px; }
  .brand h1 { font-weight: 500; }
  .brand-icon { width: 28px; height: 28px; }
  .status-compact, [data-open-settings="all"] { display: none; }
  .bar-actions .icon-btn { width: 44px; height: 44px; }
}
/* Telefon (mockup A-Telefon): pasek bez linii, etykiety w osobnym rzędzie. */
@media (max-width: 719px) {
  .app-bar { padding: calc(8px + env(safe-area-inset-top)) 4px 12px 16px; gap: 4px 8px; border-bottom: 0; }
  .brand-icon { width: 24px; height: 24px; }
  .chips { order: 3; flex-basis: 100%; margin-right: -4px; }
  .status-wide { display: none; }
}
.status-compact, .status-wide { display: contents; }
@media (min-width: 720px) { .status-compact { display: none; } }
@media (max-width: 719px) { .status-wide { display: none; } }

/* ---------- układ ---------- */
main { max-width: 1200px; margin: 0 auto; padding: 24px; }
#app { display: flex; flex-direction: column; gap: 24px; }
@media (max-width: 719px) { main { padding: 12px 12px 104px; } #app { gap: 12px; } }
.empty { text-align: center; color: var(--on-surface-variant); padding: 32px 16px; margin: 0; }
.footnote { margin: 0; font-size: 12px; color: var(--on-surface-variant); }

/* ---------- pola i przyciski ---------- */
.btn {
  height: 40px; padding: 0 24px; border-radius: 20px; border: 0; font: inherit; font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.filled { background: var(--primary); color: var(--on-primary); }
.btn.outlined { background: transparent; color: var(--primary); border: 1px solid var(--outline); }
.btn.text { background: transparent; color: var(--primary); padding: 0 12px; }
.btn.danger { color: var(--error); }
.btn.with-icon { padding-left: 16px; }
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

.field {
  display: flex; flex-direction: column; gap: 2px; padding: 6px 14px; border-radius: 4px;
  border: 1px solid var(--outline); background: var(--card); min-width: 0;
}
.field:focus-within { border: 2px solid var(--primary); padding: 5px 13px; }
.field:focus-within .field-label { color: var(--primary); }
.field-label { font-size: 12px; color: var(--on-surface-variant); }
.field input { border: 0; outline: 0; padding: 0; background: transparent; font: inherit; font-size: 16px; color: var(--on-surface); min-width: 0; }
.field.inline { display: inline-flex; width: 180px; }
.form-msg { margin: 0; min-height: 0; font-size: 13px; color: var(--on-surface-variant); }
.form-msg:empty { display: none; }
.form-msg.err { color: var(--error); }
.form-msg.warn { color: var(--warn); }

.segmented { display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--outline); border-radius: 20px; overflow: hidden; height: 40px; margin: 0; padding: 0; }
.segmented label { display: grid; place-items: center; padding: 0 16px; cursor: pointer; font-weight: 500; }
.segmented label + label { border-left: 1px solid var(--outline); }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked) { background: var(--primary-container); color: var(--on-primary-container); }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: -2px; }

/* ---------- dodawanie lotu ---------- */
.add-bar { background: var(--surface-container); border-radius: 16px; padding: 16px; }
.add-form { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.add-form .ident { flex: 1 1 200px; }
.add-form .ident input { text-transform: uppercase; }
.add-form .ident input::placeholder { text-transform: none; }
.add-form .grow { flex: 2 1 240px; }
.add-form .form-msg { flex-basis: 100%; }
.add-form .counter { font-size: 13px; color: var(--on-surface-variant); }
@media (min-width: 720px) {
  .add-bar .add-form .ident { order: 1; }
  .add-bar .add-form .grow { order: 2; }
  .add-bar .add-form .segmented { order: 3; }
  .add-bar .add-form .btn { order: 4; }
  .add-bar .add-form .counter { order: 5; }
  .add-bar .add-form .form-msg { order: 6; }
}
#add-sheet .add-form .counter, #add-sheet .add-form > .btn { display: none; }
.recent { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.recent-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.recent-chips .chip { background: transparent; color: var(--on-surface); font: inherit; font-size: 13px; cursor: pointer; font-family: "Roboto Mono", ui-monospace, monospace; }
.recent-chips .chip:hover { background: var(--surface-container); }
@media (max-width: 719px) { .add-bar { display: none; } }

#add-sheet .add-form { flex-direction: column; align-items: stretch; }
#add-sheet .add-form .ident, #add-sheet .add-form .grow { flex: none; }
#add-sheet .segmented { display: grid; }
#add-sheet .add-form .btn { align-self: flex-end; }

.fab {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 600;
  height: 56px; padding: 0 20px 0 16px; border-radius: 16px; border: 0;
  background: var(--primary-container); color: var(--on-primary-container); font: inherit; font-weight: 500;
  display: inline-flex; align-items: center; gap: 10px; cursor: pointer; box-shadow: 0 3px 8px rgba(0,0,0,.25);
}
.fab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
@media (min-width: 720px) { .fab { display: none; } }

/* ---------- karty lotów ---------- */
.flights { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 460px), 1fr)); gap: 20px; }
@media (max-width: 719px) { .flights { gap: 12px; } }

.card { background: var(--card); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; scroll-margin-top: 120px; }
.card.done { opacity: .82; }
.card.highlight { outline: 3px solid var(--primary); }

.photo { position: relative; height: 168px; background: var(--photo-bg); display: grid; place-items: center; overflow: hidden; }
.photo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.photo .placeholder { width: 140px; height: 140px; fill: var(--photo-fg); transform: rotate(90deg); }
.photo .phase { position: absolute; left: 12px; top: 12px; display: flex; gap: 6px; flex-wrap: wrap; }
.photo .credit { position: absolute; right: 12px; bottom: 12px; max-width: calc(100% - 16px); padding: 3px 8px; border-radius: 6px; background: rgba(255,255,255,.92); color: #43474E; font-size: 11px; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 719px) { .photo { height: 136px; } .photo .credit { right: 8px; bottom: 8px; } }
@media (min-width: 720px) { .photo .phase { left: 16px; top: 16px; } .photo .credit { font-size: 12px; padding: 4px 10px; border-radius: 8px; } .card-head .sub { font-size: 14px; } }

.badge { display: inline-flex; align-items: center; height: 28px; padding: 0 12px; border-radius: 8px; font-weight: 500; font-size: 13px; background: var(--chip-idle-bg); color: var(--chip-idle-fg); }
.badge.cruise, .badge.climb, .badge.descent { background: var(--chip-cruise-bg); color: var(--chip-cruise-fg); }
.badge.approach { background: var(--chip-approach-bg); color: var(--chip-approach-fg); }
.badge.taxi { background: var(--chip-taxi-bg); color: var(--chip-taxi-fg); }
.badge.landed { background: var(--chip-landed-bg); color: var(--chip-landed-fg); }
.badge.lost { background: var(--chip-lost-bg); color: var(--chip-lost-fg); }

.card-body { padding: 12px 16px 8px 20px; display: flex; flex-direction: column; gap: 14px; }
.card-head { display: flex; justify-content: space-between; align-items: start; gap: 8px; margin-right: -8px; }
.card-head .cs { font-size: 22px; font-weight: 500; letter-spacing: .02em; }
.card-head .sub { color: var(--on-surface-variant); font-size: 13px; }
@media (max-width: 719px) { .card-body { padding: 12px 8px 12px 16px; gap: 12px; } .card-body > :not(.card-head) { margin-right: 8px; } .card-head .cs { font-size: 20px; } .route .code { font-size: 20px; } .photo .placeholder { width: 110px; height: 110px; } }

.route { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; }
.route .code { font-size: 24px; font-weight: 700; line-height: 1.1; }
.route .city { font-size: 12px; color: var(--on-surface-variant); }
.route .end { text-align: right; }
.route .bar { height: 4px; border-radius: 2px; background: var(--outline-variant); }
.route .bar span { display: block; height: 4px; border-radius: 2px; background: var(--primary); }
.route-warn { font-size: 12px; color: var(--warn); margin-top: 8px; }
.route .code.unknown { color: var(--on-surface-variant); }

.detail { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: center; }
@media (max-width: 719px) { .detail { grid-template-columns: 150px 1fr; gap: 12px; } }
.map { height: 150px; border-radius: 12px; overflow: hidden; background: var(--surface-container); z-index: 0; }
@media (min-width: 720px) { .map { height: auto; aspect-ratio: 280 / 160; } }
@media (max-width: 719px) { .map { height: 86px; } }
.map .leaflet-control-attribution { font-size: 9px; padding: 0 4px; }
.map-empty { display: grid; place-items: center; font-size: 12px; color: var(--on-surface-variant); text-align: center; padding: 8px; }

.stats { margin: 0; display: grid; gap: 6px; }
.stats dt { font-size: 12px; color: var(--on-surface-variant); }
.stats dd { margin: 0; font-weight: 500; font-variant-numeric: tabular-nums; }
@media (min-width: 720px) { .stats .phone-only { display: none; } .photo .credit::before { content: "Zdjęcie: "; } }
@media (max-width: 719px) { .stats .wide-only { display: none; } }
@media (max-width: 719px) {
  .stats { gap: 2px; font-size: 13px; }
  .stats div { display: flex; justify-content: space-between; gap: 6px; }
  .stats dt { font-size: 13px; }
}

.events { display: flex; gap: 6px; flex-wrap: wrap; }
.events .chip { color: var(--on-surface); }
.events .chip time { color: var(--on-surface-variant); }
.links { display: flex; gap: 4px; flex-wrap: wrap; padding: 4px 12px 12px; }
.more-wrap { position: relative; }
.menu {
  position: absolute; right: 4px; top: 44px; z-index: 20; min-width: 200px; padding: 8px 0;
  background: var(--surface-low); border-radius: 4px; box-shadow: 0 2px 6px 2px rgba(0,0,0,.15), 0 1px 2px rgba(0,0,0,.3);
  display: flex; flex-direction: column;
}
.menu a, .menu button { display: block; padding: 12px 16px; font: inherit; text-align: left; text-decoration: none; color: var(--on-surface); background: none; border: 0; cursor: pointer; }
.menu a:hover, .menu button:hover, .menu a:focus-visible, .menu button:focus-visible { background: var(--surface-container); outline: none; }
.menu .danger { color: var(--error); }
@media (min-width: 720px) { .more-wrap { display: none; } }
@media (max-width: 719px) {
  .card-head .remove, .links { display: none; }
  .card-head .more { width: 44px; height: 44px; }
  .card-head .more svg { fill: currentColor; stroke: none; width: 20px; height: 20px; }
}
.links a { padding: 10px 12px; font-weight: 500; text-decoration: none; }

/* ---------- logowanie ---------- */
.login { display: grid; place-items: center; min-height: 60vh; }
.login-card { width: min(100%, 360px); background: var(--card); border-radius: 28px; box-shadow: var(--shadow); padding: 28px 24px; display: flex; flex-direction: column; gap: 16px; }
.login-card h2 { margin: 0; font-size: 24px; font-weight: 400; }
.login-icon { width: 40px; height: 40px; fill: var(--primary); transform: rotate(45deg); }

/* ---------- arkusze (dialogi) ---------- */
.sheet {
  border: 0; padding: 12px 24px 24px; background: var(--surface-low); color: var(--on-surface);
  width: min(100%, 560px); max-height: 90vh; overflow-y: auto; border-radius: 28px;
}
.sheet::backdrop { background: var(--scrim); }
.sheet h2 { margin: 4px 0 16px; font-size: 22px; font-weight: 400; }
.sheet-handle { width: 32px; height: 4px; border-radius: 2px; background: var(--outline); margin: 0 auto 8px; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
@media (max-width: 719px) {
  .sheet { margin: auto 0 0; max-width: 100%; border-radius: 28px 28px 0 0; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
}
@media (min-width: 720px) { .sheet-handle { display: none; } }

.hint { display: flex; gap: 12px; align-items: start; background: var(--card); border-radius: 12px; padding: 12px 14px; margin-top: 16px; }
.hint svg { width: 20px; height: 20px; fill: none; stroke: var(--on-surface-variant); stroke-width: 1.8; stroke-linecap: round; }
.hint p { margin: 0; font-size: 13px; color: var(--on-surface-variant); }

.settings-group { padding: 12px 0; border-top: 1px solid var(--outline-variant); display: flex; flex-direction: column; gap: 10px; }
.settings-group h3 { margin: 0; font-size: 14px; font-weight: 500; }
.settings-group p { margin: 0; }
.settings-group .row { display: flex; gap: 8px; flex-wrap: wrap; }
.checks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 12px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 40px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
.help summary { cursor: pointer; font-weight: 500; }
.help ul { margin: 0; padding-left: 18px; color: var(--on-surface-variant); }
.help li { margin-bottom: 6px; }
.help b { color: var(--on-surface); }

/* ---------- komunikaty ---------- */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(88px + env(safe-area-inset-bottom)); z-index: 1000; display: grid; gap: 8px; width: min(calc(100% - 24px), 420px); }
.toast { background: #2E3036; color: #EFF0F7; border-radius: 8px; padding: 12px 16px; box-shadow: 0 4px 12px rgba(0,0,0,.3); animation: toast-in .2s ease-out; }
.toast b { display: block; font-weight: 500; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }
@media (min-width: 720px) { .toasts { left: auto; right: 24px; transform: none; bottom: 24px; } }
