/* Mobile overrides are isolated so the desktop layout keeps its current dimensions. */
.hp-mobile-nav-backdrop,
.hp-mobile-nav-close,
.hp-mobile-filter-toggle,
.hp-mobile-filter-label { display: none; }
.hp-mobile-filter-group,
.hp-mobile-filter-date { display: contents; }

@media (max-width: 900px) {
  html { scroll-padding-top: 72px; }
  body { overflow-wrap: anywhere; }
  .main { margin-left: 0; min-width: 0; }
  .main .content {
    width: 100%; max-width: 100%; min-width: 0;
    padding: 16px 12px calc(20px + env(safe-area-inset-bottom)) !important;
  }
  .main .topbar {
    position: sticky; top: 0; z-index: 100;
    height: calc(56px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 12px 0;
    gap: 10px; justify-content: flex-start;
  }
  .topbar .menu {
    display: inline-flex; align-items: center; justify-content: center;
    flex: 0 0 44px; width: 44px; height: 44px; margin: 0;
    border: 0; border-radius: 10px; background: #f6f8fc; color: #17253b;
    font-size: 22px; cursor: pointer;
  }
  .topbar .crumb { min-width: 0; font-size: 14px; }
  .topbar .crumb span, .topbar .crumb b, .topbar .top-actions { display: none; }
  .page-head { margin-bottom: 16px; }
  .page-head h1 { font-size: 24px; line-height: 1.3; }
  .page-head p { font-size: 13px; line-height: 1.5; margin-top: 6px; }
  .sidebar {
    z-index: 120; width: min(288px, 84vw); height: 100dvh;
    padding: calc(16px + env(safe-area-inset-top)) 14px calc(16px + env(safe-area-inset-bottom));
    overflow-y: auto; overscroll-behavior: contain; transform: translateX(-100%);
  }
  body.nav-open { overflow: hidden; }
  body.nav-open .sidebar { transform: translateX(0); box-shadow: 12px 0 36px rgba(12,20,36,.18); }
  .sidebar .brand { padding: 8px 8px 20px; }
  .sidebar nav a { min-height: 44px; }
  .hp-mobile-nav-close {
    position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 10px;
    display: inline-flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; border: 0; border-radius: 10px;
    background: #f6f8fc; color: #344054; font-size: 28px; cursor: pointer;
  }
  .hp-mobile-nav-backdrop {
    display: block; position: fixed; inset: 0; z-index: 110;
    border: 0; padding: 0; background: rgba(12,20,36,.38);
    backdrop-filter: blur(2px); touch-action: none;
  }
  .hp-mobile-nav-backdrop[hidden] { display: none; }
  .split { grid-template-columns: minmax(0,1fr) !important; gap: 14px; }
  .split > *, .panel, .panel-body, .panel-head > *, .order-ledger-head > * { min-width: 0; }
  .panel, .order-ledger { border-radius: 14px; margin-bottom: 16px; }
  .panel-head, .order-ledger-head {
    padding: 14px !important; gap: 12px; flex-wrap: wrap;
    align-items: flex-start; flex-direction: column;
  }
  .panel-head h2, .order-ledger-head h2 { font-size: 16px; margin-bottom: 4px; }
  .panel-head p, .order-ledger-head p { font-size: 12px; line-height: 1.55; }
  .panel-body { padding: 14px !important; }
  .dash-hero { grid-template-columns: minmax(0,1fr); gap: 12px; margin-bottom: 16px; }
  .dash-fig { padding: 20px 18px; border-radius: 16px; }
  .dash-fig-value { font-size: 34px; line-height: 1.25; }
  .dash-chart { margin-top: 12px; }
  .dash-chart svg { height: 60px; }
  .dash-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
  .dash-card { padding: 14px 12px; min-width: 0; border-radius: 14px; }
  .dash-card .k { font-size: 12px; }
  .dash-card .v { font-size: 24px; line-height: 1.3; margin-top: 7px; }
  .dash-card .s { font-size: 11px; margin-top: 5px; }
  .stats { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
  .stats .stat { padding: 14px 12px; min-width: 0; }
  .stats .stat > strong { font-size: 22px; margin: 10px 0 4px; line-height: 1.3; }
  .stats .stat small { font-size: 11px; }
  .balance-summary-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
  .balance-currency-grid { grid-template-columns: minmax(0,1fr); }
  .form-grid, .invoice-form-grid, .permission-grid, .human-grid, .detail-grid {
    grid-template-columns: minmax(0,1fr) !important; gap: 12px;
  }
  .form-grid > .field { grid-column: 1 / -1 !important; min-width: 0; }
  .field input, .field select, .field textarea,
  .order-search input, .order-search select,
  .filters input, .filters select, .url-field {
    min-width: 0; max-width: 100%; width: 100%; min-height: 44px;
    font-size: 16px !important;
  }
  .field textarea { min-height: 96px; }
  .btn { min-height: 42px; padding: 9px 12px; white-space: normal; text-align: center; }
  .icon-only { min-width: 40px; min-height: 40px; }
  .actions, .form-actions { flex-wrap: wrap; gap: 8px; }
  .form-actions > .btn, .form-actions > form { flex: 1 1 130px; }
  .refresh-controls {
    display: grid !important; grid-template-columns: minmax(0,1fr);
    width: 100%; gap: 8px; margin: 0;
  }
  .refresh-controls > form { width: 100%; min-width: 0; margin: 0; }
  .refresh-controls > .actions { display: grid; grid-template-columns: minmax(0,1fr); gap: 8px; }
  .refresh-controls .btn, .refresh-controls select {
    width: 100%; max-width: 100%; min-width: 0; min-height: 42px; margin: 0;
  }
  .refresh-controls select { font-size: 16px !important; }
  .merchant-accounts-panel .account-save-form {
    display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px;
    grid-template-areas: "status limit" "name name" "save save";
  }
  .merchant-accounts-panel .account-save-form label {
    display: flex; flex-direction: column; align-items: stretch; min-width: 0; gap: 5px;
  }
  .account-save-form label:nth-of-type(1) { grid-area: status; }
  .account-save-form label:nth-of-type(2) { grid-area: name; }
  .account-save-form label:nth-of-type(3) { grid-area: limit; }
  .account-save-form > .btn { grid-area: save; width: 100%; }
  .merchant-accounts-panel .account-save-form select,
  .merchant-accounts-panel .account-save-form input {
    width: 100%; max-width: 100%; min-width: 0; min-height: 44px; font-size: 16px !important;
  }
  .order-filters { padding: 12px 10px; }
  .order-ledger .filter-chips.compact { margin-bottom: 8px; }
  .order-ledger .filter-chips > div {
    display: flex; align-items: center; flex-wrap: nowrap; gap: 6px; max-width: 100%;
    overflow-x: auto; scrollbar-width: none; padding-bottom: 3px;
  }
  .order-ledger .filter-chips > div::-webkit-scrollbar { display: none; }
  .order-ledger .filter-chips b { flex: 0 0 54px; min-width: 54px; white-space: nowrap; }
  .order-ledger .filter-chips a { flex: 0 0 auto; min-height: 34px; display: inline-flex; align-items: center; }
  .order-search:not(.hp-mobile-filter-form), .filters {
    display: grid !important; grid-template-columns: repeat(2,minmax(0,1fr));
    gap: 8px; min-width: 0; padding: 12px;
  }
  .order-search:not(.hp-mobile-filter-form) > input[name="q"],
  .order-search:not(.hp-mobile-filter-form) > select,
  .filters > input, .filters > select { grid-column: 1 / -1; }
  .order-ledger .order-search.hp-mobile-filter-form {
    display: grid; grid-template-columns: repeat(4,minmax(0,1fr));
    gap: 8px; margin-top: 8px; padding: 12px; border-radius: 14px;
  }
  .order-ledger .order-search.ledger-search.hp-mobile-filter-form > input[name="q"] {
    grid-column: 1 / -1; order: 1; width: 100%; min-width: 0;
    height: 44px; padding: 0 12px;
  }
  .order-ledger .order-search.ledger-search.hp-mobile-filter-form > .btn {
    order: 4; min-height: 40px; height: auto; padding: 8px 4px;
    transition: background-color .15s, border-color .15s, color .15s;
  }
  .order-ledger .order-search.ledger-search.hp-mobile-filter-form > button.primary { order: 2; }
  .order-ledger .order-search.ledger-search.hp-mobile-filter-form > .hp-mobile-filter-toggle { order: 3; }
  .order-ledger .order-search.ledger-search .hp-mobile-filter-toggle { display: inline-flex; }
  .hp-mobile-filter-form .hp-mobile-filter-group {
    display: grid; grid-column: 1 / -1; order: 5;
    grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px;
    padding-top: 10px; border-top: 1px solid #e7ebf1;
  }
  .hp-mobile-filter-form[data-mobile-filters="closed"] .hp-mobile-filter-group { display: none; }
  .order-ledger .order-search.ledger-search.hp-mobile-filter-form .hp-mobile-filter-group > select {
    grid-column: 1 / -1; width: 100%; max-width: 100%; height: 44px;
  }
  .hp-mobile-filter-date { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
  .hp-mobile-filter-label { display: block; font-size: 12px; color: #55657d; }
  .order-ledger .order-search.ledger-search.hp-mobile-filter-form input[type="date"].rp-date { flex: none; width: 100%; min-width: 0; height: 44px; padding: 0 8px; }
  .table-wrap:has(.hp-mobile-cards) { overflow: visible; border-radius: 0; box-shadow: none; }
  table.hp-mobile-cards {
    display: block !important; position: relative; width: 100% !important;
    min-width: 0 !important; max-width: 100%; table-layout: auto !important;
  }
  .hp-mobile-cards thead {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip-path: inset(50%); white-space: nowrap;
  }
  .hp-mobile-cards tbody { display: grid !important; gap: 10px; padding: 10px; }
  .hp-mobile-cards tbody tr {
    display: grid !important; grid-template-columns: repeat(2,minmax(0,1fr));
    gap: 10px 12px; padding: 12px !important; margin: 0;
    border: 1px solid #e3e8f0; border-radius: 12px; background: #fff;
  }
  .hp-mobile-cards tbody tr td {
    display: block !important; width: auto !important; min-width: 0;
    height: auto !important; min-height: 0; padding: 0 !important;
    border: 0 !important; border-radius: 0 !important;
    background: transparent !important; white-space: normal !important;
    overflow-wrap: anywhere; text-align: left; line-height: 1.45;
  }
  .hp-mobile-cards tbody tr td::before {
    content: attr(data-mobile-label); display: block; margin-bottom: 4px;
    color: #667085; font-size: 11px; font-weight: 600; line-height: 1.4;
  }
  .hp-mobile-cards td:first-child, .hp-mobile-cards td[data-mobile-field="wide"] { grid-column: 1 / -1; }
  .hp-mobile-cards tr[data-mobile-kind="empty"] { grid-template-columns: minmax(0,1fr); grid-column: 1 / -1; }
  .hp-mobile-cards tr[data-mobile-kind="empty"] td::before { display: none; }
  .hp-mobile-cards .empty { padding: 20px 8px; }
  .hp-mobile-cards td code, .hp-mobile-cards td .cell-subtext,
  .hp-mobile-cards td .ledger-site strong, .hp-mobile-cards .link-public-url,
  .hp-mobile-cards .invoice-v2-url, .hp-mobile-cards .invoice-account-name {
    max-width: 100%; white-space: normal !important;
    overflow: visible; text-overflow: clip; overflow-wrap: anywhere;
  }
  .hp-mobile-cards td .cell-subtext { margin-top: 3px; }
  .hp-mobile-cards .url-field { margin-top: 4px; }
  .hp-mobile-cards .hp-mobile-actions { padding-top: 10px !important; border-top: 1px solid #eef1f6 !important; }
  .hp-mobile-cards .hp-mobile-actions .btn { min-height: 40px; }
  .hp-mobile-cards .ledger-actions, .hp-mobile-cards .link-row-actions { display: flex; flex-wrap: wrap; width: 100%; gap: 8px; }
  .hp-mobile-cards .ledger-actions .btn, .hp-mobile-cards .link-row-actions > .btn { flex: 1; min-height: 40px; padding: 8px 12px; }
  .hp-mobile-cards.order-logistics-table tr[data-mobile-kind="record"] {
    grid-template-areas: "transaction transaction" "payer amount" "paid paid" "account carrier" "tracking tracking" "actions actions";
  }
  .hp-mobile-cards.order-logistics-table td:nth-child(1) { grid-area: transaction; }
  .hp-mobile-cards.order-logistics-table td:nth-child(2) { grid-area: paid; display: flex !important; align-items: baseline; gap: 8px; }
  .hp-mobile-cards.order-logistics-table td:nth-child(2)::before { flex-shrink: 0; margin-bottom: 0; }
  .hp-mobile-cards.order-logistics-table td:nth-child(3) { grid-area: payer; }
  .hp-mobile-cards.order-logistics-table td:nth-child(4) { grid-area: amount; font-weight: 700; }
  .hp-mobile-cards.order-logistics-table td:nth-child(5) { grid-area: account; }
  .hp-mobile-cards.order-logistics-table td:nth-child(6) { grid-area: carrier; }
  .hp-mobile-cards.order-logistics-table td:nth-child(7) { grid-area: tracking; }
  .hp-mobile-cards.order-logistics-table td:nth-child(8) { grid-area: actions; }
  .hp-mobile-cards.order-logistics-table .ledger-paypal-id { font-size: 13px; padding: 5px 7px; }
  .hp-mobile-cards.order-logistics-table .copy-transaction { flex: 0 0 40px; }
  .hp-mobile-cards.order-logistics-table .ledger-tracking-number { font-size: 14px; }
  .hp-mobile-cards.order-logistics-table .badge { margin-top: 3px; }
  .hp-mobile-cards.order-logistics-table .ledger-actions .btn { padding: 8px 12px; }
  .pagination { flex-direction: column; align-items: stretch; gap: 10px; margin-top: 16px; }
  .pagination-summary { white-space: normal; }
  .pagination-pages { display: flex; flex-wrap: wrap; gap: 5px; max-width: 100%; }
  .pagination-pages a, .pagination-pages span { min-height: 38px; min-width: 32px; padding: 7px 9px; }
  dialog[open], .order-dialog[open], .create-modal[open], .invoice-create-modal[open] {
    width: calc(100vw - 24px) !important; max-width: calc(100vw - 24px) !important;
    max-height: calc(100dvh - 24px) !important; margin: auto;
    border-radius: 16px; overflow-y: auto; overscroll-behavior: contain;
  }
  .order-dialog-head, .shipping-dialog-head {
    position: sticky; top: 0; z-index: 3; background: #fff;
    padding: 14px !important; gap: 10px; align-items: flex-start;
  }
  .order-dialog-title { min-width: 0; }
  .order-dialog-title h3 { font-size: 15px; white-space: normal; overflow-wrap: anywhere; }
  .dialog-close { min-width: 40px; min-height: 40px; flex-shrink: 0; }
  .order-dialog-body { padding: 12px !important; }
  .order-detail-layout, .order-dialog-actions, .detail-list { grid-template-columns: minmax(0,1fr) !important; }
  .detail-list > div { min-width: 0; padding: 12px; }
  .detail-card > header, .order-action-card > header { padding: 12px; }
  .shipping-dialog .ship-carriers { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
  .shipping-dialog .ship-carrier { min-height: 44px; min-width: 0; justify-content: center; padding: 6px 8px; white-space: normal; }
  .ship-order-row strong { min-width: 0; max-width: 70%; overflow-wrap: anywhere; }
  .ship-form input, .ship-form select { min-width: 0; width: 100%; min-height: 44px; font-size: 16px !important; }
  .shipping-dialog .ship-form input[type="text"] {
    border: 1px solid #c7d1df; border-radius: 10px; padding: 10px 12px;
    background: #fff; color: #17253b; line-height: 1.4;
  }
  .ship-actions { display: flex; flex-wrap: wrap; gap: 8px; }
  .ship-actions .btn { flex: 1; min-height: 44px; }
  .permission-fieldset, .permission-fieldset > *, .permission-summary { min-width: 0; }
  .login-page { min-height: 100svh; padding: 24px 16px; }
  .login-shell { width: 100%; max-width: 380px; }
  .login-page .login-box { width: 100%; }
  .login-page .field input { min-height: 48px; font-size: 16px !important; }
}

@media (min-width: 600px) and (max-width: 900px) {
  .hp-mobile-cards tbody { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .dash-hero { grid-template-columns: minmax(0,1.1fr) minmax(0,.9fr); align-items: stretch; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}
