/* Stable tabular layout: values stay intact and wide tables scroll inside their panel. */
th,
td,
dd,
.message,
.list-row {
  overflow-wrap: normal;
  word-break: normal;
  hyphens: none;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  -webkit-overflow-scrolling: touch;
}

.table-wrap table:not(.work-calendar) {
  table-layout: auto;
  width: max-content;
  min-width: 100%;
}

.table-wrap table:not(.work-calendar) th,
.table-wrap table:not(.work-calendar) td {
  white-space: nowrap;
  vertical-align: top;
}

.compact-text {
  display: inline-block;
  max-width: min(28rem, 70vw);
  white-space: normal;
}

.compact-text summary {
  color: var(--green);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.compact-text-full {
  margin-top: 6px;
  padding: 8px 10px;
  border-left: 3px solid var(--line);
  color: var(--ink);
  white-space: normal;
}

.compact-text-hide {
  display: none;
}

.compact-text[open] .compact-text-show {
  display: none;
}

.compact-text[open] .compact-text-hide {
  display: inline;
}

.purchase-receipt-content {
  white-space: normal !important;
  min-width: 28rem;
}

.purchase-receipt-lines {
  display: grid;
  gap: 10px;
}

.purchase-receipt-line {
  display: grid;
  grid-template-columns: minmax(12rem, 1fr) minmax(7rem, auto) minmax(10rem, auto);
  align-items: baseline;
  gap: 8px 18px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.purchase-receipt-line:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.purchase-receipt-line small:not(.stock-confirmed) {
  display: block;
  color: var(--muted);
}

.purchase-receipt-line .stock-confirmed {
  grid-column: 1 / -1;
  color: var(--green);
}

@media (max-width: 720px) {
  .purchase-receipt-content { min-width: 0; }
  .purchase-receipt-line { grid-template-columns: 1fr 1fr; }
  .purchase-receipt-line > strong { grid-column: 1 / -1; }
}

.page-head > *,
.section-head > *,
.list-row > * {
  min-width: 0;
}

.financial-table .financial-party,
.financial-table .financial-text,
.table-wrap .wrap-text,
.fuel-purchases .purchase-supplier,
.fuel-purchases .purchase-documents {
  white-space: normal !important;
  min-width: 11rem;
  max-width: 28rem;
}

.financial-table .financial-text {
  min-width: 16rem;
}

/* Issued and received invoices share an identical, compact column grid. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

.table-wrap table.invoice-table {
  width: 86rem;
  min-width: 86rem;
  table-layout: fixed;
}

.invoice-table .invoice-col-select { width: 3rem; }
.invoice-table .invoice-col-pdf { width: 11rem; }
.invoice-table .invoice-col-number { width: 8rem; }
.invoice-table .invoice-col-date { width: 7rem; }
.invoice-table .invoice-col-party { width: 14rem; }
.invoice-table .invoice-col-money { width: 8rem; }
.invoice-table .invoice-col-vat { width: 7rem; }
.invoice-table .invoice-col-status { width: 11rem; }
.invoice-table .invoice-col-actions { width: 9rem; }

.invoice-bulk-actions {
  align-items: center;
  justify-content: flex-start;
  margin: 14px 0 0;
}

.invoice-bulk-actions small { color: var(--muted); }

.invoice-table .financial-party {
  min-width: 0;
  max-width: none;
}

.invoice-pdf-link {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 850px) {
  .invoice-bulk-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .invoice-bulk-actions .button { width: 100%; }
}

.fuel-purchases .purchase-date { min-width: 8rem; }
.fuel-purchases .purchase-supplier { width: 17rem; }
.fuel-purchases .purchase-quantity { min-width: 10rem; }
.fuel-purchases .purchase-documents { width: 16rem; }
.fuel-purchases .purchase-amount { min-width: 8rem; }
.fuel-purchases .purchase-unit-price { min-width: 11rem; }

.fuel-purchases .purchase-supplier .cell-wrap,
.fuel-purchases .purchase-documents .cell-wrap {
  display: block;
  max-width: 100%;
  white-space: normal;
}

.fuel-purchases .purchase-supplier .cell-wrap { width: 17rem; }
.fuel-purchases .purchase-documents .cell-wrap { width: 16rem; }

.fuel-purchases .purchase-documents a,
.table-wrap a[href^="http"],
.table-wrap a[href*="/media/"] {
  overflow-wrap: anywhere;
  word-break: normal;
}

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

.accounting-card {
  display: flex;
  min-width: 0;
  min-height: 150px;
  padding: 21px;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 5px 18px rgba(36, 92, 54, .08);
  color: var(--ink);
  text-decoration: none;
}

.accounting-card span,
.accounting-card strong,
.accounting-card small { display: block; }

.accounting-card span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .02em;
}

.accounting-card span b {
  display: inline-grid;
  width: 30px;
  height: 30px;
  margin-right: 7px;
  place-items: center;
  border-radius: 50%;
  background: #e8ede5;
  color: var(--green);
  font-size: 18px;
}

.accounting-card strong {
  white-space: nowrap;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.1;
}

.accounting-card small { color: var(--muted); }
.accounting-card-in { border-top: 5px solid #3f7f4a; }
.accounting-card-out { border-top: 5px solid #b5653d; }
.accounting-card-balance { border-top: 5px solid #47728d; }
.accounting-card:hover { box-shadow: 0 7px 22px rgba(36, 92, 54, .14); }

.calendar-order,
.calendar-absence {
  overflow-wrap: normal !important;
  word-break: normal;
  hyphens: none;
}

/* OT list: reserve the useful width for people instead of empty planting space. */
.table-wrap table.work-order-list {
  width: 100%;
  min-width: 72rem;
  table-layout: fixed;
}

.work-order-list .order-col-number { width: 4.5rem; }
.work-order-list .order-col-status { width: 9rem; }
.work-order-list .order-col-labor { width: 12rem; }
.work-order-list .order-col-plantings { width: 10rem; }
.work-order-list .order-col-date { width: 8.5rem; }
.work-order-list .order-col-workers { width: 16.5rem; }
.work-order-list .order-col-machines { width: 11.5rem; }

.table-wrap table.work-order-list th,
.table-wrap table.work-order-list td {
  padding-inline: 8px;
}

.table-wrap table.work-order-list .order-labor,
.table-wrap table.work-order-list .order-plantings,
.table-wrap table.work-order-list .order-workers,
.table-wrap table.work-order-list .order-machines {
  white-space: normal;
  overflow-wrap: normal;
  word-break: normal;
  hyphens: none;
}

.work-order-list .order-planting,
.work-order-list .order-workers > span,
.work-order-list .order-machines > span {
  display: block;
  margin-bottom: 4px;
  line-height: 1.3;
}

.work-order-list .order-planting:last-child,
.work-order-list .order-workers > span:last-child,
.work-order-list .order-machines > span:last-child { margin-bottom: 0; }

.table-wrap table.work-order-list .order-workers > span {
  white-space: nowrap;
}

.work-order-list .order-tag {
  display: block;
  width: max-content;
  max-width: 100%;
  margin: 0 0 5px;
  padding: 3px 8px;
  border: 1px solid #d5ddcf;
  border-radius: 999px;
  background: #f3f6ed;
  font-size: 13px;
  line-height: 1.25;
  white-space: normal;
}

.work-order-list .order-tag:last-child { margin-bottom: 0; }
.work-order-list .order-tag-list { display: grid; justify-items: start; }
.order-mobile-values { display: none; }
.order-status-tag {
  display: inline-flex;
  max-width: 100%;
  padding: 4px 9px;
  border-radius: 999px;
  background: #edf1e8;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
  white-space: normal;
}
.work-order-list .status-running .order-status-tag { background: #dcefe3; color: #1d653d; }
.work-order-list .status-paused .order-status-tag { background: #fff0c9; color: #76500b; }
.work-order-list .status-not_done .order-status-tag { background: #f9e1dc; color: #832a22; }
.work-order-list .status-done .order-status-tag { background: #e5eae6; color: #4f5b53; }
.work-order-list .status-cancelled .order-status-tag { background: #ececec; color: #686868; }

.table-wrap table.work-order-list .order-number,
.table-wrap table.work-order-list .order-date,
.table-wrap table.work-order-list .order-status { white-space: nowrap; }

.work-order-list .order-number a {
  color: var(--green);
  font-size: 18px;
  line-height: 1;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

/* Compact manufacturer history: short data columns and multi-line headings. */
.table-wrap .manufacturer-history {
  font-size: 14px;
}

.table-wrap table.manufacturer-history th,
.table-wrap table.manufacturer-history td {
  padding: 9px 8px;
  text-align: center;
}

.table-wrap table.manufacturer-history th {
  width: 8.5rem;
  min-width: 8.5rem;
  max-width: none;
  white-space: normal !important;
  overflow-wrap: normal;
  word-break: keep-all;
  hyphens: none;
  line-height: 1.2;
  vertical-align: bottom;
}

.manufacturer-history th small {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  line-height: 1.15;
}

.table-wrap table.manufacturer-history .manufacturer-history-date {
  width: 8.5rem;
  min-width: 8.5rem;
  max-width: 8.5rem;
}

.table-wrap table.manufacturer-history .manufacturer-history-meter {
  width: 7.75rem;
  min-width: 7.75rem;
  max-width: 7.75rem;
}

.table-wrap table.manufacturer-history .manufacturer-history-operation {
  width: 8.5rem;
  min-width: 8.5rem;
  max-width: none;
}

.table-wrap table.manufacturer-history .manufacturer-history-notes {
  width: 12rem;
  min-width: 10rem;
  max-width: 14rem;
  text-align: left;
  white-space: normal !important;
}

.manufacturer-history .manufacturer-history-notes .compact-text {
  max-width: 100%;
}

@media (max-width: 850px) {
  .accounting-summary { grid-template-columns: 1fr; }
  .accounting-card { min-height: 125px; }

  .mobile-operator .table-wrap {
    overflow-x: auto;
  }

  .table-wrap table.mobile-cards {
    min-width: 0;
    width: 100%;
  }

  .table-wrap table.work-order-list { min-width: 0; }

  .mobile-cards.work-order-list tr.order-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0 10px;
    padding: 12px;
    border-left: 4px solid #a7b1a8;
  }

  .mobile-cards.work-order-list tr.status-running { border-left-color: #1f7a4c; }
  .mobile-cards.work-order-list tr.status-paused { border-left-color: #c58a24; }
  .mobile-cards.work-order-list tr.status-not_done { border-left-color: #b42318; }

  .mobile-cards.work-order-list td {
    grid-column: 1 / -1;
    grid-template-columns: minmax(68px, 25%) minmax(0, 1fr);
    gap: 8px;
    padding: 7px 0;
  }

  .mobile-cards.work-order-list .order-number {
    grid-column: 1;
    grid-row: 1;
    display: block;
    padding: 0;
    border: 0;
    font-size: 22px;
    font-weight: 800;
    line-height: 1;
  }

  .mobile-cards.work-order-list .order-number a { font-size: inherit; }

  .mobile-cards.work-order-list .order-status {
    grid-column: 2;
    grid-row: 1;
    display: block;
    padding: 0;
    border: 0;
    text-align: right;
  }

  .mobile-cards.work-order-list .order-number::before,
  .mobile-cards.work-order-list .order-status::before,
  .mobile-cards.work-order-list .order-labor::before { content: none; }

  .mobile-cards.work-order-list .order-labor {
    grid-column: 1 / -1;
    grid-row: 2;
    display: block;
    padding: 5px 0 10px;
    font-size: 16px;
    font-weight: 600;
  }

  .work-order-list .order-plantings {
    grid-row: 3;
    display: block;
  }
  .work-order-list .order-plantings::before {
    display: block;
    margin-bottom: 6px;
  }
  .work-order-list .order-plantings .order-tag-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px;
  }
  .work-order-list .order-plantings .order-tag {
    width: 100%;
    margin: 0;
    border-radius: 7px;
    text-align: center;
  }
  .work-order-list .order-date { grid-row: 4; }
  .work-order-list .order-workers { grid-row: 5; }
  .work-order-list .order-machines { grid-row: 6; }
  .work-order-list .order-desktop-values { display: none; }
  .work-order-list .order-mobile-values { display: block; min-width: 0; }
  .work-order-list .order-mobile-values summary { color: var(--green); cursor: pointer; font-weight: 700; }
  .work-order-list .order-mobile-value-list { display: grid; gap: 5px; margin-top: 8px; }
  .work-order-list .order-tag { margin-bottom: 4px; }
  .work-order-list .order-mobile-value-list .order-tag { width: 100%; margin: 0; border-radius: 7px; }

  .table-wrap table.mobile-cards td,
  .table-wrap table.mobile-cards td::before {
    white-space: normal;
  }

  .fuel-purchases .purchase-date,
  .fuel-purchases .purchase-supplier,
  .fuel-purchases .purchase-quantity,
  .fuel-purchases .purchase-documents,
  .fuel-purchases .purchase-amount,
  .fuel-purchases .purchase-unit-price {
    width: 100%;
    min-width: 0;
    max-width: none;
  }

  .fuel-purchases .purchase-supplier .cell-wrap,
  .fuel-purchases .purchase-documents .cell-wrap {
    width: auto;
  }
}
