:root {
  --bg-app: #f1f5f9;
  --bg-sidebar: #0f172a;
  --bg-input: #1e293b;
  --text-main: #334155;
  --text-muted: #64748b;
  --text-light: #f1f5f9;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --border-light: #e2e8f0;
  --border-dark: #334155;
  --font-ui: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --sidebar-width: 340px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-ui);
  background: var(--bg-app);
  height: 100vh;
  overflow: hidden;
  color: var(--text-main);
  display: flex;
  flex-direction: column;
}

.site-header {
  flex-shrink: 0;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(44,90,160,0.08);
  z-index: 100;
}

.main-nav {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  gap: 1rem;
}

.brand a {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  color: #173765;
  font-weight: 800;
  text-decoration: none;
}

.brand-logo-img {
  width: 24px;
  height: 24px;
  object-fit: contain;
  border-radius: 7px;
  background: #fff;
  border: 1px solid rgba(44,90,160,0.12);
  padding: 1px;
  box-shadow: 0 2px 8px rgba(44,90,160,0.08);
}

.nav-menu {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  list-style: none;
}

.nav-menu a {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0.45rem 0.75rem;
  border-radius: 10px;
  color: #64748b;
  font-weight: 500;
  text-decoration: none;
  transition: color 0.2s, background 0.2s;
}

.nav-menu a:hover,
.nav-menu a[aria-current="page"] {
  color: #173765;
  background: rgba(44,90,160,0.05);
}

.app-layout {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  color: var(--text-light);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid var(--border-dark);
  z-index: 20;
  overflow-y: auto;           
}

.brand-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-dark);
  background: rgba(0,0,0,0.2);
}

.logo {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
  color: white;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo small {
  background: var(--primary);
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 4px;
}

.sidebar-scroll {
  flex: 1;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  overflow-y: auto;
}

.control-group { display: flex; flex-direction: column; gap: 0.5rem; }

.group-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  font-weight: 600;
  color: #94a3b8;
  letter-spacing: 0.05em;
}

.input-dark {
  background: var(--bg-input);
  border: 1px solid var(--border-dark);
  color: #f8fafc;
  padding: 0.6rem;
  border-radius: 6px;
  width: 100%;
  font-family: var(--font-ui);
  font-size: 0.85rem;
}
.input-dark:focus { border-color: var(--primary); outline: none; }

select.input-dark { color-scheme: dark; }
select.input-dark option,
select.input-dark optgroup {
  color: #0f172a;
  background: #ffffff;
}

.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  background: rgba(255,255,255,0.03);
  padding: 0.8rem;
  border-radius: 6px;
  border: 1px solid var(--border-dark);
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.85rem;
  cursor: pointer;
  color: #cbd5e1;
}

.hint-text {
  font-size: 0.78rem;
  color: #a8b3c7;
  line-height: 1.35;
}

.flex-grow { flex: 1; display: flex; flex-direction: column; }

.group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.group-actions button {
  background: none;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  padding: 4px;
  transition: color 0.2s;
}
.group-actions button:hover { color: white; }

.drop-zone {
  border: 1px dashed var(--border-dark);
  border-radius: 6px;
  padding: 0.75rem;
  text-align: center;
  font-size: 0.82rem;
  cursor: pointer;
  background: rgba(255,255,255,0.03);
  color: #cbd5e1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  transition: all 0.2s;
}
.drop-zone:hover { border-color: #cbd5e1; color: white; }

.editor-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-input);
  border: 1px solid var(--border-dark);
  border-radius: 6px;
  min-height: 200px;
  overflow: hidden;
}

.code-editor {
  flex: 1;
  background: transparent;
  border: none;
  color: #e2e8f0;
  padding: 0.8rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  resize: none;
  outline: none;
  white-space: pre;
}

.status-bar {
  background: rgba(0,0,0,0.3);
  padding: 4px 8px;
  font-size: 0.72rem;
  text-align: right;
  color: #94a3b8;
  border-top: 1px solid var(--border-dark);
}

.sidebar-footer {
  padding: 1.25rem 1.5rem;
  border-top: 1px solid var(--border-dark);
  background: rgba(0,0,0,0.2);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  flex-shrink: 0;
}

.method-info {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border-dark);
  border-left: 3px solid var(--primary);
  padding: 0.75rem;
  border-radius: 4px;
}

.method-header {
  display: flex;
  gap: 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #d7deea;
  margin-bottom: 4px;
}
.method-header i { color: var(--primary); }

#methodDescription {
  font-size: 0.78rem;
  color: #b8c2d6;
  line-height: 1.45;
}

.btn-primary {
  width: 100%;
  padding: 0.85rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 6px;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-primary:hover { background: var(--primary-hover); }

.viewport {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: white;
  position: relative;
  min-width: 0;               
}

.toolbar {
  height: 56px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1.5rem;
  background: white;
  z-index: 10;
  flex-shrink: 0;
}

.breadcrumbs {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
  display: flex;
  align-items: center;
}
.breadcrumbs i { color: #10b981; margin-right: 8px; }
.divider { margin: 0 0.8rem; color: var(--border-light); }

.toolbar-actions { display: flex; gap: 0.75rem; align-items: center; }

.btn-ghost {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
}

.btn-secondary {
  background: white;
  border: 1px solid var(--border-light);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
}

.dropdown { position: relative; }
.dropdown-menu {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  background: white;
  border: 1px solid var(--border-light);
  box-shadow: 0 10px 24px rgba(0,0,0,0.10);
  border-radius: 10px;
  padding: 6px;
  width: 170px;
  z-index: 50;
}
.dropdown:hover .dropdown-menu { display: block; }
.dropdown-menu a {
  display: block;
  padding: 9px 10px;
  text-decoration: none;
  color: var(--text-main);
  font-size: 0.85rem;
  cursor: pointer;
  border-radius: 8px;
}
.dropdown-menu a:hover { background: #f8fafc; color: var(--primary); }

.workspace {
  flex: 1;
  position: relative;
  background-color: #f8fafc;
  overflow: hidden;
  background-image:
    linear-gradient(var(--border-light) 1px, transparent 1px),
    linear-gradient(90deg, var(--border-light) 1px, transparent 1px);
  background-size: 40px 40px;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.map-search {
  position: absolute;
  top: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  width: min(380px, 86%);
  font-family: var(--font-ui);
}

.map-search-input-wrap {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 0.6rem 0.9rem;
  box-shadow: 0 4px 14px rgba(15,23,42,0.12);
}

.map-search-input-wrap i.fa-magnifying-glass {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.map-search-input-wrap input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  color: var(--text-main);
}

.map-search-clear {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.2rem;
  display: flex;
  align-items: center;
  font-size: 0.75rem;
}
.map-search-clear:hover { color: var(--text-main); }

.map-search-results {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0.3rem;
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: 10px;
  box-shadow: 0 10px 24px rgba(15,23,42,0.14);
  max-height: 280px;
  overflow-y: auto;
  display: none;
}
.map-search-results.open { display: block; }

.map-search-result {
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.map-search-result:hover,
.map-search-result.active { background: #f1f5f9; }
.map-search-result .result-name {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-main);
}
.map-search-result .result-detail {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.map-search-status {
  padding: 0.6rem 0.7rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.map-search-attribution {
  font-size: 0.62rem;
  color: var(--text-muted);
  text-align: right;
  padding: 0.3rem 0.5rem 0.15rem;
  border-top: 1px solid var(--border-light);
  margin-top: 0.2rem;
}

/* Numbered vertex labels shown on the confirmed/calculated polygon so the
   point order (winding) can be visually verified against the pasted list. */
.vertex-label {
  background: #2563eb;
  color: #ffffff;
  border: 2px solid #ffffff;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-ui);
  font-size: 0.68rem;
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(15,23,42,0.35);
  pointer-events: none;
}

@media (max-width: 640px) {
  .map-search { width: 92%; top: 0.85rem; }

  /* The full-width search bar sits above the map's stacking context and was
     covering the Leaflet.draw toolbar (polygon / edit / delete) in the
     top-left corner. Push the top-left control stack down so it starts
     just beneath the search bar instead of underneath it. */
  .leaflet-top.leaflet-left { top: 3.5rem; }
}

.hud-container {
  position: absolute;
  top: 1.5rem;
  left: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  z-index: 10;
  pointer-events: none;
  max-width: 320px;            
}

.hud-container::before {
  content: "";
  position: absolute;
  inset: -0.5rem;
  background: rgba(255,255,255,0.6);
  backdrop-filter: blur(6px);
  border-radius: 12px;
  z-index: -1;
  pointer-events: none;
}

.hud-card {
  background: #ffffff;
  border: 1px solid var(--border-light);
  padding: 0.85rem 1rem;
  border-radius: 10px;
  min-width: 240px;
  box-shadow: 0 4px 12px rgba(15,23,42,0.06);
  pointer-events: auto;
  border-left: 4px solid transparent;
  position: relative;
}

.hud-card.primary { border-left-color: var(--primary); }
.hud-card.geodesic { border-left-color: #0f172a; }
.hud-card.ground { border-left-color: #334155; }

.hud-card .label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  font-weight: 800;
  color: var(--text-muted);
  margin-bottom: 3px;
  letter-spacing: 0.05em;
}
.hud-card .value {
  font-size: 1.5rem;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--text-main);
  line-height: 1.1;
}
.hud-card .unit {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 600;
}
.hud-card .sub-value {
  border-top: 1px solid var(--border-light);
  margin-top: 7px;
  padding-top: 6px;
  font-size: 0.78rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.hud-footnote {
  pointer-events: auto;
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  box-shadow: 0 4px 12px rgba(15,23,42,0.06);
  font-size: 0.78rem;
  color: #475569;
  line-height: 1.35;
}
.hud-footnote b { color: #0f172a; }

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  pointer-events: none;
}
.empty-state i { font-size: 3rem; margin-bottom: 1rem; opacity: 0.22; }

#resultsContainer {
  display: none;
}

.bottom-panel {
  height: 260px;
  border-top: 1px solid var(--border-light);
  background: white;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.panel-header {
  padding: 0.8rem 1.5rem;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  background: #f8fafc;
}
.panel-header h3 {
  margin: 0;
  font-size: 0.8rem;
  text-transform: uppercase;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--text-main);
}

.table-wrapper { overflow: auto; flex: 1; }

table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }

th {
  text-align: left;
  padding: 10px 1.5rem;
  background: white;
  position: sticky;
  top: 0;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-muted);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.72rem;
}

td {
  padding: 8px 1.5rem;
  border-bottom: 1px solid var(--border-light);
  font-family: var(--font-mono);
  color: var(--text-main);
}

tfoot td {
  background: #f1f5f9;
  border-top: 2px solid var(--border-light);
}

.loader-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.82);
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: center;
}
.loader {
  width: 40px;
  height: 40px;
  border: 4px solid var(--primary);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.site-footer {
  flex-shrink: 0;
  background: linear-gradient(180deg, #1c3158 0%, #182b4d 100%);
  color: #e7eef8;
  border-top: 1px solid rgba(255,255,255,0.05);
  font-size: 0.85rem;
  padding: 0.75rem 1.5rem;
}

.site-footer .container {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.footer-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-weight: 600;
  color: white;
}
.footer-brand img {
  width: 20px;
  height: 20px;
  object-fit: contain;
  border-radius: 4px;
  background: #fff;
  padding: 1px;
}

.footer-links {
  display: flex;
  gap: 1.2rem;
  color: #d7e2f0;
}
.footer-links a {
  color: inherit;
  text-decoration: none;
}
.footer-links a:hover { text-decoration: underline; }

.footer-bottom {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(255,255,255,0.07);
  font-size: 0.75rem;
  color: #cbd7e8;
}

.row { display: flex; gap: 0.5rem; width: 100%; }
.gap-2 { gap: 0.5rem; }
.bold { font-weight: 700; }
.text-right { text-align: right; }

.custom-scrollbar::-webkit-scrollbar { width: 6px; height: 6px; }
.custom-scrollbar::-webkit-scrollbar-thumb { background: var(--border-dark); border-radius: 3px; }
.custom-scrollbar::-webkit-scrollbar-track { background: transparent; }
.table-wrapper::-webkit-scrollbar-thumb { background: #cbd5e1; }

@media (max-width: 1024px) {
  .app-layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    max-height: 40vh;
    overflow-y: auto;
    border-right: none;
    border-bottom: 1px solid var(--border-dark);
  }

  .sidebar-scroll {
    padding: 1rem;
  }

  .viewport {
    flex: 1;
    min-height: 50vh;
  }

  .bottom-panel {
    height: auto;
    max-height: 30vh;
  }

  .hud-container {
    position: static;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 1rem;
    width: 100%;
    max-width: none;
  }

  .hud-container::before {
    display: none;   
  }

  .hud-card {
    width: 100%;
  }

  .workspace {
    background: white;   
  }
}

@media (max-width: 768px) {
  .sidebar {
    max-height: 35vh;
  }

  .hud-container {
    padding: 0.75rem;
  }
}