:is(h1, h2, h3, p) {
  margin-top: 0;
}

label {
  display: block;
  margin-bottom: 6px;
  font-weight: 700;
}

.muted {
  color: var(--color-text-muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: var(--color-batch-support-soft);
  color: var(--color-batch-support);
  font-size: 0.85rem;
  font-weight: 700;
  padding: 4px 10px;
}

.field {
  margin-bottom: 16px;
}

.batch-hero {
  margin-top: var(--space-2);
  border: var(--border-width) solid color-mix(in srgb, var(--color-batch-support) 14%, white);
  border-radius: 1.25rem;
  background:
    radial-gradient(circle at top right, rgb(255 255 255 / 0.34), transparent 18rem),
    linear-gradient(180deg, rgb(255 255 255 / 0.94), rgb(255 255 255 / 0.88));
  box-shadow: var(--shadow-sm);
  padding: clamp(var(--space-4), 2vw, var(--space-5));

  .batch-hero__meta {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: flex-end;
    gap: var(--space-2);
  }
}

.batch-layout {
  display: grid;
  align-items: start;
  gap: clamp(var(--space-4), 2vw, var(--space-6));
  grid-template-columns: minmax(320px, 380px) minmax(0, 1fr);

  > * {
    min-width: 0;
  }
}

.batch-column {
  display: grid;
  min-width: 0;
  align-content: start;
  gap: clamp(var(--space-4), 2vw, var(--space-6));
}

.batch-card {
  display: grid;
  gap: var(--space-4);
  min-width: 0;
  overflow: hidden;
  border: var(--border-width) solid color-mix(in srgb, var(--color-batch-support) 14%, white);
  border-radius: 1.25rem;
  background:
    radial-gradient(circle at top right, rgb(255 255 255 / 0.34), transparent 18rem),
    linear-gradient(180deg, rgb(255 255 255 / 0.94), rgb(255 255 255 / 0.88));
  box-shadow: var(--shadow-sm);
  padding: clamp(var(--space-4), 2vw, var(--space-5));
}

.batch-card__head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
}

.batch-card__title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);

  h2 {
    margin-bottom: 0;
  }
}

.batch-card__eyebrow {
  margin: 0;
  color: var(--color-batch-accent);
  font-size: var(--font-size-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.batch-card__toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 2.5rem;
  border: var(--border-width) solid color-mix(in srgb, var(--color-batch-support) 22%, white);
  border-radius: var(--radius-pill);
  background: var(--color-surface-muted);
  color: var(--color-text);
  font-size: var(--font-size-sm);
  font-weight: 700;
  padding: 0.5rem 0.85rem;
  transition:
    border-color var(--transition-fast),
    background var(--transition-fast),
    transform var(--transition-fast);

  svg {
    width: 1rem;
    height: 1rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform var(--transition-fast);
  }

  &[aria-expanded="true"] svg {
    transform: rotate(180deg);
  }

  &:is(:hover, :focus-visible) {
    border-color: var(--color-batch-support);
    background: var(--color-batch-support-soft);
    transform: translateY(-1px);
  }
}

.batch-upload-panel[hidden] {
  display: none;
}

.batch-upload-form {
  display: grid;
  gap: var(--space-4);
}

.batch-rules-tooltip {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.batch-rules-tooltip__trigger {
  display: inline-flex;
  align-items: center;
  min-height: 1.9rem;
  border: var(--border-width) solid var(--color-batch-rules-border);
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, white 80%, var(--color-brand-accent) 20%);
  color: var(--color-brand-accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.35rem 0.7rem;
}

.batch-rules-tooltip__panel {
  position: absolute;
  top: calc(100% + 0.65rem);
  left: 0;
  z-index: var(--z-dropdown);
  width: min(19rem, calc(100vw - 3rem));
  border: var(--border-width) solid var(--color-batch-rules-border);
  border-radius: 1rem;
  background: var(--color-batch-rules-surface);
  box-shadow: 0 18px 34px rgb(15 23 42 / 0.16);
  color: var(--color-text);
  font-size: var(--font-size-sm);
  line-height: 1.5;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  padding: var(--space-3);
  transition:
    opacity var(--transition-fast),
    transform var(--transition-fast);
}

.batch-rules-tooltip:is(:hover, :focus-within) .batch-rules-tooltip__panel {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.batch-file-input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.batch-dropzone {
  position: relative;
  display: flex;
  min-height: 220px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 2px dashed color-mix(in srgb, var(--color-batch-support) 38%, white);
  border-radius: 24px;
  background: var(--color-batch-zip-surface);
  color: var(--color-text);
  cursor: pointer;
  outline: 3px solid transparent;
  text-align: center;
  padding: 24px;
  transition:
    transform 0.18s ease,
    border-color 0.18s ease,
    box-shadow 0.18s ease,
    background 0.18s ease,
    outline-color 0.18s ease;

  &:is(:hover, .is-dragover) {
    border-color: var(--color-batch-support);
    background:
      radial-gradient(circle at top, color-mix(in srgb, white 76%, var(--color-batch-support) 24%), transparent 58%),
      linear-gradient(180deg, color-mix(in srgb, white 98%, var(--color-batch-support) 2%) 0%, color-mix(in srgb, white 86%, var(--color-batch-support) 14%) 100%);
    box-shadow: 0 16px 36px rgb(37 99 235 / 0.14);
    transform: translateY(-2px);
  }

  &:focus-visible {
    outline-color: color-mix(in srgb, var(--color-batch-support) 24%, white);
  }

  &.has-file {
    border-style: solid;
    border-color: var(--color-batch-success);
    background:
      radial-gradient(circle at top, color-mix(in srgb, white 76%, var(--color-batch-success) 24%), transparent 58%),
      linear-gradient(180deg, color-mix(in srgb, white 96%, var(--color-batch-success) 4%) 0%, color-mix(in srgb, white 86%, var(--color-batch-success) 14%) 100%);
    box-shadow: 0 14px 30px rgb(15 118 110 / 0.12);
  }

  &.has-error {
    border-style: solid;
    border-color: var(--color-batch-error);
    background:
      radial-gradient(circle at top, color-mix(in srgb, white 76%, var(--color-batch-error) 24%), transparent 58%),
      linear-gradient(180deg, color-mix(in srgb, white 96%, var(--color-batch-error) 4%) 0%, color-mix(in srgb, white 86%, var(--color-batch-error) 14%) 100%);
    box-shadow: 0 14px 30px rgb(220 38 38 / 0.12);
  }

  .batch-dropzone__badge {
    position: absolute;
    top: 18px;
    right: 18px;
    border: 1px solid color-mix(in srgb, var(--color-batch-support) 24%, white);
    border-radius: 999px;
    background: rgb(255 255 255 / 0.9);
    color: var(--color-batch-support);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding: 6px 10px;
  }

  .batch-dropzone__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 78px;
    height: 78px;
    border-radius: 24px;
    background: linear-gradient(135deg, var(--color-batch-support) 0%, var(--color-batch-accent) 100%);
    box-shadow: 0 12px 28px rgb(37 99 235 / 0.25);
    color: var(--color-surface);
    font-size: 2.2rem;
    font-weight: 700;
  }

  .batch-dropzone__title {
    font-size: 1.3rem;
    font-weight: 700;
  }

  .batch-dropzone__subtitle {
    color: var(--color-text-muted);
  }

  .batch-dropzone__cta {
    display: inline-flex;
    min-width: 180px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    margin-top: 4px;
    border-radius: 999px;
    background: var(--color-text);
    box-shadow: 0 12px 24px rgb(15 23 42 / 0.16);
    color: var(--color-surface);
    font-weight: 700;
    letter-spacing: 0.01em;
    padding: 10px 18px;
  }

  .batch-dropzone__file {
    max-width: 100%;
    margin-top: 6px;
    overflow-wrap: anywhere;
    border: 1px solid color-mix(in srgb, var(--color-batch-support) 20%, white);
    border-radius: 999px;
    background: rgb(255 255 255 / 0.78);
    color: var(--color-batch-support);
    font-size: 0.95rem;
    padding: 10px 14px;
  }
}

.btn {
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  padding: 12px 16px;

  &.btn-primary {
    width: 100%;
    background: var(--color-batch-accent);
    color: var(--color-surface);

    &:hover {
      background: color-mix(in srgb, var(--color-batch-accent) 86%, black);
    }
  }

  &.btn-secondary {
    background: var(--color-surface-muted);
    color: var(--color-text);

    &:hover {
      background: color-mix(in srgb, var(--color-batch-support-soft) 80%, white);
    }
  }

  &.btn-ghost {
    border: 1px solid var(--color-border);
    background: transparent;
    color: var(--color-text);
  }

  &.btn-sm {
    border-radius: 8px;
    font-size: 0.85rem;
    padding: 8px 10px;
  }
}

.batch-note {
  margin-top: 16px;
  border-left: 4px solid var(--color-batch-support);
  border-radius: 8px;
  background: var(--color-batch-support-soft);
  color: var(--color-text);
  padding: 14px;

  .batch-note__text {
    margin: 8px 0 0;
  }

  &.batch-note--error {
    border-left-color: var(--color-batch-error);
    background: var(--color-batch-error-bg);
  }
}

.batch-tracking-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;

  p {
    margin-bottom: 0;
  }
}

.batch-tracking-title {
  margin-bottom: 6px;
}

.summary-grid {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.summary-item {
  border: 1px solid var(--color-border);
  border-radius: 12px;
  background: var(--color-surface-muted);
  padding: 14px;

  strong {
    display: block;
    color: var(--color-text);
    font-size: 1.4rem;
  }
}

.batch-bulk-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 18px;
  border: 1px solid var(--color-batch-support-border);
  border-radius: 14px;
  background: linear-gradient(135deg, var(--color-batch-panel) 0%, var(--color-surface-muted) 100%);
  padding: 16px 18px;

  .batch-bulk-panel__content {
    display: grid;
    min-width: 0;
    gap: 8px;
  }

  .batch-bulk-panel__heading {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  .batch-bulk-panel__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;

    &.batch-bulk-panel__actions--excel :is(.btn-primary, .btn-secondary) {
      width: auto;
      flex: 1;
    }
  }
}

.status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 700;
  padding: 6px 12px;

  &:is(.status--recibido, .status--preparando, .status--procesando, .status--clasificado) {
    background: var(--color-batch-support-soft);
    color: var(--color-batch-support);
  }

  &:is(.status--asociado, .status--completado) {
    background: var(--color-batch-success-bg);
    color: var(--color-batch-success);
  }

  &:is(.status--pendiente_validacion, .status--completado_con_errores) {
    background: var(--color-batch-warning-bg);
    color: var(--color-batch-warning);
  }

  &.status--fallido {
    background: var(--color-batch-error-bg);
    color: var(--color-batch-error);
  }
}

table {
  width: 100%;
  margin-top: 14px;
  border-collapse: collapse;
}

:is(th, td) {
  border-bottom: 1px solid var(--color-border);
  font-size: 0.95rem;
  padding: 12px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: var(--color-batch-panel);
  color: var(--color-batch-support);
}

.traceability-cell {
  display: grid;
  min-width: 240px;
  gap: 4px;
  color: var(--color-text);
  font-size: 0.84rem;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  max-height: 560px;
  overflow: auto;
  border: 1px solid var(--color-border);
  border-radius: 14px;

  &.table-wrap--history {
    max-height: 420px;
  }

  &.table-wrap--group {
    max-height: 420px;
    margin: 0;
    border: 0;
    border-top: 1px solid var(--color-border);
    border-radius: 0 0 18px 18px;
  }
}

.batch-groups {
  display: grid;
  gap: 18px;
}

.batch-file-group {
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--color-batch-support) 16%, white);
  border-radius: 14px;
  background: var(--color-surface);
  box-shadow: 0 6px 18px rgb(15 23 42 / 0.05);

  &.batch-file-group--unassigned {
    border-color: var(--color-batch-warning-border);

    .batch-file-group__summary {
      background: color-mix(in srgb, white 82%, var(--color-batch-warning-bg) 18%);
    }

    .batch-case-key-pill {
      border-color: var(--color-batch-warning-border);
      background: color-mix(in srgb, white 76%, var(--color-batch-warning-bg) 24%);
      color: var(--color-batch-warning);
    }
  }

  .batch-file-group__summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    list-style: none;
    background: color-mix(in srgb, white 86%, var(--color-batch-support-soft) 14%);
    cursor: pointer;
    padding: 14px 16px;

    &::-webkit-details-marker {
      display: none;
    }

    &::after {
      content: "▾";
      flex: 0 0 auto;
      color: var(--color-text-muted);
      font-size: 0.95rem;
      line-height: 1;
      transition: transform 0.18s ease;
    }
  }

  &:not([open]) .batch-file-group__summary::after {
    transform: rotate(-90deg);
  }

  .batch-file-group__summary-main {
    min-width: 0;
    flex: 1 1 auto;
  }

  .batch-file-group__title-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
  }

  .batch-file-group__title {
    margin: 0;
    color: #0f172a;
    font-size: 1rem;
  }

  .batch-file-group__meta {
    margin: 6px 0 0;
    color: var(--color-text-muted);
    font-size: 0.9rem;
  }

  .batch-file-group__stats {
    flex: 0 1 auto;
    color: var(--color-text-muted);
    font-size: 0.86rem;
    white-space: nowrap;
  }
}

.batch-case-key-pill {
  display: inline-flex;
  max-width: 100%;
  align-items: center;
  gap: 8px;
  border: 1px solid color-mix(in srgb, var(--color-batch-support) 22%, white);
  border-radius: 999px;
  background: color-mix(in srgb, white 76%, var(--color-batch-support) 24%);
  box-shadow: none;
  color: var(--color-batch-support);
  padding: 5px 10px;

  .batch-case-key-pill__label {
    color: inherit;
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    opacity: 0.78;
    text-transform: uppercase;
  }

  .batch-case-key-pill__value {
    overflow-wrap: anywhere;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 0.8rem;
    font-weight: 700;
  }
}

.history-row--active {
  background: color-mix(in srgb, white 74%, var(--color-batch-support-soft) 26%);
}

.history-row__meta {
  margin-top: 4px;
  font-size: 0.8rem;
}

.empty-state {
  border: 1px dashed var(--color-border-strong);
  border-radius: 14px;
  background: var(--color-surface-muted);
  color: var(--color-text-muted);
  padding: 26px;
}

.is-hidden {
  display: none !important;
}

.resolve-modal {
  width: min(680px, calc(100vw - 32px));
  border: none;
  border-radius: 14px;
  box-shadow: 0 16px 48px rgb(15 23 42 / 0.25);
  padding: 0;

  &::backdrop {
    background: rgb(15 23 42 / 0.45);
  }

  .resolve-form {
    display: grid;
    gap: 10px;
    padding: 22px;

    :is(input, select, textarea) {
      width: 100%;
      border: 1px solid var(--color-border);
      border-radius: 8px;
      font: inherit;
      padding: 10px;
    }
  }

  .resolve-modal__actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 8px;

    .btn-primary {
      width: auto;
    }
  }
}

@media (max-width: 960px) {
  .batch-hero .batch-hero__meta {
    justify-content: flex-start;
  }

  .batch-layout {
    grid-template-columns: 1fr;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .batch-bulk-panel {
    align-items: stretch;
  }

  .batch-dropzone .batch-dropzone__badge {
    position: static;
    margin-bottom: 4px;
  }

  .batch-file-group .batch-file-group__stats {
    width: 100%;
    white-space: normal;
  }

  .table-wrap.table-wrap--group {
    max-height: 360px;
  }
}

@media (max-width: 640px) {
  .batch-file-group .batch-file-group__title {
    font-size: 1rem;
  }

  .batch-case-key-pill {
    width: 100%;
    justify-content: flex-start;
    border-radius: 12px;
  }
}
