:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1b1f24;
  --muted: #6a737d;
  --line: #e3e6ea;
  --accent: #2563eb;
  --on: #22a55b;
  --off: #d93a3a;
  --maybe: #e8a317;
  --none: #c4c9cf;
  --danger: #c62828;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111418;
    --panel: #1a1e23;
    --text: #e6e8eb;
    --muted: #98a1ab;
    --line: #2c3239;
    --accent: #5b8def;
    --none: #4a5058;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111418; --panel: #1a1e23; --text: #e6e8eb; --muted: #98a1ab;
  --line: #2c3239; --accent: #5b8def; --none: #4a5058; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); }

#app { display: flex; height: 100vh; height: 100dvh; }
#panel {
  width: 380px;
  flex: none;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
#map-wrap { position: relative; flex: 1; min-width: 0; }
#map { position: absolute; inset: 0; }

h1 { font-size: 20px; margin: 0 0 2px; }
h2 { font-size: 18px; margin: 0 0 12px; }

/* время */
.time-box { border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.time-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.time-label { font-size: 17px; font-weight: 600; }
#time-slider { width: 100%; margin: 10px 0 2px; accent-color: var(--accent); }
.slider-scale { display: flex; justify-content: space-between; font-size: 11px; }

/* кнопки */
.btn {
  border: 0; border-radius: 8px; padding: 8px 12px; cursor: pointer;
  background: var(--accent); color: #fff; font: inherit; font-weight: 600;
}
.btn:disabled { opacity: .45; cursor: default; }
.btn-ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; text-align: left; }
.actions { display: flex; gap: 8px; margin-bottom: 10px; }
.actions .btn:first-child { flex: 1; }

.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1; background: none; border: 0; padding: 8px; cursor: pointer; font: inherit;
  color: var(--muted); border-bottom: 2px solid transparent;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.chip {
  border: 1px solid var(--line); background: none; color: var(--text); border-radius: 999px;
  padding: 4px 12px; cursor: pointer; font: inherit;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.day-switch { display: flex; gap: 6px; margin-bottom: 10px; }

/* места */
.places { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.places li { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; cursor: pointer; }
.places li:hover { border-color: var(--accent); }
.pc { display: flex; flex-direction: column; gap: 4px; }
.pc-status { font-weight: 600; }
.pc-actions { text-align: right; font-size: 13px; }
.st-on { color: var(--on); }
.st-off { color: var(--off); }
.st-maybe { color: var(--maybe); }
.st-none { color: var(--muted); }
.badge {
  font-size: 11px; padding: 1px 6px; border-radius: 6px;
  background: color-mix(in srgb, var(--maybe) 20%, transparent); color: var(--text);
}
.iv { white-space: nowrap; padding: 0 4px; border-radius: 4px; }
.iv-off { background: color-mix(in srgb, var(--off) 18%, transparent); }
.iv-maybe { background: color-mix(in srgb, var(--maybe) 22%, transparent); }

/* полоса суток */
.strip { display: grid; grid-template-columns: repeat(48, 1fr); height: 14px; margin-top: 4px; border-radius: 4px; overflow: hidden; }
.c { display: block; }
.c.h { box-shadow: inset 1px 0 0 rgba(255, 255, 255, .25); }
.c-on { background: var(--on); }
.c-off { background: var(--off); }
.c-maybe { background: repeating-linear-gradient(45deg, var(--maybe) 0 3px, color-mix(in srgb, var(--maybe) 55%, transparent) 3px 6px); }
.c-none { background: var(--none); }
.c.cur { outline: 2px solid var(--text); outline-offset: -2px; position: relative; z-index: 1; }
.strip-scale { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); }

/* очереди */
.groups { display: flex; flex-direction: column; gap: 10px; }
.grp { padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; }
.grp.mine { border-color: var(--accent); }
.grp-head { display: flex; gap: 8px; align-items: baseline; }
.grp-head .small { margin-left: auto; font-weight: 600; }

/* легенда */
.legend { margin-top: auto; display: flex; flex-wrap: wrap; gap: 6px 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.legend .muted { width: 100%; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 4px; vertical-align: -2px; }
.sw-on { background: var(--on); } .sw-off { background: var(--off); }
.sw-maybe { background: var(--maybe); } .sw-none { background: var(--none); }

/* маркеры */
.pin {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 11px; border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .4);
}
.pin-on { background: var(--on); }
.pin-off { background: var(--off); }
.pin-maybe { background: var(--maybe); }
.pin-none { background: #8a9199; }
.leaflet-popup-content .pc { color: #1b1f24; }
.leaflet-popup-content .pc .muted { color: #6a737d; }
.tip { font-size: 13px; }
body.picking #map { cursor: crosshair; }
body.picking .leaflet-grab { cursor: crosshair; }

.pick-hint {
  position: absolute; top: 10px; left: 56px; right: 10px; z-index: 1000; max-width: 460px;
  background: var(--panel); border-radius: 12px; padding: 10px; box-shadow: 0 2px 12px rgba(0, 0, 0, .25);
  display: flex; flex-direction: column; gap: 6px;
}
.search { display: flex; gap: 6px; }
.search input, dialog input, dialog select {
  flex: 1; min-width: 0; font: inherit; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
.search-results { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }

dialog {
  border: 0; border-radius: 14px; padding: 18px; width: min(420px, calc(100vw - 32px));
  background: var(--panel); color: var(--text); box-shadow: 0 8px 40px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-weight: 600; }
dialog input, dialog select { width: 100%; font-weight: 400; }
.dialog-actions { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 2000;
  background: #222; color: #fff; padding: 10px 16px; border-radius: 10px;
}

/* телефон: карта сверху, панель снизу */
@media (max-width: 800px) {
  #app { flex-direction: column-reverse; height: auto; min-height: 100dvh; }
  #map-wrap { height: 60vh; height: 60dvh; flex: none; }
  #panel { width: 100%; border-right: 0; overflow: visible; }
  .pick-hint { left: 16px; right: 16px; top: auto; bottom: 10px; max-width: none; }
}

/* слой города */
.dots-layer { pointer-events: none; }
.poi {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  font-size: 15px; background: #fff; border: 3px solid #9aa1a9; box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
}
.poi-on { border-color: var(--on); }
.poi-off { border-color: var(--off); }
.poi-maybe { border-color: var(--maybe); }
.wrap { flex-wrap: wrap; }
.go-search {
  width: 100%; font: inherit; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
.go-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.go-list li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.go-list li:hover { border-color: var(--accent); }
.dot { flex: none; width: 12px; height: 12px; border-radius: 50%; margin-top: 4px; background: var(--none); }
.dot-on { background: var(--on); } .dot-off { background: var(--off); } .dot-maybe { background: var(--maybe); }
.layers { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.layers summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.layer-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; margin: 8px 0; }
.layer-grid label { display: flex; gap: 6px; align-items: center; cursor: pointer; }

/* подсветка очереди */
.grp[data-group] { cursor: pointer; }
.grp[data-group]:hover { border-color: var(--accent); }
.grp.focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.grp[data-group]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.focus-banner {
  position: absolute; top: 10px; left: 56px; z-index: 900; max-width: min(420px, calc(100% - 72px));
  background: var(--panel); color: var(--text); border-radius: 12px; padding: 8px 40px 8px 12px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .25); font-size: 14px;
}
.focus-close {
  position: absolute; top: 6px; right: 6px; width: 28px; height: 28px; border: 0; border-radius: 50%;
  background: transparent; color: var(--muted); font-size: 16px; cursor: pointer;
}
.focus-close:hover { background: var(--bg); color: var(--text); }

.grp.empty { opacity: .55; }
