/* =========================================================
   Historial de cortes
   ========================================================= */

.history-view {
  display: none;
  position: relative;
  margin-top: 18px;
  border: 1px solid var(--ui-border, var(--border));
  border-radius: 26px;
  background: var(--surface);
  box-shadow: var(--ui-shadow, 0 18px 50px rgba(30,22,110,.09));
  overflow: hidden;
  animation: historyReveal .45s cubic-bezier(.2,.8,.2,1) both;
}

body.is-history-view .history-view {
  display: block;
}

body.is-history-view .hero-card,
body.is-history-view .content-grid,
body.is-history-view #availabilityPanel,
body.is-history-view #successPanel {
  display: none !important;
}

.history-grid-bg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .34;
  background-image:
    linear-gradient(to right, color-mix(in srgb, var(--brand-500) 8%, transparent) 1px, transparent 1px),
    linear-gradient(to bottom, color-mix(in srgb, var(--brand-500) 8%, transparent) 1px, transparent 1px);
  background-size: 1rem 1rem;
  mask-image: linear-gradient(to bottom, #000 0, transparent 58%);
  -webkit-mask-image: linear-gradient(to bottom, #000 0, transparent 58%);
}

.history-content {
  position: relative;
  z-index: 1;
  padding: clamp(22px, 3vw, 38px);
}

.history-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 22px;
  margin-bottom: 26px;
}

.history-title-wrap .section-number {
  display: block;
  margin-bottom: 7px;
}

.history-title-wrap h2 {
  margin: 0;
  font-size: clamp(24px, 2.5vw, 34px);
}

.history-title-wrap p {
  margin: 8px 0 0;
  color: var(--text-soft);
}

.history-count {
  flex: 0 0 auto;
  min-width: 124px;
  padding: 12px 16px;
  border: 1px solid color-mix(in srgb, var(--brand-500) 18%, var(--border));
  border-radius: 16px;
  background: color-mix(in srgb, var(--brand-100) 52%, var(--surface));
  text-align: center;
  box-shadow: 0 10px 30px rgba(73,58,255,.07);
}

.history-count strong {
  display: block;
  font-size: 22px;
  color: var(--brand-700);
}

.history-count span {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: .08em;
}

/* Buscador inspirado en la referencia del usuario, adaptado a la paleta lila */
.history-search-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
}

.history-search {
  position: relative;
  width: min(100%, 430px);
  height: 62px;
  isolation: isolate;
}

.history-search__glow,
.history-search__border,
.history-search__inner-border {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  pointer-events: none;
  overflow: hidden;
}

.history-search__glow {
  inset: -6px;
  filter: blur(18px);
  opacity: .23;
  background: conic-gradient(from 60deg,
    transparent 0 18%,
    var(--brand-500) 25%,
    transparent 38% 58%,
    var(--brand-300) 67%,
    transparent 80% 100%);
  transition: opacity .35s ease, transform .8s cubic-bezier(.2,.8,.2,1);
}

.history-search__border {
  padding: 1px;
  background: linear-gradient(115deg,
    color-mix(in srgb, var(--brand-500) 78%, transparent),
    color-mix(in srgb, var(--brand-300) 42%, transparent) 42%,
    color-mix(in srgb, var(--brand-500) 18%, transparent) 70%,
    color-mix(in srgb, var(--brand-400) 72%, transparent));
  box-shadow: 0 14px 34px rgba(73,58,255,.10);
}

.history-search__inner-border {
  inset: 2px;
  border: 1px solid color-mix(in srgb, var(--brand-500) 12%, transparent);
}

.history-search:focus-within .history-search__glow,
.history-search:hover .history-search__glow {
  opacity: .42;
  transform: rotate(12deg) scale(1.04);
}

.history-search__input {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  border: 0 !important;
  border-radius: 15px;
  padding: 0 64px 0 52px;
  background: color-mix(in srgb, var(--surface) 92%, var(--brand-50));
  color: var(--text);
  font-size: 15px;
  font-weight: 650;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.65);
  outline: none;
}

.history-search__input:focus {
  transform: none !important;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.75),
    0 0 0 4px color-mix(in srgb, var(--brand-500) 10%, transparent) !important;
}

.history-search__input::placeholder {
  color: var(--text-soft);
  font-weight: 560;
}

.history-search__icon {
  position: absolute;
  z-index: 3;
  left: 18px;
  top: 50%;
  width: 21px;
  height: 21px;
  transform: translateY(-50%);
  color: var(--brand-500);
  pointer-events: none;
}

.history-filter-button {
  position: absolute;
  z-index: 4;
  right: 9px;
  top: 9px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--brand-400) 30%, var(--border));
  border-radius: 12px;
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--brand-100) 72%, var(--surface)),
    color-mix(in srgb, var(--brand-50) 88%, var(--surface)));
  color: var(--brand-700);
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(73,58,255,.10);
  transition: transform .2s cubic-bezier(.2,.8,.2,1), box-shadow .2s ease, border-color .2s ease;
}

.history-filter-button:hover {
  transform: translateY(-1px) scale(1.03);
  border-color: color-mix(in srgb, var(--brand-500) 58%, var(--border));
  box-shadow: 0 11px 24px rgba(73,58,255,.16);
}

.history-filter-button svg {
  width: 20px;
  height: 20px;
}

.history-date-native {
  position: absolute;
  z-index: -1;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.history-refresh {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 13px;
  border: 1px solid var(--ui-border, var(--border));
  background: var(--surface-soft);
  color: var(--text);
  font: inherit;
  font-weight: 720;
  cursor: pointer;
  transition: transform .2s ease, border-color .2s ease, box-shadow .2s ease;
}

.history-refresh:hover {
  transform: translateY(-2px);
  border-color: var(--ui-border-hover, var(--brand-400));
  box-shadow: 0 10px 24px rgba(73,58,255,.10);
}

.history-table-shell {
  position: relative;
  border: 1px solid var(--ui-border, var(--border));
  border-radius: 20px;
  background: color-mix(in srgb, var(--surface) 96%, var(--brand-50));
  overflow: hidden;
  box-shadow: 0 16px 44px rgba(30,22,110,.07);
}

.history-table-wrap {
  overflow-x: auto;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

.history-table th,
.history-table td {
  padding: 16px 18px;
  text-align: left;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 72%, transparent);
}

.history-table th {
  background: color-mix(in srgb, var(--brand-100) 44%, var(--surface));
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .075em;
  text-transform: uppercase;
}

.history-table td {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.history-table tbody tr {
  transition: background .18s ease, transform .18s ease;
  animation: historyRowIn .36s cubic-bezier(.2,.8,.2,1) both;
}

.history-table tbody tr:hover {
  background: color-mix(in srgb, var(--brand-100) 34%, transparent);
}

.history-table tbody tr:last-child td {
  border-bottom: 0;
}

.history-channel {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--brand-500) 20%, transparent);
  background: color-mix(in srgb, var(--brand-100) 62%, var(--surface));
  color: var(--brand-700);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: .035em;
}

.history-empty,
.history-loading,
.history-error {
  display: grid;
  place-items: center;
  min-height: 240px;
  padding: 34px;
  text-align: center;
  color: var(--text-soft);
}

.history-empty strong,
.history-error strong {
  display: block;
  margin-bottom: 7px;
  color: var(--text);
  font-size: 16px;
}

.history-error button {
  margin-top: 14px;
}

.history-loading::before {
  content: "";
  width: 34px;
  height: 34px;
  margin-bottom: 12px;
  border: 3px solid color-mix(in srgb, var(--brand-500) 16%, transparent);
  border-top-color: var(--brand-500);
  border-radius: 50%;
  animation: historySpin .8s linear infinite;
}

html[data-theme="dark"] .history-view {
  background: color-mix(in srgb, var(--surface) 96%, #fff 4%);
}

html[data-theme="dark"] .history-search__input {
  background: color-mix(in srgb, var(--input) 92%, var(--brand-400) 8%);
}

html[data-theme="dark"] .history-filter-button {
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--surface-soft) 82%, var(--brand-400) 18%),
    var(--input));
  color: #eceaff;
}

html[data-theme="dark"] .history-table-shell {
  background: color-mix(in srgb, var(--surface) 94%, #fff 6%);
}

html[data-theme="dark"] .history-table th {
  background: color-mix(in srgb, var(--surface-soft) 86%, var(--brand-400) 14%);
}

@keyframes historyReveal {
  from { opacity: 0; transform: translateY(14px) scale(.995); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes historyRowIn {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes historySpin {
  to { transform: rotate(360deg); }
}

@media (max-width: 760px) {
  .history-head,
  .history-search-row {
    align-items: stretch;
    flex-direction: column;
  }

  .history-count {
    width: 100%;
  }

  .history-search {
    width: 100%;
  }

  .history-refresh {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .history-view,
  .history-table tbody tr,
  .history-loading::before {
    animation: none !important;
  }
}


/* =========================================================
   Historial · filas SERVICIOS
   ========================================================= */

.history-type-cell {
  display: grid;
  justify-items: start;
  gap: 7px;
  min-width: 0;
}

.history-channel--services {
  border-color: color-mix(in srgb, var(--brand-500) 34%, transparent);
  background:
    linear-gradient(
      180deg,
      color-mix(in srgb, var(--brand-100) 86%, var(--surface)),
      color-mix(in srgb, var(--brand-50) 76%, var(--surface))
    );
  color: var(--brand-700);
  box-shadow:
    0 7px 18px rgba(73,58,255,.08),
    inset 0 1px 0 rgba(255,255,255,.72);
}

.history-service-code {
  display: inline-block;
  max-width: 250px;
  padding-left: 2px;
  overflow: hidden;
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 720;
  line-height: 1.25;
  letter-spacing: .015em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-table tbody tr:hover .history-service-code {
  color: var(--text);
}

@media (max-width: 760px) {
  .history-service-code {
    max-width: 210px;
  }
}


/* =========================================================
   Historial · filtros profesionales
   ========================================================= */

.history-type-filter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: -6px 0 20px;
  padding: 6px;
  border: 1px solid color-mix(in srgb, var(--brand-500) 14%, var(--border));
  border-radius: 16px;
  background: color-mix(in srgb, var(--surface-soft) 78%, var(--surface));
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.58),
    0 10px 26px rgba(73,58,255,.05);
}

.history-type-filter__button {
  min-height: 36px;
  padding: 0 15px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--text-soft);
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .035em;
  cursor: pointer;
  transition:
    color .2s ease,
    background .2s ease,
    box-shadow .2s ease,
    transform .2s cubic-bezier(.2,.8,.2,1);
}

.history-type-filter__button:hover {
  color: var(--brand-700);
  background: color-mix(in srgb, var(--brand-100) 48%, transparent);
}

.history-type-filter__button.is-active {
  color: #fff;
  background:
    linear-gradient(135deg, var(--brand-500), var(--brand-700));
  box-shadow:
    0 8px 20px rgba(73,58,255,.20),
    inset 0 1px 0 rgba(255,255,255,.18);
  transform: translateY(-1px);
}

/* Calendario propio */
.history-calendar {
  position: absolute;
  z-index: 40;
  top: calc(100% + 12px);
  right: 0;
  width: min(324px, calc(100vw - 44px));
  padding: 16px;
  border: 1px solid color-mix(in srgb, var(--brand-500) 22%, var(--border));
  border-radius: 20px;
  background:
    radial-gradient(circle at 100% 0%, color-mix(in srgb, var(--brand-100) 60%, transparent), transparent 34%),
    var(--surface);
  box-shadow:
    0 24px 60px rgba(38,28,120,.20),
    inset 0 1px 0 rgba(255,255,255,.72);
  opacity: 0;
  transform: translateY(-8px) scale(.985);
  transform-origin: top right;
  transition:
    opacity .18s ease,
    transform .22s cubic-bezier(.2,.8,.2,1);
}

.history-calendar.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.history-calendar__head {
  display: grid;
  grid-template-columns: 36px 1fr 36px;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.history-calendar__head strong {
  color: var(--text);
  text-align: center;
  font-size: 14px;
  font-weight: 850;
  text-transform: capitalize;
}

.history-calendar__nav {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--brand-500) 16%, var(--border));
  border-radius: 11px;
  background: color-mix(in srgb, var(--brand-50) 74%, var(--surface));
  color: var(--brand-700);
  font: inherit;
  font-size: 17px;
  cursor: pointer;
  transition: transform .18s ease, border-color .18s ease, background .18s ease;
}

.history-calendar__nav:hover {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--brand-500) 48%, var(--border));
  background: color-mix(in srgb, var(--brand-100) 64%, var(--surface));
}

.history-calendar__weekdays,
.history-calendar__days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}

.history-calendar__weekdays {
  margin-bottom: 6px;
}

.history-calendar__weekdays span {
  display: grid;
  place-items: center;
  height: 24px;
  color: var(--text-soft);
  font-size: 9px;
  font-weight: 850;
  letter-spacing: .08em;
}

.history-calendar__day {
  position: relative;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  font-weight: 720;
  cursor: pointer;
  transition:
    color .16s ease,
    background .16s ease,
    transform .16s ease,
    box-shadow .16s ease;
}

.history-calendar__day:hover {
  color: var(--brand-700);
  background: color-mix(in srgb, var(--brand-100) 58%, transparent);
  transform: translateY(-1px);
}

.history-calendar__day.is-outside {
  color: color-mix(in srgb, var(--text-soft) 48%, transparent);
}

.history-calendar__day.is-today::after {
  content: "";
  position: absolute;
  bottom: 4px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--brand-500);
}

.history-calendar__day.is-selected {
  color: #fff;
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  box-shadow: 0 8px 18px rgba(73,58,255,.25);
}

.history-calendar__day.is-selected::after {
  background: #fff;
}

.history-calendar__footer {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid color-mix(in srgb, var(--border) 74%, transparent);
}

.history-calendar__footer button {
  min-height: 34px;
  padding: 0 11px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--brand-700);
  font: inherit;
  font-size: 11px;
  font-weight: 820;
  cursor: pointer;
}

.history-calendar__footer button:hover {
  background: color-mix(in srgb, var(--brand-100) 60%, transparent);
}

@media (max-width: 760px) {
  .history-type-filter {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .history-type-filter__button {
    width: 100%;
  }

  .history-calendar {
    right: auto;
    left: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .history-calendar,
  .history-type-filter__button {
    transition: none !important;
  }
}


/* =========================================================
   FIX CALENDARIO · stacking y posicionamiento
   ========================================================= */

.history-search-row {
  position: relative;
  z-index: 120;
}

.history-search {
  position: relative;
  z-index: 130;
  overflow: visible;
}

.history-calendar {
  z-index: 9999;
  top: calc(100% + 14px);
  right: 0;
  left: auto;
  min-width: 324px;
  isolation: isolate;
}

.history-type-filter {
  position: relative;
  z-index: 10;
}

.history-table-shell {
  position: relative;
  z-index: 1;
}

.history-pagination {
  position: relative;
  z-index: 1;
}

@media (max-width: 760px) {
  .history-calendar {
    left: 0;
    right: auto;
    min-width: 0;
    width: min(324px, calc(100vw - 32px));
  }
}


/* =========================================================
   FIX CALENDARIO · no recortar acciones con historial vacío
   ========================================================= */

.history-view {
  overflow: visible;
}

.history-content {
  overflow: visible;
}

.history-calendar {
  max-height: min(470px, calc(100vh - 120px));
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color:
    color-mix(in srgb, var(--brand-500) 42%, transparent)
    transparent;
}

.history-calendar::-webkit-scrollbar {
  width: 7px;
}

.history-calendar::-webkit-scrollbar-track {
  background: transparent;
}

.history-calendar::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background:
    color-mix(in srgb, var(--brand-500) 38%, transparent);
}

.history-calendar__footer {
  position: sticky;
  bottom: -16px;
  z-index: 2;
  margin-right: -16px;
  margin-bottom: -16px;
  margin-left: -16px;
  padding: 12px 16px 14px;
  background:
    color-mix(in srgb, var(--surface) 96%, var(--brand-50));
  box-shadow:
    0 -10px 24px color-mix(in srgb, var(--surface) 76%, transparent);
}

@media (max-width: 760px) {
  .history-calendar {
    max-height: min(430px, calc(100vh - 96px));
  }
}
