.trabajos-page {
  width: 100%;
  max-width: 1700px;
  margin: 0 auto;
  padding: 32px;
}

.trabajos-page__header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.trabajos-page__header h1 {
  margin: 6px 0;
  font-size: 32px;
}

.trabajos-page__header p {
  margin: 0;
  color: var(--text-muted);
}

.trabajos-panel {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}

.trabajos-filters {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) 170px 180px 150px auto;
  align-items: end;
  gap: 12px;
  padding: 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-muted);
}

.trabajos-table-header {
  display: flex;
  align-items: center;
  min-height: 54px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
}

.trabajos-table-wrapper {
  width: 100%;
  overflow-x: auto;
}

.trabajos-table {
  width: 100%;
  min-width: 1450px;
  border-collapse: collapse;
}

.trabajos-table th,
.trabajos-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.trabajos-table th {
  background: #fafbf8;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.trabajos-table td {
  font-size: 13px;
}

.work-title-cell strong,
.work-title-cell span {
  display: block;
}

.work-title-cell span {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 11px;
}

.work-status,
.work-priority {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 27px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
}

.work-priority--alta,
.work-priority--urgente {
  border-color: #dfc791;
  background: #fff8e6;
  color: #806426;
}

.work-priority--critica {
  border-color: #d7aaa7;
  background: #fff1f0;
  color: #963f3a;
}

.trabajos-pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  min-height: 66px;
  padding: 12px 20px;
}

.trabajos-empty {
  height: 180px;
  color: var(--text-muted);
  text-align: center !important;
}

.trabajos-empty--error {
  color: #963f3a;
}

.trabajos-message {
  margin-bottom: 16px;
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
}

.trabajos-message--success {
  border-color: #b8cfaf;
  background: #edf5e9;
  color: #456b39;
}

.trabajos-message--error {
  border-color: #d5b9b7;
  background: #fff2f1;
  color: #8f423e;
}

.trabajos-modal {
  position: fixed;
  z-index: 1200;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
}

.trabajos-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(25, 30, 24, .58);
}

.trabajos-modal__dialog {
  position: relative;
  z-index: 1;
  width: min(1050px, 100%);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--surface);
}

.trabajos-modal__header {
  position: sticky;
  z-index: 5;
  top: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.trabajos-modal__header span,
.section-heading > span,
.section-heading > div > span {
  color: var(--accent);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .09em;
}

.trabajos-modal__header h2,
.section-heading h3 {
  margin: 5px 0 0;
}

.trabajo-form {
  padding: 24px;
}

.trabajo-form__section {
  margin-bottom: 30px;
  padding-bottom: 30px;
  border-bottom: 1px solid var(--border);
}

.section-heading {
  margin-bottom: 18px;
}

.section-heading--actions {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

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

.trabajo-form textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  outline: none;
  resize: vertical;
  background: var(--surface);
  color: var(--text);
}

.dynamic-items {
  display: grid;
  gap: 14px;
}

.work-item-card {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-muted);
}

.work-item-card > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.remove-item-button {
  border: 0;
  background: transparent;
  color: #963f3a;
  font-weight: 700;
  cursor: pointer;
}

.trabajos-modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 18px 24px;
  border-top: 1px solid var(--border);
  background: #fafbf8;
}

.trabajo-form > .trabajos-modal__footer {
  margin: 24px -24px -24px;
}

.trabajo-detail {
  padding: 24px;
}

.trabajo-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.trabajo-detail-grid > div {
  min-height: 78px;
  padding: 15px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.trabajo-detail-grid span,
.trabajo-detail-grid strong {
  display: block;
}

.trabajo-detail-grid span {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.trabajo-detail-grid strong {
  margin-top: 7px;
  font-size: 13px;
}

.detail-section {
  margin-top: 26px;
}

.detail-item {
  margin-top: 10px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.detail-item strong,
.detail-item span {
  display: block;
}

.detail-item span,
.detail-item p,
.empty-copy {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 12px;
}

.photos-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.photo-card {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
}

.photo-card img {
  display: block;
  width: 100%;
  height: 150px;
  object-fit: cover;
}

.photo-card span {
  display: block;
  padding: 9px;
  font-size: 11px;
  font-weight: 800;
}

@media (max-width: 1100px) {
  .trabajos-filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filter-field--search {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .trabajos-page {
    padding: 18px;
  }

  .trabajos-page__header {
    align-items: stretch;
    flex-direction: column;
  }

  .trabajos-filters,
  .work-form-grid,
  .trabajo-detail-grid {
    grid-template-columns: 1fr;
  }

  .filter-field--search {
    grid-column: auto;
  }

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

  .section-heading--actions {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (max-width: 520px) {
  .trabajos-modal {
    align-items: end;
    padding: 0;
  }

  .trabajos-modal__dialog {
    width: 100%;
    max-height: 94vh;
    border-radius: 16px 16px 0 0;
  }

  .trabajos-modal__footer {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .trabajos-modal__footer button {
    width: 100%;
  }
}

/* =========================================================
   AGRO INTEL · TRABAJOS SIN SCROLL HORIZONTAL EN MÓVIL
   ========================================================= */

@media (max-width: 820px) {
  html,
  body,
  #app,
  .app-layout,
  .workspace,
  #page-content,
  .content {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  .works-page,
  .trabajos-page,
  .work-page,
  .works-container,
  .trabajos-container,
  .table-container,
  .table-wrapper,
  .data-table-container {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow: visible;
  }

  .works-page *,
  .trabajos-page *,
  .work-page * {
    min-width: 0;
  }

  /* =======================================================
     CABECERA
     ======================================================= */

  .works-page__header,
  .trabajos-page__header,
  .work-page__header,
  .page-header {
    align-items: stretch;
    flex-direction: column;
    gap: 16px;
  }

  .works-page__header h1,
  .trabajos-page__header h1,
  .work-page__header h1,
  .page-header h1 {
    font-size: 30px;
  }

  .works-page__header .primary-button,
  .trabajos-page__header .primary-button,
  .work-page__header .primary-button,
  .page-header .primary-button,
  [data-create-work] {
    width: 100%;
  }

  /* =======================================================
     FILTROS
     ======================================================= */

  .works-filters,
  .trabajos-filters,
  .work-filters,
  .filters,
  .filters-grid,
  .table-filters {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
    gap: 13px;
  }

  .works-filters label,
  .trabajos-filters label,
  .work-filters label,
  .filters label,
  .filters-grid label,
  .table-filters label {
    width: 100%;
    min-width: 0;
  }

  .works-filters input,
  .works-filters select,
  .works-filters button,
  .trabajos-filters input,
  .trabajos-filters select,
  .trabajos-filters button,
  .work-filters input,
  .work-filters select,
  .work-filters button,
  .filters input,
  .filters select,
  .filters button,
  .filters-grid input,
  .filters-grid select,
  .filters-grid button,
  .table-filters input,
  .table-filters select,
  .table-filters button {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  /* =======================================================
     TABLA CONVERTIDA EN TARJETAS
     ======================================================= */

  #page-content table {
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    border-collapse: separate;
  }

  #page-content table thead {
    display: none;
  }

  #page-content table tbody {
    display: grid;
    width: 100%;
    gap: 12px;
    padding: 12px;
  }

  #page-content table tbody tr {
    display: grid;
    width: 100%;
    min-width: 0;
    overflow: hidden;
    gap: 0;
    padding: 5px 14px;
    border: 1px solid var(--border, #d9ddd2);
    border-radius: 12px;
    background: var(--surface, #ffffff);
  }

  #page-content table tbody td {
    display: grid;
    grid-template-columns: minmax(105px, 38%) minmax(0, 1fr);
    width: 100%;
    max-width: 100%;
    min-width: 0;
    align-items: center;
    gap: 12px;
    padding: 11px 0;
    border: 0;
    border-bottom: 1px solid var(--border, #d9ddd2);
    overflow-wrap: anywhere;
    white-space: normal;
  }

  #page-content table tbody td:last-child {
    border-bottom: 0;
  }

  #page-content table tbody td::before {
    color: var(--text-muted, #697267);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
  }

  #page-content table tbody td:nth-child(1)::before {
    content: "Trabajo";
  }

  #page-content table tbody td:nth-child(2)::before {
    content: "Cliente";
  }

  #page-content table tbody td:nth-child(3)::before {
    content: "Técnico";
  }

  #page-content table tbody td:nth-child(4)::before {
    content: "Tipo";
  }

  #page-content table tbody td:nth-child(5)::before {
    content: "Ubicación";
  }

  #page-content table tbody td:nth-child(6)::before {
    content: "Fecha";
  }

  #page-content table tbody td:nth-child(7)::before {
    content: "Prioridad";
  }

  #page-content table tbody td:nth-child(8)::before {
    content: "Estado";
  }

  #page-content table tbody td:nth-child(9)::before {
    content: "Cámaras / fotos";
  }

  #page-content table tbody td:nth-child(10)::before {
    content: "Acciones";
  }

  #page-content table tbody td > * {
    min-width: 0;
    max-width: 100%;
  }

  #page-content table tbody td:last-child {
    grid-template-columns: 1fr;
  }

  #page-content table tbody td:last-child::before {
    margin-bottom: 3px;
  }

  #page-content table tbody td:last-child > div,
  #page-content table tbody td:last-child .table-actions,
  #page-content table tbody td:last-child .actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    gap: 7px;
  }

  #page-content table tbody td:last-child button,
  #page-content table tbody td:last-child a {
    width: 100%;
    min-width: 0;
    min-height: 38px;
    padding: 0 8px;
    text-align: center;
  }

  /* =======================================================
     PAGINACIÓN
     ======================================================= */

  .pagination,
  .table-pagination,
  .pagination-container,
  .works-pagination,
  .trabajos-pagination {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
    gap: 10px;
    padding: 14px;
    text-align: center;
  }

  .pagination button,
  .table-pagination button,
  .pagination-container button,
  .works-pagination button,
  .trabajos-pagination button {
    width: 100%;
  }
}

@media (max-width: 480px) {
  #page-content table tbody {
    padding: 10px;
  }

  #page-content table tbody tr {
    padding: 4px 12px;
  }

  #page-content table tbody td {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  #page-content table tbody td::before {
    display: block;
  }

  #page-content table tbody td:last-child > div,
  #page-content table tbody td:last-child .table-actions,
  #page-content table tbody td:last-child .actions {
    grid-template-columns: 1fr;
  }
}
