/* Komponentai. Jokiu tiesioginiu spalvu: tik kintamieji is tokens.css. */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body { background: var(--bg); color: var(--ink); font: var(--t-body); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; }
button:active, .tab:active { opacity: 0.6; transition: opacity var(--dur-press); }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
a { color: var(--green-text); text-decoration: none; }
.ico { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.cell { background: var(--cell); border: var(--hair) solid var(--line); border-radius: var(--r-card); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ink-2); flex: none; }
.dot.ok { background: var(--green); }
.dot.wait { background: var(--orange-text); }
.dot.bad { background: var(--red); }

/* ---------- Telefonas (pagrindinis isdestymas) ---------- */
#app { position: fixed; inset: 0; overflow: hidden; }
#brand { display: none; }
#mapwrap { position: absolute; left: 0; right: 0; top: 0; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
#map { position: absolute; inset: 0; background: var(--bg); z-index: 0; isolation: isolate; }

#tabs { position: absolute; left: 0; right: 0; bottom: 0; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding: 0 8px env(safe-area-inset-bottom); background: var(--cell); border-top: var(--hair) solid var(--line); display: flex; z-index: 30; }
.tab { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font: var(--t-cap); color: var(--ink-2); }
.tab[aria-current="page"] { color: var(--green-text); font: var(--t-cap-strong); }

.float { position: absolute; z-index: 20; }
#status { left: var(--m); top: calc(var(--m) + env(safe-area-inset-top)); height: 48px; max-width: calc(100% - 3 * var(--m) - 48px); padding: 0 14px 0 12px; display: flex; align-items: center; gap: 8px; font: var(--t-sub); }
#status-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#controls { right: var(--m); top: calc(var(--m) + env(safe-area-inset-top)); display: flex; flex-direction: column; overflow: hidden; }
.ctl { width: 48px; height: 48px; display: flex; align-items: center; justify-content: center; flex: none; }
#controls .ctl + .ctl { border-top: var(--hair) solid var(--line); }
#hint { left: 50%; transform: translateX(-50%); top: calc(var(--m) + 60px + env(safe-area-inset-top)); min-height: var(--touch); padding: 8px 14px; font: var(--t-foot); color: var(--ink-2); white-space: nowrap; max-width: calc(100% - 2 * var(--m)); overflow: hidden; text-overflow: ellipsis; }
#alert { left: var(--m); right: var(--m); top: calc(var(--m) + env(safe-area-inset-top)); padding: 8px 4px 8px 8px; display: flex; align-items: center; gap: 12px; z-index: 25; }
@media (max-width: 1023px) { .alerting #controls { top: calc(var(--m) + 72px + env(safe-area-inset-top)); } }
#hint.bad { color: var(--red-text); }
#hint:disabled { opacity: 1; cursor: default; }
.grabber, .sheet-head { touch-action: none; }
.alert-ico { width: 44px; height: 44px; border-radius: var(--r-tile); background: var(--red); color: var(--on-red); display: flex; align-items: center; justify-content: center; flex: none; }
.alert-text { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; }
.alert-text strong { font: var(--t-body-strong); }
.alert-text span { font: var(--t-sub); color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.panel, .page { display: none; }
#app[data-tab="map"] #panel-route { display: flex; }
#panel-route { position: absolute; z-index: 20; left: var(--m); right: var(--m); bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 28px); border-radius: var(--r-sheet); padding: var(--m); flex-direction: column; gap: var(--gap); }
.route-head, .route-nums { display: flex; align-items: center; justify-content: space-between; gap: var(--gap); }
.route-nums { align-items: baseline; }
.route-state { display: flex; align-items: center; gap: 8px; font: var(--t-sub); min-width: 0; }
.route-time { font: var(--t-sub); color: var(--ink-2); font-variant-numeric: tabular-nums; flex: none; }
.big { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.big > span:first-child { font: 600 34px/41px var(--font); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.unit { font: var(--t-body); color: var(--ink-2); white-space: nowrap; }
.route-actions { display: flex; gap: 10px; }
.note { font: var(--t-foot); color: var(--ink-2); }

.btn { height: var(--btn-h); min-width: var(--touch); padding: 0 20px; border-radius: var(--r-card); font: var(--t-body); display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap; flex: none; }
.btn.primary { background: var(--green); color: var(--on-green); font: var(--t-body-strong); }
.btn.grey { background: var(--fill-on-cell); color: var(--ink); }
.page .btn.grey, #sheet .btn.grey { background: var(--fill); }
.btn.danger { color: var(--red-text); }
.btn.text { color: var(--green-text); padding: 0 8px; }
.btn.grow { flex: 1 1 0; min-width: 0; }
.btn.block { width: 100%; }
.btn.small { height: var(--touch); padding: 0 14px; font: var(--t-sub); }
.btn:disabled { opacity: 0.4; cursor: default; }

/* Puslapiai (Radiniai, Be rysio) */
.page { position: absolute; z-index: 26; left: 0; right: 0; top: 0; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); background: var(--bg); overflow-x: hidden; overflow-y: auto; padding: calc(44px + env(safe-area-inset-top)) var(--m) var(--m); flex-direction: column; gap: var(--gap); }
#app[data-tab="finds"] #page-finds, #app[data-tab="offline"] #page-offline { display: flex; }
.page-title { font: var(--t-title); letter-spacing: -0.02em; padding: 0 4px; }
.lead { font: var(--t-sub); color: var(--ink-2); padding: 0 4px; }
.group-head { font: var(--t-foot); color: var(--ink-2); padding: 8px var(--m) 0; margin-bottom: -4px; }
.foot { font: var(--t-foot); color: var(--ink-2); padding: 0 var(--m); }
.notice { font: var(--t-sub); color: var(--orange-text); background: var(--cell); border: var(--hair) solid var(--line); border-radius: var(--r-card); padding: 12px var(--m); }
.group { background: var(--cell); border-radius: var(--r-card); overflow: hidden; flex: none; }
.row { min-height: 60px; margin-left: var(--m); padding: 8px var(--m) 8px 0; display: flex; align-items: center; gap: var(--gap); width: calc(100% - var(--m)); text-align: left; }
.row + .row, .row + .bar { border-top: var(--hair) solid var(--line); }
.row-text { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; }
.row-title { font: var(--t-body); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font: var(--t-foot); color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { font: var(--t-foot); color: var(--ink-2); flex: none; }
.row .ico { color: var(--ink-2); width: 20px; height: 20px; }
.row-slider { min-height: var(--touch); padding-left: 56px; }
.row-slider input { flex: 1 1 0; min-width: 0; }
.thumb { width: 44px; height: 44px; border-radius: var(--r-tile); background: var(--fill-on-cell); flex: none; display: flex; align-items: center; justify-content: center; font: var(--t-cap-strong); color: var(--ink-2); }
.thumb-zone::before { content: ""; width: 20px; height: 20px; border-radius: 4px; background: var(--zone); opacity: 0.75; transform: rotate(12deg); }
.thumb-1944::before { content: "1944"; }
.thumb-1995::before { content: "1995"; }
.thumb-relief::before { content: "1 m"; }
.thumb-parcels { background: var(--cell); border: var(--hair) solid var(--line); }
.thumb-parcels::before { content: ""; width: 26px; height: 26px; border: 1.5px solid var(--parcel); border-radius: 2px; box-shadow: inset 9px 0 0 -7.5px var(--parcel); }
.row-seg { min-height: var(--touch); padding-top: 0; }
.row-seg .seg { flex: 1 1 0; min-width: 0; }
.leaflet-relief-pane { mix-blend-mode: multiply; }
.bar { height: 4px; background: var(--fill-on-cell); }
.bar-fill { height: 4px; width: 0; background: var(--orange-text); }

.empty { flex: 1 1 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--gap); text-align: center; padding: var(--m); }
.empty-title { font: var(--t-sheet); }
.empty-text { font: var(--t-sub); color: var(--ink-2); max-width: 300px; }

.seg { display: flex; padding: 2px; border-radius: var(--r-tile); background: var(--fill); }
.seg-btn { flex: 1 1 0; height: 44px; border-radius: 8px; font: var(--t-sub); }
.seg-btn[aria-pressed="true"] { background: var(--cell); font-weight: 500; }

.switch { width: 51px; height: var(--touch); min-height: 44px; display: flex; align-items: center; flex: none; }
.switch-track { width: 51px; height: 31px; padding: 2px; border-radius: 16px; background: var(--switch-off); display: flex; }
.switch-knob { width: 27px; height: 27px; border-radius: 50%; background: var(--knob); transition: transform var(--dur-fade) var(--ease-sheet); }
.switch[aria-checked="true"] .switch-track { background: var(--green); }
.switch[aria-checked="true"] .switch-knob { transform: translateX(20px); }

input[type=range] { -webkit-appearance: none; appearance: none; height: var(--touch); min-width: var(--touch); background: transparent; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--switch-off); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 28px; height: 28px; margin-top: -12px; border-radius: 50%; background: var(--knob); border: var(--hair) solid var(--line); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--switch-off); }
input[type=range]::-moz-range-thumb { width: 28px; height: 28px; border-radius: 50%; background: var(--knob); border: var(--hair) solid var(--line); }

/* Lapas is apacios */
#scrim { position: absolute; inset: 0; z-index: 40; background: var(--scrim); opacity: 0; transition: opacity var(--dur-sheet) var(--ease-sheet); }
#scrim.open { opacity: 1; }
#sheet { position: absolute; z-index: 50; left: 0; right: 0; bottom: 0; max-height: 88%; background: var(--bg); border-radius: var(--r-sheet) var(--r-sheet) 0 0; padding: 8px var(--m) calc(var(--m) + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: var(--gap); overflow-x: hidden; overflow-y: auto; transform: translateY(100%); transition: transform var(--dur-sheet) var(--ease-sheet); }
#sheet.open { transform: translateY(0); }
#sheet:focus { outline: none; }
.grabber { align-self: center; width: 36px; height: 5px; border-radius: 3px; background: var(--switch-off); flex: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: var(--gap); padding-left: 4px; }
.sheet-head h2 { font: var(--t-sheet); letter-spacing: -0.01em; min-width: 0; overflow-wrap: anywhere; }
.close { width: 44px; height: 44px; margin-right: -8px; display: flex; align-items: center; justify-content: center; flex: none; color: var(--ink-2); }
.close .ico { width: 30px; height: 30px; padding: 7px; border-radius: 50%; background: var(--fill); }
#sheet-body { display: flex; flex-direction: column; gap: var(--gap); }
#sheet-body #panel-layers { display: flex; flex-direction: column; gap: var(--gap); }
.sheet-text { font: var(--t-body); color: var(--ink-2); padding: 0 4px; overflow-wrap: anywhere; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font: var(--t-foot); color: var(--ink-2); padding: 0 var(--m); }
.field input, .field textarea { font: var(--t-body); color: var(--ink); background: var(--cell); border: 0; border-radius: var(--r-card); padding: 13px var(--m); width: 100%; resize: none; outline: none; }
.stack { display: flex; flex-direction: column; gap: 4px; }

/* Leaflet priderinimas */
.leaflet-container { font: var(--t-cap); background: var(--bg); }
.leaflet-control-attribution { font: var(--t-cap); background: var(--cell) !important; color: var(--ink-2) !important; padding: 2px 6px !important; border-radius: var(--r-tile) 0 0 0; }
.leaflet-control-attribution a { color: var(--ink-2) !important; }
.me { width: 22px; height: 22px; border-radius: 50%; background: var(--blue); border: 4px solid var(--knob); }
.findpin { width: 20px; height: 20px; border-radius: 50%; background: var(--find); border: 3px solid var(--cell); }
.only-desktop { display: none; }

/* ---------- Plansete ir kompiuteris: sarasas kaireje, zemelapis desineje ---------- */
@media (min-width: 1024px) {
  #app { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); grid-template-rows: auto auto auto minmax(0, 1fr); column-gap: 0; }
  #brand { display: block; grid-column: 1; grid-row: 1; padding: 20px calc(var(--m) + 4px) 8px; }
  .brand-name { font: var(--t-sheet); letter-spacing: -0.01em; }
  #tabs { position: static; grid-column: 1; grid-row: 2; height: auto; margin: 4px var(--m) var(--m); padding: 2px; border: 0; border-radius: var(--r-tile); background: var(--fill); }
  .tab { flex-direction: row; gap: 6px; height: 36px; border-radius: 8px; font: var(--t-sub); color: var(--ink); }
  .tab .ico { width: 18px; height: 18px; }
  .tab[aria-current="page"] { background: var(--cell); color: var(--ink); font: var(--t-sub); font-weight: 500; }
  #mapwrap { position: relative; grid-column: 2; grid-row: 1 / span 4; inset: auto; border-left: var(--hair) solid var(--line); min-width: 0; }
  #panel-route { position: static; grid-column: 1; grid-row: 3; margin: 0 var(--m) var(--m); border-radius: var(--r-card); }
  #app[data-tab="map"] #panel-layers { display: flex; flex-direction: column; gap: var(--gap); grid-column: 1; grid-row: 4; padding: 0 var(--m) var(--m); overflow-x: hidden; overflow-y: auto; }
  .page { position: static; grid-column: 1; grid-row: 3 / span 2; padding: 0 var(--m) var(--m); }
  .page-title { display: none; }
  .only-phone { display: none; }
  .only-desktop { display: flex; }
  .ctl { width: 40px; height: 40px; }
  #status { height: 40px; }
  #alert { right: auto; width: 400px; }
  #sheet { left: 50%; right: auto; bottom: auto; top: 50%; width: 420px; max-height: 80%; border-radius: var(--r-sheet); border: var(--hair) solid var(--line); padding-top: var(--m); transform: translate(-50%, -48%); opacity: 0; transition: opacity var(--dur-fade), transform var(--dur-sheet) var(--ease-sheet); }
  #sheet.open { transform: translate(-50%, -50%); opacity: 1; }
  .grabber { display: none; }
  .seg-btn { height: 32px; }
  .btn { font: var(--t-sub); padding: 0 14px; }
  .btn.primary { font-weight: 600; }
  .row { min-height: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  #sheet, #scrim, .switch-knob { transition: opacity var(--dur-fade) !important; }
  #sheet { opacity: 0; }
  #sheet.open { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) and (max-width: 1023px) { #sheet { transform: none !important; } }
@media (prefers-reduced-motion: reduce) and (min-width: 1024px) { #sheet { transform: translate(-50%, -50%) !important; } }
