:root {
  --bg-panel: rgba(255, 255, 255, 0.94);
  --bg-card: #ffffff;
  --bg-subtle: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --shadow-md: 0 10px 25px -5px rgba(15, 23, 42, 0.14), 0 8px 10px -6px rgba(15, 23, 42, 0.08);
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.08);
  --radius: 14px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: "Be Vietnam Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: #e2e8f0;
}

#map {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  z-index: 1;
}

.hidden {
  display: none !important;
}

.sidebar {
  position: fixed;
  top: 14px;
  left: 14px;
  bottom: 14px;
  width: 370px;
  max-width: calc(100vw - 28px);
  background: var(--bg-panel);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  z-index: 500;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.22s ease, opacity 0.22s ease;
}

.sidebar.collapsed {
  transform: translateX(calc(-100% - 24px));
  opacity: 0;
  pointer-events: none;
}

.sidebar-header {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand-identity {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.14);
}

.eyebrow {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--primary);
  margin-bottom: 2px;
}

.sidebar-header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.25;
}

.stats-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.stat-item {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.sidebar-controls {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 11px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 9px 12px 9px 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 13px;
  background: #ffffff;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-box input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.filter-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.link-btn {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  cursor: pointer;
}

.link-btn:hover {
  text-decoration: underline;
}

.sector-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.sector-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #ffffff;
  font: inherit;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s ease;
}

.sector-chip:hover {
  border-color: #cbd5e1;
  background: #f8fafc;
}

.sector-chip.active {
  background: #0f172a;
  border-color: #0f172a;
  color: #ffffff;
}

.sector-chip.active .chip-count {
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
}

.chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.chip-count {
  font-size: 10.5px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--text-muted);
}

.project-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.project-card {
  position: relative;
  flex-shrink: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px 10px 14px;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.12s ease;
  overflow: hidden;
}

.project-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--card-accent, var(--primary));
}

.project-card:hover {
  border-color: #94a3b8;
  box-shadow: var(--shadow-sm);
}

.project-card.selected {
  border-color: var(--primary);
  background: #eff6ff;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.card-sector {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--card-accent, var(--primary));
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.card-area {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.card-name {
  margin: 0 0 5px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
}

.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11.5px;
  color: var(--text-muted);
}

.card-loc {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
  font-size: 13px;
}

.expand-sidebar-btn {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  background: var(--bg-panel);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: #f1f5f9;
}

.map-controls {
  position: fixed;
  top: 14px;
  right: 14px;
  width: 248px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.control-card {
  background: var(--bg-panel);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  box-shadow: var(--shadow-md);
}

.control-title {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 7px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  background: #f1f5f9;
  padding: 3px;
  border-radius: 8px;
}

.seg-btn {
  border: none;
  background: transparent;
  padding: 6px 4px;
  border-radius: 6px;
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

.seg-btn.active {
  background: #ffffff;
  color: var(--text);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.switch-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.switch-label input {
  width: 15px;
  height: 15px;
  accent-color: var(--primary);
  cursor: pointer;
}

.muted-pct {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
}

#opacitySlider {
  width: 100%;
  margin: 8px 0 8px;
  accent-color: var(--primary);
  cursor: pointer;
}

.control-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.mini-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.mini-btn:hover {
  background: #f1f5f9;
}

.mini-btn.full,
.primary-btn.full {
  width: 100%;
}

.primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: #ffffff;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.primary-btn:hover {
  background: var(--primary-hover);
}

.admin-tools {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.admin-hint {
  margin: 0;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--text-muted);
}

.calibrate-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.cal-grid label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}

.cal-grid input {
  width: 100%;
  padding: 5px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  font-size: 11.5px;
  color: var(--text);
}

.admin-banner {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 520;
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #f59e0b;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  white-space: nowrap;
}

.detail-drawer {
  position: fixed;
  top: 14px;
  right: 14px;
  bottom: 14px;
  width: 410px;
  max-width: calc(100vw - 28px);
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  z-index: 600;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}

.drawer-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.sector-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  color: #ffffff;
}

.stt-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: #e2e8f0;
  color: var(--text);
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.detail-title {
  margin: 0 0 8px;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.35;
}

.detail-location-row {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.detail-location-row svg {
  flex-shrink: 0;
  margin-top: 2px;
  color: var(--primary);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.kpi-card {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-label {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
}

.kpi-value {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.info-block {
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid #f1f5f9;
}

.info-block:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.info-block h3 {
  margin: 0 0 5px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}

.info-block p {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--text);
}

.coord-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.coord-text {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--text);
}

.coord-tag {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--text-muted);
}

.coord-tag.manual {
  background: #dcfce7;
  color: #166534;
}

.coord-tag.planning {
  background: #dbeafe;
  color: #1e40af;
}

.detail-actions {
  display: flex;
  gap: 8px;
}

.custom-pin {
  background: transparent;
  border: none;
}

.pin-dot {
  width: 24px;
  height: 24px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2.5px solid #ffffff;
  box-shadow: 0 3px 10px rgba(15, 23, 42, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease;
}

.pin-dot::after {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ffffff;
}

.pin-dot.selected {
  transform: rotate(-45deg) scale(1.25);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.35), 0 4px 12px rgba(15, 23, 42, 0.45);
}

.leaflet-tooltip.project-tooltip {
  font-family: "Be Vietnam Pro", sans-serif;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.legend-dialog {
  width: min(92vw, 1080px);
  max-height: 90vh;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.legend-dialog::backdrop {
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}

.dialog-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.dialog-body {
  padding: 16px;
  overflow: auto;
  max-height: calc(90vh - 64px);
  background: #ffffff;
}

.dialog-body img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 800;
  background: #0f172a;
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
}

.mobile-layers-btn,
.mobile-brand-pill {
  display: none;
}

@media (max-width: 768px) {
  .mobile-brand-pill {
    position: fixed;
    top: calc(12px + env(safe-area-inset-top, 0px));
    left: 12px;
    z-index: 505;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 5px 12px 5px 6px;
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.8);
    border-radius: 999px;
    box-shadow: var(--shadow-md);
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
  }

  .mobile-brand-pill img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
  }

  .brand-logo {
    width: 36px;
    height: 36px;
  }
  .sidebar {
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    max-width: 100%;
    height: 76dvh;
    border-radius: 18px 18px 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    transform: translateY(0);
  }

  .sidebar::before {
    content: "";
    display: block;
    width: 40px;
    height: 4px;
    border-radius: 999px;
    background: #cbd5e1;
    margin: 8px auto 0;
    flex-shrink: 0;
  }

  .sidebar.collapsed {
    transform: translateY(calc(100% + 20px));
    opacity: 0;
    pointer-events: none;
  }

  .sidebar-header {
    padding: 10px 14px 10px;
  }

  .sidebar-header h1 {
    font-size: 16px;
  }

  .stats-bar {
    margin-top: 8px;
    gap: 6px;
  }

  .stat-item {
    padding: 6px 8px;
  }

  .stat-value {
    font-size: 14px;
  }

  .sidebar-controls {
    padding: 10px 14px;
    gap: 8px;
  }

  .search-box input {
    font-size: 16px;
    padding: 10px 12px 10px 36px;
  }

  .sector-chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
    scrollbar-width: none;
  }

  .sector-chips::-webkit-scrollbar {
    display: none;
  }

  .sector-chip {
    flex-shrink: 0;
    padding: 7px 11px;
    font-size: 12px;
  }

  .project-list {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 8px 12px 18px;
  }

  .project-card {
    padding: 12px 12px 12px 14px;
  }

  .expand-sidebar-btn {
    top: auto;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    padding: 11px 18px;
    border-radius: 999px;
    background: #0f172a;
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.18);
    font-size: 13.5px;
    white-space: nowrap;
  }

  .mobile-layers-btn {
    position: fixed;
    top: calc(12px + env(safe-area-inset-top, 0px));
    right: 12px;
    z-index: 510;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 13px;
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.8);
    border-radius: 999px;
    box-shadow: var(--shadow-md);
    font: inherit;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
  }

  .map-controls {
    top: calc(56px + env(safe-area-inset-top, 0px));
    right: 12px;
    width: min(260px, calc(100vw - 24px));
    display: none;
  }

  .map-controls.mobile-open {
    display: flex;
  }

  .detail-drawer {
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    max-width: 100%;
    max-height: 76dvh;
    border-radius: 18px 18px 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .drawer-body {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 14px 16px 20px;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .kpi-grid .kpi-card:last-child {
    grid-column: 1 / -1;
  }

  .detail-actions {
    flex-wrap: wrap;
  }

  .detail-actions .mini-btn {
    flex: 1;
    padding: 10px 12px;
    font-size: 13px;
  }

  .icon-btn {
    width: 38px;
    height: 38px;
  }

  .leaflet-bottom.leaflet-right {
    bottom: calc(68px + env(safe-area-inset-bottom, 0px));
    right: 4px;
  }

  .leaflet-bottom.leaflet-left {
    bottom: calc(68px + env(safe-area-inset-bottom, 0px));
  }

  .admin-banner {
    top: calc(56px + env(safe-area-inset-top, 0px));
    font-size: 11px;
    white-space: normal;
    text-align: center;
    max-width: calc(100vw - 24px);
  }

  .legend-dialog {
    width: 96vw;
    max-height: 88dvh;
  }
}
