:root {
  --bg: #0f1419;
  --bg-panel: #1a2332;
  --bg-card: #243044;
  --border: #2d3f56;
  --text: #e8edf4;
  --text-muted: #8b9cb3;
  --accent: #3b9eff;
  --accent-hover: #5cb0ff;
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --terrain: #8b6914;
  --flight: #3b9eff;
  --waypoint: #fbbf24;
  --radius: 8px;
  --toolbar-h: 52px;
  --sidebar-w: 300px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.hidden { display: none !important; }

/* Landing */
.landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  padding: 1.5rem;
  position: relative;
  background: radial-gradient(ellipse at 50% 0%, #1a3050 0%, var(--bg) 70%);
}

.landing-brand {
  position: absolute;
  top: 2.5rem;
  left: 0;
  right: 0;
  text-align: center;
  pointer-events: none;
}

.landing-title {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.landing-tagline {
  font-size: clamp(0.9rem, 2vw, 1.1rem);
  font-weight: 400;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

.landing-card {
  text-align: center;
  padding: 3rem 2.5rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  max-width: 440px;
  width: 90%;
  box-shadow: 0 24px 48px rgba(0,0,0,.4);
}

.logo {
  margin-bottom: 1rem;
  display: flex;
  justify-content: center;
}

.logo-img {
  width: 80px;
  height: auto;
  object-fit: contain;
  display: block;
}

.landing-card h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: .5rem;
}

.subtitle {
  color: var(--text-muted);
  font-size: .9rem;
  margin-bottom: 2rem;
  line-height: 1.5;
}

.btn-import {
  display: inline-flex;
  align-items: center;
  gap: .6rem;
  padding: .85rem 1.75rem;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, transform .1s;
}

.btn-import:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.hint {
  margin-top: 1.25rem;
  font-size: .78rem;
  color: var(--text-muted);
}

/* Editor layout */
.editor {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.editor-body {
  display: flex;
  flex: 1;
  min-height: 0;
}

.editor-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  min-height: 0;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: var(--toolbar-h);
  padding: 0 1rem;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
}

.toolbar-left { justify-self: start; }
.toolbar-right { justify-self: end; }

.toolbar-center {
  justify-self: center;
  text-align: center;
  pointer-events: none;
}

.toolbar-brand {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.toolbar-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.toolbar-tagline {
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.filename {
  font-weight: 500;
  font-size: .9rem;
}

.badge {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: .2rem .6rem;
  border-radius: 20px;
  font-size: .75rem;
  color: var(--text-muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .45rem .9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text);
  font-size: .85rem;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}

.btn:hover { background: #2d4060; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-card);
  border-color: var(--text-muted);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) { background: #2d4060; }

.btn-secondary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  padding: .45rem;
}

.btn-ghost:hover { background: var(--bg-card); }

.btn-sm {
  padding: .3rem .65rem;
  font-size: .78rem;
}

.btn-accent {
  background: #1e4d2b;
  border-color: var(--success);
  color: var(--success);
}

.btn-accent.active {
  background: var(--success);
  color: #0f1419;
}

.btn-danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
  margin-top: .5rem;
}

.btn-danger:hover { background: rgba(248,113,113,.15); }

.btn-block { width: 100%; justify-content: center; margin-top: .75rem; }

.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
}

.btn-icon:hover { color: var(--text); }

/* Workspace — 3 panel grid, tinggi dinamis via CSS variables */
.workspace {
  display: grid;
  grid-template-rows: var(--row-map, 1fr) var(--row-profile, 1fr) var(--row-detail, minmax(160px, 38vh));
  flex: 1;
  min-height: 0;
  gap: 1px;
  background: var(--border);
}

.panel {
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel.panel-hidden {
  visibility: hidden;
  pointer-events: none;
}

.panel-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-body-section {
  flex: 1;
  min-height: 0;
}

.map-viewport {
  position: relative;
  flex: 1;
  min-height: 120px;
  height: 100%;
  display: flex;
}

.map-viewport #map,
.map-viewport #map-3d {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.map-viewport #map-3d {
  z-index: 2;
}

.map-layer-hidden {
  visibility: hidden !important;
  pointer-events: none !important;
  z-index: 0 !important;
}

.btn-map-3d {
  font-size: .72rem;
  font-weight: 600;
  padding: .22rem .6rem;
  color: #fbbf24;
  border-color: rgba(251, 191, 36, 0.55);
  background: rgba(251, 191, 36, 0.1);
  letter-spacing: .04em;
}

.btn-map-3d:hover:not(:disabled) {
  background: rgba(251, 191, 36, 0.2);
  border-color: #fbbf24;
}

.btn-map-3d:disabled {
  opacity: 0.5;
  cursor: wait;
}

.map-marquee,
.map-3d-marquee {
  position: absolute;
  border: 2px solid #fbbf24;
  background: rgba(251, 191, 36, 0.18);
  pointer-events: none;
  z-index: 10000;
  box-sizing: border-box;
}

.leaflet-container .map-marquee {
  z-index: 10000;
}

.map-marquee.hidden,
.map-3d-marquee.hidden {
  display: none;
}

.leaflet-container.map-marquee-drag {
  cursor: crosshair;
}

.map-viewport .cesium-viewer-infoBoxContainer,
.map-viewport .cesium-viewer-selectionIndicatorContainer {
  display: none !important;
}

.detail-panel .panel-body {
  overflow: hidden;
}

.detail-table-wrap {
  flex: 1;
  overflow: auto;
  min-height: 0;
}

/* Panel toggle */
.btn-panel-toggle {
  margin-left: .25rem;
  color: var(--text-muted);
  border-color: var(--border);
}

.btn-panel-toggle:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

/* Restore bar for hidden panels */
.panel-restore {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .35rem .75rem;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-restore.hidden {
  display: none;
}

.btn-restore {
  padding: .25rem .65rem;
  font-size: .75rem;
  background: transparent;
  border: 1px dashed var(--accent);
  border-radius: 4px;
  color: var(--accent);
  cursor: pointer;
}

.btn-restore:hover {
  background: rgba(59, 158, 255, 0.12);
}

.detail-empty {
  padding: 1.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: .85rem;
}

/* Waypoints table */
.wp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .78rem;
  white-space: nowrap;
}

.wp-table thead {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #121a26;
}

.wp-table th {
  padding: .4rem .35rem;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  text-transform: uppercase;
  font-size: .68rem;
  letter-spacing: .03em;
}

.wp-table td {
  padding: .15rem .2rem;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid rgba(45, 63, 86, 0.5);
  vertical-align: middle;
}

.wp-table tbody tr {
  cursor: pointer;
  transition: background .1s;
}

.wp-table tbody tr:hover {
  background: rgba(59, 158, 255, 0.06);
}

.wp-table tbody tr.selected {
  background: rgba(251, 191, 36, 0.12);
}

.wp-table tbody tr.row-home {
  background: rgba(59, 158, 255, 0.08);
}

.wp-table input,
.wp-table select {
  width: 100%;
  min-width: 0;
  padding: .25rem .3rem;
  background: var(--bg-card);
  border: 1px solid transparent;
  border-radius: 3px;
  color: var(--text);
  font-size: .78rem;
  font-family: inherit;
}

.wp-table input:focus,
.wp-table select:focus {
  outline: none;
  border-color: var(--accent);
  background: #1e2d42;
}

.wp-table select {
  cursor: pointer;
  padding-right: 1rem;
}

.col-calc.angle-warn,
.col-calc-wide.angle-warn {
  background: rgba(251, 191, 36, 0.35);
  color: #fde68a;
  font-weight: 600;
}

.col-calc.angle-danger,
.col-calc-wide.angle-danger {
  background: rgba(248, 113, 113, 0.4);
  color: #fecaca;
  font-weight: 600;
}

.col-idx { width: 36px; text-align: center; position: relative; }
.col-cmd { min-width: 160px; }
.col-p { min-width: 72px; }
.col-p-sm { min-width: 36px; width: 36px; max-width: 44px; }
.col-p-sm input { padding: .25rem .15rem; text-align: center; }
.col-coord { min-width: 110px; }
.col-alt { min-width: 64px; }
.col-frame { min-width: 88px; }
.col-act { width: 32px; text-align: center; }
.col-calc { min-width: 56px; text-align: right; color: var(--text-muted); padding-right: .5rem !important; }
.col-calc-wide { min-width: 84px; text-align: right; color: var(--text-muted); padding-right: .5rem !important; }

.row-marker {
  position: absolute;
  left: 2px;
  color: var(--warning);
  font-size: .6rem;
}

.btn-cell {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: pointer;
  font-size: .85rem;
  line-height: 1;
}

.btn-cell:hover:not(:disabled) {
  background: #2d4060;
  color: var(--text);
}

.btn-cell:disabled {
  opacity: 0.25;
  cursor: not-allowed;
}

.btn-del:hover:not(:disabled) {
  background: rgba(248, 113, 113, 0.2);
  color: var(--danger);
  border-color: var(--danger);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .5rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
  gap: .5rem;
}

.panel-header h2 {
  font-size: .85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
}

.panel-header-left {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.btn-reload-srtm {
  font-size: .72rem;
  padding: .22rem .55rem;
  color: var(--accent);
  border-color: rgba(59, 158, 255, 0.45);
  background: rgba(59, 158, 255, 0.08);
}

.btn-reload-srtm:hover:not(:disabled) {
  background: rgba(59, 158, 255, 0.18);
  border-color: var(--accent);
}

.btn-reload-srtm:disabled {
  opacity: 0.5;
  cursor: wait;
}

.dem-badge {
  font-size: .68rem;
  padding: .18rem .5rem;
  border-radius: 4px;
  border: 1px solid var(--success);
  color: var(--success);
  background: rgba(52, 211, 153, 0.1);
  white-space: nowrap;
}

.dem-badge.warn {
  border-color: var(--warning);
  color: var(--warning);
  background: rgba(251, 191, 36, 0.1);
}

.btn-automate {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  color: #c4b5fd;
  border-color: rgba(196, 181, 253, 0.55);
  background: rgba(139, 92, 246, 0.12);
}

.btn-automate:hover:not(:disabled) {
  background: rgba(139, 92, 246, 0.22);
  border-color: #c4b5fd;
}

.confirm-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.confirm-modal.hidden {
  display: none;
}

.confirm-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 12, 18, 0.72);
}

.confirm-modal-box {
  position: relative;
  z-index: 1;
  width: min(420px, calc(100vw - 2rem));
  padding: 1.25rem 1.35rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
}

.confirm-modal-text {
  margin: 0 0 1rem;
  font-size: .95rem;
  line-height: 1.45;
  color: var(--text);
}

.confirm-modal-field {
  margin-bottom: 1.1rem;
}

.confirm-modal-field label {
  display: block;
  font-size: .72rem;
  color: var(--text-muted);
  margin-bottom: .35rem;
  text-transform: uppercase;
  letter-spacing: .03em;
}

.confirm-modal-field input {
  width: 100%;
  padding: .5rem .65rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: .95rem;
}

.confirm-modal-field input:focus {
  outline: none;
  border-color: var(--accent);
}

.confirm-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
}

.srtm-loading-badge {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: .22rem .6rem;
  border-radius: 4px;
  border: 1px solid #fbbf24;
  white-space: nowrap;
  animation: srtm-loading-flash 0.7s step-end infinite;
}

@keyframes srtm-loading-flash {
  0%, 100% {
    color: #fbbf24;
    background: rgba(251, 191, 36, 0.18);
    border-color: #fbbf24;
  }
  50% {
    color: #f87171;
    background: rgba(248, 113, 113, 0.18);
    border-color: #f87171;
  }
}

.panel-tools {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .78rem;
  color: var(--text-muted);
  cursor: pointer;
}

.section-controls {
  gap: .5rem 1rem;
}

.control-group {
  display: flex;
  align-items: center;
  gap: .35rem;
  font-size: .75rem;
  color: var(--text-muted);
}

.control-group label { white-space: nowrap; }

.control-group input[type="range"] {
  width: 70px;
  accent-color: var(--accent);
}

.control-group select {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: .25rem .5rem;
  border-radius: 4px;
  font-size: .78rem;
  max-width: 200px;
}

.mission-stats {
  font-size: .75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.legend-hint {
  margin-left: auto;
  font-size: .72rem;
  color: var(--accent);
  font-style: italic;
}

.section-canvas-wrap {
  flex: 1;
  position: relative;
  min-height: 220px;
  overflow: hidden;
  cursor: default;
}
.section-canvas-wrap.panning { cursor: grab; }
.section-canvas-wrap.panning:active { cursor: grabbing; }
.section-canvas-wrap.marquee-drag { cursor: crosshair; }

#section-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.section-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(15,20,25,.92);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .4rem .65rem;
  font-size: .75rem;
  white-space: nowrap;
  z-index: 10;
}

.section-context-menu {
  position: fixed;
  z-index: 200;
  min-width: 180px;
  background: #1a2433;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .35rem 0;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.section-context-menu.hidden {
  display: none;
}

.section-context-item {
  display: block;
  width: 100%;
  padding: .5rem 1rem;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-align: left;
  cursor: pointer;
}

.section-context-item:hover {
  background: rgba(59, 158, 255, 0.12);
  color: var(--accent);
}

.section-legend {
  display: flex;
  gap: 1.25rem;
  padding: .4rem 1rem;
  border-top: 1px solid var(--border);
  font-size: .72rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: .35rem;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.dot.terrain { background: #a0782c; }
.dot.flight { background: var(--flight); }
.dot.angle-warn { background: #fbbf24; }
.dot.angle-danger { background: #f87171; }
.dot.waypoint { background: var(--waypoint); }
.dot.agl { background: rgba(52,211,153,.4); border: 1px solid var(--success); }

/* Sidebar — kolom permanen di kanan */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.5;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h3 { font-size: .95rem; }

.sidebar-header #sel-index {
  display: inline;
  font-weight: 600;
  color: var(--accent);
  word-break: break-word;
}

.sidebar-body {
  padding: 1rem;
  overflow-y: auto;
  flex: 1;
}

.field {
  margin-bottom: .85rem;
}

.field label {
  display: block;
  font-size: .72rem;
  color: var(--text-muted);
  margin-bottom: .3rem;
  text-transform: uppercase;
  letter-spacing: .03em;
}

.field input {
  width: 100%;
  padding: .45rem .6rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: .85rem;
}

.field input:focus {
  outline: none;
  border-color: var(--accent);
}

.field-hint {
  display: block;
  margin-top: .25rem;
  font-size: .68rem;
  color: var(--text-muted);
  line-height: 1.3;
}

.field.readonly span {
  font-size: .9rem;
  font-weight: 500;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: .65rem 1.25rem;
  border-radius: var(--radius);
  font-size: .85rem;
  z-index: 9999;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  transition: opacity .3s;
}

.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }

/* Leaflet overrides */
.leaflet-container { background: #1a2332; font-family: inherit; }

@media (max-width: 768px) {
  .editor-body { flex-direction: column; }
  .sidebar { width: 100%; max-height: 42vh; border-left: none; border-top: 1px solid var(--border); }
  .section-controls { width: 100%; }
}
