:root {
  --sb-bg: #12171f;
  --sb-bg-2: #1a212c;
  --sb-line: #2a3444;
  --sb-text: #dbe3ee;
  --sb-muted: #8896a9;
  --accent: #37a8ff;
  --danger: #e05a5a;
  --ok: #3fbf7f;
  --sb-w: 320px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: system-ui, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
}

.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  position: relative;
  overflow: hidden;
}

/* ---------- SIDEBAR ---------- */

.sidebar {
  width: var(--sb-w);
  flex: 0 0 var(--sb-w);
  background: var(--sb-bg);
  color: var(--sb-text);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--sb-line);
  min-height: 0;
  transition: margin-left .2s ease;
}

.app.sb-closed .sidebar { margin-left: calc(-1 * var(--sb-w)); }

.map-btn {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  z-index: 1001;
  width: 34px;
  height: 34px;
  background: rgba(18, 23, 31, .92);
  border: 1px solid var(--sb-line);
  color: var(--sb-text);
  border-radius: 3px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.map-btn:hover { border-color: var(--accent); }
.map-btn.active { border-color: var(--accent); color: var(--accent); }

.sb-toggle { left: 10px; }
.fs-toggle { left: 52px; }

/* zoom kontrole ispod gumba iznad karte */
.leaflet-top.leaflet-left { margin-top: calc(44px + env(safe-area-inset-top)); }
.leaflet-top.leaflet-right { margin-top: env(safe-area-inset-top); }

.sb-close {
  display: none;
  background: none;
  border: 0;
  color: var(--sb-muted);
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
}
.sb-close:hover { color: var(--sb-text); }

.sb-head {
  padding: calc(10px + env(safe-area-inset-top)) 12px 12px;
  border-bottom: 1px solid var(--sb-line);
}

.sb-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 10px;
  font-weight: 600;
}

.sb-label {
  display: block;
  font-size: 10px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--sb-muted);
  margin-bottom: 3px;
}

.sb-input {
  width: 100%;
  background: var(--sb-bg-2);
  border: 1px solid var(--sb-line);
  color: var(--sb-text);
  border-radius: 3px;
  padding: 5px 8px;
  font-size: 14px;
  font-weight: 600;
}
.sb-input:focus { outline: none; border-color: var(--accent); }

.sb-tools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--sb-line);
}

.tool {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--sb-bg-2);
  border: 1px solid var(--sb-line);
  color: var(--sb-text);
  border-radius: 3px;
  padding: 7px 8px;
  font-size: 13px;
  cursor: pointer;
  text-align: left;
}
.tool:hover { border-color: var(--accent); }
.tool.active { background: var(--accent); border-color: var(--accent); color: #06121d; font-weight: 600; }
.tool i { font-size: 14px; }

.sb-actions {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--sb-line);
}

.mini-btn {
  flex: 1;
  background: transparent;
  border: 1px solid var(--sb-line);
  color: var(--sb-muted);
  border-radius: 3px;
  padding: 5px 8px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.mini-btn:hover { color: var(--sb-text); border-color: var(--accent); }
.mini-btn.active { background: #2a4a1f; border-color: var(--ok); color: #cdf0dc; }
#btnFitAll { flex: 0 0 34px; }

.sb-list { flex: 1 1 auto; overflow-y: auto; min-height: 0; padding-bottom: 8px; }

.sb-group-title {
  font-size: 10px;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--sb-muted);
  padding: 9px 12px 4px;
  border-bottom: 1px solid var(--sb-line);
  background: var(--sb-bg);
  position: sticky;
  top: 0;
  z-index: 2;
}
.sb-group-title span { color: #56617a; }

.item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px 5px 10px;
  border-bottom: 1px solid rgba(42, 52, 68, .5);
  cursor: pointer;
}
.item:hover { background: var(--sb-bg-2); }
.item.hidden-obj .item-main { opacity: .4; }

.item-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: 0 0 9px;
  border: 1px solid rgba(255, 255, 255, .35);
}

.item-main { flex: 1 1 auto; min-width: 0; }
.item-name {
  font-size: 13px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-meta {
  font-size: 11px;
  color: var(--sb-muted);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-btn {
  background: none;
  border: 0;
  color: #6d7b90;
  padding: 2px 4px;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  border-radius: 3px;
}
.item-btn:hover { color: var(--sb-text); background: #2a3444; }
.item-btn.del:hover { color: var(--danger); }

.sb-empty { color: #566379; font-size: 12px; padding: 10px 12px; }

.sb-foot {
  border-top: 1px solid var(--sb-line);
  padding: 6px 12px;
  font-size: 11px;
  color: var(--sb-muted);
  display: flex;
  justify-content: space-between;
  font-family: ui-monospace, Menlo, monospace;
}
.save-state.saving { color: var(--accent); }
.save-state.error { color: var(--danger); }

/* ---------- KARTA ---------- */

.map-wrap { position: relative; flex: 1 1 auto; min-width: 0; }
#map { position: absolute; inset: 0; background: #dfe3e8; }

.coord-bar {
  position: absolute;
  left: calc(10px + env(safe-area-inset-left));
  bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 900;
  background: rgba(18, 23, 31, .88);
  color: #e6edf6;
  border: 1px solid #2a3444;
  border-radius: 3px;
  padding: 4px 9px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px;
  display: flex;
  gap: 12px;
  align-items: center;
  cursor: pointer;
  user-select: none;
}
.leaflet-bottom { margin-bottom: env(safe-area-inset-bottom); }

.coord-bar:hover { border-color: var(--accent); }
.coord-bar b { font-weight: 600; }
.coord-bar i { color: #7b8798; }

.ctx-menu {
  position: absolute;
  z-index: 1000;
  display: none;
  min-width: 210px;
  background: #12171f;
  border: 1px solid #2a3444;
  border-radius: 4px;
  padding: 4px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, .45);
}
.ctx-menu.open { display: block; }
.ctx-coords {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  color: #8896a9;
  padding: 4px 8px 6px;
  border-bottom: 1px solid #2a3444;
  margin-bottom: 4px;
}
.ctx-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: none;
  border: 0;
  color: #dbe3ee;
  text-align: left;
  padding: 6px 8px;
  font-size: 13px;
  border-radius: 3px;
  cursor: pointer;
}
.ctx-menu button:hover { background: #1f2836; }

.draw-hint {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 900;
  background: rgba(18, 23, 31, .9);
  color: #e6edf6;
  border: 1px solid var(--accent);
  border-radius: 3px;
  padding: 5px 12px;
  font-size: 12px;
  display: none;
}
.draw-hint.show { display: block; }

/* ---------- LEAFLET ELEMENTI ---------- */

.pin-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50% 50% 50% 4px;
  transform: rotate(-45deg);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .5);
  color: #fff;
}
.pin-icon i { transform: rotate(45deg); font-size: 13px; }

.map-label {
  background: rgba(18, 23, 31, .78);
  border: 0;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 3px;
  box-shadow: none;
  white-space: nowrap;
}
.map-label::before { display: none; }
.map-label .lbl-meta {
  display: block;
  font-weight: 400;
  font-family: ui-monospace, Menlo, monospace;
  color: #a9b6c7;
  font-size: 10px;
}

.leaflet-popup-content { margin: 9px 12px; min-width: 170px; }
.pop-title { font-weight: 600; font-size: 13px; }
.pop-type { font-size: 11px; color: #6c7a8c; text-transform: uppercase; letter-spacing: .06em; }
.pop-desc { font-size: 12px; margin-top: 5px; white-space: pre-wrap; }
.pop-meta { font-size: 11px; font-family: ui-monospace, Menlo, monospace; color: #55637a; margin-top: 4px; }
.pop-actions { display: flex; gap: 6px; margin-top: 8px; }
.pop-actions button {
  flex: 1;
  border: 1px solid #ccd4de;
  background: #fff;
  border-radius: 3px;
  font-size: 12px;
  padding: 3px 6px;
  cursor: pointer;
}
.pop-actions button:hover { border-color: #7f8b9b; }
.pop-actions .del { color: #c33; }

/* ---------- MODAL / TOAST ---------- */

.modal-sm-custom { max-width: 380px; }
.modal-content { border-radius: 5px; }
.modal-header, .modal-footer { padding: 8px 12px; }
.modal-body { padding: 12px; }
.form-label { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: #6b7787; margin-bottom: 2px; }
.modal-meta { font-size: 11px; font-family: ui-monospace, Menlo, monospace; color: #7b8798; }

.toast-box {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.toast-msg {
  background: #12171f;
  color: #e6edf6;
  border-left: 3px solid var(--accent);
  padding: 7px 12px;
  border-radius: 3px;
  font-size: 13px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
}
.toast-msg.err { border-left-color: var(--danger); }

/* ---------- TABLET ---------- */

@media (max-width: 900px) {
  :root { --sb-w: 260px; }
  .sb-tools { grid-template-columns: 1fr 1fr; }
  .tool span { font-size: 12px; }
}

/* ---------- MOBITEL: sidebar preko karte ---------- */

@media (max-width: 768px) {
  :root { --sb-w: 82vw; }

  .sidebar {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    max-width: 320px;
    z-index: 1200;
    box-shadow: 4px 0 18px rgba(0, 0, 0, .45);
  }

  .app.sb-closed .sidebar { margin-left: -82vw; }

  .sb-close { display: block; }

  .tool { padding: 10px 8px; }
  .item { padding: 8px 8px 8px 10px; }
  .item-btn { padding: 4px 6px; font-size: 15px; }
  .coord-bar { font-size: 11px; gap: 8px; }
}
