:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --border: #d0d7de;
  --border-input: #767676;
  --text: #1b1f23;
  --text-muted: #57606a;
  --primary: #0b57d0;
  --primary-hover: #0842a0;
  --danger: #c62828;
  --danger-bg: #fce8e6;
  --success: #188038;
  --success-bg: #e6f4ea;
  --warning: #b06000;
  --warning-bg: #fef7e0;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

.visually-hidden:where(:not(:focus-within, :active)) {
  position: absolute !important;
  clip-path: inset(50%) !important;
  overflow: hidden !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  border: 0 !important;
  white-space: nowrap !important;
}

.container {
  width: min(1280px, 100% - 2rem);
  margin-inline: auto;
}

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-block: 1.25rem;
  margin-block-end: 1.5rem;
}

.header-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.eyebrow {
  margin: 0 0 0.25rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary);
}

h1 {
  margin: 0;
  font-size: clamp(1.4rem, 2.2vw, 1.85rem);
  line-height: 1.2;
}

h2 {
  margin: 0 0 0.25rem;
  font-size: 1.25rem;
  line-height: 1.3;
}

.subtitle,
.section-desc {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.health-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  font-size: 0.875rem;
  font-weight: 500;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
}

.health-badge.is-ok {
  border-color: #a8dab5;
  background: var(--success-bg);
  color: var(--success);
}

.health-badge.is-ok .status-dot {
  background: var(--success);
}

.health-badge.is-error {
  border-color: #f6aea9;
  background: var(--danger-bg);
  color: var(--danger);
}

.health-badge.is-error .status-dot {
  background: var(--danger);
}

.layout-grid {
  display: grid;
  grid-template-columns: minmax(300px, 440px) minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
  padding-block-end: 3rem;
}

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.section-desc {
  margin-block-end: 1.25rem;
}

/* Form controls & validation */
.field {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.25rem;
  margin-block-end: 1.35rem;
}

.fieldset-group {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem 1rem 1rem;
}

.fieldset-group legend {
  font-weight: 600;
  padding-inline: 0.35rem;
}

label {
  font-weight: 600;
  font-size: 0.95rem;
}

.hint {
  display: block;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-block-end: 0.15rem;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="search"],
select,
textarea {
  font: inherit;
  font-size: max(1rem, 1em);
  line-height: 1.4;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--border-input);
  border-radius: 8px;
  padding: 0.65rem 0.8rem;
  min-height: 48px;
  width: 100%;
}

textarea {
  resize: vertical;
  min-height: 112px;
}

input[type="radio"],
input[type="checkbox"] {
  accent-color: var(--primary);
  width: 1.2rem;
  height: 1.2rem;
  flex-shrink: 0;
}

.radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-block-start: 0.35rem;
}

.radio-option,
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 44px;
}

.radio-option label,
.checkbox-row label {
  font-weight: 500;
  cursor: pointer;
}

:is(input, select, textarea):focus-visible,
button:focus-visible,
a:focus-visible,
.table-wrapper:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

.error-msg {
  display: none;
  color: var(--danger);
  font-size: 0.875rem;
  margin-block-start: 0.25rem;
}

:is(input, select, textarea):is(:user-invalid, .user-invalid-fallback) {
  border-color: var(--danger);
  background-color: var(--danger-bg);
}

:is(input, select, textarea):is(:user-invalid, .user-invalid-fallback) + .error-msg,
.checkbox-field:has(input:is(:user-invalid, .user-invalid-fallback)) .error-msg {
  display: block;
}

:is(input, select, textarea):is(:user-valid, .user-valid-fallback) {
  border-color: var(--success);
}

.feedback-banner {
  padding: 0.85rem 1rem;
  border-radius: 8px;
  margin-block-end: 1.25rem;
  font-size: 0.95rem;
  font-weight: 500;
}

.feedback-banner.is-success {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid #a8dab5;
}

.feedback-banner.is-error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #f6aea9;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font: inherit;
  font-size: max(0.95rem, 0.95em);
  font-weight: 600;
  text-decoration: none;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0.65rem 1.15rem;
  min-height: 48px;
  cursor: pointer;
}

.btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-input);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-subtle);
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  min-height: 44px;
  min-width: 44px;
  padding: 0.35rem 0.6rem;
}

.btn-sm {
  min-height: 38px;
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
}

/* List & Stats */
.list-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
  margin-block-end: 1.25rem;
}

.stat-box {
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 0.9rem;
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.stat-value {
  font-size: 1.35rem;
  line-height: 1.25;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: end;
  margin-block-end: 1.25rem;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 140px;
  flex: 1 1 150px;
}

.filter-search {
  flex: 2 1 220px;
}

.filter-buttons {
  display: flex;
  align-items: end;
}

/* Responsive Table */
.table-wrapper {
  overflow: auto;
  max-inline-size: 100%;
  max-block-size: min(560px, 72vh);
  container-type: inline-size;
  border: 1px solid var(--border);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.92rem;
  --label-2: "Correo / Empresa";
  --label-3: "Categoría";
  --label-4: "Prioridad";
  --label-5: "Asunto";
  --label-6: "Estado";
  --label-7: "Fecha";
  --label-8: "Acciones";
}

thead {
  position: sticky;
  inset-block-start: 0;
  z-index: 2;
  background: var(--surface-subtle);
}

th,
td {
  padding: 0.75rem 0.8rem;
  text-align: start;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

thead th {
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

tbody th {
  position: sticky;
  inset-inline-start: 0;
  z-index: 1;
  background: var(--surface);
  font-weight: 600;
  min-width: 150px;
}

.empty-cell {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem 1rem;
}

.cell-sub {
  display: block;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: capitalize;
  white-space: nowrap;
}

.badge-alta {
  background: var(--danger-bg);
  color: var(--danger);
}

.badge-media {
  background: var(--warning-bg);
  color: var(--warning);
}

.badge-baja {
  background: var(--surface-subtle);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.estado-select {
  min-height: 38px;
  padding: 0.3rem 0.55rem;
  font-size: 0.86rem;
  min-width: 130px;
}

.row-actions {
  display: flex;
  gap: 0.4rem;
  white-space: nowrap;
}

@container (width < 680px) {
  .table-wrapper {
    max-block-size: none;
    border: 0;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  thead {
    display: none;
  }

  tr {
    margin-block-end: 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    overflow: hidden;
  }

  tbody th {
    position: sticky;
    inset-block-start: 0;
    z-index: 2;
    background: var(--surface-subtle);
    border-bottom: 1px solid var(--border);
  }

  td {
    border-bottom: 1px solid #eef1f4;
  }

  td:last-child {
    border-bottom: 0;
  }

  td:nth-child(2)::before { content: var(--label-2) ": "; font-weight: 600; color: var(--text-muted); }
  td:nth-child(3)::before { content: var(--label-3) ": "; font-weight: 600; color: var(--text-muted); }
  td:nth-child(4)::before { content: var(--label-4) ": "; font-weight: 600; color: var(--text-muted); }
  td:nth-child(5)::before { content: var(--label-5) ": "; font-weight: 600; color: var(--text-muted); }
  td:nth-child(6)::before { content: var(--label-6) ": "; font-weight: 600; color: var(--text-muted); display: block; margin-bottom: 0.25rem; }
  td:nth-child(7)::before { content: var(--label-7) ": "; font-weight: 600; color: var(--text-muted); }
  td:nth-child(8)::before { content: var(--label-8) ": "; font-weight: 600; color: var(--text-muted); display: block; margin-bottom: 0.35rem; }
}

/* Native Modal Dialogs */
dialog {
  width: min(520px, calc(100% - 2rem));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.22);
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.5);
  overflow: hidden;
  overscroll-behavior: contain;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-block-end: 1rem;
}

.dialog-body {
  color: var(--text-muted);
  margin: 0.75rem 0 1.25rem;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-block-start: 1.25rem;
}

.detail-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.55rem 1rem;
  margin: 0;
}

.detail-list dt {
  font-weight: 600;
  color: var(--text-muted);
}

.detail-list dd {
  margin: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
