/* CRM Prospector · rediseño v1 — componentes base
 *
 * Todos los estilos están scoped bajo .crm-root para aislar del index.html
 * actual durante coexistencia (Fases A–G). En Fase H, cuando hagamos el swap,
 * se pueden des-namespacizar si conviene.
 *
 * Estructura del archivo:
 *   1. Layout · app shell (#app, sidebar, topbar, main)
 *   2. iPhone frame (statusbar, tabbar, topapp, home-indicator)
 *   3. Botones · .btn (-primary, -strong, -ghost, -block, -lg)
 *   4. Tarjetas · .card, .card-flat
 *   5. Chips · .chip (-accent, -red, -green)
 *   6. Campos · .field, .field-label, textarea, select
 *   7. Filas · .row (label / value)
 *   8. Progreso · .progress + .fill
 *   9. Skeleton shimmer
 *  10. Sheet bottom · .sheet-overlay, .sheet
 *  11. CmdK palette · .cmdk-overlay, .cmdk-palette, .cmdk-hit
 *  12. KPIs · .kpi, .kpi-grid-{3,5}
 *  13. Próxima visita hero
 *  14. Utilidades (.eyebrow, .mono, .muted, .t-num, etc.)
 *  15. Loader inicial
 *  16. Responsive
 */

/* ============================================================
   1. LAYOUT · APP SHELL
   ============================================================ */
html, body { margin: 0; padding: 0; height: 100%; }
html { background: var(--bg-app); }
body {
  background: var(--bg-app);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: 1.5;
  color: var(--fg-1);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
* { box-sizing: border-box; }

.crm-root { height: 100%; display: flex; flex-direction: column; }
.shell {
  display: flex;
  height: 100%;
  overflow: hidden;
}
.shell > .main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-app);
  min-width: 0;
}
.shell > .main > .content {
  flex: 1;
  overflow: auto;
  padding: var(--sp-6) var(--sp-7);
}
@media (max-width: 1000px) {
  .shell > .main > .content { padding: var(--sp-5) var(--sp-5); }
}

/* ============================================================
   SIDEBAR (desktop) — fondo azul GPF, item activo con franja roja
   ============================================================ */
.crm-root .sidebar {
  width: 230px;
  flex: 0 0 230px;
  background: var(--gpf-blue-900);
  color: #fff;
  display: flex;
  flex-direction: column;
  transition: width .15s ease;
  position: relative;
}
.crm-root .sidebar.collapsed { width: 64px; flex: 0 0 64px; }

.crm-root .sidebar .sidebar-logo {
  padding: 22px 22px 24px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}
.crm-root .sidebar.collapsed .sidebar-logo { padding: 20px 0; justify-content: center; }
.crm-root .sidebar .logo-mark {
  width: 32px; height: 32px;
  background: var(--mute-red);
  border-radius: var(--radius-m);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 14px;
  color: #fff;
  letter-spacing: 0.04em;
}
.crm-root .sidebar .logo-full {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 22px;
  letter-spacing: 0.02em;
  color: #fff;
  line-height: 1;
}
.crm-root .sidebar .logo-sub {
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: rgba(255,255,255,.55);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin-top: 4px;
}
.crm-root .sidebar.collapsed .logo-full,
.crm-root .sidebar.collapsed .logo-sub { display: none; }

.crm-root .sidebar nav {
  flex: 1;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: auto;
}
.crm-root .sidebar.collapsed nav { padding: 12px 8px; }

.crm-root .nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: var(--radius-m);
  cursor: pointer;
  color: rgba(255,255,255,.75);
  font-weight: 500;
  font-size: 14px;
  position: relative;
  text-decoration: none;
  transition: background .12s, color .12s;
}
.crm-root .sidebar.collapsed .nav-item { padding: 10px 0; justify-content: center; }
.crm-root .nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.crm-root .nav-item.active {
  background: rgba(255,255,255,.10);
  color: #fff;
  font-weight: 600;
}
.crm-root .nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 6px; bottom: 6px;
  width: 3px;
  background: var(--mute-red);
  border-radius: 2px;
}
.crm-root .sidebar.collapsed .nav-item.active::before { display: none; }
.crm-root .nav-item .nav-label { flex: 1; }
.crm-root .sidebar.collapsed .nav-item .nav-label { display: none; }
.crm-root .nav-item .nav-badge {
  background: rgba(255,255,255,.15);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  font-variant-numeric: tabular-nums;
}
.crm-root .sidebar.collapsed .nav-badge { display: none; }

.crm-root .sidebar-section-title {
  font-size: 10px;
  color: rgba(255,255,255,.5);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  padding: 0 12px;
  font-weight: 600;
  margin: 14px 0 6px;
}
.crm-root .sidebar-divider {
  height: 1px;
  background: rgba(255,255,255,.08);
  margin: 14px 12px 10px;
}
.crm-root .sidebar.collapsed .sidebar-section-title,
.crm-root .sidebar.collapsed .sidebar-divider { display: none; }

.crm-root .sidebar-user {
  padding: 14px;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex;
  gap: 10px;
  align-items: center;
  /* Ahora es un <button>: neutralizar chrome nativo y ocupar el ancho */
  width: 100%;
  border-left: 0; border-right: 0; border-bottom: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  font: inherit;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  transition: background .15s ease;
}
.crm-root .sidebar-user:hover { background: rgba(255,255,255,.06); }
.crm-root .sidebar.collapsed .sidebar-user { padding: 12px 8px; justify-content: center; }
.crm-root .sidebar-user .avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--mute-red);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 12px;
  flex: 0 0 auto;
}
.crm-root .sidebar.collapsed .sidebar-user .user-meta { display: none; }
.crm-root .sidebar-user .user-name { font-size: 13px; font-weight: 600; color: #fff; }
.crm-root .sidebar-user .user-role { font-size: 11px; color: rgba(255,255,255,.55); }

/* ============================================================
   TOPBAR (desktop)
   ============================================================ */
.crm-root .topbar {
  height: 56px;
  flex: 0 0 auto;
  border-bottom: 1px solid var(--line);
  background: var(--bg-card);
  display: flex;
  align-items: center;
  padding: 0 var(--sp-7);
  gap: 16px;
}
.crm-root .topbar.tight { padding: 0 16px; }

.crm-root .topbar .breadcrumb {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--fg-3);
  font-size: 13px;
}
.crm-root .topbar .breadcrumb .current { color: var(--fg-1); font-weight: 600; }

.crm-root .topbar .search-pill {
  flex: 1;
  max-width: 520px;
  margin-left: 24px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--paper-warm);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  padding: 7px 10px;
  cursor: text;
}
.crm-root .topbar .search-pill .placeholder { flex: 1; font-size: 13px; color: var(--fg-3); }
.crm-root .topbar .search-pill .kbd {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-3);
}

.crm-root .topbar .actions { display: flex; align-items: center; gap: 8px; }
.crm-root .topbar .btn { height: 36px; padding: 0 12px; font-size: 13px; }
.crm-root .topbar .icon-btn {
  width: 36px; height: 36px;
  background: transparent;
  border: 0;
  border-radius: var(--radius-m);
  position: relative;
  color: var(--fg-2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.crm-root .topbar .icon-btn:hover { background: var(--ink-100); }
.crm-root .topbar .icon-btn .badge-dot {
  position: absolute;
  top: 8px; right: 9px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--mute-red);
  border: 2px solid #fff;
}

/* ============================================================
   2. IPHONE FRAME
   ============================================================ */
.crm-root .iphone-frame {
  width: 100%;
  max-width: 430px;
  height: 100%;
  min-height: 100vh;
  background: var(--bg-app);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  margin: 0 auto;
}
.crm-root .iphone-frame .statusbar {
  height: var(--safe-top);
  padding: 16px 28px 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-900);
  letter-spacing: -0.01em;
  flex: 0 0 auto;
  background: transparent;
  z-index: 5;
}
.crm-root .iphone-frame .statusbar.dark { color: #fff; }
.crm-root .iphone-frame .statusbar .right {
  display: flex;
  gap: 6px;
  align-items: center;
}
.crm-root .iphone-frame .home-indicator {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 134px;
  height: 5px;
  background: var(--ink-900);
  border-radius: 3px;
  opacity: 0.35;
  z-index: 20;
}

.crm-root .iphone-frame .content {
  flex: 1;
  overflow: auto;
  padding: 0 var(--sp-5) calc(100px + var(--safe-bot));
}

/* Tab bar (PWA standalone) */
.crm-root .tabbar {
  position: absolute;
  bottom: 0;
  left: 0; right: 0;
  padding-bottom: calc(var(--safe-bot) + 4px);
  background: rgba(255,255,255,.92);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-around;
  align-items: flex-start;
  padding-top: 8px;
  z-index: 10;
}
.crm-root .tabbar .tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 60px;
  padding: 6px 4px;
  color: var(--fg-3);
  cursor: pointer;
  text-decoration: none;
  background: transparent;
  border: 0;
}
.crm-root .tabbar .tab .icon { width: 24px; height: 24px; }
.crm-root .tabbar .tab .lbl {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: -0.005em;
}
.crm-root .tabbar .tab.active { color: var(--gpf-blue-700); }
.crm-root .tabbar .tab.active .lbl { font-weight: 700; }

/* Top app bar móvil */
.crm-root .topapp {
  padding: 8px 16px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-app);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.crm-root .topapp .title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
  color: var(--fg-1);
  letter-spacing: -0.005em;
}
.crm-root .topapp .back-btn {
  background: transparent;
  border: 0;
  color: var(--gpf-blue-700);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px 6px 0;
  font: inherit;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  min-height: 44px;
}
.crm-root .topapp .action-btn {
  background: transparent;
  border: 0;
  padding: 6px;
  color: var(--gpf-blue-700);
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
}

/* ============================================================
   3. BOTONES — .btn con variantes
   ============================================================ */
.crm-root .btn {
  appearance: none;
  border: 0;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: var(--fs-body);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-5);
  height: 48px;
  min-width: 44px;
  border-radius: var(--radius-m);
  cursor: pointer;
  letter-spacing: -0.005em;
  transition: background .12s, color .12s, transform .04s;
  text-decoration: none;
  color: inherit;
}
.crm-root .btn:active { transform: translateY(1px); }
.crm-root .btn-primary { background: var(--cta); color: #fff; }
.crm-root .btn-primary:hover { background: var(--cta-hover); }
.crm-root .btn-strong { background: var(--cta-strong); color: #fff; }
.crm-root .btn-strong:hover { background: var(--cta-strong-hover); }
.crm-root .btn-ghost {
  background: transparent;
  color: var(--fg-1);
  border: 1px solid var(--line-strong);
}
.crm-root .btn-ghost:hover { background: var(--ink-100); }
.crm-root .btn-block { width: 100%; }
.crm-root .btn-lg { height: 56px; font-size: var(--fs-body-l); }

/* ============================================================
   4. TARJETAS
   ============================================================ */
.crm-root .card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
}
.crm-root .card-flat {
  background: var(--bg-card);
  border: 1px solid var(--line);
}

/* ============================================================
   5. CHIPS
   ============================================================ */
.crm-root .chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-cap);
  font-weight: 600;
  background: var(--ink-100);
  color: var(--fg-2);
  letter-spacing: -0.005em;
  border: 1px solid var(--line);
}
.crm-root .chip-accent {
  background: var(--gpf-blue-100);
  color: var(--gpf-blue-700);
  border-color: transparent;
}
.crm-root .chip-red {
  background: #fbe4e7;
  color: var(--mute-red-dark);
  border-color: transparent;
}
.crm-root .chip-green {
  background: #e3f3ec;
  color: #14704a;
  border-color: transparent;
}

/* ============================================================
   6. CAMPOS
   ============================================================ */
.crm-root .field {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  padding: 14px 16px;
  font-size: var(--fs-body);
  width: 100%;
  font-family: inherit;
  color: var(--fg-1);
  min-height: 52px;
}
.crm-root .field:focus {
  outline: 2px solid var(--gpf-blue-500);
  outline-offset: -1px;
  border-color: var(--gpf-blue-500);
}
.crm-root .field-label {
  display: block;
  font-size: var(--fs-eyebrow);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-3);
  font-weight: 600;
  margin-bottom: 6px;
}
.crm-root textarea.field { resize: vertical; line-height: 1.55; }
.crm-root select.field { appearance: none; background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="%235b6672" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg>'); background-repeat: no-repeat; background-position: right 12px center; padding-right: 40px; }

/* ============================================================
   7. FILAS label / value
   ============================================================ */
.crm-root .row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  min-height: 48px;
  border-bottom: 1px solid var(--line);
}
.crm-root .row:last-child { border-bottom: 0; }
.crm-root .row .label { font-size: 14px; color: var(--fg-3); }
.crm-root .row .value { font-size: 15px; font-weight: 500; color: var(--fg-1); }

/* ============================================================
   8. PROGRESO
   ============================================================ */
.crm-root .progress {
  height: 6px;
  background: var(--ink-100);
  border-radius: 3px;
  overflow: hidden;
}
.crm-root .progress .fill {
  height: 100%;
  background: var(--gpf-blue-700);
  transition: width .3s ease;
}
.crm-root .progress .fill.red { background: var(--mute-red); }
.crm-root .progress .fill.gray { background: var(--ink-300); }

/* ============================================================
   9. SKELETON shimmer (en tokens.css ya, lo replico scoped) ===
   ============================================================ */
.crm-root .skeleton {
  background: linear-gradient(90deg,
    var(--ink-100) 0%,
    var(--paper-warm) 50%,
    var(--ink-100) 100%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
  border-radius: var(--radius-m);
}

/* ============================================================
   10. SHEET BOTTOM
   ============================================================ */
.crm-root .sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,.45);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s, visibility .2s;
}
.crm-root .sheet-overlay.open { opacity: 1; visibility: visible; }
.crm-root .sheet {
  background: var(--bg-card);
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  box-shadow: 0 -10px 40px rgba(0,0,0,.25);
  transform: translateY(20px);
  transition: transform .2s ease;
  max-height: 80vh;
  overflow: hidden;          /* el scroll lo gestiona el hijo interno */
  display: flex;
  flex-direction: column;
}
.crm-root .sheet-overlay.open .sheet { transform: translateY(0); }
.crm-root .sheet .handle {
  width: 40px;
  height: 4px;
  background: var(--ink-300);
  border-radius: 2px;
  margin: 4px auto 16px;
}

/* En desktop (≥ 768 px): panel flotante centrado, con margen inferior para
   que no quede oculto detrás del dock de macOS. */
@media (min-width: 768px) {
  .crm-root .sheet-overlay {
    justify-content: center;
    align-items: center;
  }
  .crm-root .sheet {
    width: 100%;
    max-width: 600px;
    max-height: 82vh;
    border-radius: 20px;       /* radio completo, ya no es un "bottom sheet" */
    margin-bottom: 72px;       /* espacio libre por encima del dock (≈ 60-80 px) */
    transform: translateY(16px);
  }
  .crm-root .sheet-overlay.open .sheet { transform: translateY(0); }
  /* El handle no tiene mucho sentido en modal de escritorio, lo ocultamos */
  .crm-root .sheet .handle { display: none; }
}

/* ============================================================
   11. CMD+K PALETTE
   ============================================================ */
.crm-root .cmdk-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  background: rgba(10,45,82,.45);
  display: none;
}
.crm-root .cmdk-overlay.open { display: block; }
.crm-root .cmdk-palette {
  position: absolute;
  top: 120px;
  left: 50%;
  transform: translateX(-50%);
  width: 640px;
  max-width: calc(100vw - 32px);
  background: #fff;
  border-radius: 12px;
  box-shadow: var(--shadow-modal);
  overflow: hidden;
}
.crm-root .cmdk-palette .input-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px var(--sp-5);
  border-bottom: 1px solid var(--line);
}
.crm-root .cmdk-palette input {
  flex: 1;
  border: 0;
  outline: none;
  font: inherit;
  font-size: 16px;
  color: var(--fg-1);
  background: transparent;
}
.crm-root .cmdk-palette .esc-kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-3);
  background: var(--paper-warm);
  border: 1px solid var(--line);
  padding: 3px 7px;
  border-radius: 4px;
}
.crm-root .cmdk-results {
  max-height: 480px;
  overflow: auto;
  padding: 4px 0 8px;
}
.crm-root .cmdk-section { padding: 8px 0; }
.crm-root .cmdk-section-title {
  padding: 4px var(--sp-5) 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-3);
}
.crm-root .cmdk-hit {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px var(--sp-5);
  cursor: pointer;
  border-left: 3px solid transparent;
}
.crm-root .cmdk-hit:hover,
.crm-root .cmdk-hit.selected {
  background: var(--gpf-blue-100);
  border-left-color: var(--gpf-blue-700);
}
.crm-root .cmdk-hit .icon { color: var(--fg-2); flex: 0 0 auto; }
.crm-root .cmdk-hit.selected .icon,
.crm-root .cmdk-hit:hover .icon { color: var(--gpf-blue-700); }
.crm-root .cmdk-hit .title { font-size: 14px; font-weight: 500; color: var(--fg-1); }
.crm-root .cmdk-hit.selected .title { font-weight: 600; color: var(--gpf-blue-900); }
.crm-root .cmdk-hit .sub { font-size: 12px; color: var(--fg-3); margin-top: 1px; }
.crm-root .cmdk-hit .trail {
  font-size: 12px;
  color: var(--fg-3);
  font-family: var(--font-mono);
}
.crm-root .cmdk-hit .kbd-trail {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 3px;
  font-size: 10px;
  color: var(--fg-2);
  font-family: var(--font-mono);
}
.crm-root .cmdk-footer {
  padding: 10px var(--sp-5);
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--fg-3);
  font-family: var(--font-mono);
  background: var(--paper-warm);
}

/* ============================================================
   12. KPIs
   ============================================================ */
.crm-root .kpi {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.crm-root .kpi.big { padding: 18px 20px; }
.crm-root .kpi .label {
  font-size: var(--fs-eyebrow);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--fg-3);
  font-weight: 600;
}
.crm-root .kpi .value {
  font-family: var(--font-display);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-size: 30px;
  line-height: 1;
  color: var(--fg-1);
}
.crm-root .kpi.big .value { font-size: 36px; }
.crm-root .kpi .delta { font-size: 12px; color: var(--fg-3); }
.crm-root .kpi-grid-5 {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
}
.crm-root .kpi-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.crm-root .kpi-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ============================================================
   13. PRÓXIMA VISITA HERO (azul oscuro, halo decorativo)
   ============================================================ */
.crm-root .next-visit-hero {
  background: var(--gpf-blue-900);
  color: #fff;
  border-radius: 14px;
  padding: 18px 20px 20px;
  position: relative;
  overflow: hidden;
}
.crm-root .next-visit-hero::before {
  content: '';
  position: absolute;
  right: -20px; top: -20px;
  width: 140px; height: 140px;
  border-radius: 50%;
  background: var(--gpf-blue-700);
  opacity: 0.5;
}
.crm-root .next-visit-hero > * { position: relative; }
.crm-root .next-visit-hero .eyebrow-light {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #7fb1e6;
  font-weight: 600;
  margin-bottom: 8px;
}
.crm-root .next-visit-hero h2,
.crm-root .next-visit-hero .h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 26px;
  line-height: 1.05;
  margin: 0 0 6px;
  color: #fff;
}
.crm-root .next-visit-hero .meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: rgba(255,255,255,.85);
  margin-bottom: 4px;
}

/* ============================================================
   14. UTILIDADES
   ============================================================ */
.crm-root h1, .crm-root h2, .crm-root h3, .crm-root h4 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
  line-height: 1.05;
  color: var(--fg-1);
}
.crm-root .eyebrow {
  font-family: var(--font-sans);
  font-size: var(--fs-eyebrow);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--fg-3);
  font-weight: 600;
}
.crm-root .mono { font-family: var(--font-mono); }
.crm-root .muted { color: var(--fg-3); }
.crm-root .t-display {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.005em;
}
.crm-root .t-num {
  font-family: var(--font-display);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Iconos */
.crm-root .icon {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 1.75;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: middle;
  flex: 0 0 auto;
}
.crm-root .icon-sm { width: 16px; height: 16px; }
.crm-root .icon-lg { width: 24px; height: 24px; }

/* ============================================================
   15. LOADER INICIAL
   ============================================================ */
#app-loader {
  position: fixed;
  inset: 0;
  background: var(--paper-warm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
  z-index: 9999;
  transition: opacity .3s ease;
}
#app-loader.hidden { opacity: 0; pointer-events: none; }
#app-loader .spinner {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 3px solid var(--ink-100);
  border-top-color: var(--gpf-blue-700);
  animation: skeleton-spin 0.9s linear infinite;
}
#app-loader .label { font-size: 13px; color: var(--fg-3); }
@keyframes skeleton-spin { to { transform: rotate(360deg); } }

/* ============================================================
   16. RESPONSIVE
   ============================================================ */
/* < 1000px: sidebar colapsada por defecto, KPIs 3 columnas */
@media (max-width: 1000px) {
  .crm-root .sidebar {
    width: 64px;
    flex: 0 0 64px;
  }
  .crm-root .sidebar .sidebar-logo {
    padding: 20px 0;
    justify-content: center;
  }
  .crm-root .sidebar .logo-full,
  .crm-root .sidebar .logo-sub { display: none; }
  .crm-root .sidebar nav { padding: 12px 8px; }
  .crm-root .nav-item {
    padding: 10px 0;
    justify-content: center;
  }
  .crm-root .nav-item .nav-label,
  .crm-root .nav-badge,
  .crm-root .sidebar-section-title,
  .crm-root .sidebar-divider { display: none; }
  .crm-root .nav-item.active::before { display: none; }
  .crm-root .sidebar-user {
    padding: 12px 8px;
    justify-content: center;
  }
  .crm-root .sidebar-user .user-meta { display: none; }
  .crm-root .kpi-grid-5 { grid-template-columns: repeat(3, 1fr); }
  .crm-root .topbar { padding: 0 16px; }
}

/* ≥ 701px: desktop — neutralizar iphone-frame (max-width, chrome, scroll anidado)
   Los screens que usan iphone-frame en móvil (briefing, informe) tienen su propio
   renderDesktopColumn sin iphone-frame en ≥768px. Esta regla actúa como red de
   seguridad para cualquier residuo y gestiona el layout del inicio.js. */
@media (min-width: 701px) {
  .crm-root .iphone-frame {
    max-width: none;
    margin: 0;
    height: auto;
    min-height: 0;
    overflow: visible;
  }
  .crm-root .iphone-frame .statusbar,
  .crm-root .iphone-frame .home-indicator,
  .crm-root .iphone-frame .tabbar {
    display: none;
  }
  /* El scroll lo gestiona .shell > .main > .content; no scroll anidado */
  .crm-root .iphone-frame .content {
    overflow: visible;
    padding-bottom: 0;
    flex: none;
  }
}

/* < 700px: vista mobile, sin sidebar */
@media (max-width: 700px) {
  .crm-root .shell > .sidebar,
  .crm-root .shell > .main > .topbar { display: none; }
  .crm-root .shell > .main > .content { padding: 0; }
  .crm-root .kpi-grid-5 { grid-template-columns: 1fr 1fr; }
  /* Respetar el Dynamic Island / notch en el top */
  .crm-root .shell > .main > .content {
    padding-top: env(safe-area-inset-top, 0px);
  }
  /* Espacio en el fondo para que el contenido no quede bajo la tab bar global */
  .crm-root .view.active {
    padding-bottom: calc(83px + env(safe-area-inset-bottom, 0px));
  }
  /* Excepciones: briefing e informe ocupan pantalla completa */
  #view-briefing.active,
  #view-informe.active {
    padding-bottom: 0;
  }
  /* El header sticky del briefing/informe debe respetar el safe area para
     no quedar bajo el Dynamic Island cuando el usuario hace scroll */
  .crm-root .iphone-frame .briefing-sticky-header {
    top: 0; /* fallback — sobreescrito por la regla de abajo */
    top: env(safe-area-inset-top, 0px);
  }
  /* Touch polish global */
  .crm-root * {
    -webkit-tap-highlight-color: transparent;
  }
  .crm-root button,
  .crm-root a,
  .crm-root [role="button"] {
    touch-action: manipulation;
  }
  /* Inputs: evitar zoom automático iOS (requiere font-size ≥ 16px) */
  .crm-root input,
  .crm-root select,
  .crm-root textarea {
    font-size: max(16px, 1rem) !important;
  }
}

/* Overscroll: evita el rebote de página en standalone */
@media (display-mode: standalone) {
  html, body { overscroll-behavior: none; }
  .crm-root .iphone-frame { overscroll-behavior-y: contain; }
}

/* ============================================================
   BOTÓN DE CUENTA MÓVIL
   Oculto en desktop; fijo arriba-derecha en < 700px (donde no hay
   sidebar ni topbar). No colisiona con la tab bar (abajo) ni el voice-fab.
   ============================================================ */
.mobile-account-btn { display: none; }

@media (max-width: 700px) {
  .mobile-account-btn {
    display: flex;
    position: fixed;
    top: calc(env(safe-area-inset-top, 0px) + 8px);
    right: calc(env(safe-area-inset-right, 0px) + 12px);
    z-index: 101;
    width: 36px; height: 36px;
    align-items: center; justify-content: center;
    border: 0.5px solid rgba(0,0,0,.10);
    border-radius: 50%;
    background: var(--mute-red);
    color: #fff;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,.18);
    -webkit-appearance: none;
    appearance: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-account-btn:active { opacity: .85; }
}

/* ============================================================
   MOBILE TAB BAR GLOBAL (Opción B)
   Reemplaza el tabbar interno del iphone-frame.
   Sólo visible en móvil real (< 700px).
   ============================================================ */
.mobile-tabbar {
  display: none; /* oculto en desktop */
}

@media (max-width: 700px) {
  .mobile-tabbar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0; right: 0;
    z-index: 100;
    justify-content: space-around;
    align-items: flex-start;
    padding-top: 8px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    background: rgba(255,255,255,.88);
    -webkit-backdrop-filter: saturate(180%) blur(24px);
    backdrop-filter: saturate(180%) blur(24px);
    border-top: 0.5px solid rgba(0,0,0,.12);
  }
  .mobile-tabbar .m-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    min-width: 64px;
    padding: 4px 8px 2px;
    color: var(--fg-3);
    cursor: pointer;
    text-decoration: none;
    background: transparent;
    border: 0;
    font-family: var(--font-body);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
  .mobile-tabbar .m-tab .m-icon { width: 24px; height: 24px; }
  .mobile-tabbar .m-tab .m-lbl {
    font-size: 10px;
    font-weight: 500;
    letter-spacing: -0.005em;
  }
  .mobile-tabbar .m-tab.active { color: var(--gpf-blue-700); }
  .mobile-tabbar .m-tab.active .m-lbl { font-weight: 700; }
  /* El tabbar interno del iphone-frame no se muestra en móvil real */
  .crm-root .tabbar { display: none; }
  /* La statusbar simulada (9:41, wifi, batería) no se muestra en móvil real:
     en iPhone la barra de estado nativa ya está arriba */
  .crm-root .iphone-frame .statusbar { display: none; }
}

/* ============================================================
   VOICE FAB (Opción D)
   Botón de micrófono flotante — sólo en móvil.
   ============================================================ */
.voice-fab {
  display: none;
}

@media (max-width: 700px) {
  .voice-fab {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    right: 18px;
    bottom: calc(83px + env(safe-area-inset-bottom, 0px) + 14px);
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--gpf-blue-700);
    color: #fff;
    border: none;
    cursor: pointer;
    z-index: 99;
    box-shadow: 0 4px 16px rgba(29,78,216,.4);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: transform .15s ease, box-shadow .15s ease;
  }
  .voice-fab:active {
    transform: scale(.93);
    box-shadow: 0 2px 8px rgba(29,78,216,.3);
  }
  .voice-fab svg { width: 22px; height: 22px; }
  /* Ocultar en pantallas donde no tiene sentido */
  .voice-fab.hidden { display: none !important; }
  /* En la ficha hay una barra de acciones fija encima de la tab bar
     (Llamar/Briefing/Informe, ~62px). Subimos el FAB para que no la tape. */
  .voice-fab.over-actionbar {
    bottom: calc(83px + env(safe-area-inset-bottom, 0px) + 62px + 14px);
  }
}

/* ============================================================
   DETAIL STICKY ACTION BAR (barra fija en ficha de empresa)
   ============================================================ */
.detail-action-bar {
  display: none;
}

@media (max-width: 700px) {
  .detail-action-bar {
    display: flex;
    position: fixed;
    left: 0; right: 0;
    bottom: calc(83px + env(safe-area-inset-bottom, 0px));
    z-index: 90;
    gap: 8px;
    padding: 10px 16px;
    background: rgba(255,255,255,.92);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border-top: 0.5px solid rgba(0,0,0,.1);
  }
  .detail-action-bar .dab-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 42px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    text-decoration: none;
    border: 1px solid var(--line);
    background: var(--bg-card);
    color: var(--fg-1);
  }
  .detail-action-bar .dab-btn.primary {
    background: var(--gpf-blue-700);
    color: #fff;
    border-color: transparent;
  }
  .detail-action-bar .dab-btn svg { width: 15px; height: 15px; }
  /* Ajuste de padding extra para que el contenido no quede bajo la barra doble */
  #view-detail.active {
    padding-bottom: calc(83px + env(safe-area-inset-bottom, 0px) + 62px);
  }
}

/* Vistas */
.crm-root .view { display: none; }
.crm-root .view.active { display: block; }

/* =====================================================================
   Planificador — responsivo
   Desktop: 7 columnas (lun…dom)
   Tablet/Mobile (<900px): stack vertical de un día encima del otro
   ===================================================================== */
.crm-root .planner-week-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 10px;
}
@media (max-width: 900px) {
  .crm-root .planner-week-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .crm-root .planner-col {
    min-height: auto !important;
  }
  /* Toolbar: el row se parte en varias líneas si no caben */
  .crm-root .planner-toolbar {
    flex-wrap: wrap;
    gap: 6px !important;
  }
  .crm-root .planner-toolbar > .planner-week-label {
    flex-basis: 100%;
    order: -1;
    text-align: center;
  }
}

/* Panel "Pendiente en la zona": grids a 1 columna en pantallas estrechas */
@media (max-width: 700px) {
  .crm-root .planner-zona-grid {
    grid-template-columns: 1fr !important;
  }
}

/* Modal del planificador (alta/edición de visita) — full-screen en mobile */
@media (max-width: 600px) {
  .planner-modal-overlay > div {
    min-width: 0 !important;
    width: 96vw !important;
    max-width: 96vw !important;
    max-height: 92vh;
    overflow: auto;
    padding: 16px !important;
  }
}

/* =====================================================================
   @media print — Briefing pre-visita estilo informe profesional GPF.
   Inspiración: planning_murcia_abril_2026.html (banda azul, badges,
   tipografía profesional, headers acentuados).
   ===================================================================== */

/* Cabecera de impresión: oculta en pantalla, visible en print */
.print-only { display: none !important; }

@media print {
  /* Cabecera, título y meta solo en print */
  .print-only { display: block !important; }
  .print-meta.print-only { display: flex !important; }

  /* Ocultar TODA la UI de la app */
  .crm-root .shell > .sidebar,
  .crm-root .shell > .main > .topbar,
  .crm-root .nav-pill,
  .crm-root #app-loader,
  .crm-root .search-pill,
  .crm-root .cmdk-overlay,
  .crm-root .sheet-overlay,
  .crm-root .briefing-toolbar,
  .crm-root .back-btn,
  .crm-root .home-indicator,
  .crm-root .statusbar,
  .crm-root .iphone-frame::before,
  .crm-root .iphone-frame::after,
  .crm-root .view:not(.active),
  /* Ocultar el header sticky del briefing en pantalla (con flecha "Atrás" y title interno),
     porque ahora tenemos la cabecera de impresión propia */
  #view-briefing .iphone-frame > div:first-of-type:not(.briefing-body),
  #view-briefing > div > div:first-child {
    display: none !important;
  }

  /* Contenedores a sangre, sin marco iPhone */
  .crm-root,
  .crm-root .shell,
  .crm-root .shell > .main,
  .crm-root .shell > .main > .content,
  .crm-root .view.active,
  .crm-root .iphone-frame,
  .crm-root .briefing-body {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
    background: white !important;
    overflow: visible !important;
    height: auto !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    border: 0 !important;
  }

  /* Tipografía base */
  body, .crm-root {
    font-family: -apple-system, "Helvetica Neue", Arial, sans-serif !important;
    font-size: 10.5pt !important;
    line-height: 1.5 !important;
    color: #222 !important;
    background: white !important;
  }

  /* ── CABECERA DE IMPRESIÓN ──────────────────────────────────── */
  .print-header {
    background: #0a2d52;
    color: white;
    padding: 12pt 16pt;
    margin: 0 0 4pt 0;
    border-radius: 4pt;
    display: flex !important;
    justify-content: space-between;
    align-items: baseline;
    page-break-after: avoid;
  }
  .print-brand {
    font-family: "Helvetica Neue", Arial, sans-serif;
    font-weight: 700;
    font-size: 10pt;
    letter-spacing: 0.08em;
    color: #aed6f1;
  }
  .print-doc-type {
    font-size: 11pt;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  /* Título del cliente */
  .print-title {
    font-family: "Helvetica Neue", Arial, sans-serif !important;
    font-size: 20pt !important;
    font-weight: 700 !important;
    color: #0a2d52 !important;
    margin: 10pt 0 2pt 0 !important;
    line-height: 1.15 !important;
    page-break-after: avoid;
  }

  /* Banda de metadatos bajo el título */
  .print-meta {
    flex-wrap: wrap;
    gap: 18pt;
    margin: 0 0 16pt 0 !important;
    padding: 6pt 0 10pt 0;
    border-bottom: 2pt solid #0a2d52;
    font-size: 10pt;
    color: #555;
  }
  .print-meta span strong { color: #222; font-weight: 600; }

  /* ── SECCIONES DEL BRIEFING ──────────────────────────────────── */
  .crm-root h2 {
    background: #1f3a5a;
    color: white !important;
    padding: 6pt 12pt !important;
    border-radius: 3pt;
    font-family: "Helvetica Neue", Arial, sans-serif !important;
    font-size: 13pt !important;
    font-weight: 600 !important;
    margin: 14pt 0 6pt 0 !important;
    letter-spacing: 0 !important;
    text-transform: none !important;
    border-bottom: 0 !important;
    page-break-after: avoid;
    page-break-inside: avoid;
  }

  .crm-root h3 {
    color: #1f3a5a !important;
    font-family: "Helvetica Neue", Arial, sans-serif !important;
    font-size: 11pt !important;
    font-weight: 700 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.05em !important;
    margin: 10pt 0 4pt 0 !important;
    padding-left: 10pt;
    border-left: 3pt solid #2e6da4;
    page-break-after: avoid;
  }

  .crm-root h4 {
    color: #2e6da4 !important;
    font-size: 10.5pt !important;
    font-weight: 600 !important;
    margin: 8pt 0 3pt 0 !important;
    page-break-after: avoid;
  }

  /* Texto y listas */
  .crm-root p, .crm-root li {
    margin: 3pt 0 !important;
  }
  .crm-root p, .crm-root li, .crm-root blockquote {
    page-break-inside: avoid;
  }
  .crm-root ul, .crm-root ol {
    margin: 4pt 0 6pt 22pt !important;
  }

  /* Blockquote: caja destacada con barra lateral */
  .crm-root blockquote {
    background: #e8f0f7 !important;
    border-left: 4pt solid #2e6da4 !important;
    color: #1a3a5c !important;
    padding: 6pt 12pt !important;
    margin: 8pt 0 !important;
    font-style: normal !important;
    font-size: 10pt !important;
    border-radius: 3pt;
  }

  /* Código inline (raro en briefings, pero por si aparece) */
  .crm-root code {
    background: #f0f5fc !important;
    border: 1px solid #d0d8e8 !important;
    color: #0a2d52 !important;
    padding: 0.5pt 4pt !important;
    border-radius: 2pt;
    font-size: 9.5pt !important;
  }

  /* Strong: color GPF para destacar */
  .crm-root strong, .crm-root b {
    color: #0a2d52 !important;
    font-weight: 600 !important;
  }

  .crm-root a {
    color: #2e6da4 !important;
    text-decoration: none !important;
  }

  .crm-root hr {
    border: 0 !important;
    border-top: 1pt solid #d0d8e8 !important;
    margin: 12pt 0 !important;
  }

  /* CTA y botones ocultos en impresión */
  .crm-root .btn,
  .crm-root button {
    display: none !important;
  }

  /* Pie de página con número de página */
  @page {
    size: A4;
    margin: 14mm 14mm 16mm 14mm;
    @bottom-center {
      content: "Ferroplast · Tuyper · Uso interno · Página " counter(page) " de " counter(pages);
      font-family: "Helvetica Neue", Arial, sans-serif;
      font-size: 8pt;
      color: #888;
    }
  }
}

/* ============================================================
   AUTH GATE — formulario de login (redesign/auth.js)
   ============================================================ */
.auth-gate {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: var(--bg-app);
}
.auth-card {
  width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-2);
  padding: 32px 28px;
}
.auth-brand {
  font-family: var(--font-mono); font-size: 12px; letter-spacing: .04em;
  text-transform: uppercase; color: var(--gpf-blue-700); margin-bottom: 4px;
}
.auth-title {
  font-family: var(--font-display); font-weight: 700; font-size: 28px;
  text-transform: uppercase; letter-spacing: .005em; color: var(--fg-1); margin: 0;
}
.auth-sub { font-size: 14px; color: var(--fg-3); margin: 2px 0 18px; }
.auth-label {
  font-size: 12px; font-weight: 600; color: var(--fg-2);
  text-transform: uppercase; letter-spacing: .03em; margin-top: 12px;
}
.auth-input {
  font-family: var(--font-sans); font-size: 15px; color: var(--fg-1);
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: var(--radius-m); padding: 11px 12px; margin-top: 4px;
}
.auth-input:focus { outline: 2px solid var(--gpf-blue-500); outline-offset: -1px; border-color: var(--gpf-blue-500); }
.auth-error {
  background: #fbe4e7; color: var(--mute-red-dark);
  border-radius: var(--radius-m); padding: 9px 11px; font-size: 13px; margin-top: 14px;
}
.auth-btn {
  margin-top: 20px; padding: 13px; cursor: pointer;
  font-family: var(--font-display); font-weight: 600; font-size: 16px;
  text-transform: uppercase; letter-spacing: .02em;
  color: #fff; background: var(--cta); border: none; border-radius: var(--radius-m);
}
.auth-btn:hover { background: var(--cta-hover); }
.auth-btn:disabled { opacity: .6; cursor: default; }
