*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font: 14px/1.45 var(--font-body); -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }
.gutter { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }

.app { height: 100dvh; display: flex; flex-direction: column; min-height: 0; }
.bar { flex: none; background: var(--einhell-black); border-bottom: 3px solid var(--accent); color: #fff; }
.bar-in { display: flex; align-items: center; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; padding-block: 10px; }
h1 { margin: 0; font-size: 17px; font-weight: 800; letter-spacing: .01em; text-transform: uppercase; }
.sub { margin: 2px 0 0; color: var(--einhell-grey); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.who { color: var(--einhell-grey); font-size: 12px; }

.btn { padding: 8px 14px; min-height: 36px; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; font-weight: 600; cursor: pointer; line-height: 1.2; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.bar .btn { background: transparent; color: #fff; border-color: var(--einhell-professional-grey); }
.btn:hover { background: var(--surface-2); }
.bar .btn:hover { background: var(--einhell-professional-grey); }
.btn-primary, .bar .btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover, .bar .btn-primary:hover { background: var(--einhell-neon-red); border-color: var(--einhell-neon-red); }
.btn-danger { color: var(--accent-text); border-color: var(--accent-text); }
.btn-small { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: default; }

.main { flex: 1; min-height: 0; display: flex; }
.panel { width: 380px; flex: none; background: var(--surface); border-right: 1px solid var(--line); overflow-y: auto; overscroll-behavior: contain; min-height: 0; }
.mapwrap { position: relative; flex: 1; min-width: 0; }
#map { position: absolute; inset: 0; z-index: 0; }

.filters { position: sticky; top: 0; z-index: 3; background: var(--surface); display: grid; gap: 8px; padding-block: 10px; border-bottom: 1px solid var(--line); }
.filters-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.input { width: 100%; min-height: 38px; padding: 7px 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
:root[data-theme="light"] .input { background: #fff; }
textarea.input { min-height: 76px; resize: vertical; }
.input::placeholder { color: var(--muted); }
.totals { display: flex; justify-content: space-between; gap: 8px; padding-block: 8px; color: var(--muted); font-size: 12.5px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.list { list-style: none; margin: 0; padding: 0; }
.row { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 2px 12px; width: 100%; text-align: left; padding-block: 10px; background: none; border: 0; border-bottom: 1px solid var(--line); cursor: pointer; align-items: center; }
.row:hover { background: var(--surface-2); }
.row[aria-current="true"] { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.thumb { width: 44px; height: 44px; border-radius: 6px; background: var(--surface-2); object-fit: cover; display: block; grid-row: span 2; }
.row-name { font-weight: 700; overflow-wrap: anywhere; }
.row-turn { font-size: 13px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.row-turn.none { color: var(--muted); }
.row-sub { grid-column: 2 / -1; color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }

.empty { padding-block: 28px; display: grid; gap: 10px; justify-items: start; }
.empty h2 { margin: 0; font-size: 16px; }
.empty p { margin: 0; color: var(--muted); max-width: 36ch; }

.form { display: grid; gap: 12px; padding-block: 14px; }
.form h2 { margin: 0; font-size: 16px; font-weight: 800; text-transform: uppercase; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { min-width: 0; }
.field label { display: block; margin-bottom: 4px; font-size: 12px; font-weight: 700; letter-spacing: .03em; color: var(--muted); }
.hint-text { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.err { margin: 0; color: var(--accent-text); font-size: 13px; }
.ok { margin: 0; font-size: 13px; }
.inline { display: flex; gap: 8px; }
.inline .input { flex: 1; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; position: sticky; bottom: 0; background: var(--surface); padding-block: 10px; border-top: 1px solid var(--line); margin-top: 4px; }
.form-actions .spacer { flex: 1; }
.confirm { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; width: 100%; }
.confirm span { flex: 1; min-width: 160px; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.photo { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo button { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, .75); color: #fff; cursor: pointer; font-size: 16px; line-height: 1; }
.photo.pending::after { content: "новое"; position: absolute; left: 4px; bottom: 4px; padding: 0 6px; border-radius: 4px; background: var(--accent); color: #fff; font-size: 10px; font-weight: 700; text-transform: uppercase; }
.skipped { margin: 4px 0 0; padding-left: 18px; color: var(--muted); font-size: 12.5px; }

.ov { position: absolute; z-index: 5; }
.ov-tl { top: 10px; left: max(10px, env(safe-area-inset-left)); display: flex; gap: 6px; flex-wrap: wrap; max-width: calc(100% - 80px); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 7px 11px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); font-size: 13px; font-weight: 600; cursor: pointer; }
.pill input { margin: 0; accent-color: var(--accent); }
.ov-hint { top: 56px; left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100% - 32px); text-align: center; background: var(--accent); color: #fff; padding: 8px 14px; border-radius: 8px; font-size: 13px; font-weight: 600; box-shadow: var(--shadow); pointer-events: none; }
.legend { left: max(10px, env(safe-area-inset-left)); bottom: 22px; max-width: min(300px, calc(100% - 20px)); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 8px 10px; font-size: 12px; color: var(--muted); display: grid; gap: 6px; }
.legend strong { color: var(--fg); }
.lg-toggle { display: none; align-items: center; justify-content: space-between; gap: 8px; border: 0; background: none; padding: 0; font: inherit; font-weight: 700; color: var(--fg); cursor: pointer; }
.legend[data-collapsed="false"] .lg-toggle { position: absolute; top: 4px; right: 6px; display: inline-flex; padding: 2px 4px; }
.legend[data-collapsed="false"] .lg-toggle-label { display: none; }
.legend[data-collapsed="false"] .lg-body { padding-right: 18px; }
.legend[data-collapsed="true"] { padding: 0; }
.legend[data-collapsed="true"] .lg-toggle { display: inline-flex; padding: 7px 11px; }
.legend[data-collapsed="true"] .lg-toggle .lg-chev { display: none; }
.legend[data-collapsed="true"] .lg-body { display: none; }
.lg-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.lg-item { display: inline-flex; align-items: center; gap: 5px; font-variant-numeric: tabular-nums; }
.dot { display: inline-block; border-radius: 50%; background: var(--accent); border: 2px solid var(--pin-ring); }
.dot.none { background: var(--pin-empty); border-color: var(--muted); }
.dot.approx { border-style: dashed; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 70px); z-index: 2000; max-width: calc(100% - 32px); background: var(--fg); color: var(--bg); padding: 9px 14px; border-radius: 8px; box-shadow: var(--shadow); font-size: 13px; font-weight: 600; }

.tabs { display: none; }

/* map pieces */
.leaflet-container { font: inherit; background: var(--surface-2); }
.leaflet-bar { border: 1px solid var(--line); box-shadow: var(--shadow); }
.leaflet-bar a { background: var(--surface); color: var(--fg); border-bottom-color: var(--line); }
.leaflet-bar a:hover { background: var(--surface-2); color: var(--fg); }
.leaflet-control-attribution { background: var(--surface) !important; color: var(--muted) !important; opacity: .92; }
.leaflet-control-attribution a { color: var(--muted) !important; }
.leaflet-tile-pane { filter: var(--tile-filter); }
.pin-wrap, .cluster-wrap { background: none; border: 0; }
.pin { display: block; border-radius: 50%; background: var(--accent); border: 2px solid var(--pin-ring); box-shadow: 0 1px 4px rgba(0, 0, 0, .45); transition: transform .12s; }
.pin:hover { transform: scale(1.12); }
.pin.pin-none { background: var(--pin-empty); border-color: var(--muted); }
.pin.pin-approx { border-style: dashed; }
.pin.pin-sel { outline: 3px solid var(--einhell-neon-red); outline-offset: 2px; }
.pin.pin-draft { background: var(--fg); border: 3px solid var(--accent); cursor: grab; }
.cluster { display: grid; place-items: center; width: 100%; height: 100%; border-radius: 50%; background: var(--einhell-gradient); border: 2px solid var(--pin-ring); color: #fff; font-weight: 800; font-size: 13px; box-shadow: 0 1px 6px rgba(0, 0, 0, .5); }
.leaflet-tooltip { background: var(--surface); color: var(--fg); border: 1px solid var(--line); box-shadow: var(--shadow); font: 600 12.5px var(--font-body); }
.leaflet-tooltip::before { display: none; }
.leaflet-popup-content-wrapper { background: var(--surface); color: var(--fg); border-radius: 10px; box-shadow: var(--shadow); padding: 0; overflow: hidden; }
.leaflet-popup-tip { background: var(--surface); }
.leaflet-popup-content { margin: 0; width: min(300px, 70vw) !important; font: 13px/1.45 var(--font-body); }
.leaflet-container a.leaflet-popup-close-button { color: #fff; text-shadow: 0 1px 3px #000; z-index: 2; }
.pop-hero { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; display: block; background: var(--surface-2); cursor: zoom-in; }
.pop-thumbs { display: flex; gap: 4px; padding: 4px; overflow-x: auto; }
.pop-thumbs img { width: 44px; height: 44px; object-fit: cover; border-radius: 4px; cursor: pointer; opacity: .75; flex: none; }
.pop-thumbs img.on { opacity: 1; outline: 2px solid var(--accent); }
.pop-body { padding: 12px 14px 14px; display: grid; gap: 6px; }
.pop-body h3 { margin: 0; font-size: 15px; font-weight: 800; overflow-wrap: anywhere; }
.pop-body p { margin: 0; overflow-wrap: anywhere; }
.pop-sub { color: var(--muted); }
.pop-turn { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-block: 1px solid var(--line); }
.pop-label { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.pop-notes { white-space: pre-wrap; }
.pop-warn { color: var(--warn); font-size: 12px; }
.pop-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.leaflet-popup-content a.btn { color: var(--fg); }

dialog#lightbox { border: 0; padding: 0; background: transparent; max-width: 96vw; max-height: 96vh; }
dialog#lightbox::backdrop { background: rgba(0, 0, 0, .85); }
dialog#lightbox img { max-width: 96vw; max-height: 92vh; display: block; border-radius: 8px; }

@media (max-width: 860px) {
  .main { flex-direction: column; }
  .panel { width: auto; flex: 1; border-right: 0; }
  .mapwrap { flex: 1; min-height: 0; }
  .app[data-tab="map"] .panel { display: none; }
  .app[data-tab="list"] .mapwrap { display: none; }
  .tabs { display: grid; grid-template-columns: 1fr 1fr; flex: none; background: var(--einhell-black); border-top: 1px solid var(--einhell-professional-grey); padding-bottom: env(safe-area-inset-bottom); }
  .tabs button { background: none; border: 0; color: var(--einhell-grey); font-weight: 700; padding: 13px 0; cursor: pointer; border-top: 3px solid transparent; }
  .tabs button[aria-selected="true"] { color: #fff; border-top-color: var(--accent); }
  .input { font-size: 16px; }
  .legend-more { display: none; }
  .legend { bottom: 12px; }
  .grid2 { grid-template-columns: 1fr; }
  .toast { bottom: calc(env(safe-area-inset-bottom) + 70px); }
}
@media (prefers-reduced-motion: reduce) { .pin { transition: none; } }
