/* ==========================================================================
   WhatsExtract — panel de inteligencia de mercado farmacéutico
   Tema oscuro, sin frameworks. Tipografía del sistema.
   ========================================================================== */

:root {
  --bg:        #0f1115;
  --bg-soft:   #12151b;
  --panel:     #161a21;
  --panel-2:   #1c212a;
  --panel-3:   #222933;
  --line:      #272e39;
  --line-soft: #1f252e;

  --text:      #e7edf4;
  --text-2:    #b8c3cf;
  --muted:     #8b98a7;
  --faint:     #64707e;

  --accent:      #25d366;
  --accent-deep: #128c7e;
  --accent-dim:  rgba(37, 211, 102, .14);
  --accent-line: rgba(37, 211, 102, .35);

  --warn:  #f0b429;
  --error: #ff6b6b;
  --info:  #58a6ff;

  --r-sm: 6px;
  --r-md: 9px;
  --r-lg: 14px;

  --shadow-1: 0 1px 2px rgba(0,0,0,.4);
  --shadow-2: 0 10px 30px rgba(0,0,0,.45);
  --shadow-3: 0 24px 60px rgba(0,0,0,.6);

  --topbar-h: 56px;
  --tabs-h:   44px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

/* Muchas clases de este panel fijan display (flex/grid/inline-flex) y ganarían
   a la regla [hidden] del navegador: el atributo debe seguir mandando. */
[hidden] { display: none !important; }

/* Sin height:100% en body: acotaría el bloque contenedor y rompería los
   position:sticky de la barra superior, las pestañas y el thead. */
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 16px; }
h3 { font-size: 13px; }
p  { margin: 0; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
  font: 12px/1.4 var(--mono);
  background: #0a0d11;
  border: 1px solid var(--line-soft);
  padding: .08em .38em;
  border-radius: var(--r-sm);
  color: #a9e6c0;
  word-break: break-all;
}

.muted { color: var(--muted); }
.faint { color: var(--faint); }
.spacer { flex: 1 1 auto; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Foco visible y consistente en todo el panel */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 200;
  background: var(--accent); color: #04130a; padding: .6rem 1rem;
  border-radius: 0 0 var(--r-md) 0; font-weight: 700;
}
.skip-link:focus { left: 0; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2b333e; border-radius: 8px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #3a444f; }

/* ==========================================================================
   Controles base
   ========================================================================== */

input, select, textarea, button { font: inherit; color: var(--text); }

/* Selector por exclusión: un <input> sin atributo type es de texto y no lo
   alcanzaría un selector [type=text]. */
input:not([type=checkbox]):not([type=radio]):not([type=file]):not([type=range]),
select, textarea {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: .46rem .6rem;
  width: 100%;
  transition: border-color .15s, background .15s;
}

/* El autorrelleno de Chrome pinta el campo de blanco: se fuerza el tema. */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px var(--panel-2) inset;
  caret-color: var(--text);
}
input:hover, select:hover { border-color: #333c48; }
input:focus, select:focus { border-color: var(--accent-line); background: var(--panel-3); }
input::placeholder { color: var(--faint); }
input[type=search]::-webkit-search-cancel-button { display: none; }
input[type=date] { color-scheme: dark; }

input[type=checkbox], input[type=radio] {
  accent-color: var(--accent);
  width: 15px; height: 15px;
  cursor: pointer;
  flex: none;
}

.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--r-md);
  padding: .46rem .8rem;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, transform .06s;
}
.btn:hover { background: var(--panel-3); border-color: #38424f; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.btn.primary {
  background: var(--accent); border-color: var(--accent); color: #04130a; font-weight: 700;
}
.btn.primary:hover { background: #2ee574; border-color: #2ee574; }
.btn.primary.strong { box-shadow: 0 2px 14px rgba(37,211,102,.25); }

.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }

.btn.link {
  background: none; border: none; color: var(--accent);
  padding: .15rem .2rem; font-weight: 550; font-size: 12.5px;
}
.btn.link:hover { text-decoration: underline; background: none; }

.btn.small { padding: .26rem .55rem; font-size: 12.5px; }
.btn.danger:hover { border-color: #6b2b2b; color: #ffb4b4; background: #241618; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; flex: none;
  background: transparent; border: none; color: var(--muted);
  border-radius: var(--r-sm); cursor: pointer;
}
.icon-btn:hover { background: var(--panel-3); color: var(--text); }

/* Segmentos (Todas / Cualquiera, Tabla / Galería / Analítica) */
.seg {
  display: inline-flex; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: var(--r-md); padding: 2px; flex: none;
}
.seg-opt { position: relative; display: inline-flex; }
.seg-opt input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.seg-opt span, .seg-btn {
  display: inline-block; padding: .32rem .7rem; border-radius: 7px;
  font-size: 13px; color: var(--muted); font-weight: 550; white-space: nowrap;
  background: transparent; border: none; cursor: pointer;
}
.seg-opt input:checked + span, .seg-btn.active { background: var(--panel-3); color: var(--text); box-shadow: var(--shadow-1); }
.seg-opt input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg-btn:hover { color: var(--text); }

/* Switch */
.switch {
  display: flex; align-items: center; gap: .55rem;
  padding: .3rem 0; cursor: pointer; font-size: 13px; color: var(--text-2);
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  width: 34px; height: 19px; border-radius: 999px; flex: none;
  background: var(--panel-3); border: 1px solid var(--line); position: relative;
  transition: background .18s, border-color .18s;
}
.switch .track::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 13px; height: 13px; border-radius: 50%; background: var(--muted);
  transition: transform .18s, background .18s;
}
.switch input:checked + .track { background: var(--accent-dim); border-color: var(--accent-line); }
.switch input:checked + .track::after { transform: translateX(15px); background: var(--accent); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch:hover { color: var(--text); }

/* Chips */
.chip {
  display: inline-flex; align-items: center; gap: .35rem;
  background: var(--panel-2); border: 1px solid var(--line);
  color: var(--text-2); border-radius: 999px;
  padding: .26rem .7rem; font-size: 12.5px; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.chip:hover { background: var(--panel-3); color: var(--text); }
.chip.active { background: var(--accent-dim); border-color: var(--accent-line); color: #a8f0c4; }
.chip code { background: transparent; border: none; padding: 0; color: inherit; font-size: 12px; }
.chip.hint { color: var(--muted); }
.chip.add { border-style: dashed; }
.chip .x { color: var(--faint); font-weight: 700; margin-left: .1rem; }
.chip:hover .x { color: var(--text); }

.field { display: flex; flex-direction: column; gap: .25rem; font-size: 12px; color: var(--muted); }
.field > span { font-weight: 550; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.inline-field { display: inline-flex; align-items: center; gap: .4rem; font-size: 12.5px; color: var(--muted); }
.inline-field select { width: auto; padding: .34rem .5rem; }
.wide-input { width: 100%; }
.fnote { font-size: 11.5px; color: var(--faint); margin-top: .35rem; }
.form-error { color: var(--error); font-size: 13px; margin-top: .6rem; }

/* ==========================================================================
   Login (compartido con login.html)
   ========================================================================== */

.login-body {
  display: flex; min-height: 100vh; align-items: center; justify-content: center;
  background: radial-gradient(1000px 500px at 50% -10%, #16241d 0%, var(--bg) 60%);
}
.login-card { width: 340px; box-shadow: var(--shadow-2); }
.login-card h1 { font-size: 22px; color: var(--accent); }
.login-card label { display: block; margin: .8rem 0; font-size: 12.5px; color: var(--muted); }
.login-card input { margin-top: .25rem; }
.login-card button { width: 100%; margin-top: .5rem; background: var(--accent); color: #04130a; border: none; font-weight: 700; padding: .55rem; border-radius: var(--r-md); cursor: pointer; }
.login-card button:hover { background: #2ee574; }
.error { color: var(--error); margin-top: .6rem; font-size: 13px; }

/* ==========================================================================
   A. Barra superior + pestañas
   ========================================================================== */

.topbar {
  position: sticky; top: 0; z-index: 60;
  display: flex; align-items: center; gap: .9rem;
  height: var(--topbar-h); padding: 0 1rem;
  background: rgba(19,23,29,.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .5rem; flex: none; }
.brand-mark {
  display: grid; place-items: center; width: 30px; height: 30px;
  border-radius: 9px; color: #04130a;
  background: linear-gradient(145deg, var(--accent), var(--accent-deep));
}
.brand-name { font-size: 15.5px; font-weight: 600; letter-spacing: -.02em; color: var(--text-2); }
.brand-name b { color: var(--text); font-weight: 750; }

.live {
  display: flex; align-items: center; gap: .5rem;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 999px; padding: .25rem .75rem .25rem .6rem;
  font-size: 12.5px; color: var(--text-2); min-width: 0;
}
.live-txt { display: flex; align-items: center; gap: .35rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.live-label { font-size: 10.5px; font-weight: 750; letter-spacing: .08em; color: var(--accent); }
.live-unit, .live-sep { color: var(--faint); }
.live-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none;
  box-shadow: 0 0 0 0 rgba(37,211,102,.6); animation: pulse 2.4s infinite;
}
.live-dot.stale { background: var(--warn); animation: none; box-shadow: none; }
.live-dot.down  { background: var(--error); animation: none; box-shadow: none; }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(37,211,102,.5); }
  70%  { box-shadow: 0 0 0 7px rgba(37,211,102,0); }
  100% { box-shadow: 0 0 0 0 rgba(37,211,102,0); }
}
@media (prefers-reduced-motion: reduce) { .live-dot { animation: none; } }

.user-chip { display: flex; align-items: center; gap: .5rem; font-size: 12.5px; }
.avatar {
  display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  background: var(--panel-3); border: 1px solid var(--line);
  font-weight: 700; font-size: 12px; color: var(--accent); text-transform: uppercase;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-meta .muted { font-size: 11px; }

.tabs {
  position: sticky; top: var(--topbar-h); z-index: 55;
  display: flex; gap: .15rem; align-items: center;
  height: var(--tabs-h); padding: 0 1rem;
  background: var(--bg-soft); border-bottom: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; background: none; border: none; cursor: pointer;
  color: var(--muted); font-weight: 550; font-size: 13.5px;
  padding: 0 .85rem; height: 100%; white-space: nowrap;
}
.tab:hover { color: var(--text-2); }
.tab.active { color: var(--text); }
.tab.active::after {
  content: ''; position: absolute; left: .6rem; right: .6rem; bottom: 0;
  height: 2px; background: var(--accent); border-radius: 2px 2px 0 0;
}

main { padding: 1rem 1.15rem 3rem; max-width: 1680px; margin: 0 auto; }
.panel[hidden] { display: none; }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 1.1rem; margin-bottom: 1rem;
}
.card-head {
  display: flex; align-items: flex-start; gap: 1rem;
  justify-content: space-between; margin-bottom: .9rem;
}
.card-head .muted { font-size: 12.5px; margin-top: .15rem; }

/* ==========================================================================
   B. Barra de búsqueda
   ========================================================================== */

.searchbar {
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg-soft) 100%);
  border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 1rem 1.1rem .85rem; margin-bottom: 1rem;
}
.search-row { display: flex; gap: .6rem; align-items: center; }
.search-field { position: relative; flex: 1 1 auto; min-width: 0; }
.search-field .search-icon { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-field input {
  height: 46px; padding-left: 2.4rem; padding-right: 2.4rem;
  font-size: 15px; background: var(--bg); border-radius: 11px;
}
.search-field input:focus { box-shadow: 0 0 0 3px var(--accent-dim); }
#qClear { position: absolute; right: .5rem; top: 50%; transform: translateY(-50%); }
.search-row .btn.primary { height: 46px; padding: 0 1.4rem; font-size: 14.5px; }
.search-row .seg { height: 46px; align-items: center; }

.hints, .presets {
  display: flex; align-items: center; gap: .4rem;
  flex-wrap: wrap; margin-top: .7rem;
}
.hints-label { font-size: 11.5px; color: var(--faint); text-transform: uppercase; letter-spacing: .06em; font-weight: 650; margin-right: .1rem; }
.presets { padding-top: .7rem; border-top: 1px solid var(--line-soft); }
.presets-list { display: contents; }
.chip.preset { font-weight: 600; color: var(--text); }
.chip.preset .x { margin-left: .25rem; }

/* ==========================================================================
   B. Rejilla explorar: filtros + resultados
   ========================================================================== */

.explore-grid {
  display: grid; grid-template-columns: 266px minmax(0, 1fr); gap: 1rem;
  align-items: start;
}

.filters-panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: .9rem;
  position: sticky; top: calc(var(--topbar-h) + var(--tabs-h) + 1rem);
  max-height: calc(100vh - var(--topbar-h) - var(--tabs-h) - 2rem);
  overflow-y: auto;
}
.filters-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .3rem; }
.filters-head h2 { flex: 1; font-size: 14px; }
.fgroup { padding: .8rem 0; border-top: 1px solid var(--line-soft); }
.fgroup:first-of-type { border-top: none; }
.fgroup-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--faint); font-weight: 700; margin-bottom: .5rem;
}
.mini-input { padding: .32rem .5rem; font-size: 12.5px; margin-bottom: .45rem; }
.quick-dates { display: flex; flex-wrap: wrap; gap: .3rem; margin-bottom: .55rem; }
.quick-dates .chip { padding: .2rem .55rem; font-size: 12px; }

.check-list { max-height: 224px; overflow-y: auto; margin: -.15rem -.25rem; padding: 0 .25rem; }
.check-row {
  display: flex; align-items: center; gap: .5rem;
  padding: .26rem .3rem; border-radius: var(--r-sm); cursor: pointer;
  font-size: 12.5px; color: var(--text-2);
}
.check-row:hover { background: var(--panel-2); color: var(--text); }
.check-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.check-row .cnt {
  font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums;
  background: var(--panel-2); border-radius: 999px; padding: .05rem .4rem; flex: none;
}
.check-row input:checked ~ .name { color: var(--text); font-weight: 600; }

.vendor-list { margin-top: .5rem; display: flex; flex-direction: column; gap: .1rem; }
.vendor-row {
  display: flex; align-items: baseline; gap: .45rem; width: 100%;
  background: none; border: none; cursor: pointer; text-align: left;
  padding: .28rem .3rem; border-radius: var(--r-sm); color: var(--text-2); font-size: 12.5px;
}
.vendor-row:hover { background: var(--panel-2); color: var(--text); }
.vendor-row .vn { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vendor-row .vc { font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums; }
.vendor-row.active { background: var(--accent-dim); color: #a8f0c4; }

/* ==========================================================================
   B. Resultados: totales, barra de herramientas
   ========================================================================== */

.results { min-width: 0; }

.totals { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); gap: .6rem; margin-bottom: .8rem; }
.tot {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: .6rem .75rem;
}
.tot .v { font-size: 19px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.tot .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.tot.accent .v { color: var(--accent); }

.toolbar {
  display: flex; align-items: center; gap: .55rem; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: .5rem .65rem; margin-bottom: .6rem;
  position: sticky; top: calc(var(--topbar-h) + var(--tabs-h)); z-index: 40;
}
.result-count { font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.result-count b { color: var(--text); }

.selbar {
  display: flex; align-items: center; gap: .7rem; font-size: 13px;
  background: var(--accent-dim); border: 1px solid var(--accent-line);
  color: #bff3d3; border-radius: var(--r-md); padding: .45rem .7rem; margin-bottom: .6rem;
}
.selbar strong { color: #fff; }

.active-chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .7rem; }
.active-chips:empty { display: none; }

/* ==========================================================================
   B. Tabla de resultados
   ========================================================================== */

.table-wrap {
  overflow: auto; max-height: calc(100vh - 250px);
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md);
}
table.grid { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12.8px; }
table.grid th, table.grid td {
  text-align: left; padding: .5rem .6rem;
  border-bottom: 1px solid var(--line-soft); vertical-align: top;
}
table.grid thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--panel-2); color: var(--muted);
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  white-space: nowrap; border-bottom: 1px solid var(--line);
}
table.grid th.sortable { cursor: pointer; user-select: none; }
table.grid th.sortable:hover { color: var(--text); }
table.grid th.sorted { color: var(--accent); }
table.grid th .arrow { margin-left: .25rem; font-size: 9px; }
table.grid th.num, table.grid td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid tbody tr:hover { background: #1a1f27; }
table.grid tbody tr.selected { background: rgba(37,211,102,.07); }
table.grid tbody tr:last-child td { border-bottom: none; }
.col-check { width: 32px; }
td.col-check { vertical-align: middle; }

.cell-date  { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--text-2); }
.cell-group { max-width: 170px; }
.cell-vendor{ max-width: 150px; font-weight: 550; }
.cell-phone { white-space: nowrap; font-family: var(--mono); font-size: 11.5px; color: var(--text-2); }
.cell-text  { max-width: 460px; min-width: 240px; color: var(--text-2); }
.cell-text .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.cell-text.clamped .body {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.ellip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }

.tag {
  display: inline-block; font-size: 10.5px; font-weight: 650; letter-spacing: .03em;
  padding: .08rem .4rem; border-radius: var(--r-sm);
  background: var(--panel-3); color: var(--text-2); border: 1px solid var(--line);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle;
}
.tag.cat { background: rgba(88,166,255,.12); border-color: rgba(88,166,255,.3); color: #a5cdff; }
.tag.prod { background: var(--accent-dim); border-color: var(--accent-line); color: #a8f0c4; }
.price { font-weight: 700; color: #ffd479; white-space: nowrap; font-variant-numeric: tabular-nums; }
.media-icons { display: flex; gap: .2rem; color: var(--muted); }

.thumb {
  width: 46px; height: 46px; object-fit: cover; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--panel-2); cursor: zoom-in; display: block;
}
.thumb:hover { border-color: var(--accent-line); }
button.thumb-btn { padding: 0; border: none; background: none; cursor: zoom-in; border-radius: var(--r-sm); }
.no-photo { color: var(--faint); font-size: 11px; }

/* ==========================================================================
   B. Galería
   ========================================================================== */

.gallery {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .8rem;
}
.gcard {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md);
  overflow: hidden; display: flex; flex-direction: column; text-align: left;
}
.gcard-img { position: relative; width: 100%; aspect-ratio: 1 / 1; background: var(--panel-2); border: none; padding: 0; cursor: zoom-in; display: block; }
.gcard-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gcard-body { padding: .55rem .65rem .65rem; display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.gcard-top { display: flex; align-items: center; gap: .4rem; justify-content: space-between; }
.gcard .g-vendor { font-weight: 650; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gcard .g-group  { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gcard .g-text   { font-size: 11.5px; color: var(--text-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.gcard .g-foot   { display: flex; justify-content: space-between; align-items: center; gap: .4rem; margin-top: .1rem; }
.gcard-check { position: absolute; top: .4rem; left: .4rem; z-index: 2; background: rgba(0,0,0,.55); border-radius: 4px; padding: 2px; }

/* ==========================================================================
   B. Analítica (SVG generado por JS)
   ========================================================================== */

.analytics { display: grid; grid-template-columns: repeat(12, 1fr); gap: .8rem; }
.chart-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: .9rem 1rem;
  grid-column: span 12; min-width: 0;
}
.chart-card.half { grid-column: span 6; }
.chart-card.third { grid-column: span 4; }
.chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: .6rem; margin-bottom: .7rem; }
.chart-head h3 { font-size: 13.5px; }
.chart-head .sub { font-size: 11.5px; color: var(--faint); }
.chart-card svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-card svg text { font: 11px var(--font); fill: var(--muted); }
.chart-card svg .lbl-strong { fill: var(--text-2); }
.chart-card svg .grid-line { stroke: var(--line-soft); stroke-width: 1; }
.chart-card svg .axis-line { stroke: var(--line); stroke-width: 1; }
.chart-card svg .bar-bg { fill: var(--panel-2); }
.chart-card svg .bar-fg { fill: var(--accent); }
.chart-card svg .bar-fg.alt { fill: var(--accent-deep); }
.chart-card svg .dot { fill: var(--accent); }
.chart-card svg .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }

.pricecards { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: .55rem; }
.pricecard { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r-md); padding: .55rem .65rem; }
.pricecard .k { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.pricecard .v { font-size: 17px; font-weight: 700; color: #ffd479; font-variant-numeric: tabular-nums; margin-top: .1rem; }

.legend { display: flex; flex-direction: column; gap: .3rem; margin-top: .5rem; }
.legend-row { display: flex; align-items: center; gap: .45rem; font-size: 12px; color: var(--text-2); }
.legend-sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend-row .lc { margin-left: auto; color: var(--faint); font-variant-numeric: tabular-nums; }

/* ==========================================================================
   Paginación
   ========================================================================== */

.pager {
  display: flex; align-items: center; gap: .45rem; justify-content: center;
  margin-top: .9rem; flex-wrap: wrap;
}
.pager .btn { padding: .35rem .65rem; }
.pager-info { font-size: 12.5px; color: var(--muted); margin: 0 .5rem; font-variant-numeric: tabular-nums; }

/* ==========================================================================
   Estados: carga, vacío, error
   ========================================================================== */

.skeleton {
  background: linear-gradient(90deg, var(--panel-2) 25%, var(--panel-3) 50%, var(--panel-2) 75%);
  background-size: 400% 100%; animation: shimmer 1.3s infinite linear;
  border-radius: var(--r-sm); height: 11px; display: block;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

.spinner {
  width: 18px; height: 18px; border-radius: 50%; flex: none;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .5rem; padding: 3rem 1.5rem; text-align: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md);
}
.state .icon { font-size: 26px; opacity: .5; }
.state h3 { font-size: 15px; }
.state p { color: var(--muted); font-size: 13px; max-width: 44ch; }
.state.error { border-color: #4a2a2c; background: #1c1517; }
.state.error h3 { color: var(--error); }
.state-inline { padding: 1.4rem; }

/* ==========================================================================
   Modales
   ========================================================================== */

.backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(4,7,10,.72); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 1.2rem;
  animation: fade .13s ease-out;
}
.backdrop[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow-3);
  width: 100%; max-width: 640px; max-height: 90vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-sm { max-width: 420px; }
.modal-lg { max-width: 760px; }
.modal-photo { max-width: 1080px; }
.modal-head {
  display: flex; align-items: center; gap: .6rem;
  padding: .85rem 1.1rem; border-bottom: 1px solid var(--line);
}
.modal-head h2 { flex: 1; font-size: 15.5px; }
.modal-body { padding: 1.1rem; overflow-y: auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: .6rem;
  padding: .8rem 1.1rem; border-top: 1px solid var(--line); background: var(--bg-soft);
}

.rp-block { margin-bottom: 1.2rem; }
.rp-block:last-child { margin-bottom: 0; }
.rp-block h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--faint); font-weight: 700; margin-bottom: .5rem;
}
.scope-summary {
  display: flex; align-items: center; gap: .8rem; flex-wrap: wrap;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: .7rem .85rem; margin-bottom: .6rem;
}
.scope-summary .n { font-size: 22px; font-weight: 750; color: var(--accent); font-variant-numeric: tabular-nums; }
.scope-summary .d { font-size: 12.5px; color: var(--muted); }

.format-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .55rem; }
.fmt { position: relative; display: block; cursor: pointer; }
.fmt input { position: absolute; opacity: 0; width: 0; height: 0; }
.fmt-inner {
  display: flex; flex-direction: column; gap: .2rem; height: 100%;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: .7rem .75rem;
  transition: border-color .15s, background .15s;
}
.fmt:hover .fmt-inner { border-color: #3a444f; }
.fmt input:checked + .fmt-inner { border-color: var(--accent); background: var(--accent-dim); }
.fmt input:focus-visible + .fmt-inner { outline: 2px solid var(--accent); outline-offset: 2px; }
.fmt-icon {
  display: inline-grid; place-items: center; width: 34px; height: 24px; border-radius: 5px;
  font-size: 10px; font-weight: 800; letter-spacing: .02em; color: #04130a; margin-bottom: .2rem;
}
.fmt-icon.pdf  { background: #ff7a7a; }
.fmt-icon.xls  { background: #6fd39a; }
.fmt-icon.csv  { background: #ffd479; }
.fmt-icon.json { background: #8ab6ff; }
.fmt-name { font-size: 13px; font-weight: 650; }
.fmt-desc { font-size: 11.5px; color: var(--muted); line-height: 1.35; }

.photo-body { display: grid; grid-template-columns: minmax(0,1fr) 268px; gap: 1rem; padding: 1rem; }
.photo-stage {
  position: relative; display: grid; place-items: center;
  background: #080a0d; border: 1px solid var(--line); border-radius: var(--r-md);
  min-height: 320px; overflow: hidden;
}
.photo-stage img { max-width: 100%; max-height: 66vh; display: block; object-fit: contain; }
.nav-arrow {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 34px; height: 46px; border-radius: var(--r-sm);
  background: rgba(0,0,0,.55); border: 1px solid var(--line);
  color: #fff; font-size: 20px; cursor: pointer; line-height: 1;
}
.nav-arrow:hover { background: rgba(0,0,0,.8); }
.nav-arrow.left { left: .5rem; } .nav-arrow.right { right: .5rem; }
.photo-meta { display: flex; flex-direction: column; gap: .55rem; font-size: 12.5px; min-width: 0; }
.meta-row { display: flex; flex-direction: column; gap: .1rem; }
.meta-row .k { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); font-weight: 700; }
.meta-row .v { color: var(--text); overflow-wrap: anywhere; }
.meta-text { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r-md); padding: .6rem; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 190px; overflow-y: auto; color: var(--text-2); }

/* Formularios en línea de las pestañas secundarias */
.inline-form { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .9rem; }
.inline-form input { width: auto; min-width: 170px; flex: 1 1 170px; }
.inline-form select { width: auto; }

/* ==========================================================================
   Toasts
   ========================================================================== */

.toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 150; display: flex; flex-direction: column; gap: .5rem; }
.toast {
  display: flex; align-items: center; gap: .55rem;
  background: var(--panel-3); border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-md); padding: .6rem .85rem; font-size: 13px;
  box-shadow: var(--shadow-2); max-width: 380px;
  animation: slidein .18s ease-out;
}
.toast.err { border-left-color: var(--error); }
.toast.warn { border-left-color: var(--warn); }
@keyframes slidein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ==========================================================================
   Responsive
   ========================================================================== */

.only-mobile { display: none !important; }

@media (max-width: 1400px) {
  .totals { grid-template-columns: repeat(3, minmax(0,1fr)); }
}
@media (max-width: 1200px) {
  .chart-card.third { grid-column: span 6; }
}
@media (max-width: 1023px) {
  main { padding: .8rem; }
  .only-mobile { display: inline-flex !important; }
  .explore-grid { grid-template-columns: 1fr; }
  .filters-panel {
    position: fixed; inset: 0 auto 0 0; z-index: 90;
    width: min(320px, 88vw); max-height: none; border-radius: 0;
    border-width: 0 1px 0 0; box-shadow: var(--shadow-3);
    transform: translateX(-102%); transition: transform .2s ease;
    overflow-y: auto;
  }
  .filters-panel.open { transform: none; }
  .chart-card.half, .chart-card.third { grid-column: span 12; }
  .photo-body { grid-template-columns: 1fr; }
  .photo-stage img { max-height: 44vh; }
  .table-wrap { max-height: none; }
  .toolbar { position: static; }
  .search-row { flex-wrap: wrap; }
  .search-field { flex: 1 1 100%; }
}
@media (max-width: 720px) {
  .topbar { gap: .5rem; padding: 0 .7rem; }
  .live { display: none; }
  .user-meta { display: none; }
  .totals { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .search-row .btn.primary { flex: 1; justify-content: center; }
  .row2 { grid-template-columns: 1fr; }
  .cell-text { min-width: 180px; }
  .modal-foot { flex-direction: column-reverse; }
  .modal-foot .btn { width: 100%; justify-content: center; }
}

/* Mejoras #1 y #3 — línea secundaria dentro de una celda (estado por LADA,
   marca de "perfil WhatsApp"). Debe leerse como dato de apoyo, no competir con el
   valor principal de la celda. */
.sub-cell {
  margin-top: .15rem;
  font-size: .72rem;
  line-height: 1.15;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
