:root {
  --sidebar-width: 460px;
  --bg: #eef3f8;
  --panel-bg: #ffffff;
  --text: #152238;
  --muted: #66758a;
  --border: #d9e2ec;
  --brand: #2563eb;
  --secondary: #64748b;
  --green: #2f7667;
  --cyan: #0e7490;
  --shadow: 0 10px 28px rgba(15, 23, 42, 0.18);
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body, #app {
  margin: 0;
  width: 100%;
  height: 100%;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

#app {
  display: flex;
  position: relative;
}

#sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  background: #f8fafc;
  border-right: 1px solid var(--border);
  padding: 14px 16px 18px;
  overflow-y: auto;
  z-index: 700;
  box-shadow: 4px 0 18px rgba(15, 23, 42, 0.10);
  transition: transform 0.25s ease;
}

body.sidebar-collapsed #sidebar {
  transform: translateX(calc(-1 * var(--sidebar-width)));
}

#map {
  flex: 1;
  height: 100vh;
  z-index: 1;
}

.app-title {
  padding: 14px 8px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.app-title-logo {
  display: flex;
  gap: 13px;
  align-items: center;
}

.app-logo {
  width: 68px;
  height: 68px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.10);
}

.app-title h1 {
  font-size: 20px;
  line-height: 1.22;
  margin: 0 0 7px;
  font-weight: 800;
}

.app-title p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

.section {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
}

.section h2 {
  margin: 0 0 12px;
  font-size: 17px;
  font-weight: 800;
}

.publish-note {
  background: #f0f9ff;
  border-left: 4px solid #0ea5e9;
  color: #075985;
  line-height: 1.45;
}

.publish-note strong,
.publish-note span {
  display: block;
}

.publish-note span {
  margin-top: 4px;
  font-size: 13px;
}

label {
  display: block;
  margin: 9px 0 5px;
  font-size: 14px;
  color: #1e293b;
}

.input-full, select, input {
  width: 100%;
  min-height: 38px;
  border: 1px solid #cfd8e3;
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
  font-size: 14px;
  color: var(--text);
  outline: none;
}

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

.search-hint,
.small-note {
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

button {
  font-family: inherit;
}

#btnSearchData {
  width: 100%;
  margin-top: 12px;
  border: 0;
  border-radius: 8px;
  background: #4f63e6;
  color: white;
  padding: 11px 12px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}

#btnSearchData:hover {
  background: #3549ca;
}

.btn-secondary {
  width: 100%;
  margin-top: 8px;
  border: 0;
  border-radius: 8px;
  background: #707b90;
  color: white;
  padding: 11px 12px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}

.btn-export {
  background: #3f7f72;
}

.dashboard-summary,
.result-summary {
  background: #eef6ff;
  border: 1px solid #dbeafe;
  border-radius: 10px;
  padding: 10px;
  font-size: 14px;
  line-height: 1.45;
  margin-bottom: 8px;
}

.dashboard-cards,
.stat-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.dashboard-card,
.stat-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
}

.dashboard-card span,
.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.dashboard-card strong,
.stat-card strong {
  font-size: 18px;
  color: #0f172a;
}

.result-tabs {
  display: flex;
  gap: 6px;
  margin: 10px 0;
}

.tab-btn {
  flex: 1;
  border: 1px solid var(--border);
  background: #f8fafc;
  color: #334155;
  border-radius: 999px;
  padding: 8px 10px;
  font-weight: 700;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
}

.result-content {
  margin-top: 10px;
}

.result-block {
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 10px;
  margin-bottom: 10px;
  background: #ffffff;
}

.result-block h3 {
  margin: 0 0 8px;
  font-size: 16px;
  color: #0f172a;
}

.meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.meta-item {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  min-width: 0;
}

.meta-item span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 3px;
}

.meta-item strong {
  font-size: 14px;
  overflow-wrap: anywhere;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  margin: 2px 4px 2px 0;
  background: #e0f2fe;
  border: 1px solid #bae6fd;
  color: #075985;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.badge.type-lohong { background: #dbeafe; border-color: #bfdbfe; color: #1d4ed8; }
.badge.type-khenut-lohong { background: #ccfbf1; border-color: #99f6e4; color: #0f766e; }
.badge.type-khenut { background: #ede9fe; border-color: #ddd6fe; color: #6d28d9; }
.badge.type-karst { background: #ffedd5; border-color: #fed7aa; color: #c2410c; }

.table-wrap {
  max-height: 420px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-top: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: white;
}

th {
  position: sticky;
  top: 0;
  background: #f1f5f9;
  z-index: 1;
  text-align: left;
  color: #0f172a;
  border-bottom: 1px solid var(--border);
  padding: 8px;
}

td {
  border-bottom: 1px solid #eef2f7;
  padding: 8px;
  vertical-align: top;
  line-height: 1.35;
}

td.num {
  text-align: right;
  white-space: nowrap;
}

details {
  max-width: 520px;
}

details summary {
  cursor: pointer;
  color: #2563eb;
  font-weight: 700;
}

.detail-text {
  margin-top: 6px;
  white-space: pre-line;
  color: #334155;
}

.empty {
  color: var(--muted);
  font-style: italic;
  padding: 10px 0;
}

.sidebar-collapse {
  position: absolute;
  left: var(--sidebar-width);
  top: 50%;
  transform: translateY(-50%);
  z-index: 850;
  width: 30px;
  height: 58px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.88);
  border-radius: 0 12px 12px 0;
  box-shadow: var(--shadow);
  font-size: 28px;
  color: #64748b;
  cursor: pointer;
  transition: left 0.25s ease, transform 0.25s ease;
}

body.sidebar-collapsed .sidebar-collapse {
  left: 0;
  transform: translateY(-50%) rotate(180deg);
}

#authPanel {
  position: absolute;
  top: 14px;
  right: 18px;
  z-index: 800;
  background: rgba(255,255,255,0.92);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 10px;
  backdrop-filter: blur(6px);
}

.auth-buttons-row {
  display: flex;
  gap: 8px;
}

.auth-btn {
  border: 0;
  border-radius: 8px;
  background: #4f63e6;
  color: white;
  font-weight: 800;
  padding: 9px 14px;
  cursor: pointer;
}

.auth-btn-secondary {
  background: #64748b;
}

.auth-status {
  margin-top: 8px;
  font-size: 12px;
  color: #475569;
  max-width: 240px;
}

#mapInfoBox {
  position: absolute;
  left: calc(var(--sidebar-width) + 22px);
  top: 18px;
  z-index: 790;
  max-width: 380px;
  background: rgba(255,255,255,0.94);
  border: 1px solid var(--border);
  border-left: 4px solid #0ea5e9;
  border-radius: 12px;
  padding: 11px 13px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}

body.sidebar-collapsed #mapInfoBox {
  left: 48px;
}

#mapInfoBox strong,
#mapInfoBox span {
  display: block;
}

#mapInfoBox span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.38;
}

#mapLegendDock {
  position: absolute;
  right: 18px;
  bottom: 20px;
  z-index: 820;
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

#btnToggleLegend {
  border: 1px solid #94a3b8;
  background: rgba(255,255,255,0.96);
  color: #0f172a;
  border-radius: 12px;
  padding: 12px 22px;
  font-weight: 800;
  box-shadow: var(--shadow);
  cursor: pointer;
}

#mapLayerPanel {
  width: 292px;
  max-height: 70vh;
  overflow-y: auto;
  background: rgba(255,255,255,0.97);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}

#mapLayerPanel.hidden, .hidden {
  display: none !important;
}

#legendContent label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
  font-size: 14px;
  cursor: pointer;
}

#legendContent input[type="checkbox"],
#legendContent input[type="radio"] {
  width: auto;
  min-height: auto;
}

.map-layer-subtitle {
  margin: 13px 0 7px;
  padding-top: 9px;
  border-top: 1px solid var(--border);
  font-weight: 800;
  color: #1e293b;
  font-size: 14px;
}

.map-layer-subtitle-first {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 7px 0;
  font-size: 14px;
}

.legend-swatch {
  width: 20px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,0.22);
}

.legend-lohong { background: #bfdbfe; }
.legend-khenut-lohong { background: #99f6e4; }
.legend-khenut { background: #c4b5fd; }
.legend-karst { background: #fdba74; }

.mobile-panel-toggle,
.mobile-sidebar-close {
  display: none;
}

@media (max-width: 980px) {
  #app {
    display: block;
  }

  #sidebar {
    position: absolute;
    width: min(94vw, 460px);
    transform: translateX(-105%);
    height: 100vh;
    left: 0;
    top: 0;
  }

  body.mobile-sidebar-open #sidebar {
    transform: translateX(0);
  }

  body.sidebar-collapsed #sidebar {
    transform: translateX(-105%);
  }

  #map {
    width: 100%;
    height: 100vh;
  }

  .sidebar-collapse {
    display: none;
  }

  .mobile-panel-toggle {
    display: block;
    position: absolute;
    left: 12px;
    bottom: 18px;
    z-index: 840;
    border: 0;
    border-radius: 12px;
    background: #4f63e6;
    color: #fff;
    font-weight: 800;
    padding: 12px 17px;
    box-shadow: var(--shadow);
  }

  .mobile-sidebar-close {
    display: block;
    width: 100%;
    margin: 0 0 10px;
    border: 0;
    border-radius: 8px;
    background: #64748b;
    color: #fff;
    padding: 9px;
    font-weight: 800;
  }

  #authPanel {
    top: 10px;
    right: 10px;
    padding: 8px;
  }

  .auth-btn {
    padding: 8px 10px;
    font-size: 13px;
  }

  #mapInfoBox {
    left: 10px;
    top: 78px;
    max-width: min(86vw, 360px);
  }

  #mapLegendDock {
    right: 10px;
    bottom: 72px;
  }

  #mapLayerPanel {
    width: min(82vw, 292px);
  }

  .meta-grid,
  .dashboard-cards,
  .stat-cards {
    grid-template-columns: 1fr;
  }
}


/* =========================
   GIS boundary module - v4
   ========================= */
.gis-section code {
  font-size: 12px;
  color: #075985;
  background: #e0f2fe;
  padding: 1px 4px;
  border-radius: 4px;
}

.selected-area-box {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-left: 4px solid #22c55e;
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 10px;
  line-height: 1.45;
}

.selected-area-box strong,
.selected-area-box span {
  display: block;
}

.selected-area-box span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.gis-layer-status {
  margin-top: 10px;
  padding: 10px;
  border: 1px dashed #94a3b8;
  background: #f8fafc;
  border-radius: 10px;
  color: #334155;
  font-size: 13px;
  line-height: 1.4;
}

.btn-gis {
  background: #0f766e;
}

.btn-gis:hover {
  background: #115e59;
}

.gis-popup-title {
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 6px;
}

.gis-popup-row {
  margin: 4px 0;
  line-height: 1.35;
}

.gis-label {
  background: rgba(255,255,255,0.86);
  border: 1px solid rgba(15,23,42,0.18);
  color: #0f172a;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 800;
  box-shadow: 0 1px 4px rgba(15,23,42,0.18);
}

.analysis-note {
  padding: 10px;
  margin: 8px 0;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-left: 4px solid #f97316;
  border-radius: 10px;
  color: #7c2d12;
  font-size: 13px;
  line-height: 1.45;
}

.analysis-ok {
  padding: 10px;
  margin: 8px 0;
  background: #ecfdf5;
  border: 1px solid #bbf7d0;
  border-left: 4px solid #22c55e;
  border-radius: 10px;
  color: #166534;
  font-size: 13px;
  line-height: 1.45;
}

.gis-pill-list {
  margin-top: 8px;
}

.layer-status-line {
  margin: 3px 0;
}


/* ===============================
   Bổ sung v6: lưu lớp GIS vào CSDL
   =============================== */
.db-box {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid #dbe6f3;
  border-radius: 12px;
  background: #f8fbff;
}

.db-box h3 {
  margin: 0 0 10px;
  font-size: 15px;
  color: #1f3b73;
}

.db-layer-legend-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.db-layer-legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  line-height: 1.3;
}

.db-layer-legend-item input {
  width: auto;
}

.small-muted {
  font-size: 12px;
  color: #6b7280;
  line-height: 1.35;
}

.db-status-ok {
  color: #047857;
}

.db-status-error {
  color: #b91c1c;
}

.db-status-warn {
  color: #b45309;
}
