/* Phone + tablet portrait screen rules for the existing document editor. Print/PDF styles are untouched. */
@media screen and (max-width: 900px) {
  .toolgrid { grid-template-columns: minmax(0, 1fr); }
  .toolgrid > *, .toolgrid .editor, .toolgrid .paper { min-width: 0; max-width: 100%; }
  .toolgrid .editor { padding: 12px 10px; }
  .toolgrid .paper { padding: 16px 12px; overflow: hidden; }
  .toolgrid .formgroup input,
  .toolgrid .formgroup select,
  .toolgrid .formgroup textarea,
  .toolgrid .control,
  .toolgrid .route-line-fields input,
  .toolgrid .route-line-fields select,
  .toolgrid .route-line-fields textarea,
  .toolgrid .route-tax-row input,
  .toolgrid .route-tax-row select,
  .toolgrid .country-payment-fields input,
  .toolgrid .country-payment-fields select,
  .toolgrid .country-field-list input,
  .toolgrid .country-field-list select,
  .toolgrid select,
  .toolgrid input:not([type="checkbox"]):not([type="radio"]),
  .toolgrid textarea {
    min-height: 44px;
    font-size: 16px;
    line-height: 1.35;
  }
  .toolgrid input[type="checkbox"],
  .toolgrid input[type="radio"] {
    width: 22px;
    height: 22px;
    min-width: 22px;
    min-height: 22px;
  }
  .toolgrid .formgroup textarea { min-height: 92px; }
  .toolgrid .formgroup label { font-size: 12px; line-height: 1.4; }
  .toolgrid .doc-tabs { gap: 7px; padding-bottom: 10px; }
  .toolgrid .doc-tabs a { min-height: 44px; display: inline-flex; align-items: center; }
  .toolgrid .add,
  .toolgrid .del,
  .toolgrid .tool-data-controls button,
  .toolgrid .actions .btn,
  .toolgrid .route-line-details summary,
  .toolgrid .industry-advanced summary {
    min-height: 44px;
  }
  .toolgrid .add { padding: 10px 12px; }
  .toolgrid .del { min-width: 44px; padding: 8px; }
  .toolgrid .actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .toolgrid .actions .btn { width: 100%; padding: 8px 6px; font-size: 12px; }
  .toolgrid .preview-jump { display: inline-flex; align-items: center; min-height: 44px; margin: 8px 0; color: var(--blue); font-weight: 750; }
  .toolgrid .meta { grid-template-columns: minmax(0, 1fr); gap: 8px; font-size: 10px; }
  .toolgrid .metaright { grid-template-columns: minmax(0, auto) minmax(0, 1fr); gap: 3px 8px; }
  .toolgrid .paperfoot { grid-template-columns: minmax(0, 1fr); gap: 9px; }
  .toolgrid .previewtotals { width: min(100%, 238px); }
  .toolgrid .preview-table-scroll { max-width: 100%; }
  .toolgrid[data-layout="financial"] .preview-table-scroll { overflow-x: visible; }
  .toolgrid[data-layout="financial"] .preview-table { width: 100%; min-width: 0; table-layout: fixed; }
  .toolgrid[data-layout="financial"] .preview-table th,
  .toolgrid[data-layout="financial"] .preview-table td {
    padding: 6px 4px;
    overflow-wrap: anywhere;
    word-break: normal;
  }
  .toolgrid[data-layout="financial"] .preview-table th { font-size: 9px; }
  .toolgrid[data-layout="financial"] .preview-table td { font-size: 9px; }
  .toolgrid .country-field-list,
  .toolgrid .country-payment-fields,
  .toolgrid .route-line-fields,
  .toolgrid .tax-advanced-grid { grid-template-columns: minmax(0, 1fr); }
  .toolgrid .tax-advanced-grid select,
  .toolgrid .tax-advanced-grid input {
    min-height: 44px;
    font-size: 16px;
    width: 100%;
  }
  .toolgrid .route-item-desc > input { min-height: 44px; font-size: 16px; }
  .toolgrid .route-line-details > summary { display: flex; align-items: center; }
  .toolgrid .route-line-fields label { font-size: 12px; }
  .toolgrid .table-scroll { max-width: 100%; }

  /* Financial line items become compact, labeled cards instead of a wide table. */
  .toolgrid[data-layout="financial"] .items-table {
    display: block;
    width: 100%;
    min-width: 0;
    border-collapse: separate;
  }
  .toolgrid[data-layout="financial"] .items-table thead { display: none; }
  .toolgrid[data-layout="financial"] .items-table tbody { display: grid; gap: 9px; }
  .toolgrid[data-layout="financial"] .items-table tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px 8px;
    min-width: 0;
    padding: 8px;
    border: 1px solid #dfe6ef;
    border-radius: 10px;
    background: #fff;
  }
  .toolgrid[data-layout="financial"] .items-table td {
    display: block;
    min-width: 0;
    padding: 3px 2px;
    border: 0;
    overflow-wrap: anywhere;
  }
  .toolgrid[data-layout="financial"] .items-table td:nth-child(1) { display: none; }
  .toolgrid[data-layout="financial"] .items-table td:nth-child(2) { grid-column: 1 / -1; }
  .toolgrid[data-layout="financial"] .items-table td:nth-child(3)::before,
  .toolgrid[data-layout="financial"] .items-table td:nth-child(4)::before,
  .toolgrid[data-layout="financial"] .items-table td:nth-child(5)::before {
    display: block;
    margin: 0 0 3px;
    color: #52647d;
    font-size: 11px;
    font-weight: 750;
  }
  .toolgrid[data-layout="financial"] .items-table td:nth-child(3)::before { content: "Quantity"; }
  .toolgrid[data-layout="financial"] .items-table td:nth-child(4)::before { content: "Rate"; }
  .toolgrid[data-layout="financial"] .items-table td:nth-child(5)::before { content: "Amount"; }
  .toolgrid[data-layout="financial"] .items-table td:nth-child(6) { grid-column: 1 / -1; justify-self: end; }
  .toolgrid[data-layout="financial"] .items-table input:not([type="checkbox"]) {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    padding: 8px;
    border: 1px solid #dce2ea;
    border-radius: 7px;
    background: #fff;
    font-size: 16px;
  }
  .toolgrid[data-layout="financial"] .items-table input[type="checkbox"] { width: 22px; height: 22px; }
  .toolgrid[data-layout="financial"] .items-table .lineamount { min-height: 24px; font-weight: 750; color: #344054; }

  /* Specialized operational ledgers keep a visible horizontal scroll region. */
  .toolgrid:not([data-layout="financial"]) .items-table { min-width: 560px; }
  .toolgrid:not([data-layout="financial"]) .items-table input,
  .toolgrid:not([data-layout="financial"]) .items-table select { min-height: 44px; font-size: 16px; }
  .toolgrid .table-scroll[role="region"],
  .toolgrid .preview-table-scroll[role="region"] { -webkit-overflow-scrolling: touch; }
}

@media screen and (max-width: 390px) {
  .toolgrid .paper { padding: 13px 9px; }
  .toolgrid .paper h2 { font-size: 19px; }
  .toolgrid .actions .btn { font-size: 11px; }
  .toolgrid .totalbox { width: 100%; }
}

@media screen and (prefers-reduced-motion: reduce) {
  .toolgrid .btn,
  .toolgrid .add,
  .toolgrid .del { transition: none; }
}
