/* =====================================================================
 *  Shell del CRM: menú lateral, topbar mobile, cabecera de página y las
 *  piezas propias del tema (tarjetas, listas, tablero de métricas).
 *
 *  Los componentes de Bootstrap (tablas, botones, formularios, modales)
 *  se restilan en app.css; acá vive sólo lo que es nuestro.
 *  El prefijo d2- identifica a este sistema de diseño.
 * ===================================================================== */

.d2{
  --d2-bg:        #000000;
  --d2-surface:   #0b0b0b;
  --d2-surface-2: #121212;
  --d2-surface-3: #171717;
  --d2-line:      #1f1f1f;
  --d2-line-2:    #2e2e2e;
  --d2-text:      #f3f1ee;
  --d2-soft:      #b8b5b0;
  --d2-muted:     #86837e;

  --d2-gold:  #e3b23c;
  --d2-sage:  #86b6a0;
  --d2-clay:  #dc8f6b;
  --d2-lilac: #a99cf0;

  --d2-nav-w: 264px;
  --d2-radius: 14px;
  --d2-radius-sm: 10px;

  background: var(--d2-bg) !important;
  color: var(--d2-text);
  font-family: 'Instrument Sans', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  letter-spacing: -0.01em;
  min-height: 100vh;
}

.d2 :focus-visible{
  outline: 2px solid var(--d2-text);
  outline-offset: 2px;
  border-radius: 6px;
}

.d2-skip{
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 200;
  background: #fff;
  color: #000;
  padding: .6rem 1rem;
  border-radius: 0 0 10px 0;
  font-weight: 600;
}
.d2-skip:focus{ left: 0; }

/* ── Estructura ───────────────────────────────────────────────── */
.d2-shell{ display: flex; min-height: 100vh; }

.d2-main{
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.d2-content{
  padding: 1.1rem 1rem 4rem;
  width: 100%;
  outline: none;
}
@media (min-width: 1024px){
  .d2-content{ padding: 1.75rem 2.25rem 5rem; }
}

/* ── Menú lateral ─────────────────────────────────────────────── */
.d2-nav{
  width: var(--d2-nav-w);
  flex: 0 0 var(--d2-nav-w);
  background: var(--d2-surface);
  border-right: 1px solid var(--d2-line);
  height: 100vh;
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  z-index: 70;
}

.d2-nav__brand{
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: 1rem 1rem .9rem;
  border-bottom: 1px solid var(--d2-line);
}
.d2-brand{
  display: flex;
  align-items: center;
  gap: .6rem;
  text-decoration: none;
  color: var(--d2-text);
  min-width: 0;
}
.d2-brand img{ border-radius: 8px; }
.d2-brand span{ display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.d2-brand strong{ font-size: .92rem; font-weight: 600; letter-spacing: -0.02em; }
.d2-brand small{ font-size: .7rem; color: var(--d2-muted); letter-spacing: .04em; }

/* Scope con .d2 para ganarle a .d2-iconbtn, que se declara más abajo. */
.d2 .d2-nav__close{ margin-left: auto; display: none; }

/* El área scrolleable: los grupos se pliegan y la cabecera de cada uno
   queda pegada arriba mientras se recorre la lista. */
.d2-nav__scroll{
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  padding: .5rem .6rem 1.25rem;
  mask-image: linear-gradient(to bottom, transparent 0, #000 14px, #000 calc(100% - 22px), transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 14px, #000 calc(100% - 22px), transparent 100%);
}
.d2-nav__scroll::-webkit-scrollbar{ width: 0; height: 0; }

.d2-nav__list{ list-style: none; margin: 0; padding: 0; }

.d2-nav__group{ margin-top: .35rem; }
.d2-nav__group + .d2-nav__group{ border-top: 1px solid var(--d2-line); padding-top: .35rem; }

.d2-nav__grouphead{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--d2-surface);
  padding: .5rem .55rem .35rem;
  font-size: .68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .11em;
  color: var(--d2-muted);
  cursor: pointer;
  list-style: none;
  border-radius: 8px;
}
.d2-nav__grouphead::-webkit-details-marker{ display: none; }
.d2-nav__grouphead:hover{ color: var(--d2-soft); }
.d2-nav__grouphead i{ font-size: .7rem; transition: transform .18s ease; }
.d2-nav__group[open] > .d2-nav__grouphead i{ transform: rotate(180deg); }

.d2-nav__link{
  position: relative;
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .5rem .6rem;
  border-radius: var(--d2-radius-sm);
  color: var(--d2-soft);
  text-decoration: none;
  font-size: .885rem;
  line-height: 1.2;
  transition: background .12s ease, color .12s ease;
}
.d2-nav__link i{ font-size: .95rem; color: var(--d2-muted); flex: 0 0 auto; }
.d2-nav__link span{ min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.d2-nav__link:hover{ background: var(--d2-surface-2); color: var(--d2-text); }
.d2-nav__link:hover i{ color: var(--d2-soft); }
.d2-nav__link.is-muted{ color: var(--d2-muted); }

.d2-nav__link.is-active{
  background: var(--d2-surface-3);
  color: #fff;
  font-weight: 600;
}
.d2-nav__link.is-active i{ color: #fff; }
/* Marca de activo: una barra fina a la izquierda en vez de una caja con borde */
.d2-nav__link.is-active::before{
  content: "";
  position: absolute;
  left: -.6rem;
  top: 50%;
  transform: translateY(-50%);
  width: 2px;
  height: 1.15rem;
  border-radius: 2px;
  background: var(--d2-text);
}

.d2-nav__badge{
  margin-left: auto;
  background: rgba(227,178,60,.16);
  color: var(--d2-gold);
  border-radius: 99px;
  font-size: .7rem;
  font-weight: 600;
  padding: .05rem .45rem;
}

.d2-nav__user{
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .8rem 1rem;
  border-top: 1px solid var(--d2-line);
}
.d2-nav__username{
  font-size: .84rem;
  color: var(--d2-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.d2-nav__user .d2-iconbtn{ margin-left: auto; }

.d2-avatar{
  width: 28px;
  height: 28px;
  border-radius: 99px;
  background: var(--d2-surface-3);
  border: 1px solid var(--d2-line-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: .78rem;
  font-weight: 600;
  color: var(--d2-text);
  flex: 0 0 auto;
}

.d2-backdrop{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 90;
}

/* ── Topbar (sólo mobile: es la forma de abrir el menú) ───────── */
.d2-topbar{
  position: sticky;
  top: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .55rem .9rem;
  background: var(--d2-bg);
  border-bottom: 1px solid var(--d2-line);
  min-height: 3.1rem;
}
.d2-topbar__title{
  font-weight: 600;
  font-size: .95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.d2 .d2-topbar__burger{ display: none; }

@media (min-width: 1024px){
  .d2-topbar{ display: none; }
}

/* ── Botones propios ──────────────────────────────────────────── */
.d2-btn{
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .45rem .8rem;
  border-radius: var(--d2-radius-sm);
  border: 1px solid var(--d2-line-2);
  background: transparent;
  color: var(--d2-text);
  font-size: .85rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.d2-btn:hover{ background: var(--d2-surface-2); color: #fff; border-color: #3a3a3a; }
.d2-btn--ghost{ border-color: transparent; color: var(--d2-soft); }
.d2-btn--ghost:hover{ border-color: var(--d2-line-2); }
.d2-btn--solid{ background: #fff; color: #000; border-color: #fff; }
.d2-btn--solid:hover{ background: #e6e2da; color: #000; border-color: #e6e2da; }
.d2-btn--warn{ border-color: rgba(227,178,60,.4); color: var(--d2-gold); }
.d2-btn--warn:hover{ background: rgba(227,178,60,.1); border-color: rgba(227,178,60,.6); color: var(--d2-gold); }

.d2-iconbtn{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--d2-radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--d2-soft);
  cursor: pointer;
  text-decoration: none;
  transition: background .12s ease, color .12s ease;
}
.d2-iconbtn:hover{ background: var(--d2-surface-2); color: #fff; }
.d2-iconbtn--danger:hover{ background: rgba(220,105,105,.12); color: #f0a3a3; }

/* ── Cabecera de página ───────────────────────────────────────── */
.d2-pagehead{
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.35rem;
}
.d2-pagehead h1{
  font-size: 1.8rem;
  font-weight: 600;
  letter-spacing: -0.035em;
  margin: .15rem 0 0;
}
.d2-eyebrow{
  font-size: .78rem;
  color: var(--d2-muted);
  text-transform: capitalize;
}

/* Segmentado: pills dentro de un riel, sin sombras */
.d2-segmented{
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--d2-line);
  border-radius: 99px;
  background: var(--d2-surface);
}
.d2-segmented a,
.d2-segmented button{
  border: 0;
  background: transparent;
  color: var(--d2-muted);
  font-size: .82rem;
  font-weight: 500;
  padding: .35rem .9rem;
  border-radius: 99px;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s ease, color .12s ease;
}
.d2-segmented a:hover,
.d2-segmented button:hover{ color: var(--d2-text); }
.d2-segmented [aria-current="page"],
.d2-segmented .is-active,
.d2-segmented .nav-link.active{
  background: var(--d2-surface-3);
  color: #fff;
}

/* ── Tablero de métricas: una caja dividida por hairlines ─────── */
.d2-board{
  border: 1px solid var(--d2-line);
  border-radius: var(--d2-radius);
  background: var(--d2-line);
  display: grid;
  grid-template-columns: 1fr;
  gap: 1px;
  overflow: hidden;
  margin-bottom: 1.1rem;
}
@media (min-width: 640px){ .d2-board{ grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1180px){ .d2-board{ grid-template-columns: repeat(4, 1fr); } }
.d2-board--3 { grid-template-columns: 1fr; }
@media (min-width: 900px){ .d2-board--3{ grid-template-columns: repeat(3, 1fr); } }

.d2-stat{
  background: var(--d2-surface);
  padding: 1.1rem 1.15rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: .3rem;
}
.d2-stat__label{
  font-size: .78rem;
  color: var(--d2-muted);
  display: flex;
  align-items: center;
  gap: .4rem;
}
.d2-stat__value{
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -0.04em;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}
.d2-stat__hint{ font-size: .78rem; color: var(--d2-muted); }

/* ── Tarjetas propias ─────────────────────────────────────────── */
.d2-grid{
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.1rem;
  margin-bottom: 1.1rem;
}
@media (min-width: 1180px){
  .d2-grid--8-4{ grid-template-columns: 2fr 1fr; }
  .d2-grid--7-5{ grid-template-columns: 1.35fr 1fr; }
}

.d2-card{
  border: 1px solid var(--d2-line);
  border-radius: var(--d2-radius);
  background: var(--d2-surface);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.d2-card__head{
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .6rem;
  padding: 1rem 1.15rem;
  border-bottom: 1px solid var(--d2-line);
}
.d2-card__title{ font-size: .95rem; font-weight: 600; margin: 0; }
.d2-card__sub{ font-size: .78rem; color: var(--d2-muted); margin: .15rem 0 0; }
.d2-card__body{ padding: 1.15rem; }
.d2-card__body--flush{ padding: 0; }
.d2-card__foot{
  padding: .65rem 1.15rem;
  border-top: 1px solid var(--d2-line);
  text-align: center;
}

.d2-tag{
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .74rem;
  color: var(--d2-muted);
  border: 1px solid var(--d2-line);
  border-radius: 99px;
  padding: .18rem .55rem;
  white-space: nowrap;
}

.d2-chart{ position: relative; height: 280px; }
.d2-chart--tall{ height: 340px; }
@media (max-width: 767.98px){
  .d2-chart{ height: 230px; }
  .d2-chart--tall{ height: 260px; }
}

/* ── Barras proporcionales ────────────────────────────────────── */
.d2-bars{ list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .95rem; }
.d2-bar__top{
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .75rem;
  font-size: .85rem;
}
.d2-bar__name{ color: var(--d2-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.d2-bar__value{ font-variant-numeric: tabular-nums; white-space: nowrap; }
.d2-bar__track{
  margin-top: .4rem;
  height: 5px;
  border-radius: 99px;
  background: var(--d2-surface-3);
  overflow: hidden;
}
.d2-bar__fill{ height: 100%; border-radius: 99px; background: var(--d2-text); }
.d2-bar__hint{ font-size: .74rem; color: var(--d2-muted); margin-top: .25rem; }

/* ── Listas ───────────────────────────────────────────────────── */
.d2-list{ list-style: none; margin: 0; padding: 0; }
.d2-list > li + li{ border-top: 1px solid var(--d2-line); }

.d2-row{
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: .7rem 1.15rem;
}
.d2-row:hover{ background: var(--d2-surface-2); }
.d2-row__time{
  font-variant-numeric: tabular-nums;
  font-size: .78rem;
  color: var(--d2-muted);
  width: 3.1rem;
  flex: 0 0 auto;
}
.d2-row__main{ min-width: 0; flex: 1 1 auto; }
.d2-row__name{
  color: var(--d2-text);
  text-decoration: none;
  font-size: .9rem;
  font-weight: 500;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.d2-row__name:hover{ text-decoration: underline; }
.d2-row__meta{
  display: flex;
  align-items: center;
  gap: .45rem;
  flex-wrap: wrap;
  margin-top: .15rem;
  font-size: .76rem;
  color: var(--d2-muted);
}
.d2-dot{
  width: 7px;
  height: 7px;
  border-radius: 99px;
  display: inline-block;
  flex: 0 0 auto;
}
.d2-row__actions{ margin-left: auto; flex: 0 0 auto; }

.d2-scroll{
  overflow-y: auto;
  max-height: 26rem;
  overscroll-behavior: contain;
  scrollbar-width: none;
}
.d2-scroll::-webkit-scrollbar{ width: 0; height: 0; }
.d2-scroll.is-open{ max-height: none; }

.d2-empty{
  padding: 2.5rem 1.15rem;
  text-align: center;
  color: var(--d2-muted);
  font-size: .88rem;
}

/* ── Tabs ─────────────────────────────────────────────────────── */
.d2 .d2-tabs.nav{ gap: 2px; border: 0; flex-wrap: nowrap; overflow-x: auto; }
.d2 .d2-tabs .nav-link{
  border: 0;
  border-radius: 99px;
  color: var(--d2-muted);
  font-size: .82rem;
  font-weight: 500;
  padding: .35rem .9rem;
  white-space: nowrap;
}
.d2 .d2-tabs .nav-link:hover{ color: var(--d2-text); }
.d2 .d2-tabs .nav-link.active{ background: var(--d2-surface-3); color: #fff; }

.d2-switch{
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  font-size: .8rem;
  color: var(--d2-soft);
  cursor: pointer;
}
.d2-switch input{ margin: 0; }

/* ── Flash ────────────────────────────────────────────────────── */
.d2-flash{ display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1.1rem; }
.d2-alert{
  border: 1px solid var(--d2-line-2);
  border-radius: var(--d2-radius-sm);
  background: var(--d2-surface);
  padding: .7rem .9rem;
  font-size: .88rem;
}
.d2-alert--success{ border-color: rgba(134,182,160,.35); color: #cfe8dd; }
.d2-alert--danger{ border-color: rgba(220,105,105,.35); color: #f0c4c4; }
.d2-alert--warning{ border-color: rgba(227,178,60,.35); color: #f0dcae; }
.d2-alert--info{ border-color: rgba(169,156,240,.35); color: #ddd6f8; }

/* ── Mobile: el menú pasa a ser un panel deslizable ───────────── */
@media (max-width: 1023.98px){
  .d2 .d2-topbar__burger{ display: inline-flex; }
  .d2 .d2-nav__close{ display: inline-flex; }

  .d2-nav{
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    width: min(86vw, 300px);
    flex-basis: auto;
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform .22s ease, visibility .22s ease;
  }
  .d2-nav-open .d2-nav{ transform: none; visibility: visible; }
  .d2-nav-open{ overflow: hidden; }

  .d2-pagehead{ margin-bottom: 1rem; }
  .d2-pagehead h1{ font-size: 1.4rem; }
  .d2-stat__value{ font-size: 1.7rem; }
  .d2-row{ padding: .7rem .9rem; }
  .d2-card__head, .d2-card__body{ padding: .95rem; }
  .d2-card__foot{ padding: .6rem .95rem; }
}

@media (prefers-reduced-motion: reduce){
  .d2 *{ transition: none !important; animation: none !important; }
}
