:root,
[data-theme="dark"] {
  --md-sys-color-background: #0b1120;
  --md-sys-color-surface: #141b2d;
  --md-sys-color-surface-container: #1a2340;
  --md-sys-color-primary: #8ab4f8;
  --md-sys-color-on-primary: #062e6f;
  --md-sys-color-secondary: #a8c7fa;
  --md-sys-color-on-surface: #e3e3e8;
  --md-sys-color-on-surface-variant: #c4c6d0;
  --md-sys-color-outline: #8e9099;
  --md-sys-color-outline-variant: #44464f;
  --md-sys-color-error: #f2b8b5;
  --md-elevation: 0 2px 6px rgba(0, 0, 0, .3);
  --md-shape: 16px;
}

[data-theme="light"] {
  --md-sys-color-background: #fafafa;
  --md-sys-color-surface: #ffffff;
  --md-sys-color-surface-container: #f0f4f9;
  --md-sys-color-primary: #1a73e8;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-secondary: #5f6368;
  --md-sys-color-on-surface: #1f1f1f;
  --md-sys-color-on-surface-variant: #444746;
  --md-sys-color-outline: #747775;
  --md-sys-color-outline-variant: #c4c7c5;
  --md-sys-color-error: #d93025;
  --md-elevation: 0 1px 3px rgba(0, 0, 0, .12);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  overflow-x: hidden;
}

/* Reglas estándar de Material Symbols para evitar flash (FOUT) */
.material-symbols-outlined {
  font-family: 'Material Symbols Outlined';
  font-weight: normal;
  font-style: normal;
  font-size: 24px;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  -webkit-font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'liga';
  vertical-align: middle;
  user-select: none;
}

html:not(.fonts-loaded) .material-symbols-outlined {
  /* Ocultar ligadura de texto sin procesar hasta que la fuente esté lista */
  visibility: visible;
}

body {
  background: var(--md-sys-color-background);
  color: var(--md-sys-color-on-surface);
  font-family: 'Google Sans', 'Roboto', sans-serif;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-x: hidden;
  position: relative;
}

.container {
  width: 100%;
  max-width: 720px;
  position: relative;
}

header {
  text-align: center;
  margin-bottom: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.brand-logo {
  background: var(--md-sys-color-primary);
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  margin-bottom: 4px;
}

.brand-logo .material-symbols-outlined {
  font-size: 2rem;
  color: var(--md-sys-color-on-primary);
}

header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -.5px;
  color: var(--md-sys-color-on-surface);
  margin: 0;
}

.card {
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape);
  padding: 24px;
  box-shadow: var(--md-elevation);
}

.row {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.mode-switch {
  display: flex;
  gap: 6px;
  margin-bottom: 18px;
  padding: 4px;
  background: var(--md-sys-color-surface-container-highest, rgba(138, 180, 248, 0.08));
  border: 1px solid var(--md-sys-color-outline-variant, rgba(138, 180, 248, 0.12));
  border-radius: 14px;
}

.mode-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 10px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  font-size: .8rem;
  font-weight: 500;
  text-align: center;
  transition: background .2s, color .2s;
}

.mode-btn.active {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: .68rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  padding-left: 4px;
}

.field select,
.field input {
  background: transparent;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 12px;
  padding: 14px 16px;
  color: var(--md-sys-color-on-surface);
  font-size: .95rem;
  font-family: inherit;
  width: 100%;
  transition: border .2s, box-shadow .2s;
}

.field select:focus,
.field input:focus {
  outline: none;
  border-color: var(--md-sys-color-primary);
  box-shadow: 0 0 0 3px rgba(138, 180, 248, .15);
}

.field select option {
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
}

/* Botón × para limpiar inputs */
.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.input-wrap input {
  padding-right: 34px;
}

.input-clear {
  position: absolute;
  right: 8px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: var(--md-sys-color-outline-variant, rgba(138, 180, 248, 0.2));
  color: var(--md-sys-color-on-surface);
  font-size: 1rem;
  line-height: 1;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

.input-clear.show {
  display: flex;
}

.input-clear:hover {
  opacity: .75;
}

button {
  font-family: inherit;
  cursor: pointer;
}

.btn {
  width: 100%;
  height: 48px;
  padding: 0 16px;
  border: none;
  border-radius: 28px;
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  font-size: .95rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: box-shadow .2s;
}

.btn:hover {
  box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
}

.btn:disabled {
  opacity: .5;
}

.submit-row {
  display: flex;
  gap: 12px;
  align-items: center;
  width: 100%;
}

.btn-cancel {
  height: 48px;
  padding: 0 24px;
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: 28px;
  background: rgba(239, 68, 68, 0.08);
  color: #ef4444;
  font-size: .95rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: background .2s, border-color .2s, box-shadow .2s;
  flex-shrink: 0;
}

.btn-cancel:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.5);
  box-shadow: 0 1px 3px rgba(239, 68, 68, .15);
}

.hidden {
  display: none !important;
}

/* Loading */
.loading {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 20px;
  padding: 16px;
  background: rgba(138, 180, 248, .06);
  border: 1px solid rgba(138, 180, 248, .1);
  border-radius: 12px;
}

.loading-title {
  font-size: .85rem;
  font-weight: 500;
}

.loading-desc {
  font-size: .75rem;
  color: var(--md-sys-color-on-surface-variant);
  margin-top: 2px;
}

/* Results */
.divider {
  height: 1px;
  background: var(--md-sys-color-outline-variant);
  margin: 20px 0;
}

/* Cabecera unificada de resultados */
.result-header {
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(138, 180, 248, 0.06);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 14px;
  padding: 14px 16px;
  transition: background .3s, border-color .3s;
}

.result-header-avatar {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: .5px;
  color: var(--md-sys-color-primary);
  background: rgba(138, 180, 248, 0.14);
  border: 1px solid rgba(138, 180, 248, 0.25);
  user-select: none;
  transition: background .3s, color .3s, border-color .3s;
}

.result-header-info {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
  min-width: 0;
}

.result-header-line {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.result-header-label {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: .58rem;
  font-weight: 600;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--md-sys-color-on-surface-variant);
  min-width: 140px;
}

.result-header-label .material-symbols-outlined {
  font-size: .8rem;
}

.result-header-value {
  font-size: .85rem;
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
  word-break: break-word;
}

.result-header-name {
  font-size: .9rem;
  font-weight: 700;
  color: var(--md-sys-color-primary);
  word-break: break-word;
}

.result-header-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  align-self: center;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  animation: fadeIn .3s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.box {
  background: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 10px;
  padding: 10px 12px;
}

.box.full {
  grid-column: 1 / -1;
}

.lbl {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: .62rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 3px;
}

.lbl .material-symbols-outlined {
  font-size: .85rem;
}

.val {
  font-size: .85rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
  word-break: break-word;
}

.val.muted {
  color: var(--md-sys-color-on-surface-variant);
  font-size: .75rem;
}

.pill {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 500;
}

.pill.ok {
  background: rgba(52, 168, 83, .12);
  color: #34a853;
}

.pill.warn {
  background: rgba(234, 67, 53, .12);
  color: #ea4335;
}

footer {
  text-align: center;
  margin-top: 16px;
}

footer a {
  font-size: .7rem;
  color: var(--md-sys-color-on-surface-variant);
  text-decoration: none;
}

.theme-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 10;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--md-sys-color-surface-container);
  box-shadow: var(--md-elevation);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--md-sys-color-on-surface-variant);
  transition: background .2s, color .2s, transform .15s;
}

.theme-btn:hover {
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  transform: scale(1.05);
}

.theme-btn:active {
  transform: scale(0.95);
}

.copy-btn {
  background: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 8px;
  padding: 6px 12px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: .75rem;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all .2s ease;
  letter-spacing: .2px;
}

.copy-btn:hover {
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
  border-color: var(--md-sys-color-outline);
}

.copy-btn:focus {
  outline: none;
  border-color: var(--md-sys-color-primary);
  box-shadow: 0 0 0 2px rgba(138, 180, 248, .25);
}

.copy-btn:active {
  transform: scale(0.97);
}

.theme-btn .material-symbols-outlined {
  font-size: 1.2rem;
}

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

.disclaimer {
  font-size: .62rem;
  color: var(--md-sys-color-on-surface-variant);
  text-align: center;
  margin-top: 14px;
  line-height: 1.6;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
  opacity: .75;
}

@media (max-width: 480px) {
  .row {
    flex-direction: column;
    gap: 16px;
  }

  .mode-switch {
    gap: 3px;
    padding: 3px;
    border-radius: 12px;
  }

  .mode-btn {
    gap: 3px;
    padding: 8px 4px;
    font-size: .72rem;
    border-radius: 9px;
  }

  .mode-btn .material-symbols-outlined {
    font-size: .85rem !important;
  }
}

@media (max-width: 520px) {
  .result-header {
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 18px 16px;
  }

  .result-header-avatar {
    width: 52px;
    height: 52px;
    font-size: 1.2rem;
  }

  .result-header-info {
    width: 100%;
  }

  .result-header-line {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    margin-bottom: 10px;
  }

  .result-header-line:last-child {
    margin-bottom: 0;
  }

  .result-header-label {
    min-width: 0;
    width: 100%;
  }

  .result-header-value {
    width: 100%;
  }

  .result-header-actions {
    width: 100%;
    justify-content: center;
    margin-top: 8px;
  }

  .grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }
}

/* Skeleton Loader Styling */
.skeleton-active .val,
.skeleton-active .pill {
  display: inline-block;
  min-width: 120px;
  max-width: 100%;
  height: 16px;
  position: relative;
  color: transparent !important;
  background: transparent !important;
  border-color: transparent !important;
  pointer-events: none;
  user-select: none;
  vertical-align: middle;
}

/* El documento se ingresa manualmente, nunca necesita skeleton */
.skeleton-active #r-header-line-doc .val {
  color: var(--md-sys-color-on-surface) !important;
}

.skeleton-active #r-header-line-doc .val::after {
  display: none !important;
}

.skeleton-active .pill {
  min-width: 60px;
  max-width: 100%;
}

.skeleton-active .box.full .val {
  min-width: 240px;
  max-width: 100%;
}

.skeleton-active .val::after,
.skeleton-active .pill::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: var(--md-sys-color-outline-variant);
  border-radius: 4px;
  opacity: 0.25;
  animation: skeleton-pulse 1.4s ease-in-out infinite;
}

@keyframes skeleton-pulse {
  0% {
    background-color: var(--md-sys-color-outline-variant);
    opacity: 0.15;
  }
  50% {
    background-color: var(--md-sys-color-outline);
    opacity: 0.35;
  }
  100% {
    background-color: var(--md-sys-color-outline-variant);
    opacity: 0.15;
  }
}

/* Pestañas del historial */
.history-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border: 1px solid var(--md-sys-color-outline-variant, rgba(138, 180, 248, 0.12));
  border-radius: 999px;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  font-size: .75rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background .2s, color .2s, border-color .2s;
}

.history-tab:hover {
  background: var(--md-sys-color-surface-container-highest, color-mix(in srgb, var(--md-sys-color-surface) 92%, #000 8%));
}

.history-tab.active {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  border-color: transparent;
}

.history-tab .count {
  background: rgba(128, 128, 128, .16);
  border-radius: 999px;
  padding: 0 6px;
  font-size: .68rem;
  line-height: 1.5;
  min-width: 18px;
  text-align: center;
}

.history-tab.active .count {
  background: rgba(255, 255, 255, .22);
}

/* Respuesta concluyente "sin registro": se muestra como informativa (azul) y
   sin botón de reintento, porque reintentar no cambia el resultado. */
.error-block.error-block-info {
  background: rgba(59, 130, 246, 0.06) !important;
  border-color: rgba(59, 130, 246, 0.15) !important;
  color: #3b82f6 !important;
}

.error-block.error-block-info>div {
  color: #3b82f6 !important;
}

.error-block.error-block-info .error-icon {
  color: #3b82f6 !important;
}
