*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #0f1117;
  color: #e2e8f0;
  overflow: hidden;
}

/* ── Login overlay ── */
#login-overlay {
  position: fixed;
  inset: 0;
  background: #0f1117;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

#login-box {
  background: #1a1d27;
  border: 1px solid #2d3148;
  border-radius: 16px;
  padding: 40px 44px;
  width: 340px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}

#login-box h2 {
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 6px;
}

#login-subtitle {
  font-size: 13px;
  color: #64748b;
  text-align: center;
  margin-bottom: 28px;
}

#login-form .field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

#login-form label {
  font-size: 12px;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#login-form input {
  background: #0f1117;
  border: 1px solid #2d3148;
  border-radius: 8px;
  color: #e2e8f0;
  font-size: 14px;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.15s;
}

#login-form input:focus { border-color: #3b5bdb; }

#login-error {
  font-size: 12px;
  color: #f87171;
  margin-bottom: 12px;
  text-align: center;
}

#login-submit {
  width: 100%;
  padding: 11px;
  background: #3b5bdb;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
  transition: background 0.15s;
}
#login-submit:hover { background: #4c6ef5; }
#login-submit:disabled { background: #334155; cursor: not-allowed; }

/* ── App wrapper ── */
#app {
  display: flex;
  height: 100vh;
  width: 100%;
}
#app.hidden { display: none; }
#login-overlay.hidden { display: none; }
#login-error.hidden { display: none; }

/* ── Layout ── */
#map {
  flex: 1;
  height: 100vh;
}

/* ── Sidebar ── */
#sidebar {
  width: 280px;
  min-width: 280px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #1a1d27;
  border-right: 1px solid #2d3148;
  transition: width 0.25s ease, min-width 0.25s ease;
  overflow: hidden;
  z-index: 10;
}

#sidebar.closed {
  width: 40px;
  min-width: 40px;
}

#sidebar.closed #sidebar-body { display: none; }

#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid #2d3148;
  flex-shrink: 0;
}

#sidebar-header h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

#sidebar.closed #sidebar-header h1 { display: none; }

#sidebar-toggle {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color 0.15s;
  flex-shrink: 0;
}
#sidebar-toggle:hover { color: #e2e8f0; }
#sidebar.closed #sidebar-toggle { transform: scaleX(-1); }

#sidebar-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 14px;
  overflow-y: auto;
}

/* ── Upload button ── */
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  background: #3b5bdb;
  color: #fff;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
  white-space: nowrap;
}
.btn-primary:hover { background: #4c6ef5; }

/* ── Dataset list ── */
#dataset-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dataset-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #23263a;
  border-radius: 8px;
  padding: 8px 10px;
  border: 1px solid #2d3148;
}

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

.ds-info {
  flex: 1;
  min-width: 0;
}

.ds-name {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ds-count {
  font-size: 11px;
  color: #64748b;
  margin-top: 1px;
}

.ds-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.ds-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 3px;
  border-radius: 4px;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.15s, background 0.15s;
  color: #94a3b8;
}
.ds-btn:hover { opacity: 1; background: #2d3148; }
.ds-btn.hidden-ds { opacity: 0.35; }

.hint {
  font-size: 11px;
  color: #475569;
  line-height: 1.5;
}

#sidebar-footer { margin-top: auto; }

/* ── Resolution badge ── */
#res-badge {
  position: fixed;
  top: 14px;
  right: 14px;
  background: rgba(26, 29, 39, 0.9);
  border: 1px solid #2d3148;
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  color: #e2e8f0;
  z-index: 20;
  backdrop-filter: blur(6px);
  pointer-events: none;
}

#res-value {
  color: #60a5fa;
  font-weight: 700;
}

/* ── Tooltip ── */
#tooltip {
  position: fixed;
  background: rgba(15, 17, 23, 0.95);
  border: 1px solid #3b5bdb;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  line-height: 1.6;
  color: #e2e8f0;
  z-index: 30;
  pointer-events: none;
  max-width: 220px;
  backdrop-filter: blur(4px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
#tooltip.hidden { display: none; }
#tooltip strong { color: #93c5fd; }

/* ── Column mapping modal ── */
#col-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
#col-modal.hidden { display: none; }

#col-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(3px);
}

#col-box {
  position: relative;
  background: #1a1d27;
  border: 1px solid #2d3148;
  border-radius: 14px;
  width: 560px;
  max-width: calc(100vw - 32px);
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
  overflow: hidden;
}

#col-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid #2d3148;
}

#col-title {
  font-size: 15px;
  font-weight: 700;
}

#col-filename {
  font-size: 12px;
  color: #64748b;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Preview table */
#col-preview-wrap {
  padding: 12px 20px;
  overflow-x: auto;
  border-bottom: 1px solid #2d3148;
  max-height: 130px;
}

#col-preview {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  white-space: nowrap;
}

#col-preview th {
  background: #23263a;
  color: #94a3b8;
  font-weight: 600;
  padding: 4px 10px;
  text-align: left;
  border-bottom: 1px solid #2d3148;
}

#col-preview td {
  color: #cbd5e1;
  padding: 3px 10px;
  border-bottom: 1px solid #1e2133;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Column selectors */
#col-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 16px 20px;
}

.col-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.col-field label {
  font-size: 12px;
  font-weight: 600;
  color: #94a3b8;
  display: flex;
  align-items: center;
  gap: 6px;
}

.col-field .req {
  font-size: 10px;
  background: #3b5bdb33;
  color: #93c5fd;
  padding: 1px 5px;
  border-radius: 4px;
  font-weight: 500;
}

.col-field .opt {
  font-size: 10px;
  background: #10b98122;
  color: #6ee7b7;
  padding: 1px 5px;
  border-radius: 4px;
  font-weight: 500;
}

.col-field select {
  background: #0f1117;
  border: 1px solid #2d3148;
  border-radius: 8px;
  color: #e2e8f0;
  font-size: 13px;
  padding: 8px 10px;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
}
.col-field select:focus { border-color: #3b5bdb; }

#col-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid #2d3148;
}

#col-cancel {
  background: none;
  border: 1px solid #2d3148;
  color: #94a3b8;
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
#col-cancel:hover { border-color: #94a3b8; color: #e2e8f0; }

#col-confirm {
  background: #3b5bdb;
  border: none;
  color: #fff;
  padding: 8px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
#col-confirm:hover { background: #4c6ef5; }

/* ── MapLibre overrides ── */
.maplibregl-ctrl-attrib { display: none; }
.maplibregl-ctrl-bottom-left { display: none; }
