/* ===================================================
   AWESOME TABLE — MAPA DE AGENCIAS
   styles.css
   =================================================== */

/* --- Reset & base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-brand:        #1a7a6e;
  --color-brand-light:  #e8f5f2;
  --color-brand-dark:   #155f56;

  --color-bg:           #ffffff;
  --color-bg-secondary: #f5f5f3;
  --color-bg-tertiary:  #efefed;

  --color-text:         #1a1a18;
  --color-text-muted:   #6b6b67;
  --color-text-hint:    #9b9b97;

  --color-border:       rgba(0,0,0,0.10);
  --color-border-md:    rgba(0,0,0,0.18);

  --radius-sm:  6px;
  --radius-md:  8px;
  --radius-lg:  12px;
  --radius-pill: 20px;

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', monospace;

  --topbar-h: 48px;
  --config-h: 46px;
  --filter-h: 44px;
  --status-h: 28px;
  --embed-h:  42px;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--color-bg-tertiary);
  color: var(--color-text);
  font-size: 14px;
  line-height: 1.5;
}

/* --- App shell --- */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  border-radius: var(--radius-lg);
  box-shadow: 0 2px 24px rgba(0,0,0,0.10);
  background: var(--color-bg);
}

/* ===================================================
   TOPBAR
   =================================================== */
#topbar {
  height: var(--topbar-h);
  background: var(--color-brand);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
}

#topbar h1 {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tb-btn {
  background: rgba(255,255,255,0.18);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
}
.tb-btn:hover { background: rgba(255,255,255,0.28); }
.tb-btn.embed {
  background: #fff;
  color: var(--color-brand);
  font-weight: 500;
}
.tb-btn.embed:hover { background: #f0f0f0; }

/* ===================================================
   CONFIG BAR (Google Sheet input)
   =================================================== */
#config-bar {
  height: var(--config-h);
  background: var(--color-bg-secondary);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  flex-shrink: 0;
}

#sheet-input {
  flex: 1;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border-md);
  background: var(--color-bg);
  color: var(--color-text);
  outline: none;
  transition: border-color 0.15s;
}
#sheet-input:focus { border-color: var(--color-brand); }
#sheet-input::placeholder { color: var(--color-text-hint); }

#load-btn {
  font-size: 12px;
  padding: 6px 14px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--color-brand);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
#load-btn:hover { background: var(--color-brand-dark); }

#demo-btn {
  font-size: 12px;
  padding: 6px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border-md);
  background: var(--color-bg);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
#demo-btn:hover { background: var(--color-bg-tertiary); color: var(--color-text); }

/* ===================================================
   FILTER BAR
   =================================================== */
#filter-bar {
  height: var(--filter-h);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  background: var(--color-bg);
  flex-shrink: 0;
  overflow: visible;
  position: relative;
  z-index: 100;
}

.filter-pill {
  display: flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--color-border-md);
  border-radius: var(--radius-pill);
  padding: 4px 12px;
  font-size: 12px;
  background: var(--color-bg);
  color: var(--color-text);
  cursor: pointer;
  position: relative;
  white-space: nowrap;
  user-select: none;
  transition: border-color 0.15s, background 0.15s;
}
.filter-pill:hover { background: var(--color-bg-secondary); }
.filter-pill.active {
  border-color: var(--color-brand);
  background: var(--color-brand-light);
  color: var(--color-brand);
}

.pill-plus  { font-size: 15px; color: var(--color-brand); line-height: 1; }
.pill-arrow { font-size: 9px; color: var(--color-text-muted); }

/* Dropdown */
.fdrop {
  display: none;
  position: fixed;
  background: var(--color-bg);
  border: 1px solid var(--color-border-md);
  border-radius: var(--radius-md);
  z-index: 99999;
  min-width: 200px;
  max-height: 240px;
  overflow-y: auto;
  box-shadow: 0 6px 20px rgba(0,0,0,0.14);
}
.fdrop.open { display: block; }

.fdrop label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  font-size: 12px;
  cursor: pointer;
  color: var(--color-text);
  transition: background 0.1s;
}
.fdrop label:hover { background: var(--color-bg-secondary); }
.fdrop label input[type="checkbox"] { accent-color: var(--color-brand); }

.clear-btn {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid #f09595;
  background: #fcebeb;
  color: #a32d2d;
  cursor: pointer;
}
.clear-btn:hover { background: #f7c1c1; }

#count-badge {
  margin-left: auto;
  font-size: 11px;
  color: var(--color-text-muted);
  white-space: nowrap;
  padding-left: 8px;
}

/* ===================================================
   BODY (mapa + sidebar)
   =================================================== */
#body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* --- Mapa --- */
#map-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#leaflet-map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
  z-index: 1;
}

/* Leaflet tooltip personalizado */
.ag-tooltip {
  background: rgba(255,255,255,0.96) !important;
  border: 1px solid rgba(0,0,0,0.15) !important;
  border-radius: 6px !important;
  font-size: 12px !important;
  font-weight: 500 !important;
  color: #1a1a18 !important;
  padding: 4px 10px !important;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12) !important;
  white-space: nowrap;
}
.ag-tooltip::before { display: none !important; }

/* Asegura que los controles de Leaflet queden sobre el detail-overlay */
.leaflet-top, .leaflet-bottom { z-index: 10 !important; }

#map-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Placeholder */
#map-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  background: #c8dfc8;
}

.placeholder-pins {
  display: flex;
  gap: 6px;
  margin-bottom: 4px;
}
.pin {
  width: 22px; height: 22px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
}
.pin-blue   { background: #378ADD; }
.pin-red    { background: #D85A30; }
.pin-yellow { background: #BA7517; }

#map-placeholder p {
  font-size: 13px;
  color: #2a5a3a;
  text-align: center;
  max-width: 340px;
  line-height: 1.7;
}
#map-placeholder code {
  font-family: var(--font-mono);
  font-size: 11px;
  background: rgba(0,0,0,0.07);
  padding: 2px 5px;
  border-radius: 4px;
}
.placeholder-hint {
  font-size: 11px !important;
  color: #3a7a4a !important;
  background: rgba(255,255,255,0.5);
  padding: 6px 12px;
  border-radius: var(--radius-md);
}

/* Detail overlay */
#detail-overlay {
  position: absolute;
  bottom: 14px;
  right: 14px;
  width: 220px;
  background: var(--color-bg);
  border: 1px solid var(--color-border-md);
  border-radius: var(--radius-lg);
  padding: 14px;
  display: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  z-index: 500;
}
#detail-overlay.visible { display: block; }

.close-x {
  position: absolute;
  top: 8px; right: 10px;
  border: none; background: none;
  font-size: 13px; cursor: pointer;
  color: var(--color-text-muted);
}
.close-x:hover { color: var(--color-text); }

.det-badge {
  display: inline-block;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--color-brand-light);
  color: var(--color-brand);
  margin-bottom: 6px;
  font-weight: 500;
}

.det-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text);
  margin-bottom: 8px;
  line-height: 1.4;
}

.det-row {
  display: flex;
  gap: 6px;
  font-size: 11px;
  color: var(--color-text-muted);
  margin-bottom: 4px;
  align-items: flex-start;
}
.det-lbl {
  color: var(--color-text);
  font-weight: 500;
  min-width: 54px;
  flex-shrink: 0;
}

.det-prods {
  font-size: 10px;
  color: var(--color-text-muted);
  margin-top: 8px;
  border-top: 1px solid var(--color-border);
  padding-top: 6px;
  line-height: 1.6;
}

.map-link {
  display: block;
  margin-top: 10px;
  font-size: 11px;
  color: var(--color-brand);
  text-decoration: none;
  padding: 5px 0;
  text-align: center;
  border: 1px solid var(--color-brand);
  border-radius: var(--radius-md);
  transition: background 0.15s;
}
.map-link:hover { background: var(--color-brand-light); }

/* --- Sidebar --- */
#sidebar {
  width: 0;
  overflow: hidden;
  border-left: 1px solid var(--color-border);
  background: var(--color-bg);
  transition: width 0.2s ease;
  flex-shrink: 0;
}
#sidebar.open { width: 260px; }

#sidebar-inner {
  width: 260px;
  padding: 10px;
  overflow-y: auto;
  height: 100%;
}

.list-count {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-bottom: 8px;
  padding: 0 4px;
}

.ag-card {
  padding: 8px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  margin-bottom: 5px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.ag-card:hover { background: var(--color-bg-secondary); }
.ag-card.sel {
  border-color: var(--color-brand);
  background: var(--color-brand-light);
}

.ag-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text);
}
.ag-dist {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-top: 2px;
}

/* ===================================================
   STATUS BAR
   =================================================== */
#status {
  display: none;
  font-size: 11px;
  color: var(--color-text-muted);
  padding: 5px 14px;
  background: var(--color-bg-secondary);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}

/* ===================================================
   EMBED BAR
   =================================================== */
#embed-bar {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--color-bg-secondary);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}
#embed-bar.visible { display: flex; }

.embed-lbl {
  font-size: 11px;
  color: var(--color-text-muted);
  white-space: nowrap;
}

#embed-code {
  flex: 1;
  font-size: 11px;
  font-family: var(--font-mono);
  padding: 5px 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border-md);
  background: var(--color-bg);
  color: var(--color-text-muted);
  outline: none;
}

#copy-btn {
  font-size: 11px;
  padding: 5px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border-md);
  background: var(--color-bg);
  color: var(--color-text);
  cursor: pointer;
  white-space: nowrap;
}
.embed-hint {
  font-size: 10px;
  color: #BA7517;
  background: #FAEEDA;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

/* ===================================================
   MODO EMBED
   Cuando la app se carga con ?sheet=ID, se activa
   la clase .embed-mode en #app que oculta el config-bar,
   los botones del topbar y la barra de status/embed.
   =================================================== */
#app.embed-mode #topbar        { display: none; }
#app.embed-mode #config-bar    { display: none; }
#app.embed-mode #status        { display: none !important; }
#app.embed-mode #embed-bar     { display: none !important; }
#app.embed-mode #topbar-embed  { display: flex !important; }
#app.embed-mode #sidebar       { display: none !important; }
#app.embed-mode #toggle-sidebar-btn { display: none; }

/* Topbar embed: solo título limpio, sin botones */
#topbar-embed {
  height: var(--topbar-h);
  background: var(--color-brand);
  display: none;
  align-items: center;
  padding: 0 16px;
  flex-shrink: 0;
}
#topbar-embed h1 {
  font-size: 14px;
  font-weight: 500;
  color: #fff;
}
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #aaa; }
