/**
 * Agrico-M — responsive product list tables (admin list pages).
 * Admin layout uses admin.css (TailAdmin); do not rely on Tailwind breakpoints in PHP thClass/tdClass.
 * Hide .agrico-table-desktop-only columns below 768px. Hide lower-priority
 * .agrico-table-wide-only columns until the admin content has a full wide desktop.
 *
 * @see docs/guides/ADMIN_RESPONSIVE_TABLES.md
 * @see .cursor/rules/admin-responsive-tables.mdc
 */
/* CSS owns visibility for card tables. DataTables keeps col elements for CSS-
 * hidden cells; letting those tracks participate reserves ghost columns. The
 * native table algorithm sizes the remaining cells without those stale tracks. */
table.admin-responsive-card-table > colgroup { display: none; }

.agrico-table-compact-only {
  display: none;
}

/* Financial registers retain this relationship metadata in phone cards and on
 * full desktops, but omit it at the squeezed sidebar/tablet width where the
 * sticky Actions column would otherwise cover the primary amount. */
@media (min-width: 768px) and (max-width: 1439.98px) {
  th.admin-financial-mid-hide,
  td.admin-financial-mid-hide {
    display: none !important;
  }
}

/* Phone table workspaces use one calm vertical control stack. Every collection
 * action, filter, search field, and export trigger owns the complete available
 * row so mixed helper wrappers cannot leave narrow, hard-to-tap controls. */
@media (max-width: 639.98px) {
  .admin-data-table-section-header .admin-section-header-actions {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  .admin-data-table-section-header .admin-section-header-actions > *,
  .admin-data-table-section-header .admin-section-header-actions .admin-action-group,
  .admin-data-table-section-header .admin-section-header-actions .admin-action-group > * {
    width: 100%;
    min-width: 0;
    max-width: none;
  }

  .admin-data-table-section-header .admin-section-header-actions .admin-action-group {
    flex-direction: column;
    align-items: stretch;
  }

  .admin-data-table-section-header .admin-section-header-actions :where(a, button, summary) {
    width: 100%;
    justify-content: center;
  }

  .admin-table-controls-left,
  .admin-table-controls-right {
    align-items: stretch;
    width: 100%;
    min-width: 0;
  }

  .admin-table-controls-left > *,
  .admin-table-controls-left > * > *,
  .admin-table-controls-right > * {
    width: 100%;
    min-width: 0;
    max-width: none !important;
  }

  .admin-table-controls-left :where(
    .admin-base-dropdown,
    .admin-filter-row,
    .admin-filter-actions,
    .admin-care-toolbar,
    .admin-care-toolbar-filters,
    .admin-care-toolbar-control,
    .admin-planting-filter-section,
    .admin-harvest-crop-summary-filter,
    .admin-work-machine-filter-controls,
    .admin-work-machine-filter-menu
  ),
  .admin-table-controls-right :where(
    .admin-table-search-shell,
    .admin-table-export-details
  ) {
    width: 100%;
    min-width: 0;
    max-width: none !important;
  }

  .admin-table-controls-left :where(a, button),
  .admin-table-controls-right :where(a, button, summary) {
    width: 100%;
    justify-content: center;
  }

  .admin-table-controls-right .admin-table-export-details {
    display: block;
  }

  /* Domain filters load after this sheet; out-rank their compact width, not
   * just their max-width, throughout the shared phone toolbar. */
  .admin-table-controls-left .admin-base-dropdown {
    width: 100%;
    min-width: 0;
    max-width: none;
  }
}

@media (max-width: 767.98px) {
  th.agrico-table-desktop-only,
  td.agrico-table-desktop-only {
    display: none !important;
  }

  .admin-table-scroll:has(:where(.admin-responsive-card-table:not(.admin-manual-table-empty))) {
    overflow-x: hidden;
  }

  table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)),
  table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tbody,
  table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tfoot {
    box-sizing: border-box;
    display: block;
    width: 100% !important;
    min-width: 0 !important;
  }

  table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) colgroup,
  table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) thead {
    display: none;
  }

  table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tbody {
    display: grid;
    gap: .75rem;
    padding: .75rem;
    background: transparent;
  }

  table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tbody > tr {
    box-sizing: border-box;
    display: grid;
    width: 100%;
    min-width: 0;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: .75rem;
    row-gap: 0;
    border: 1px solid #e5dfd6;
    border-radius: .75rem;
    background: #fffdf9;
    padding: .75rem 1rem;
    box-shadow: 0 1px 2px rgba(28, 25, 23, .04);
  }

  table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tbody > tr:hover {
    background: #fffaf5;
  }

  table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tbody > tr > td {
    display: grid;
    width: auto !important;
    min-width: 0 !important;
    grid-column: 1 / -1;
    grid-template-columns: minmax(6.5rem, 38%) minmax(0, 1fr);
    align-items: center;
    gap: .75rem;
    border: 0 !important;
    border-top: 1px solid #ebe6df !important;
    padding: .72rem 0 !important;
    background: transparent;
    box-shadow: none;
    text-align: right !important;
    white-space: normal !important;
    overflow-wrap: anywhere;
  }

  table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tbody > tr > td::before {
    content: attr(data-label);
    min-width: 0;
    color: #78716c;
    font-size: .65rem;
    font-weight: 700;
    letter-spacing: .04em;
    line-height: 1rem;
    text-align: left;
    text-transform: uppercase;
  }

  table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tbody > tr > td > * {
    min-width: 0;
    max-width: 100%;
  }

  /* Editable rows own a real, icon-bearing field label above a full-width
   * control; the ordinary ledger label must not squeeze or duplicate it. */
  table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tbody > tr > td.admin-table-field-cell {
    grid-template-columns: minmax(0, 1fr);
    text-align: left !important;
  }

  table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tbody > tr > td.admin-table-field-cell::before {
    display: none;
  }

  table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tbody > tr > td > :where(.flex, .inline-flex, .admin-action-group) {
    justify-content: flex-end;
  }

  /* Compact and interactive values must visually terminate at the card's
   * right edge too. Grid items stretch by default, which otherwise leaves
   * inline placeholders, thumbnails, telemetry stacks and links on the left
   * even though the cell itself is right-aligned. */
  table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tbody > tr > td > :where(
    .admin-table-placeholder,
    .admin-image-placeholder,
    .admin-inline-table-link,
    .admin-warehouse-current-summary,
    .admin-warehouse-temperature-cell,
    .admin-warehouse-schedule-link
  ) {
    justify-self: end;
    margin-inline-start: auto;
    text-align: right;
  }

  table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tbody > tr > td > .admin-warehouse-current-summary {
    align-items: flex-end;
  }

  table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tbody > tr > .admin-table-mobile-primary {
    display: grid;
    grid-column: 1 / -1;
    grid-row: 1;
    align-self: stretch;
    grid-template-columns: minmax(0, 1fr);
    align-content: center;
    gap: .2rem;
    border-top: 0 !important;
    padding: .1rem 0 .7rem !important;
    color: #1c1917;
    font-weight: 700;
    text-align: left !important;
  }

  table:where(.admin-responsive-card-table.admin-table-has-actions:not(.admin-manual-table-empty)) tbody > tr > .admin-table-mobile-primary {
    grid-column: 1;
    grid-row: 1;
  }

  table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tbody > tr > .admin-table-mobile-primary > * {
    justify-self: start;
    margin-inline: 0;
    text-align: left !important;
  }

  table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tbody > tr > .admin-table-mobile-primary .font-bold {
    white-space: nowrap;
  }

  /* Linked identities wrap; numeric/unit emphasis keeps its unbroken contract. */
  table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tbody > tr > .admin-table-mobile-primary a.admin-table-link {
    white-space: normal;
    overflow-wrap: anywhere;
    max-width: 100%;
    min-width: 0;
  }

  table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tbody > tr > .admin-table-action-cell::before,
  table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tbody > tr > td[data-label=""]::before {
    display: none;
  }

  table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tbody > tr > .admin-table-action-cell {
    position: static;
    display: block;
    width: auto !important;
    grid-column: 2;
    grid-row: 1;
    align-self: stretch;
    border-top: 0 !important;
    padding: 0 0 .7rem !important;
    background: transparent;
    box-shadow: none;
    text-align: right !important;
  }

  table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) .admin-table-action-cell .admin-action-group {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tbody > tr > .admin-table-action-cell::after {
    display: none;
  }

  table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tfoot {
    border-top: 1px solid #e5dfd6;
    background: #faf8f3;
    padding: .65rem 1rem;
  }

  table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tfoot tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: .35rem;
  }

  table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tfoot td {
    width: auto !important;
    min-width: 0 !important;
    border: 0;
    padding: .2rem 0 !important;
    white-space: normal;
  }

  .dark table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tbody > tr {
    border-color: #44403c;
    background: #1c1917;
  }

  .dark table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tbody > tr:hover {
    background: #292524;
  }

  .dark table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tbody > tr > td::before {
    color: #d6d3d1;
  }

  .dark table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tbody > tr > td {
    border-top-color: #44403c !important;
  }

  .dark table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tbody > tr > .admin-table-mobile-primary {
    color: #f5f5f4;
  }

  .dark table:where(.admin-responsive-card-table:not(.admin-manual-table-empty)) tfoot {
    border-color: #44403c;
    background: #292524;
  }

  .admin-profile-audit-table {
    width: 100%;
    min-width: 0;
    table-layout: fixed;
  }

  .admin-profile-audit-table th,
  .admin-profile-audit-table td {
    white-space: normal;
  }

  .admin-profile-audit-table th:nth-child(1),
  .admin-profile-audit-table td:nth-child(1) {
    width: 31%;
  }

  .admin-profile-audit-table th:nth-child(2),
  .admin-profile-audit-table td:nth-child(2) {
    width: 24%;
  }

  .admin-profile-audit-table th:nth-child(3),
  .admin-profile-audit-table td:nth-child(3) {
    width: 45%;
  }

  .planting-crop-block-table,
  .planting-crop-block-table tbody,
  .planting-crop-block-table tfoot {
    display: block;
    width: 100%;
    min-width: 0;
  }

  .planting-crop-block-table thead {
    display: none;
  }

  .planting-crop-block-table tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: .75rem 1rem;
    padding: 1rem;
  }

  .planting-crop-block-table tbody td {
    display: block;
    min-width: 0;
    padding: 0 !important;
    border: 0;
    white-space: normal;
  }

  .planting-crop-block-table .planting-crop-block-cell {
    grid-column: 1 / -1;
    width: auto !important;
    min-width: 0 !important;
  }

  .planting-crop-block-table .planting-crop-area-cell {
    width: auto !important;
    min-width: 0 !important;
  }

  .planting-crop-block-table .planting-crop-area-cell::before {
    content: attr(data-label);
    display: block;
    margin-bottom: .15rem;
    font-size: .65rem;
    line-height: 1rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: #78716c;
  }

  .planting-crop-block-table .admin-table-action-cell {
    position: static;
    grid-column: 2;
    box-shadow: none;
    background: transparent;
  }

  .planting-crop-block-table tfoot tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: .5rem 1rem;
    padding: .85rem 1rem;
    background: #f8fafc;
  }

  .planting-crop-block-table tfoot td {
    display: none;
    min-width: 0;
    padding: 0;
    border: 0;
  }

  .planting-crop-block-table tfoot .planting-crop-footer-label,
  .planting-crop-block-table tfoot .planting-crop-footer-area {
    display: block;
  }

  .planting-crop-block-table tfoot .planting-crop-footer-area {
    text-align: right;
  }

  .admin-planting-allocation-body {
    padding: .75rem 1rem;
  }

  .admin-planting-allocation-status .admin-status-tile-copy {
    display: flex !important;
    flex-direction: column;
    align-items: flex-start;
    gap: .1rem;
  }

  .admin-planting-allocation-status .admin-status-tile-description {
    text-align: left !important;
  }

  .admin-planting-detail-list {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .admin-planting-area-metric {
    min-width: 0 !important;
  }
}

@media (max-width: 1439.98px) {
  .agrico-table-compact-only {
    display: block;
  }

  th.agrico-table-wide-only,
  td.agrico-table-wide-only {
    display: none !important;
  }

  .admin-table-head-cell,
  .admin-table-cell {
    padding-left: .75rem;
    padding-right: .75rem;
  }
}

.admin-table-action-head,
.admin-table-action-cell {
  position: sticky;
  right: 0;
  z-index: 2;
  background: #fffdf9;
  box-shadow: -10px 0 16px -16px rgba(28, 25, 23, .55);
}

.admin-table-action-head {
  z-index: 3;
  background: #faf8f3;
}

tbody tr:hover .admin-table-action-cell {
  background: #fffaf5;
}

/* Retain useful secondary fields beneath their primary column on tablets. */
.admin-table-compact-detail{display:none}
@media(min-width:768px) and (max-width:1439.98px){
  .admin-table-compact-detail{display:block;margin-top:.375rem}
}

/* DataTables exposes this focusable sort target even when its empty content has no height. */
.admin-responsive-card-table th[class*="dt-orderable"]{position:relative}
.admin-responsive-card-table th[class*="dt-orderable"] .dt-column-order{position:absolute!important;top:0!important;right:0!important;bottom:0!important;width:2rem!important;height:auto!important;min-height:100%}
.admin-responsive-card-table th[class*="dt-orderable"] .dt-column-order:focus-visible{border-radius:.25rem;outline:2px solid #b93815;outline-offset:-2px}

/* Dense operational records keep all original cells and controls in one DOM.
 * Use the shared phone breakpoint; desktop content width must not trigger cards. */
.admin-table-record-sort{display:none}
@media(max-width:767.98px){
  .admin-table-record-sort{display:block;padding:1rem 1rem 0;max-width:25rem}
  table.admin-table-records.admin-responsive-card-table{display:block;width:100%!important;min-width:0!important}
  table.admin-table-records.admin-responsive-card-table thead{display:none}
  table.admin-table-records.admin-responsive-card-table tbody{display:grid;width:100%;gap:1rem;padding:1rem}
  table.admin-table-records.admin-responsive-card-table tbody>tr{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:0 1.5rem;width:100%;min-width:0;padding:1rem;border:1px solid #e5dfd6;border-radius:.75rem;background:#fffdf9}
  table.admin-table-records.admin-responsive-card-table tbody>tr>td{position:static;display:grid;grid-column:auto;grid-row:auto;grid-template-columns:minmax(0,1fr);align-content:start;gap:.35rem;width:auto!important;min-width:0!important;padding:.65rem 0!important;border:0!important;border-top:1px solid #ebe6df!important;box-shadow:none;background:transparent;white-space:normal!important;text-align:left!important;overflow-wrap:anywhere}
  table.admin-table-records.admin-responsive-card-table tbody>tr>td:is(.agrico-table-desktop-only,.agrico-table-wide-only){display:grid!important}
  table.admin-table-records.admin-responsive-card-table tbody>tr>td::before{content:attr(data-label);display:block;color:#78716c;font-size:.65rem;line-height:1rem;font-weight:700;letter-spacing:.04em;text-transform:uppercase;text-align:left}
  table.admin-table-records.admin-responsive-card-table tbody>tr>td>*{max-width:100%;min-width:0;justify-self:start}
  table.admin-table-records.admin-responsive-card-table tbody>tr>td[colspan]{grid-column:1/-1}
  table.admin-table-records.admin-responsive-card-table tbody>tr>td[colspan]::before{display:none}
  table.admin-table-records.admin-responsive-card-table tbody>tr>.admin-table-mobile-primary{grid-column:1;grid-row:1;border-top:0!important}
  table.admin-table-records.admin-responsive-card-table tbody>tr>.admin-table-action-cell{display:flex;grid-column:2;grid-row:1;align-items:center;justify-content:flex-end;border-top:0!important}
  table.admin-table-records.admin-responsive-card-table tbody>tr>.admin-table-action-cell::before,
  table.admin-table-records.admin-responsive-card-table tbody>tr>.admin-table-action-cell::after{display:none}
  table.admin-table-records.admin-responsive-card-table .admin-table-action-cell .admin-action-group{flex-wrap:wrap;justify-content:flex-end;max-width:100%}
  table.admin-table-records.admin-responsive-card-table tfoot{display:block;padding:1rem;border-top:1px solid #e5dfd6;background:#faf8f3}
  table.admin-table-records.admin-responsive-card-table tfoot tr{display:flex;flex-wrap:wrap;gap:.75rem 1.5rem}
  table.admin-table-records.admin-responsive-card-table tfoot td{display:block;width:auto!important;min-width:0!important;padding:0!important;border:0;white-space:normal}
  table.admin-table-records.admin-responsive-card-table tfoot td:empty{display:none}
  .dark table.admin-table-records.admin-responsive-card-table tbody>tr{background:#1c1917;border-color:#44403c}
  .dark table.admin-table-records.admin-responsive-card-table tbody>tr>td{border-color:#44403c!important}
  .dark table.admin-table-records.admin-responsive-card-table tbody>tr>td::before{color:#a8a29e}
  .dark table.admin-table-records.admin-responsive-card-table tfoot{background:#292524;border-color:#44403c}
}
@media(max-width:639.98px){
  table.admin-table-records.admin-responsive-card-table tbody>tr{column-gap:.75rem}
  table.admin-table-records.admin-responsive-card-table tbody>tr>td{grid-column:1/-1;grid-template-columns:minmax(6rem,35%) minmax(0,1fr)}
  table.admin-table-records.admin-responsive-card-table tbody>tr>.admin-table-mobile-primary{grid-template-columns:minmax(0,1fr)}
  table.admin-table-records.admin-responsive-card-table tbody>tr>.admin-table-action-cell{grid-column:2}
}
/* A search with no rows has no meaningful totals, including custom log footers. */
table.admin-responsive-card-table:has(tbody .dt-empty) tfoot{display:none!important}
