/* ============================================
   LEFT PANEL
   ============================================ */
.left-panel {
  width: 320px;
  min-width: 320px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.3s, min-width 0.3s;
}

.left-panel.collapsed {
  width: 0;
  min-width: 0;
  border-right: none;
}

.panel-section {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.panel-section-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 8px;
}

/* Search */
.search-wrapper { position: relative; }

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 14px;
}

.search-box {
  width: 100%;
  padding: 9px 12px 9px 34px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  outline: none;
}

.search-box:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Layer controls */
.layer-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.layer-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
}

.layer-item:hover { background: var(--bg-card); }

.layer-color {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.08);
}

.layer-color.line-style {
  height: 3px;
  border-radius: 2px;
}

.layer-toggle {
  width: 28px;
  height: 16px;
  background: var(--bg-card);
  border-radius: 8px;
  position: relative;
  cursor: pointer;
  margin-left: auto;
  border: 1px solid var(--border);
  flex-shrink: 0;
  transition: background 0.2s;
}

.layer-toggle.active {
  background: var(--accent);
  border-color: var(--accent);
}

.layer-toggle::after {
  content: '';
  position: absolute;
  width: 10px;
  height: 10px;
  background: white;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: transform 0.2s;
}

.layer-toggle.active::after {
  transform: translateX(12px);
}

/* Predio list */
.predio-list-header {
  padding: 10px 16px 6px;
}

.predio-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 8px;
}

.predio-list::-webkit-scrollbar { width: 4px; }
.predio-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.predio-card {
  padding: 8px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 7px;
  margin-bottom: 5px;
  cursor: pointer;
  transition: all 0.15s;
}

.predio-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
}

.predio-card.active {
  background: var(--accent-glow);
  border-color: var(--accent);
}

.predio-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 3px;
}

.predio-code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}

.predio-status {
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
}

.predio-name {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================
   MAP
   ============================================ */
#map {
  flex: 1;
  background: var(--bg-dark);
}

/* ============================================
   MAP CONTROLS
   ============================================ */
.basemap-switcher {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  display: flex;
  gap: 4px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
}

.basemap-btn {
  padding: 6px 12px;
  font-size: 11px;
  font-family: 'DM Sans', sans-serif;
  font-weight: 500;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 5px;
}

.basemap-btn.active {
  background: var(--accent);
  color: white;
}

.panel-toggle {
  position: fixed;
  top: 62px;
  left: 330px;
  z-index: 10;
  width: 34px;
  height: 34px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: left 0.3s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.left-panel.collapsed ~ .panel-toggle,
.main-container:has(.left-panel.collapsed) .panel-toggle {
  left: 10px;
}

.mobile-overlay {
  display: none;
}

/* ============================================
   MEASUREMENT TOOL
   ============================================ */
.measure-control {
  position: absolute;
  bottom: 95px;
  right: 10px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.measure-btn {
  width: 32px;
  height: 32px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition: all 0.15s;
}

.measure-btn:first-child { border-radius: 8px 8px 0 0; }
.measure-btn:last-child { border-radius: 0 0 8px 8px; }
.measure-btn:only-child { border-radius: 8px; }
.measure-btn:hover { background: var(--bg-card); color: var(--text-primary); }
.measure-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

.measure-tooltip {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--text-primary);
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.measure-result {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 16px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  color: var(--text-primary);
  display: none;
  gap: 16px;
  align-items: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}

.measure-result.visible { display: flex; }
.measure-result-label { color: var(--text-muted); font-size: 11px; font-family: 'DM Sans', sans-serif; }
.measure-result-value { color: var(--accent); font-weight: 600; }
.measure-result-close {
  margin-left: 8px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 14px;
}
.measure-result-close:hover { color: var(--text-primary); }

/* ============================================
   RIGHT PANEL (Detail)
   ============================================ */
.right-panel {
  width: 0;
  min-width: 0;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  overflow: hidden;
  transition: width 0.3s, min-width 0.3s;
}

.right-panel.open {
  width: 380px;
  min-width: 380px;
}

.right-panel-inner {
  width: 380px;
  height: 100%;
  overflow-y: auto;
  padding: 20px;
}

.right-panel-inner::-webkit-scrollbar { width: 4px; }
.right-panel-inner::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
}

.detail-code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
}

.detail-name {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
  line-height: 1.4;
}

.close-btn {
  width: 30px;
  height: 30px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.close-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.detail-section { margin-bottom: 16px; }

.detail-section-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 13px;
}

.detail-label { color: var(--text-muted); }

.detail-value {
  color: var(--text-primary);
  font-weight: 500;
  text-align: right;
  max-width: 60%;
  word-break: break-word;
}

.owner-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 6px;
}

.owner-name { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.owner-detail { font-size: 12px; color: var(--text-muted); }

.status-badge {
  border-radius: 8px;
  padding: 12px;
  text-align: center;
  margin-bottom: 6px;
}

.doc-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  cursor: pointer;
  text-decoration: none;
  color: var(--text-primary);
}

.doc-item:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
}

.doc-icon { font-size: 20px; }
.doc-name { font-size: 12px; font-weight: 500; flex: 1; }
.doc-download { font-size: 11px; color: var(--accent); font-weight: 600; }

.observations-box {
  font-size: 12px;
  color: var(--text-secondary);
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  line-height: 1.5;
}

/* ============================================
   MAPLIBRE OVERRIDES
   ============================================ */
.maplibregl-ctrl-group {
  background: var(--bg-panel) !important;
  border: 1px solid var(--border) !important;
  border-radius: 8px !important;
  overflow: hidden;
}

.maplibregl-ctrl-group button {
  background-color: var(--bg-panel) !important;
  border-color: var(--border) !important;
  width: 32px !important;
  height: 32px !important;
}

.maplibregl-ctrl-group button + button {
  border-top: 1px solid var(--border) !important;
}

.maplibregl-ctrl-group button .maplibregl-ctrl-icon {
  filter: invert(1);
}

.maplibregl-popup-content {
  background: var(--bg-panel) !important;
  border: 1px solid var(--border) !important;
  border-radius: 6px !important;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5) !important;
  padding: 0 !important;
  color: var(--text-primary) !important;
}

.maplibregl-popup-tip {
  border-top-color: var(--bg-panel) !important;
}

.maplibregl-popup-close-button {
  color: var(--text-muted) !important;
  font-size: 16px !important;
}

.map-popup {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  padding: 7px 12px;
  white-space: nowrap;
  color: var(--text-primary);
}


/* ============================================
   RESPONSIVE — MOBILE (max-width: 768px)
   ============================================ */
@media (max-width: 768px) {

  .login-card { padding: 32px 24px; }
  .login-logo { height: 44px; margin-bottom: 20px; }
  .login-title { font-size: 20px; }

  .logout-btn { padding: 6px 10px; font-size: 14px; margin-left: 10px; }

  .topbar { height: 46px; padding: 0 12px; }
  .topbar-left { gap: 10px; }
  .topbar-title { font-size: 13px; }
  .topbar-subtitle { font-size: 10px; }
  .topbar-logo { width: 28px; height: 28px; font-size: 10px; }

  .topbar-stats { display: none !important; }
  .dashboard-link span { display: none; }

  .topbar-center {
    display: flex !important;
    position: static !important;
    margin-left: auto;
  }

  .topbar-brand-logo { height: 26px; }

  .main-container {
    height: calc(100vh - 46px);
    position: relative;
  }

  .left-panel {
    width: 0 !important;
    min-width: 0 !important;
    border-right: none !important;
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    z-index: 1000;
    overflow: hidden;
    transition: width 0.3s ease, min-width 0.3s ease;
  }

  .left-panel.mobile-open {
    width: 85vw !important;
    min-width: 85vw !important;
    max-width: 340px;
    border-right: 1px solid var(--border) !important;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.6);
  }

  .panel-toggle {
    position: fixed !important;
    top: 54px;
    left: 10px;
    z-index: 1050 !important;
    width: 38px;
    height: 38px;
    font-size: 18px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  }

  .mobile-overlay {
    display: none;
    position: fixed;
    top: 46px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 990;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-overlay.visible { display: block; }

  .right-panel {
    position: fixed !important;
    top: 46px;
    right: 0;
    bottom: 0;
    height: auto !important;
    z-index: 950;
    transition: width 0.3s ease, min-width 0.3s ease;
    border-left: none !important;
  }

  .right-panel.open {
    width: 100% !important;
    min-width: 100% !important;
  }

  .right-panel-inner {
    width: 100% !important;
    height: 100%;
    padding: 16px;
    padding-top: 56px;
    padding-bottom: 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .detail-header {
    position: relative;
    align-items: center;
    gap: 12px;
  }

  .close-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
    font-size: 20px;
    background: var(--red);
    border: none;
    color: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
  }

  .close-btn:hover { background: #dc2626; color: white; }

  .detail-code { font-size: 20px; }
  .detail-name { font-size: 13px; }

  .basemap-switcher { top: 8px; right: 8px; }
  .basemap-btn { padding: 8px 14px; font-size: 12px; }

  .measure-control { bottom: 80px; right: 8px; }
  .measure-btn { width: 38px; height: 38px; font-size: 17px; }
  .measure-result { bottom: 8px; font-size: 12px; padding: 8px 12px; }

  .maplibregl-ctrl-group button { width: 36px !important; height: 36px !important; }
}

/* ============================================
   RESPONSIVE — TABLETS (max-width: 1024px)
   ============================================ */
@media (max-width: 1024px) and (min-width: 769px) {
  .left-panel { width: 280px; min-width: 280px; }
  .right-panel.open { width: 340px; min-width: 340px; }
  .right-panel-inner { width: 340px; }
  .topbar-center { display: none; }
}
