/* Zakázky na mapě — mobile first */

:root {
  --bg: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --green: #16a34a;
  --green-dark: #15803d;
  --danger: #dc2626;
  --pin-pending: #2563eb;
  --pin-finished: #9ca3af;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
  --radius: 12px;
  --topbar-height: 92px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  overscroll-behavior: none;
}

#map {
  position: absolute;
  inset: 0;
  z-index: 0;
}

#map.placing { cursor: crosshair; }
#map.placing .leaflet-interactive { cursor: crosshair; }

.hidden { display: none !important; }

/* ---------------------------------------------------------------- top bar */

#topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  pointer-events: none;
}

#topbar > * { pointer-events: auto; }

#searchbox {
  position: relative;
  flex: 1 1 auto;
  max-width: 420px;
}

#search-input {
  width: 100%;
  padding: 13px 16px;
  font-size: 16px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 999px;
  box-shadow: var(--shadow);
  background: var(--bg);
  outline: none;
}

#search-input:focus { border-color: var(--accent); }

#search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 46vh;
  overflow-y: auto;
}

/* No white pill under the input when there are no results */
#search-results:empty { display: none; }

#search-results li {
  padding: 11px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
  line-height: 1.25;
}

#search-results li:hover,
#search-results li.selected { background: #eff6ff; }

#search-results li .result-sub {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
}

#search-results li.empty {
  color: var(--muted);
  cursor: default;
}

#controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}

.segmented {
  display: flex;
  background: var(--bg);
  border-radius: 999px;
  box-shadow: var(--shadow);
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.12);
}

.segmented button {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 10px 14px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.segmented button.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* In-form status field: full-width segmented control */
.field-status {
  display: block;
  margin-bottom: 12px;
}
.field-status .segmented { width: 100%; }
.field-status .segmented button { flex: 1; }

.btn-delete {
  appearance: none;
  width: 100%;
  border: 1.5px solid #fecaca;
  background: #fef2f2;
  color: #b91c1c;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  padding: 10px;
  margin-bottom: 12px;
  cursor: pointer;
}
.btn-delete.armed { background: #fee2e2; border-color: #ef4444; }
.btn-delete.hidden { display: none; }

.btn-add {
  appearance: none;
  border: 0;
  border-radius: 999px;
  background: var(--green);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  padding: 11px 18px;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.btn-add:active { background: var(--green-dark); }
#btn-add.placing { background: var(--danger); }

/* ---------------------------------------------------------------- bottom bars */

.bar {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100% - 24px);
  background: rgba(17, 24, 39, 0.92);
  color: #fff;
  border-radius: 999px;
  padding: 10px 12px 10px 18px;
  font-size: 14.5px;
  box-shadow: var(--shadow);
}

.bar button {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

#btn-cancel-place { background: rgba(255, 255, 255, 0.2); color: #fff; }
#btn-add-here { background: var(--green); color: #fff; }
#btn-add-here:active { background: var(--green-dark); }

#search-place-bar { bottom: 18px; }

/* ---------------------------------------------------------------- form sheet */

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1100;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.25);
  padding: 6px 18px calc(16px + env(safe-area-inset-bottom, 0px));
  max-height: 82vh;
  overflow-y: auto;
}

.sheet-handle {
  width: 42px;
  height: 5px;
  border-radius: 999px;
  background: #d1d5db;
  margin: 6px auto 10px;
}

#order-form h2 {
  margin: 2px 0 14px;
  font-size: 19px;
}

.field { display: block; margin-bottom: 14px; }

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.field input,
.field textarea {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  border: 1.5px solid #d1d5db;
  border-radius: 10px;
  background: #fff;
  resize: vertical;
  outline: none;
}

.field input:focus,
.field textarea:focus { border-color: var(--accent); }

.counters {
  display: grid;
  grid-template-columns: 1fr;   /* always one field per row (sheet & side panel) */
  gap: 0;
}

/* Invalid counter value (enforced on save) */
.field input.invalid {
  border-color: var(--danger);
  background: #fef2f2;
}

.pos-hint {
  font-size: 13px;
  color: var(--muted);
  margin: 2px 0 12px;
  min-height: 1em;
}

.form-actions {
  display: flex;
  gap: 12px;
}

.form-actions button {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  appearance: none;
  border: 0;
  border-radius: 14px;
  padding: 15px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
}

.btn-discard {
  background: #e5e7eb;
  color: var(--text);
  flex: 0 0 38%;
}

.btn-save {
  background: var(--green);
  color: #fff;
  box-shadow: 0 3px 0 var(--green-dark);
}

.btn-save:active { transform: translateY(1px); box-shadow: 0 2px 0 var(--green-dark); }

/* ---------------------------------------------------------------- markers */

.pin {
  position: relative;
  width: 34px;
  height: 44px;
}

.pin .pin-head {
  position: absolute;
  top: 0;
  left: 0;
  width: 34px;
  height: 34px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  background: var(--pin-pending);
  border: 2.5px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.pin .pin-dot {
  position: absolute;
  top: 11px;
  left: 10.5px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #fff;
}

.pin.finished .pin-head { background: var(--pin-finished); }

.pin.draft .pin-head { background: var(--green); }

.pin .pin-check {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 16px;
  height: 16px;
  color: #fff;
}

/* ---------------------------------------------------------------- toast */

#toast {
  position: absolute;
  top: calc(var(--topbar-height) + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1200;
  background: rgba(17, 24, 39, 0.92);
  color: #fff;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 14.5px;
  box-shadow: var(--shadow);
  max-width: calc(100% - 24px);
  text-align: center;
}

#toast.error { background: rgba(185, 28, 28, 0.95); }

/* ---------------------------------------------------------------- desktop */

@media (min-width: 900px) {
  :root { --topbar-height: 64px; }

  #topbar {
    padding: 14px 18px;
  }

  #controls { flex-direction: row; align-items: center; }

  .sheet {
    top: 0;
    bottom: 0;
    right: 0;
    left: auto;
    width: 400px;
    max-height: none;
    border-radius: 0;
    box-shadow: -6px 0 24px rgba(0, 0, 0, 0.2);
  }

  .sheet-handle { display: none; }
}
