:root{
  --bg:#0b1020;
  --bg-2:#0e1530;
  --card:#0f1a39cc;
  --stroke:#243167;
  --text:#d7e3ff;
  --muted:#8aa0d6;
  --accent:#4de2ff;
  --accent-2:#7a5cff;
  --danger:#ff4d6d;
  --shadow: 0 10px 30px rgba(0,0,0,.4);
  --radius:16px;
  --topbar-height: 64px;
  --scrollbar-track: rgba(12, 20, 45, 0.9);
  --scrollbar-thumb: rgba(43, 60, 122, 0.95);
  --scrollbar-thumb-hover: rgba(77, 226, 255, 0.45);
}
*{box-sizing:border-box}

/* Viewport scrollbar theme only (avoid styling every element) */
html {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

html::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

html::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
  border-radius: 999px;
}

html::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #2b3c7a, #22306a);
  border: 1px solid rgba(77, 226, 255, 0.25);
  border-radius: 999px;
}

html::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #3550a0, #2b3c7a);
  border-color: var(--scrollbar-thumb-hover);
}
html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: radial-gradient(1200px 700px at 80% -10%, #1a2a6cff, transparent 60%),
              radial-gradient(1000px 600px at -10% 120%, #162447ff, transparent 55%),
              var(--bg);
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
}

body::before{
  content:"";
  position:fixed;
  inset:0;
  pointer-events:none;
  opacity:.25;
  mix-blend-mode:overlay;
  background-image: linear-gradient(var(--stroke) 1px, transparent 1px),
                    linear-gradient(90deg, var(--stroke) 1px, transparent 1px);
  background-size: 28px 28px;
  animation:gridShift 40s linear infinite;
}
@keyframes gridShift{ 0%{transform:translateY(0)} 100%{transform:translateY(28px)} }

#app {display:flex; flex-direction:column; height:100%; position:relative}
.chip{
  font-size:12px; padding:4px 8px;
  border:1px solid #2b3c7a; border-radius:999px;
  color:var(--muted);
}

#toolbar {
  display: flex; justify-content: space-between;
  gap: 20px; align-items:center; padding: 12px 16px;
  border-bottom: 1px solid #1b2650;
  background: linear-gradient(180deg, #0b143040, #0b143030);
  flex-wrap: wrap;
  position:relative; z-index:100;
}
.row {display:flex; gap:12px; align-items:center; flex-wrap:wrap}
.right {display:flex; gap:12px; align-items:center; flex-wrap:wrap}

@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.05); }
}

.toolbar-label {
  font-size: 13px; color: #000; font-weight: 600;
  letter-spacing: 0.5px; text-transform: uppercase;
  opacity: 0.90;
}


select, input {
  appearance:none; color:var(--text);
  background: var(--card); border:1px solid #243167;
  outline:none; padding:10px 12px; border-radius:12px; min-height:40px;
  opacity: 0.90;
}
label {
  font-size: 13px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  }
input[type="checkbox"]{
  appearance:auto; width:auto; height:auto; accent-color: var(--accent);
}

.btn {
  position:relative; border:1px solid #2a3a7a;
  background: linear-gradient(180deg, #0f1b3b, #0b142f);
  color:var(--text); padding:10px 14px;
  border-radius:14px; cursor:pointer; transition: .2s transform;
  box-shadow: 0 0 0 1px #213069 inset, 0 6px 20px #0008;
  opacity: 0.90;
}
.btn:hover{ transform: translateY(-1px); }
.btn::after{
  content:""; position:absolute; inset:-2px; border-radius:16px;
  background: radial-gradient(60% 60% at 50% -20%, #4de2ff55, transparent 60%),
              radial-gradient(60% 60% at 110% 120%, #7a5cff40, transparent 60%);
  filter: blur(8px); opacity:.6; z-index:-1;
}

#map {
  position:absolute;
  top:0;
  left:0;
  right:0;
  bottom:0;
  width:100%;
  height:100%;
  border-top:1px solid #1a2660; border-bottom:1px solid #1a2660;
  z-index:1;
}

.attribution {
  position:absolute; bottom:10px; right:10px;
  background: linear-gradient(180deg, #0d1634cc, #0a1530cc);
  padding:6px 10px; border:1px solid #22306a;
  border-radius:10px; font-size:12px; color:var(--muted);
  box-shadow: var(--shadow);
}

/* Export history tooltip: white text, no background/border */
.history-tooltip{
  color:#fff; background:transparent; border:none; box-shadow:none;
  font-weight:600; text-shadow:0 1px 2px rgba(0,0,0,.6);
}

/* Google Maps-style ruler - Dark theme adapted */

/* Segment labels: white pill, dark gray text, auto-resize */
.ruler-segment-label {
  display: inline-block;
  background: rgba(255, 255, 255, 0.97);
  color: #3c4043;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 11px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 100px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25), 0 2px 8px rgba(0, 0, 0, 0.12);
  white-space: nowrap;
  letter-spacing: 0.01em;
  pointer-events: none;
  position: relative;
}

/* Total label: larger blue pill, bold white text, auto-resize */
.ruler-total-label {
  display: inline-block;
  background: #1a73e8;
  color: #fff;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 100px;
  box-shadow: 0 2px 6px rgba(26, 115, 232, 0.5), 0 4px 12px rgba(0, 0, 0, 0.2);
  white-space: nowrap;
  letter-spacing: 0.02em;
  pointer-events: none;
  position: relative;
}

/* Ensure label icons don't interfere */
.ruler-segment-icon, .ruler-total-icon {
  background: transparent !important;
  border: none !important;
}

/* Ruler point markers - draggable with animations */
.ruler-point-marker {
  background: transparent !important;
  border: none !important;
}

.ruler-point {
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
}

.ruler-point:hover {
  transform: scale(1.2);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.ruler-point.dragging {
  cursor: grabbing;
  transform: scale(1.25);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* Pop animation for new points */
@keyframes rulerPointPop {
  0% { transform: scale(0); opacity: 0; }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); opacity: 1; }
}

.ruler-point.new {
  animation: rulerPointPop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Label fade-in animation */
@keyframes rulerLabelFade {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

.ruler-segment-label.new,
.ruler-total-label.new {
  animation: rulerLabelFade 0.2s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.leaflet-marker-icon.ruler-point-marker:active {
  cursor: grabbing !important;
}
.leaflet-dragging .leaflet-marker-icon.ruler-point-marker {
  cursor: grabbing !important;
}

/* Loading screen to prevent flash before auth check */
#authLoading {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: var(--bg); z-index: 9999; overflow: hidden;
}

#particleCanvas {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none;
}

.loading-content {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  text-align: center; z-index: 10;
}

.loading-logo {
  font-family: 'Orbitron', monospace; font-size: 3rem; font-weight: 600;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  background-clip: text; -webkit-background-clip: text; color: transparent;
  margin-bottom: 1rem; letter-spacing: 2px;
  animation: logoGlow 2s ease-in-out infinite alternate;
}

.loading-text {
  color: var(--muted); font-size: 1rem; opacity: 0.8;
  animation: fadeInOut 1.5s ease-in-out infinite alternate;
}

@keyframes logoGlow {
  0% { filter: drop-shadow(0 0 10px var(--accent)) brightness(1); }
  100% { filter: drop-shadow(0 0 20px var(--accent)) brightness(1.2); }
}

@keyframes fadeInOut {
  0% { opacity: 0.6; }
  100% { opacity: 1; }
}

.limit-indicator {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; background: var(--card); border-radius: 8px; margin: 4px 0;
}
.limit-bar {
  flex: 1; height: 6px; background: var(--stroke); border-radius: 3px;
  margin: 0 12px; overflow: hidden;
}
.limit-fill {
  height: 100%; border-radius: 3px; transition: width 0.3s ease;
}
.limit-fill.safe { background: var(--success); }
.limit-fill.warning { background: var(--warning); }
.limit-fill.danger { background: var(--danger); }

label{ font-size:13px; color:var(--muted); }
/* Keep a stable crosshair cursor while tools are active */
#map.force-crosshair,
#map.force-crosshair .leaflet-pane,
#map.force-crosshair .leaflet-interactive,
#map.force-crosshair canvas {
  cursor: crosshair !important;
}

/* Population Density Legend Bar */
.density-legend {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: none;
  flex-direction: column;
  align-items: center;
  padding: 10px 16px 8px;
  background: rgba(15, 15, 25, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  backdrop-filter: blur(12px);
  min-width: 300px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
.density-legend.visible { display: flex; }
.density-legend .info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 8px;
  min-height: 28px;
}
.density-legend .default-title {
  font-size: 12px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.7);
  width: 100%;
  text-align: center;
}
.density-legend .default-title.hidden { display: none; }
.density-legend .hover-info {
  display: none;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}
.density-legend .hover-info.visible { display: flex; }
.density-legend .area-info { display: flex; flex-direction: column; }
.density-legend .area-name {
  font-weight: 600;
  font-size: 13px;
  color: #fff;
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.density-legend .area-code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.4);
}
.density-legend .density-value-display {
  font-family: 'JetBrains Mono', monospace;
  font-size: 18px;
  font-weight: 600;
  color: #f0b866;
  display: flex;
  align-items: baseline;
  gap: 4px;
}
.density-legend .density-unit {
  font-size: 10px;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.5);
}
.density-legend .bar-container {
  position: relative;
  width: 260px;
}
.density-legend .bar {
  width: 100%;
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(to right,
    #fef9c3 0%,
    #fef08a 6%,
    #fcd34d 12%,
    #fbbf24 18%,
    #fb923c 30%,
    #f97316 45%,
    #dc2626 65%,
    #991b1b 82%,
    #7f1d1d 100%
  );
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.2);
}
.density-legend .marker {
  position: absolute;
  top: -3px;
  width: 4px;
  height: 18px;
  background: #fff;
  border-radius: 2px;
  box-shadow: 0 0 6px rgba(0,0,0,0.5), 0 0 0 2px rgba(255,255,255,0.3);
  transform: translateX(-50%);
  opacity: 0;
  transition: left 0.15s ease, opacity 0.15s ease;
}
.density-legend .marker.visible { opacity: 1; }
.density-legend .labels {
  display: flex;
  justify-content: space-between;
  width: 100%;
  margin-top: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  color: rgba(255, 255, 255, 0.5);
}

.legal-links {
  position: fixed;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  z-index: 1200;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  padding: 4px 8px;
  font-size: 11px;
  color: rgba(215, 227, 255, 0.55);
  background: rgba(11, 16, 32, 0.35);
  border: 1px solid rgba(36, 49, 103, 0.45);
  border-radius: 999px;
  backdrop-filter: blur(4px);
}

.legal-links a {
  color: inherit;
  text-decoration: none;
}

.legal-links a:hover {
  color: rgba(215, 227, 255, 0.75);
  text-decoration: underline;
}
