:root {
  --bg: #eef3f8;
  --panel: #ffffff;
  --panel-soft: #f7f9fc;
  --text: #17212f;
  --muted: #5f6b7b;
  --line: #d9e0ea;
  --accent: #0f7d71;
  --accent-2: #0a645b;
  --warn: #a14d32;
  --warn-bg: #fff2ec;
  --ok: #0b7a45;
  --ok-bg: #e9f7ef;
  --shadow-1: 0 10px 30px rgba(23, 33, 47, 0.09);
  --shadow-2: 0 26px 62px rgba(23, 33, 47, 0.18);
  --radius: 16px;
  --radius-lg: 22px;
  --space-1: 8px;
  --space-2: 12px;
  --space-3: 16px;
  --space-4: 20px;
  --space-5: 24px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 8% 0%, rgba(15, 125, 113, 0.09), transparent 35%),
    linear-gradient(180deg, #f7fafd 0%, var(--bg) 42%, #edf2f8 100%);
  color: var(--text);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

h1,h2,h3,p { margin: 0; }
h2 { font-size: 1rem; }
h3 { font-size: 0.94rem; }

button, input, select {
  font: inherit;
  min-height: 44px;
}

input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 0 12px;
  color: var(--text);
}

button {
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  padding: 0 14px;
  font-weight: 650;
  cursor: pointer;
}
button:hover:not(:disabled) { background: var(--accent-2); }
button:disabled { opacity: .55; cursor: not-allowed; }
button.secondary {
  background: var(--panel-soft);
  color: var(--text);
  border: 1px solid var(--line);
}
button.secondary.is-active {
  background: #e6f6f3;
  border-color: #b4ddd7;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 1500;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--space-3);
  padding: 8px var(--space-3);
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='64' viewBox='0 0 260 64'%3E%3Cpath fill='none' stroke='%23dce8f3' stroke-width='1.4' d='M0 44c19-8 37-8 56 0s37 8 56 0 37-8 56 0 37 8 56 0'/%3E%3C/svg%3E");
  background-repeat: repeat-x;
  background-position: left bottom;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 11px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #d9f3ef, #eefaf8);
  border: 1px solid #c5e7e2;
}
.brand-mark svg { width: 24px; height: 24px; fill: var(--accent); }
.brand h1 { font-size: 1.05rem; letter-spacing: .01em; }
.brand-eyebrow { color: var(--muted); font-size: .74rem; }

.view-nav {
  display: flex;
  gap: var(--space-1);
  overflow-x: auto;
  scrollbar-width: none;
}
.view-nav::-webkit-scrollbar { display: none; }
.tab-button {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.tab-button.active {
  color: var(--text);
  border-color: #bdd3ee;
  background: #f3f8ff;
}
.account-btn { min-width: 132px; }

.topbar-right { display: flex; align-items: center; gap: 10px; }
.api-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: .86rem;
}
.status-dot {
  width: 10px; height: 10px; border-radius: 999px; background: #b5bfcb;
}
.api-state.ok .status-dot { background: var(--ok); }
.api-state.error .status-dot { background: #d45555; }
.state-spinner {
  width: 14px; height: 14px;
  border: 2px solid #d8e0ea; border-top-color: var(--accent);
  border-radius: 999px; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.app-layout {
  position: relative;
  min-height: calc(100vh - 62px);
}

.map-stage {
  position: relative;
  height: calc(100vh - 62px);
  padding: 12px;
}
.map-view {
  width: 100%; height: 100%;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: var(--shadow-1);
}
.map-hint {
  position: absolute;
  top: 22px;
  left: 22px;
  z-index: 20;
  background: rgba(255,255,255,.96);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: .86rem;
  color: var(--muted);
  box-shadow: var(--shadow-1);
}

.map-floating {
  position: absolute;
  right: 20px;
  bottom: 74px;
  z-index: 920;
  background: rgba(255,255,255,.96);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px;
  display: grid;
  gap: 8px;
  width: 190px;
  box-shadow: var(--shadow-1);
}
.map-center-fab {
  position: absolute;
  right: 20px;
  bottom: 20px;
  z-index: 930;
  border-radius: 999px;
  min-height: 44px;
  padding: 0 16px;
  box-shadow: var(--shadow-1);
}
.floating-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.map-auto-eval { margin: 0; font-size: .86rem; }

.map-offer {
  position: absolute;
  left: 20px;
  bottom: 20px;
  z-index: 910;
  width: min(360px, calc(100% - 260px));
  background: rgba(255,255,255,.96);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow-1);
}

.alert, .feedback, .empty-state, .zone-warning {
  border-radius: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  background: #fff;
}
.empty-state::before {
  content: "";
  display: inline-block;
  width: 18px;
  height: 18px;
  margin-right: 8px;
  vertical-align: -3px;
  background: no-repeat center/18px 18px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23808c9d' d='M12 2 4 5v6c0 5 3.4 9.2 8 10 4.6-.8 8-5 8-10V5l-8-3Zm1 13h-2v-2h2v2Zm0-4h-2V7h2v4Z'/%3E%3C/svg%3E");
}
.alert, .zone-warning {
  border-color: #f0c8b9;
  background: var(--warn-bg);
  color: var(--warn);
  font-weight: 600;
}

.side-drawer {
  position: fixed;
  z-index: 1400;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 92vh;
  max-height: 92vh;
  background: var(--panel);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  box-shadow: var(--shadow-2);
  border: 1px solid var(--line);
  border-bottom: 0;
  transform: translateY(90%);
  transition: transform .34s cubic-bezier(.22, 1.22, .36, 1);
}
.side-drawer.drawer-open { transform: translateY(6%); }
.side-drawer.drawer-mid { transform: translateY(34%); }
.side-drawer.drawer-collapsed { transform: translateY(90%); }

.drawer-handle {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 12px var(--space-3);
  border-bottom: 1px solid var(--line);
}
.grabber {
  justify-self: start;
  width: 70px;
  height: 7px;
  border-radius: 999px;
  background: #cdd7e3;
}
.drawer-status {
  color: var(--muted);
  font-size: .88rem;
}
.drawer-close {
  min-height: 36px;
  width: 36px;
  padding: 0;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
}

.drawer-content {
  max-height: calc(92vh - 56px);
  overflow: auto;
  padding: var(--space-3);
}

.drawer-mini-header {
  position: sticky;
  top: -1px;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: -16px -16px 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.98), rgba(251,253,255,.96));
}
.drawer-mini-brand {
  display: grid;
  gap: 2px;
}
.mini-api {
  font-size: .8rem;
  color: var(--muted);
}
.drawer-mini-actions { display: flex; gap: 8px; }

@media (min-width: 481px) {
  .drawer-mini-header {
    display: none;
  }
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.stack { display: grid; gap: var(--space-3); }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-3);
  box-shadow: var(--shadow-1);
  background-image: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(250,252,255,0.96));
}
.card-subsection {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px dashed var(--line);
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.search-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-2);
}
.gps-form { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.quick-points { display: grid; gap: 8px; margin-top: var(--space-2); }
.quick-points-buttons { display: flex; flex-wrap: wrap; gap: 8px; }

.results-list {
  list-style: none;
  margin: var(--space-2) 0 0;
  padding: 0;
  display: grid;
  gap: 10px;
  max-height: 310px;
  overflow: auto;
}
.result-item {
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 12px;
  background: #fff;
}
.result-item.active { border-color: #b7d9d4; background: #f1f9f8; }
.result-title { font-weight: 650; word-break: break-word; }
.result-meta { color: var(--muted); font-size: .89rem; margin-top: 4px; word-break: break-word; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.results-meta,.hint,.muted { color: var(--muted); font-size: .88rem; }

.key-values {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr);
  gap: 8px 10px;
}
.kv-label { color: var(--muted); font-size: .9rem; }
.kv-value { overflow-wrap: anywhere; }

.detail-grid {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  gap: 8px 10px;
}
.detail-grid dd { margin: 0; overflow-wrap: anywhere; }

.sources-list { display: grid; gap: 10px; }
.source-item {
  border: 1px solid var(--line);
  background: var(--panel-soft);
  border-radius: 12px;
  padding: 10px;
}
.source-link { color: var(--accent-2); overflow-wrap: anywhere; }
.icon { display: inline-flex; width: 14px; height: 14px; margin-right: 6px; vertical-align: -2px; }
.icon svg { width: 14px; height: 14px; fill: currentColor; }

.action-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.action-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 12px;
  padding: 0 12px;
  text-decoration: none;
  background: var(--accent);
  color: #fff;
  font-weight: 650;
}
.checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0 10px;
  color: var(--muted);
}

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: #fff;
  font-size: .84rem;
}

.result-banner {
  border-radius: 12px;
  padding: 12px;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.result-banner.legal { background: var(--ok-bg); color: var(--ok); }
.result-banner.partial,.result-banner.unknown { background: #fff6de; color: #866316; }
.result-banner.illegal { background: var(--warn-bg); color: #9f4427; }

.bullet-list { margin: 0; padding-left: 18px; }
.bullet-list.empty { list-style: none; padding-left: 0; color: var(--muted); }
.spot-description { white-space: pre-wrap; overflow-wrap: anywhere; }

.admin-rules-table-wrap { overflow: auto; }
.admin-rules-table { width: 100%; min-width: 780px; border-collapse: collapse; }
.admin-rules-table th, .admin-rules-table td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: top;
}
.admin-rules-table th { color: var(--muted); font-size: .8rem; text-transform: uppercase; }

.admin-rules-filter { grid-template-columns: repeat(4, minmax(0, 1fr)) auto; }
.admin-spots-filter { grid-template-columns: minmax(0, 1fr) auto auto; }

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 1200;
  background: #1f2b3d;
  color: #fff;
  border-radius: 12px;
  padding: 11px 14px;
  box-shadow: var(--shadow-1);
}
.toast[data-variant="error"] { background: #8f3f2a; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 1300;
  background: rgba(19, 28, 38, .45);
  display: grid;
  place-items: center;
  padding: 14px;
}
.modal-card {
  width: min(900px, 100%);
  border-radius: 16px;
  background: #fff;
  border: 1px solid var(--line);
  padding: 14px;
}
.admin-pin-map { height: 420px; border: 1px solid var(--line); border-radius: 12px; }

.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (min-width: 481px) and (max-width: 1024px) {
  .topbar { grid-template-columns: 1fr; gap: 10px; }
  .topbar-right { justify-content: space-between; }
  .side-drawer {
    width: 390px;
    height: calc(100vh - 76px);
    max-height: none;
    top: 76px;
    right: 10px;
    left: auto;
    bottom: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--line);
    transform: none;
  }
  .side-drawer.drawer-collapsed { transform: translateX(calc(100% + 16px)); }
  .side-drawer.drawer-open,
  .side-drawer.drawer-mid { transform: none; }
  .drawer-content { max-height: calc(100vh - 148px); }
  .drawer-handle { cursor: move; }
  .map-stage { height: calc(100vh - 118px); }
  .map-floating { right: 18px; bottom: 72px; }
  .map-center-fab { right: 18px; bottom: 18px; }
  .gps-form { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 1025px) {
  .topbar { padding: 12px 16px; }
  .app-layout {
    display: grid;
    grid-template-columns: minmax(320px, 380px) minmax(0, 1fr);
    gap: 10px;
    height: calc(100vh - 70px);
    padding: 10px;
  }
  .side-drawer {
    position: relative;
    transform: none !important;
    top: auto;
    left: auto;
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: var(--radius-lg);
    border: 1px solid var(--line);
  }
  .drawer-handle { cursor: default; }
  .drawer-close, .grabber { display: none; }
  .map-stage {
    order: 2;
    height: 100%;
    padding: 0;
  }
  .map-view { border-radius: var(--radius-lg); }
  .map-hint { top: 12px; left: 12px; }
  .map-floating { right: 14px; bottom: 72px; }
  .map-center-fab { right: 14px; bottom: 14px; }
  .map-offer { left: 14px; bottom: 14px; width: min(380px, calc(100% - 260px)); }
  .drawer-content { max-height: calc(100vh - 170px); }
}

@media (max-width: 480px) {
  .topbar {
    grid-template-columns: 1fr auto;
    grid-template-areas: "brand right" "nav nav";
    gap: 8px;
    padding: 8px 10px;
  }
  .brand { grid-area: brand; }
  .view-nav { grid-area: nav; }
  .topbar-right { grid-area: right; align-items: center; }
  .api-state { min-height: 34px; font-size: .78rem; }
  .account-btn { min-width: 92px; font-size: .82rem; }
  .map-stage { height: calc(100vh - 112px); padding: 8px; }
  .map-view { border-radius: 14px; }
  .map-hint { top: 14px; left: 14px; max-width: 70%; }
  .map-floating {
    right: 14px;
    bottom: 138px;
    width: 162px;
    z-index: 32;
  }
  .map-center-fab {
    right: 14px;
    bottom: 84px;
  }
  .map-offer {
    left: 10px;
    bottom: 84px;
    right: 186px;
    width: auto;
    max-width: none;
  }
  .side-drawer {
    height: 92vh;
  }
  .drawer-content { max-height: calc(92vh - 56px); }
  .mobile-drawer-expanded .map-floating .floating-row,
  .mobile-drawer-expanded .map-floating #map-fit-view,
  .mobile-drawer-expanded .map-floating #map-copy-coordinates,
  .mobile-drawer-expanded .map-floating .map-auto-eval {
    display: none;
  }
  .mobile-drawer-expanded .leaflet-control-zoom {
    display: none;
  }
  .mobile-drawer-collapsed .leaflet-control-zoom {
    display: block;
  }
  body.mobile-drawer-expanded {
    overflow: hidden;
  }
  body.mobile-drawer-expanded .map-stage {
    touch-action: none;
  }
  .gps-form,
  .search-form,
  .key-values,
  .detail-grid,
  .admin-rules-filter,
  .admin-spots-filter {
    grid-template-columns: 1fr;
  }
  .drawer-close { display: inline-flex; align-items: center; justify-content: center; }
  .drawer-status { display: none; }
  .toast { left: 10px; right: 10px; text-align: center; }
  .admin-pin-map { height: 300px; }
}
