/* =============================================================
   MozMap – Design System (único archivo CSS)
   Google Fonts: Inter
   ============================================================= */

/* ---- Variables ---- */
:root {
  --bg:          #0f172a;
  --bg-card:     #1e293b;
  --bg-nav:      #111827;
  --border:      #334155;
  --primary:     #3b82f6;
  --primary-dark:#1d4ed8;
  --accent:      #10b981;
  --danger:      #ef4444;
  --text:        #f1f5f9;
  --text-muted:  #94a3b8;
  --glass-bg:    rgba(30,41,59,0.85);
  --glass-blur:  blur(16px);
  --shadow:      0 4px 24px rgba(0,0,0,.4);
  --radius:      12px;
  --radius-sm:   8px;
  --sidebar-w:   360px;
  --nav-h:       60px;
  --font:        'Inter', system-ui, sans-serif;
}

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

html { font-size: 16px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ================================================================
   LOGIN
   ================================================================ */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
}

.login-container { width: 100%; max-width: 420px; padding: 1rem; }

.login-card {
  padding: 2.5rem;
  border-radius: var(--radius);
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}
.login-logo .logo-icon { font-size: 3rem; }
.login-logo h1 { font-size: 1.75rem; font-weight: 700; margin: .25rem 0; }
.login-logo p  { color: var(--text-muted); font-size: .9rem; }

/* ================================================================
   MAP PAGE
   ================================================================ */
/* Bloquear altura del viewport: si no, Leaflet toma mal el tamaño (banda gris arriba / mapa “bajado”) */
body.map-page {
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  width: 100%;
  max-width: 100%;
  margin: 0;
}

.map-page {
  overflow-x: hidden;
  overflow-y: hidden;
  height: 100vh;
  max-height: 100vh;
  min-height: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

/* Panel del mapa: ocupa el espacio restante del viewport (evita 100vw + fixed, que desborda y saca los controles) */
.map-panel {
  position: relative;
  z-index: 1;
  margin: 0;
  margin-left: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  min-width: 0;
  box-sizing: border-box;
  transition: margin-left 0.3s ease, width 0.3s ease;
}

.map-panel.sidebar-open {
  margin-left: var(--sidebar-w);
  width: calc(100% - var(--sidebar-w));
}

@media (max-width: 768px) {
  .map-panel.sidebar-open {
    margin-left: 0;
    width: 100%;
  }
}

/* Leaflet: contenedor con tamaño real dentro del panel */
#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  z-index: 1;
}

#map.leaflet-container {
  width: 100%;
  height: 100%;
}

.leaflet-container {
  background: #1a1a2e;
  font-family: inherit;
  outline: none;
}

/* Zoom abajo a la derecha; separación respecto a la atribución de Leaflet */
#map .leaflet-bottom.leaflet-right {
  margin-right: 10px;
  margin-bottom: 12px;
}
#map .leaflet-control-zoom {
  margin-bottom: 8px;
}
.moz-mosque-marker-wrap,
.moz-cluster-icon-wrap {
  background: transparent !important;
  border: none !important;
}
.moz-mosque-pin {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #239f40;
  border: 2px solid #115e24;
  color: #fff;
  font-size: 14px;
  line-height: 24px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}
.moz-cluster-bubble {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.7);
  box-sizing: border-box;
}

/* ---- Sidebar ---- */
.sidebar {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform .3s ease;
  box-shadow: var(--shadow);
}

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

.sidebar-toggle {
  position: absolute;
  right: -38px; top: 50%;
  transform: translateY(-50%);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
  border-left: none;
  width: 38px; height: 56px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 1.1rem;
  color: var(--text-muted);
  transition: color .2s, background .2s;
  user-select: none;
}
.sidebar-toggle:hover { color: var(--text); background: var(--bg-card); }
.sidebar.collapsed .sidebar-toggle { transform: translateY(-50%) scaleX(-1); }

.sidebar-inner {
  display: flex; flex-direction: column;
  height: 100%; overflow: hidden;
}

.sidebar-logo {
  padding: 1.25rem 1.25rem .75rem;
  font-size: 1.2rem;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: .5rem;
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  flex: 1;
  padding: .75rem .5rem;
  background: none;
  border: none; border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: .85rem;
  cursor: pointer;
  transition: all .2s;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-btn:hover  { color: var(--text); }

.tab-content { display: none; flex: 1; overflow-y: auto; padding: 1rem; }
.tab-content.active { display: flex; flex-direction: column; gap: .75rem; }

/* Search form in sidebar */
.search-form { display: flex; flex-direction: column; gap: .5rem; }
.search-form input,
.search-form select { width: 100%; }
.search-form .btn { width: 100%; }

/* Result list */
.result-list { display: flex; flex-direction: column; gap: .4rem; margin-top: .5rem; }
.result-item {
  display: flex; gap: .75rem; align-items: center;
  padding: .6rem .8rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: .85rem;
  line-height: 1.4;
  transition: background .15s, border-color .15s;
}
.result-item:hover { background: #2d3f56; border-color: var(--primary); }
.result-img { width: 38px; height: 38px; object-fit: cover; border-radius: 6px; flex-shrink: 0; background: #0f172a; }
.result-img-placeholder { width: 38px; height: 38px; border-radius: 6px; flex-shrink: 0; background: #1e3a5f; display: flex; align-items: center; justify-content: center; font-size: 1.1rem; color: #64748b; }
.result-info { flex: 1; min-width: 0; }
.result-info strong { display: block; font-size: .9rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-info span   { color: var(--text-muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }

/* Ficha detail en sidebar */
.ficha-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: .75rem; color: var(--text-muted); text-align: center;
  font-size: 1.5rem;
}
.ficha-empty p { font-size: .9rem; }

.ficha-detail { display: flex; flex-direction: column; gap: .75rem; }
.ficha-img-wrap img { width: 100%; border-radius: var(--radius-sm); object-fit: cover; max-height: 180px; }
.ficha-name   { font-size: 1rem; font-weight: 600; }
.ficha-row    { display: flex; gap: .5rem; align-items: flex-start; font-size: .83rem; color: var(--text-muted); }
.ficha-row span.val { color: var(--text); flex: 1; }
.ficha-edit-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: .75rem; padding: 0 .25rem;
  transition: color .2s;
}
.ficha-edit-btn:hover { color: var(--primary); }
.ficha-action-btns { display: flex; gap: .5rem; }
.ficha-action-btns a { flex: 1; text-align: center; font-size: .78rem; }

/* Sidebar footer */
.sidebar-footer {
  padding: .75rem 1rem;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  font-size: .82rem;
}
.user-info { color: var(--text-muted); margin-right: auto; }

/* ---- Float search bar ---- */
.map-float-search {
  position: fixed;
  top: 1rem; left: calc(var(--sidebar-w) + 1rem);
  display: flex; gap: .5rem;
  z-index: 1000;
  transition: left .3s ease;
}
.sidebar.collapsed ~ .map-float-search { left: 1rem; }
.map-float-search input {
  width: 280px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
}

/* ---- Map popup ---- */
.map-popup {
  position: fixed;
  top: 50%; right: 1.5rem;
  transform: translateY(-50%);
  width: 320px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  z-index: 1100;
  box-shadow: var(--shadow);
  animation: slideIn .25s ease;
}
@keyframes slideIn { from { opacity:0; transform: translateY(-50%) scale(.95); } }
.popup-close {
  position: absolute; top: .75rem; right: .75rem;
  background: none; border: none; color: var(--text-muted);
  font-size: 1rem; cursor: pointer;
}
.popup-close:hover { color: var(--text); }
.popup-img { width: 100%; height: 140px; object-fit: cover; border-radius: var(--radius-sm); margin-bottom: .75rem; }
.popup-name  { font-weight: 600; font-size: 1rem; margin-bottom: .25rem; }
.popup-sub   { font-size: .82rem; color: var(--text-muted); margin-bottom: 1rem; }
.popup-btns  { display: flex; gap: .5rem; }
.popup-btns a { flex: 1; font-size: .78rem; text-align: center; }

/* ================================================================
   ADMIN LAYOUT
   ================================================================ */
.admin-page { display: flex; min-height: 100vh; background: var(--bg); }

.admin-nav {
  width: 220px; min-height: 100vh;
  background: var(--bg-nav);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  flex-shrink: 0;
}

.admin-brand {
  padding: 1.25rem 1.5rem;
  font-size: 1.15rem; font-weight: 700;
  border-bottom: 1px solid var(--border);
  letter-spacing: -.01em;
}

.nav-link {
  display: flex; align-items: center; gap: .5rem;
  padding: .7rem 1.5rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: .88rem;
  transition: background .15s, color .15s;
  border-left: 2px solid transparent;
}
.nav-link:hover  { background: #1e293b; color: var(--text); }
.nav-link.active { color: var(--primary); border-left-color: var(--primary); background: #1e3a5f22; }
.nav-link.nav-logout { color: var(--danger); margin-top: auto; }

.admin-nav-footer { margin-top: auto; border-top: 1px solid var(--border); }

.admin-wrapper { display: flex; width: 100%; }
.admin-main    { flex: 1; padding: 1.5rem 2rem; overflow-x: hidden; }

.admin-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.5rem;
}
.admin-header h1 { font-size: 1.5rem; font-weight: 700; }
.admin-user { font-size: .85rem; color: var(--text-muted); }

/* ---- Stat grids ---- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex; align-items: center; gap: 1rem;
}
.stat-icon  { font-size: 2rem; }
.stat-number { font-size: 1.75rem; font-weight: 700; line-height: 1; }
.stat-label  { font-size: .8rem; color: var(--text-muted); margin-top: .15rem; }

.shortcuts { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.shortcut-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1rem;
  text-align: center;
  text-decoration: none; color: var(--text);
  display: flex; flex-direction: column; align-items: center; gap: .5rem;
  font-size: 1.75rem;
  transition: border-color .2s, transform .2s;
}
.shortcut-card strong { font-size: .9rem; }
.shortcut-card:hover  { border-color: var(--primary); transform: translateY(-2px); }

/* ---- Charts ---- */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.chart-card h3 { margin-bottom: .75rem; font-size: .95rem; font-weight: 600; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); margin-bottom: 1rem; }
.data-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.data-table th {
  background: #1a2744;
  padding: .7rem 1rem;
  text-align: left;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}
.data-table td { padding: .65rem 1rem; border-top: 1px solid var(--border); vertical-align: middle; }
.data-table tr:hover td { background: #1e2d40; }
.actions { display: flex; gap: .35rem; }
.table-count { font-size: .8rem; color: var(--text-muted); margin-bottom: 1rem; }

/* ---- Filter bar ---- */
.filter-bar {
  display: flex; flex-wrap: wrap; gap: .5rem; align-items: center;
  margin-bottom: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem 1rem;
}
.filter-bar input, .filter-bar select { flex: 1; min-width: 120px; }
.filter-bar input[name="id"] { flex: 0 0 70px; min-width: 70px; }

/* ---- Pagination ---- */
.pagination { display: flex; gap: .25rem; flex-wrap: wrap; margin-bottom: 1rem; align-items: center; }
.pagination a {
  padding: .35rem .65rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: .8rem;
  transition: all .15s;
}
.pagination a.active, .pagination a:hover { background: var(--primary); border-color: var(--primary); color: #fff; }
.page-dots { padding: 0 .4rem; color: var(--text-muted); font-size: .9rem; letter-spacing: 1px; }

/* ---- Forms ---- */
.form-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 860px;
}

.form-section { margin-bottom: 1.75rem; }
.form-section h3 { font-size: .95rem; font-weight: 600; color: var(--text-muted); margin-bottom: 1rem; padding-bottom: .4rem; border-bottom: 1px solid var(--border); }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.form-grid .span-2    { grid-column: span 2; }
.form-grid .span-full { grid-column: 1/-1; }

.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-group label { font-size: .82rem; color: var(--text-muted); font-weight: 500; }

.form-actions { display: flex; gap: .75rem; margin-top: 1rem; }

/* ---- Inputs / Selects ---- */
input[type=text], input[type=email], input[type=password],
input[type=url], input[type=number], input[type=file],
select, textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: .55rem .85rem;
  font-family: var(--font);
  font-size: .9rem;
  width: 100%;
  transition: border-color .2s;
  outline: none;
  appearance: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%2394a3b8' viewBox='0 0 24 24'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .7rem center; background-size: 1.2rem; padding-right: 2.2rem; }
textarea { resize: vertical; min-height: 80px; }

/* ---- Password Toggle ---- */
.password-wrapper { position: relative; display: flex; align-items: center; }
.password-wrapper input { padding-right: 2.5rem; }
.btn-toggle-pwd {
  position: absolute; right: 0.5rem;
  background: none; border: none; font-size: 1.1rem;
  color: var(--text-muted); cursor: pointer;
  padding: 0.2rem;
  transition: color 0.15s;
}
.btn-toggle-pwd:hover { color: var(--text); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  padding: .55rem 1.1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: var(--font);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: all .2s;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost   { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover { color: var(--text); border-color: #64748b; }
.btn-glass   { background: var(--glass-bg); backdrop-filter: var(--glass-blur); border-color: var(--border); color: var(--text); }
.btn-glass:hover { border-color: var(--primary); }
.btn-danger  { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-full    { width: 100%; }
.btn-sm      { padding: .3rem .65rem; font-size: .8rem; }

/* ---- Alerts ---- */
.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  margin-bottom: 1rem;
}
.alert-error { background: #451a1a; border: 1px solid var(--danger); color: #fca5a5; }
.alert-ok    { background: #052e16; border: 1px solid var(--accent); color: #86efac; }

/* ---- Badges ---- */
.badge { padding: .2rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.badge-admin  { background: #1d4ed8; color: #fff; }
.badge-usuario { background: #374151; color: #d1d5db; }

/* ---- Glass utility ---- */
.glass {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
}

/* ---- Hidden ---- */
.hidden { display: none !important; }

/* ---- Importar progress ---- */
.progress-bar-bg { background: var(--border); border-radius: 999px; height: 10px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--primary); border-radius: 999px; transition: width .3s ease; }
.import-log { margin-top: 1rem; }

/* ---- Modal ---- */
.modal {
  position: fixed; inset: 0; z-index: 300;
  display: flex; align-items: center; justify-content: center;
}
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,.55); }
.modal-card { position: relative; width: 480px; max-width: 96vw; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; z-index: 1; }
.modal-card h3 { margin-bottom: 1.25rem; font-size: 1.1rem; }

/* ---- Tools ---- */
.tools-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.tool-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; }
.tool-card h3 { margin-bottom: .5rem; font-size: 1rem; }
.tool-card p  { color: var(--text-muted); font-size: .875rem; margin-bottom: 1rem; }

/* ================================================================
   FICHA IMPRIMIBLE
   ================================================================ */
.ficha-print { background: #fff; color: #111; font-family: var(--font); }
.print-controls { display: flex; gap: .75rem; padding: 1rem 1.5rem; background: #f1f5f9; border-bottom: 1px solid #e2e8f0; }
.print-controls .btn-primary { background: #1d4ed8; color: #fff; }
.print-controls .btn-ghost { border-color: #cbd5e1; color: #64748b; }

.ficha-page { max-width: 860px; margin: 0 auto; padding: 3rem 2rem; }
.ficha-header { display: flex; align-items: flex-start; gap: 1.5rem; border-bottom: 2px solid #e2e8f0; padding-bottom: 1.5rem; margin-bottom: 2rem; }
.ficha-brand-logo { height: 48px; object-fit: contain; }
.ficha-title h1 { font-size: 1.5rem; font-weight: 700; color: #0f172a; }
.ficha-alt { color: #64748b; font-size: .9rem; margin-top: .2rem; }
.ficha-id { margin-left: auto; font-size: .85rem; color: #94a3b8; white-space: nowrap; padding-top: .3rem; }
.ficha-img { width: 100%; max-height: 280px; object-fit: cover; border-radius: 8px; margin-bottom: 1.5rem; }
.ficha-table { width: 100%; border-collapse: collapse; margin-bottom: 1.5rem; font-size: .875rem; }
.ficha-table th { text-align: left; width: 160px; color: #64748b; font-weight: 500; padding: .5rem .75rem .5rem 0; border-top: 1px solid #e2e8f0; }
.ficha-table td { padding: .5rem .75rem .5rem 0; border-top: 1px solid #e2e8f0; color: #1e293b; }
.ficha-section { margin-bottom: 1.25rem; }
.ficha-section h3 { font-size: .95rem; font-weight: 600; color: #1d4ed8; margin-bottom: .4rem; }
.ficha-section p  { font-size: .875rem; color: #374151; line-height: 1.7; }
.ficha-footer { text-align: center; color: #94a3b8; font-size: .8rem; margin-top: 3rem; padding-top: 1rem; border-top: 1px solid #e2e8f0; }

@media print {
  .no-print { display: none !important; }
  .ficha-page { padding: 0; }
  body { background: #fff; }
}

/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 768px) {
  .admin-nav { display: none; }
  .admin-main { padding: 1rem; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2, .form-grid .span-full { grid-column: 1; }
  .charts-grid { grid-template-columns: 1fr; }
  .sidebar { width: 100vw; }
  :root { --sidebar-w: 100vw; }
  .map-float-search { left: .5rem; top: .5rem; }
  .map-float-search input { width: 200px; }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
}
