:root {
  --bg: #f4efe5;
  --bg-accent: #e9d8b7;
  --surface: rgba(255, 252, 245, 0.88);
  --surface-strong: #fffaf0;
  --ink: #1e1b18;
  --muted: #5e584f;
  --line: rgba(76, 61, 37, 0.18);
  --brand: #125b50;
  --brand-strong: #0d4139;
  --danger: #b8402a;
  --ok: #1c7c54;
  --shadow: 0 20px 50px rgba(76, 61, 37, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'IBM Plex Sans', sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(18, 91, 80, 0.18), transparent 30%),
    radial-gradient(circle at top right, rgba(184, 64, 42, 0.12), transparent 25%),
    linear-gradient(135deg, var(--bg) 0%, #f8f5ef 55%, #efe5d3 100%);
}

.page-shell {
  width: min(1220px, calc(100% - 32px));
  margin: 0 auto;
  padding: 40px 0 56px;
}

.auth-shell {
  margin-bottom: 24px;
}

.form-disabled {
  opacity: 0.55;
  pointer-events: none;
}

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

.hero {
  display: grid;
  grid-template-columns: 1.4fr 0.9fr;
  gap: 24px;
  align-items: stretch;
}

.hero-copy,
.hero-card,
.panel {
  background: var(--surface);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.hero-copy {
  padding: 34px;
}

.eyebrow {
  margin: 0 0 12px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 12px;
  color: var(--brand);
  font-weight: 700;
}

h1,
h2 {
  margin: 0;
  font-family: 'Space Grotesk', sans-serif;
}

h1 {
  font-size: clamp(2.2rem, 4vw, 4.5rem);
  line-height: 0.98;
  max-width: 12ch;
}

.hero-text,
.panel-header p,
#resultSummary,
.status-label {
  color: var(--muted);
}

.hero-text {
  margin: 18px 0 0;
  max-width: 60ch;
  font-size: 1.05rem;
  line-height: 1.65;
}

.hero-actions {
  margin-top: 18px;
}

.hero-card {
  padding: 28px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
}

.hero-image {
  width: 100%;
  height: clamp(160px, 22vw, 240px);
  object-fit: contain;
  object-position: center;
  background: rgba(255, 250, 240, 0.72);
  border-radius: 16px;
  border: 1px solid var(--line);
}

.status-banner {
  border-radius: 20px;
  padding: 18px 20px;
  background: linear-gradient(135deg, rgba(18, 91, 80, 0.12), rgba(18, 91, 80, 0.04));
  font-weight: 600;
}

.status-banner.warning {
  background: linear-gradient(135deg, rgba(184, 64, 42, 0.16), rgba(184, 64, 42, 0.05));
  color: var(--danger);
}

.status-banner.success {
  color: var(--ok);
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.status-grid div {
  padding: 18px;
  border-radius: 20px;
  background: var(--surface-strong);
  border: 1px solid var(--line);
}

.status-label {
  display: block;
  margin-bottom: 10px;
  font-size: 0.85rem;
}

.sections-tabs {
  margin-top: 22px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.section-tab {
  color: var(--ink);
  background: rgba(239, 227, 206, 0.9);
  border: 1px solid var(--line);
  box-shadow: none;
  transition: background 180ms ease, color 180ms ease, transform 180ms ease;
}

.section-tab.is-active {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
}

.section-tab:not(.is-active):hover {
  transform: translateY(-1px);
}

.sections-stack {
  display: grid;
  gap: 0;
  margin-top: 24px;
}

.section-block {
  display: grid;
  gap: 18px;
}

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: grid;
  animation: tabPanelIn 220ms ease both;
}

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

.section-form {
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px;
  background: rgba(255, 250, 240, 0.72);
}

.result-surface {
  padding: 18px;
}

.panel-header.compact {
  margin-bottom: 12px;
}

.panel {
  padding: 28px;
}

.panel-header {
  margin-bottom: 20px;
}

.panel-header p {
  margin: 10px 0 0;
}

.report-form {
  display: grid;
  gap: 22px;
}

.field-grid {
  display: grid;
  gap: 16px;
}

.table-selector {
  display: grid;
  gap: 10px;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

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

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid rgba(18, 91, 80, 0.14);
  border-radius: 14px;
  background: #fffef9;
  font-weight: 600;
}

.checkbox-item input {
  width: auto;
  margin: 0;
  padding: 0;
  box-shadow: none;
  transform: none;
}

.checkbox-disabled {
  opacity: 0.8;
}

.table-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.inline-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fffef9;
}

.inline-toggle input {
  width: auto;
  margin: 0;
  padding: 0;
  box-shadow: none;
  transform: none;
}

.join-section-title h3 {
  margin: 0 0 6px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.05rem;
}

.join-section-title p {
  margin: 0;
  color: var(--muted);
}

.join-block {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 250, 240, 0.72);
}

.form-disabled {
  opacity: 0.55;
  pointer-events: none;
}

.join-header {
  margin-bottom: 14px;
}

.join-header h3 {
  margin: 0 0 6px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1rem;
}

.join-header p {
  margin: 0;
  color: var(--muted);
}

.join-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.select-input {
  width: 100%;
  border: 1px solid rgba(18, 91, 80, 0.18);
  border-radius: 16px;
  padding: 15px 16px;
  font: inherit;
  background: #fffef9;
  color: var(--ink);
  outline: none;
}

.select-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(18, 91, 80, 0.12);
}

.field-pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fffef9;
  min-height: 56px;
}

.field-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(18, 91, 80, 0.1);
  color: var(--brand-strong);
  font-size: 0.9rem;
  font-weight: 600;
}

.field-pill small {
  color: var(--muted);
  font-weight: 500;
}

.filtro-row {
  display: grid;
  grid-template-columns: 1.4fr 0.8fr 1.2fr auto;
  gap: 10px;
  margin-bottom: 10px;
}

.btn-small {
  padding: 10px 14px;
  font-size: 0.92rem;
}

.btn-icon {
  padding: 10px 12px;
  min-width: 42px;
}

.query-tool-section {
  width: min(1220px, calc(100% - 32px));
  margin: 0 auto 56px;
}

.query-tool-header {
  margin-bottom: 18px;
}

.query-tool-body {
  display: grid;
  grid-template-columns: minmax(320px, 430px) minmax(0, 1fr);
  gap: 24px;
}

.query-pagination {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.pagination-label {
  color: var(--muted);
  font-weight: 600;
}

label {
  display: grid;
  gap: 8px;
  font-weight: 600;
}

label span {
  font-size: 0.95rem;
}

input {
  width: 100%;
  border: 1px solid rgba(18, 91, 80, 0.18);
  border-radius: 16px;
  padding: 15px 16px;
  font: inherit;
  background: #fffef9;
  color: var(--ink);
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

textarea {
  width: 100%;
  border: 1px solid rgba(18, 91, 80, 0.18);
  border-radius: 16px;
  padding: 15px 16px;
  font: inherit;
  background: #fffef9;
  color: var(--ink);
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
  resize: vertical;
}

textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(18, 91, 80, 0.12);
  transform: translateY(-1px);
}

input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(18, 91, 80, 0.12);
  transform: translateY(-1px);
}

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

.actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 14px 22px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
  box-shadow: 0 10px 20px rgba(18, 91, 80, 0.18);
  transition: transform 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}

button.secondary {
  color: var(--ink);
  background: #efe3ce;
  box-shadow: none;
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.7;
  cursor: wait;
}

.feedback {
  min-height: 24px;
  margin-bottom: 14px;
  font-weight: 600;
}

.feedback.error {
  color: var(--danger);
}

.feedback.success {
  color: var(--ok);
}

.table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 250, 240, 0.72);
}

table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}

thead {
  background: rgba(18, 91, 80, 0.08);
}

th,
td {
  text-align: left;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  white-space: nowrap;
}

th {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.92rem;
}

table thead th:first-child,
table tbody td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface-strong);
}

table thead th:first-child {
  z-index: 2;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 26px;
}

@media (max-width: 920px) {
  .hero {
    grid-template-columns: 1fr;
  }

  .sections-stack {
    gap: 0;
  }

  .status-grid {
    grid-template-columns: 1fr;
  }

  .page-shell {
    width: min(100% - 20px, 1220px);
    padding-top: 20px;
  }

  .hero-copy,
  .hero-card,
  .panel {
    border-radius: 22px;
  }

  h1 {
    max-width: none;
  }

  .checkbox-grid {
    grid-template-columns: 1fr;
  }

  .checkbox-grid--dynamic {
    grid-template-columns: 1fr;
  }

  .auth-grid,
  .join-grid,
  .query-tool-body,
  .filtro-row {
    grid-template-columns: 1fr;
  }
}


/* ─────────────────────────────────────────────
   QUERY TOOL
   ───────────────────────────────────────────── */

.query-tool-section {
  margin-top: 48px;
}

.query-tool-header {
  background: var(--surface);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 34px;
  margin-bottom: 24px;
}

.query-tool-body {
  display: grid;
  grid-template-columns: minmax(300px, 400px) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

/* Campo label standalone (sin <label> wrapper) */
.field-label {
  display: block;
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 8px;
}

/* Select nativo con estilo coherente */
.select-input {
  width: 100%;
  border: 1px solid rgba(18, 91, 80, 0.18);
  border-radius: 16px;
  padding: 15px 16px;
  font: inherit;
  background: #fffef9;
  color: var(--ink);
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%235e584f' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  cursor: pointer;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.select-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(18, 91, 80, 0.12);
}

/* Botón pequeño */
.btn-small {
  padding: 9px 16px;
  font-size: 0.88rem;
  border-radius: 999px;
}

/* Botón icono (eliminar filtro) */
.btn-icon {
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 0.85rem;
  line-height: 1;
  flex-shrink: 0;
}

/* ── Filtros dinámicos ─────────────────────── */
.filtros-list {
  display: grid;
  gap: 10px;
  margin-bottom: 10px;
}

.filtro-row {
  display: grid;
  grid-template-columns: 1fr 130px 1fr auto;
  gap: 8px;
  align-items: center;
}

.filtro-row input,
.filtro-row .select-input {
  padding: 11px 14px;
  border-radius: 14px;
  font-size: 0.9rem;
}

.filtro-row .filtro-operador {
  background-position: right 10px center;
}

/* ── Paginación ────────────────────────────── */
.query-pagination {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.pagination-label {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 600;
}

/* ── Responsive ────────────────────────────── */
@media (max-width: 920px) {
  .query-tool-body {
    grid-template-columns: 1fr;
  }

  .filtro-row {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
  }

  .filtro-row .filtro-operador {
    grid-column: 1 / -1;
  }

  .filtro-row .btn-icon {
    grid-column: 2;
    justify-self: end;
  }

  .query-tool-header {
    border-radius: 22px;
  }
}
