/* ==========================================================================
   Responsive layer — loaded after enhancements.css and owns the final layout
   for every screen size. Earlier files contain many competing !important
   overrides (some with ID selectors), so every selector here starts with
   ":is(#rsp#rsp#rsp#rsp, html) body". It still only matches <html>, but carries
   the specificity of four IDs, so these rules win the cascade. Visual style
   (colours, radii, shadows) is left to the earlier files.

   Breakpoints
     ≥ 1440px     desktop
     901–1439px   laptop / iPad landscape (sidebar stays)
     ≤ 900px      iPad portrait + phones: bottom dock navigation
     ≤ 640px      phones
     ≤ 380px      small phones
   Items hidden by permissions use [hidden] + inline display:none, so every
   display rule on nav items below excludes [hidden].
   ========================================================================== */

/* ---------- All sizes ---------- */
html, body { max-width: 100%; overflow-x: clip; }
:is(#rsp#rsp#rsp#rsp, html) body .table-wrap { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
:is(#rsp#rsp#rsp#rsp, html) body #mobile-more-button { display: none !important; }

/* Invoice material lines: field wrappers are invisible to the desktop grid. */
:is(#rsp#rsp#rsp#rsp, html) body .material-line .material-field { display: contents !important; }
:is(#rsp#rsp#rsp#rsp, html) body .material-line .material-field-label { display: none !important; }

/* Report tables: columns may shrink instead of pushing the page sideways. */
:is(#rsp#rsp#rsp#rsp, html) body .reports-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
:is(#rsp#rsp#rsp#rsp, html) body .reports-grid > * { min-width: 0 !important; }
:is(#rsp#rsp#rsp#rsp, html) body .reports-grid > .report-wide { grid-column: 1 / -1 !important; }

/* ---------- Laptop / iPad landscape ---------- */
@media (max-width: 1439px) {
  :is(#rsp#rsp#rsp#rsp, html) body .reports-grid { grid-template-columns: minmax(0, 1fr) !important; }
}

@media (min-width: 641px) and (max-width: 1599px) {
  /* Five KPI cards: 3 on top, 2 below, no empty slot. */
  /* Pesë karta rrinë në pesë kolona; rregulli është te design.css. */
}

/* ---------- iPad portrait + phones: dock navigation ---------- */
@media (max-width: 900px) {
  :root { --rsp-dock: 72px; --rsp-pad: 16px; }

  :is(#rsp#rsp#rsp#rsp, html) body .app-shell { display: block !important; padding-left: 0 !important; padding-bottom: calc(var(--rsp-dock) + 16px + env(safe-area-inset-bottom)) !important; }
  :is(#rsp#rsp#rsp#rsp, html) body main { margin-left: 0 !important; padding-left: var(--rsp-pad) !important; padding-right: var(--rsp-pad) !important; width: auto !important; max-width: 100% !important; }

  /* Dock */
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar {
    position: fixed !important; top: auto !important; left: 0 !important; right: 0 !important; bottom: 0 !important;
    width: auto !important; height: auto !important; min-height: 0 !important; max-height: none !important;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom)) !important;
    display: flex !important; flex-direction: row !important; align-items: center !important; gap: 4px !important;
    overflow: visible !important; z-index: 90 !important; transform: none !important;
  }
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar .brand,
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar .sidebar-toggle { display: none !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar #nav {
    display: flex !important; flex-direction: row !important; flex: 1 1 auto !important;
    min-width: 0 !important; width: auto !important; margin: 0 !important; padding: 0 !important;
    gap: 4px !important; overflow: visible !important; transform: none !important; border: 0 !important;
  }
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar #nav .nav-item:not([hidden]),
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar #mobile-more-button {
    display: flex !important; flex-direction: column !important; align-items: center !important; justify-content: center !important;
    flex: 1 1 0 !important; min-width: 0 !important; max-width: 96px !important; width: auto !important;
    height: 56px !important; min-height: 56px !important; margin: 0 !important; padding: 4px 2px !important; gap: 3px !important;
    border-radius: 16px !important; position: relative !important;
  }
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar #mobile-more-button { flex: 0 0 56px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body #mobile-more-button svg { width: 22px !important; height: 22px !important; fill: currentColor !important; stroke: none !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar #nav .nav-icon,
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar #mobile-more-button .nav-icon { width: 22px !important; height: 22px !important; margin: 0 !important; display: flex !important; align-items: center !important; justify-content: center !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar #nav .nav-label,
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar #mobile-more-button .nav-label {
    display: block !important; max-width: 100% !important; overflow: hidden !important; text-overflow: ellipsis !important; white-space: nowrap !important;
    font-size: 10.5px !important; line-height: 1.1 !important; font-weight: 600 !important; opacity: .85;
  }
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar #nav .nav-lock { position: absolute !important; top: 6px !important; right: calc(50% - 20px) !important; width: 11px !important; height: 11px !important; margin: 0 !important; display: block !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar #nav .nav-lock svg { width: 11px !important; height: 11px !important; }

  /* "More" sheet with Admin, Settings, language, account, logout */
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar .sidebar-bottom {
    display: none !important; position: absolute !important; right: 10px !important; left: auto !important;
    bottom: calc(100% + 8px) !important; top: auto !important;
    width: min(320px, calc(100vw - 20px)) !important; min-width: 0 !important; max-height: calc(100dvh - var(--rsp-dock) - 40px) !important; overflow-y: auto !important;
    flex-direction: column !important; align-items: stretch !important; gap: 6px !important; margin: 0 !important; padding: 10px !important;
    background: #0d0d0f !important; border: 1px solid rgba(255,255,255,.12) !important; border-radius: 22px !important;
    box-shadow: 0 24px 60px rgba(0,0,0,.4) !important; z-index: 95 !important;
  }
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell.mobile-more-open .sidebar .sidebar-bottom { display: flex !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell.mobile-more-open::after { content: ""; position: fixed; inset: 0; z-index: 85; background: rgba(8,10,14,.38); }
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell.mobile-more-open .sidebar #mobile-more-button { background: rgba(255,255,255,.14) !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar .sidebar-admin-nav { display: flex !important; flex-direction: column !important; gap: 4px !important; width: 100% !important; min-width: 0 !important; margin: 0 !important; padding: 0 !important; border: 0 !important; overflow: visible !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar .sidebar-bottom .nav-item:not([hidden]),
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar .sidebar-bottom .sidebar-user,
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar .sidebar-bottom .logout-button,
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar .sidebar-bottom .sidebar-language {
    display: flex !important; flex-direction: row !important; align-items: center !important; justify-content: flex-start !important;
    flex: 0 0 auto !important; width: 100% !important; min-width: 0 !important; max-width: none !important; height: 48px !important; min-height: 48px !important;
    margin: 0 !important; padding: 0 12px !important; gap: 12px !important; border-radius: 14px !important; position: static !important;
  }
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar .sidebar-bottom .sidebar-language { justify-content: space-between !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar .sidebar-bottom .sidebar-user { height: 56px !important; min-height: 56px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar .sidebar-bottom .nav-label,
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar .sidebar-bottom .logout-label,
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar .sidebar-bottom .sidebar-language span { display: block !important; font-size: 14px !important; white-space: nowrap !important; opacity: 1; }
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar .sidebar-bottom .sidebar-user-text { display: grid !important; min-width: 0 !important; text-align: left !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar .sidebar-bottom .sidebar-user-text strong,
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar .sidebar-bottom .sidebar-user-text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar .sidebar-bottom .sidebar-language select { width: 76px !important; min-width: 76px !important; height: 36px !important; }

  /* Top bar: title row, then one row of actions */
  :is(#rsp#rsp#rsp#rsp, html) body main .topbar {
    display: grid !important; grid-template-columns: minmax(0, 1fr) !important; gap: 10px !important; align-items: center !important;
    min-height: 0 !important; height: auto !important; padding-top: 12px !important; padding-bottom: 12px !important; margin-bottom: 14px !important;
  }
  :is(#rsp#rsp#rsp#rsp, html) body main .topbar .topbar-leading { min-width: 0 !important; width: 100% !important; }
  :is(#rsp#rsp#rsp#rsp, html) body main .topbar h1 { overflow-wrap: anywhere; }
  :is(#rsp#rsp#rsp#rsp, html) body main .topbar .topbar-actions {
    display: flex !important; flex-direction: row !important; flex-wrap: nowrap !important; align-items: center !important; justify-content: flex-end !important;
    gap: 8px !important; width: 100% !important; min-width: 0 !important; grid-template-columns: none !important;
  }
  :is(#rsp#rsp#rsp#rsp, html) body main .topbar .topbar-actions > * { flex: 0 0 auto !important; width: auto !important; max-width: none !important; margin: 0 !important; height: 44px !important; min-height: 44px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body main .topbar .global-search {
    display: flex !important; flex: 1 1 auto !important; width: auto !important; min-width: 0 !important; max-width: none !important; order: 0;
  }
  :is(#rsp#rsp#rsp#rsp, html) body main .topbar .global-search input {
    display: block !important; width: 100% !important; min-width: 0 !important; opacity: 1 !important;
    border: 0 !important; background: transparent !important; box-shadow: none !important; padding: 0 !important; height: auto !important;
  }
  :is(#rsp#rsp#rsp#rsp, html) body main .topbar #privacy-toggle { order: -1; }
  :is(#rsp#rsp#rsp#rsp, html) body main .topbar .notification-button { width: 44px !important; min-width: 44px !important; padding: 0 !important; }

  /* Five KPI cards on tablet portrait: 3 + 2 */
  :is(#rsp#rsp#rsp#rsp, html) body .kpi-grid { gap: 12px !important; }

  /* Filter toolbars become tidy grids instead of one select per row */
  :is(#rsp#rsp#rsp#rsp, html) body .view .toolbar.panel.slim {
    display: grid !important; grid-template-columns: repeat(3, minmax(0, 1fr)) !important; gap: 8px !important; align-items: stretch !important;
  }
  :is(#rsp#rsp#rsp#rsp, html) body .view .toolbar.panel.slim > * { min-width: 0 !important; width: 100% !important; max-width: none !important; margin: 0 !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .view .toolbar.panel.slim > .search,
  :is(#rsp#rsp#rsp#rsp, html) body .view .toolbar.panel.slim > .selection-status,
  :is(#rsp#rsp#rsp#rsp, html) body .view .toolbar.project-toolbar > div { grid-column: 1 / -1 !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .view .toolbar.project-toolbar { grid-template-columns: minmax(0, 1fr) !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .view .section-actions .search { min-width: 0 !important; }

  /* Admin tabs scroll sideways instead of wrapping */
  :is(#rsp#rsp#rsp#rsp, html) body .admin-tabs { display: flex !important; flex-wrap: nowrap !important; overflow-x: auto !important; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  :is(#rsp#rsp#rsp#rsp, html) body .admin-tabs::-webkit-scrollbar { display: none; }
  :is(#rsp#rsp#rsp#rsp, html) body .admin-tabs .admin-tab { flex: 0 0 auto !important; white-space: nowrap !important; }

  /* Modals sit above the dock */
  :is(#rsp#rsp#rsp#rsp, html) body .modal.open { z-index: 200 !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .modal .dialog:not(.small) { width: calc(100% - 32px) !important; max-width: none !important; margin: 16px auto !important; max-height: calc(100dvh - 32px) !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .agreement-access-card { width: min(430px, calc(100vw - 32px)) !important; max-width: calc(100vw - 32px) !important; margin: 0 auto !important; box-sizing: border-box !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .linked-documents-head { grid-template-columns: minmax(0, 1fr) !important; }

  /* Invoice material lines become labelled cards */
  :is(#rsp#rsp#rsp#rsp, html) body .material-head { display: none !important; }
  :is(#rsp#rsp#rsp#rsp, html) body #material-lines { overflow: visible !important; display: grid !important; gap: 10px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .material-line {
    display: grid !important; grid-template-columns: repeat(4, minmax(0, 1fr)) !important; gap: 10px !important; align-items: end !important;
    width: auto !important; min-width: 0 !important; margin: 0 !important; padding: 14px !important; position: relative !important;
    border: 1px solid #e3e8ec !important; border-radius: 16px !important; background: #fff !important;
  }
  :is(#rsp#rsp#rsp#rsp, html) body .material-line .material-field { display: grid !important; gap: 5px !important; min-width: 0 !important; grid-column: auto !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .material-line .material-field-label { display: block !important; font-size: 11px; font-weight: 700; color: #6d7c87; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  :is(#rsp#rsp#rsp#rsp, html) body .material-line .material-field input,
  :is(#rsp#rsp#rsp#rsp, html) body .material-line .material-field select { width: 100% !important; min-width: 0 !important; grid-column: auto !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .material-line .material-field[data-field=name] { grid-column: 1 / -1 !important; padding-right: 44px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .material-line .material-field[data-field=total] {
    grid-column: span 2 !important; display: flex !important; align-items: baseline !important; justify-content: space-between !important; gap: 10px !important;
  }
  :is(#rsp#rsp#rsp#rsp, html) body .material-line .line-total { text-align: right !important; font-size: 16px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .material-line .remove-line { position: absolute !important; top: 10px !important; right: 10px !important; grid-column: auto !important; width: 36px !important; height: 36px !important; }

  /* Toasts clear the dock */
  :is(#rsp#rsp#rsp#rsp, html) body .toast { left: 16px !important; right: 16px !important; bottom: calc(var(--rsp-dock) + 20px + env(safe-area-inset-bottom)) !important; text-align: center; }

  /* iOS zooms into inputs under 16px */
  @media (pointer: coarse) {
    :is(#rsp#rsp#rsp#rsp, html) body input:not([type=checkbox]):not([type=radio]), :is(#rsp#rsp#rsp#rsp, html) body select, :is(#rsp#rsp#rsp#rsp, html) body textarea { font-size: 16px !important; }
  }
}

/* ---------- Phones ---------- */
@media (max-width: 640px) {
  :root { --rsp-pad: 12px; --rsp-dock: 68px; }

  /* Dock: icons only */
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar { padding: 6px 6px calc(6px + env(safe-area-inset-bottom)) !important; gap: 2px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar #nav { gap: 2px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar #nav .nav-item:not([hidden]),
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar #mobile-more-button { height: 52px !important; min-height: 52px !important; border-radius: 14px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar #mobile-more-button { flex: 0 0 46px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar #nav .nav-label,
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar #mobile-more-button .nav-label { display: none !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .app-shell .sidebar #nav .nav-lock { top: 8px !important; right: calc(50% - 17px) !important; }

  /* Top bar: icon-only privacy + new document buttons */
  :is(#rsp#rsp#rsp#rsp, html) body main .topbar { padding-top: 10px !important; padding-bottom: 10px !important; gap: 8px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body main .topbar h1 { font-size: 24px !important; line-height: 1.15 !important; }
  :is(#rsp#rsp#rsp#rsp, html) body main .topbar .page-title-icon { width: 38px !important; height: 38px !important; min-width: 38px !important; border-radius: 12px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body main .topbar #page-subtitle { font-size: 12.5px !important; margin-top: 4px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body main .topbar #privacy-toggle { width: 44px !important; min-width: 44px !important; padding: 0 !important; justify-content: center !important; gap: 0 !important; }
  :is(#rsp#rsp#rsp#rsp, html) body main .topbar #privacy-toggle > span:not(.privacy-icon) { display: none !important; }
  :is(#rsp#rsp#rsp#rsp, html) body main .topbar #new-invoice { width: 44px !important; min-width: 44px !important; padding: 0 !important; font-size: 0 !important; justify-content: center !important; }
  :is(#rsp#rsp#rsp#rsp, html) body main .topbar #new-invoice::before { content: "＋"; font-size: 20px; line-height: 1; }
  /* The ERP views add their own "new" button to the same row; left with its label it
     squeezed the search box and pushed the account avatar off the screen. */
  :is(#rsp#rsp#rsp#rsp, html) body main .topbar #erp-new-button { width: 44px !important; min-width: 44px !important; padding: 0 !important; justify-content: center !important; gap: 0 !important; }
  :is(#rsp#rsp#rsp#rsp, html) body main .topbar #erp-new-button > span { display: none !important; }
  :is(#rsp#rsp#rsp#rsp, html) body main .topbar #erp-new-button::before { content: "＋"; font-size: 20px; line-height: 1; }
  :is(#c9#c9#c9#c9#c9#c9#c9#c9#c9, html) body main .topbar #erp-new-button { font-size: 0 !important; overflow: hidden !important; letter-spacing: 0 !important; }
  :is(#c9#c9#c9#c9#c9#c9#c9#c9#c9, html) body main .topbar #erp-new-button::before { font-size: 21px !important; }

  /* KPI cards: compact rows that fit long amounts */
  :is(#rsp#rsp#rsp#rsp, html) body .kpi-grid { grid-template-columns: minmax(0, 1fr) !important; gap: 10px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .kpi-grid > .kpi { grid-column: auto !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .kpi {
    grid-template-columns: 44px minmax(0, 1fr) auto !important; grid-template-rows: auto auto !important;
    grid-template-areas: "icon label chev" "icon value chev" !important;
    column-gap: 14px !important; row-gap: 2px !important; align-items: center !important;
    min-height: 0 !important; height: auto !important; padding: 14px 16px !important;
  }
  :is(#rsp#rsp#rsp#rsp, html) body .kpi > .kpi-icon { grid-area: icon !important; width: 44px !important; height: 44px !important; min-width: 44px !important; border-radius: 14px !important; margin: 0 !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .kpi > .kpi-icon svg { width: 20px !important; height: 20px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .kpi > div > span { grid-area: label !important; margin: 0 !important; align-self: end !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .kpi > div > strong { grid-area: value !important; font-size: 21px !important; line-height: 1.2 !important; margin: 0 !important; align-self: start !important; overflow-wrap: anywhere; }
  :is(#rsp#rsp#rsp#rsp, html) body .kpi > div > small { display: none !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .kpi::after { grid-area: chev !important; position: static !important; margin: 0 !important; }

  /* Filters: two per row */
  :is(#rsp#rsp#rsp#rsp, html) body .view .toolbar.panel.slim { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; padding: 10px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .view .toolbar.panel.slim select { padding-left: 12px !important; padding-right: 28px !important; text-overflow: ellipsis; }
  :is(#rsp#rsp#rsp#rsp, html) body .view .toolbar.panel.slim > .btn { padding-left: 8px !important; padding-right: 8px !important; }

  /* Project donut stacks */
  :is(#rsp#rsp#rsp#rsp, html) body .donut-row { flex-direction: column !important; align-items: center !important; gap: 18px !important; padding: 18px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .donut-row .legend { width: 100% !important; min-width: 0 !important; }

  /* Panels and tables */
  :is(#rsp#rsp#rsp#rsp, html) body .panel-head { flex-wrap: wrap !important; gap: 10px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .panel-head > div { min-width: 0 !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .panel-actions { flex-wrap: wrap !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 8px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .detail-field { min-width: 0 !important; overflow-wrap: anywhere; }

  /* Large dialogs fill the screen; small ones stay as cards */
  :is(#rsp#rsp#rsp#rsp, html) body .modal.open:not(.agreement-access-modal) { padding: 0 !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .modal .dialog:not(.small) {
    width: 100% !important; height: 100dvh !important; max-height: 100dvh !important; margin: 0 !important; border-radius: 0 !important;
  }
  :is(#rsp#rsp#rsp#rsp, html) body .modal .dialog.small { width: calc(100% - 24px) !important; max-width: none !important; margin: 12vh auto 0 !important; max-height: calc(100dvh - 24vh) !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .dialog-head { padding: 14px 16px !important; gap: 12px !important; padding-top: calc(14px + env(safe-area-inset-top)) !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .dialog form, :is(#rsp#rsp#rsp#rsp, html) body .detail-content, :is(#rsp#rsp#rsp#rsp, html) body .supplier-info-content { padding: 16px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .dialog-actions, :is(#rsp#rsp#rsp#rsp, html) body .detail-actions { flex-wrap: wrap !important; padding-bottom: calc(14px + env(safe-area-inset-bottom)) !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .form-grid.four, :is(#rsp#rsp#rsp#rsp, html) body .two-cols { grid-template-columns: minmax(0, 1fr) !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .form-grid > *, :is(#rsp#rsp#rsp#rsp, html) body .field-with-inline-action { min-width: 0 !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .form-grid input, :is(#rsp#rsp#rsp#rsp, html) body .form-grid select { width: 100% !important; min-width: 0 !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .material-line { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; padding: 12px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .material-line .material-field[data-field=total] { grid-column: 1 / -1 !important; border-top: 1px solid #edf1f3; padding-top: 10px !important; }
}

/* ---------- Small phones ---------- */
@media (max-width: 380px) {
  :root { --rsp-pad: 10px; }
  :is(#rsp#rsp#rsp#rsp, html) body main .topbar h1 { font-size: 21px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .view .toolbar.panel.slim { grid-template-columns: minmax(0, 1fr) !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .detail-grid { grid-template-columns: minmax(0, 1fr) !important; }
}

/* ---------- Never print the dock or the More sheet ---------- */
@media print {
  :is(#rsp#rsp#rsp#rsp, html) body #mobile-more-button, :is(#rsp#rsp#rsp#rsp, html) body .app-shell.mobile-more-open::after { display: none !important; }
}

/* ==========================================================================
   Compact phone layout
   Fits more of the actual content on a phone screen: the top bar is icon-only,
   KPI cards sit two per row, filters and panels use tighter spacing.
   A few rules need nine IDs to win over typography.css (which carries eight).
   Form controls keep a 16px font so iOS does not zoom when they are tapped.
   ========================================================================== */
@media (max-width: 640px) {
  /* Top bar: the "new document" button is a round ＋ only (its label used to spill out) */
  :is(#c9#c9#c9#c9#c9#c9#c9#c9#c9, html) body main .topbar #new-invoice { font-size: 0 !important; overflow: hidden !important; letter-spacing: 0 !important; }
  :is(#c9#c9#c9#c9#c9#c9#c9#c9#c9, html) body main .topbar #new-invoice::before { font-size: 21px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body main .topbar { padding-top: 8px !important; padding-bottom: 8px !important; }

  /* KPI cards: two per row, half the height */
  :is(#rsp#rsp#rsp#rsp, html) body .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 8px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .kpi {
    grid-template-columns: 34px minmax(0, 1fr) !important;
    grid-template-areas: "icon label" "icon value" !important;
    column-gap: 10px !important; padding: 10px 12px !important;
  }
  :is(#rsp#rsp#rsp#rsp, html) body .kpi > .kpi-icon { width: 34px !important; height: 34px !important; min-width: 34px !important; border-radius: 11px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .kpi > .kpi-icon svg { width: 17px !important; height: 17px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .kpi::after, :is(#rsp#rsp#rsp#rsp, html) body .kpi-action::after { display: none !important; }
  :is(#c9#c9#c9#c9#c9#c9#c9#c9#c9, html) body .kpi > div > span { font-size: 9.5px !important; letter-spacing: .04em !important; }
  :is(#c9#c9#c9#c9#c9#c9#c9#c9#c9, html) body .kpi > div > strong { font-size: 17px !important; overflow-wrap: anywhere !important; }

  /* Filters and toolbars: same two columns, less height around them */
  :is(#rsp#rsp#rsp#rsp, html) body .view .toolbar.panel.slim { padding: 8px !important; gap: 6px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .view .toolbar.panel.slim select,
  :is(#rsp#rsp#rsp#rsp, html) body .view .toolbar.panel.slim input { height: 40px !important; min-height: 40px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .view .toolbar.panel.slim .search { min-height: 40px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .view .toolbar.panel.slim > .btn { min-height: 40px !important; }
  /* Selection bar: only there once rows are actually selected, and then on one line */
  :is(#rsp#rsp#rsp#rsp, html) body .view .toolbar.panel.slim .selection-status:not(.show) { display: none !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .view .toolbar.panel.slim .selection-status.show {
    display: flex !important; flex-wrap: wrap !important; align-items: center !important;
    gap: 6px !important; padding: 6px !important; grid-column: 1 / -1 !important;
  }
  :is(#rsp#rsp#rsp#rsp, html) body .view .toolbar.panel.slim .selection-status.show .selection-count { flex: 1 0 100% !important; text-align: center !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .view .toolbar.panel.slim .selection-status.show > button {
    flex: 1 1 0 !important; min-width: 0 !important; min-height: 36px !important; padding: 0 8px !important;
    overflow: hidden !important; text-overflow: ellipsis !important; white-space: nowrap !important;
  }
  :is(#c9#c9#c9#c9#c9#c9#c9#c9#c9, html) body .view .toolbar.panel.slim .selection-status.show > button { font-size: 12px !important; }

  /* Page header and panel headings: tighter, so the first row of data comes sooner.
     Panel padding itself is left alone — tables run edge to edge inside it on purpose. */
  :is(#rsp#rsp#rsp#rsp, html) body .view .panel-head { margin-bottom: 10px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body main { padding-top: 10px !important; }

  /* Classic tables: shorter rows, so more than three fit on a phone screen */
  :is(#rsp#rsp#rsp#rsp, html) body .view .panel .table-wrap td { padding-top: 9px !important; padding-bottom: 9px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .view .panel .table-wrap th { padding-top: 8px !important; padding-bottom: 8px !important; }

  /* Forms inside dialogs: more fields per screen, and a 16px control font so iOS
     does not zoom the page when a field is tapped (the height comes down instead). */
  :is(#rsp#rsp#rsp#rsp, html) body .modal .dialog .dialog-head { padding: 14px 16px !important; }
  :is(#c9#c9#c9#c9#c9#c9#c9#c9#c9, html) body .modal .dialog .dialog-head h2 { font-size: 17px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .modal .dialog form { padding: 14px 16px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .modal .dialog .form-grid { row-gap: 12px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .modal .dialog .form-grid > label,
  :is(#rsp#rsp#rsp#rsp, html) body .modal .dialog .invoice-bottom > label { row-gap: 4px !important; }
  :is(#c9#c9#c9#c9#c9#c9#c9#c9#c9, html) body .modal .dialog .form-grid > label,
  :is(#c9#c9#c9#c9#c9#c9#c9#c9#c9, html) body .modal .dialog .invoice-bottom > label { font-size: 11px !important; }
  :is(#c9#c9#c9#c9#c9#c9#c9#c9#c9, html) body .modal .dialog input:not([type="checkbox"]):not([type="radio"]),
  :is(#c9#c9#c9#c9#c9#c9#c9#c9#c9, html) body .modal .dialog select,
  :is(#c9#c9#c9#c9#c9#c9#c9#c9#c9, html) body .modal .dialog textarea {
    font-size: 16px !important; padding: 9px 11px !important; min-height: 42px !important;
  }
  :is(#c9#c9#c9#c9#c9#c9#c9#c9#c9, html) body .modal .dialog .material-line input,
  :is(#c9#c9#c9#c9#c9#c9#c9#c9#c9, html) body .modal .dialog .material-line select { min-height: 38px !important; padding: 7px 9px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .modal .dialog .section-title { margin: 16px 0 8px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .modal .dialog .dialog-actions { margin-top: 14px !important; padding-top: 12px !important; }
}

/* ---------- Small phones: the page subtitle gives way to the content ---------- */
@media (max-width: 480px) {
  :is(#rsp#rsp#rsp#rsp, html) body main .topbar #page-subtitle { display: none !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .kpi-grid { gap: 7px !important; }
}

/* ---------- Phones: the received-quantity summary reads down, not across ---------- */
@media (max-width: 640px) {
  :is(#rsp#rsp#rsp#rsp, html) body .quantity-check { grid-template-columns: minmax(0, 1fr) !important; gap: 8px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .quantity-check > div { display: flex !important; align-items: baseline !important; justify-content: space-between !important; gap: 10px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .quantity-check > div span { margin-bottom: 0 !important; }
  :is(#c9#c9#c9#c9#c9#c9#c9#c9#c9, html) body .quantity-table input.quantity-price { width: 84px !important; min-height: 38px !important; font-size: 16px !important; }
}

/* ---------- Phones: the material check filters stack ---------- */
@media (max-width: 640px) {
  :is(#rsp#rsp#rsp#rsp, html) body .material-check-filters { padding: 10px !important; gap: 8px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .material-check-filters label { flex: 1 1 140px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .material-check-filters #material-check-clear { flex: 1 1 100% !important; }
  :is(#c9#c9#c9#c9#c9#c9#c9#c9#c9, html) body .material-check-filters input,
  :is(#c9#c9#c9#c9#c9#c9#c9#c9#c9, html) body .material-check-filters select { font-size: 16px !important; min-height: 40px !important; }
}

/* ==========================================================================
   Phones: the classic tables become cards
   The ERP tables already did this; these did not, so a documents row was over
   1100px wide on a 390px screen and had to be dragged sideways to be read.
   The heading of each column is carried on the cell as data-label.
   ========================================================================== */
@media (max-width: 760px) {
  :is(#c9#c9#c9#c9#c9#c9#c9#c9#c9, html) body .view .panel .table-wrap > table:not(.erp-table) { min-width: 0 !important; width: 100% !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .view .panel .table-wrap { overflow-x: visible !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .view .panel .table-wrap > table:not(.erp-table),
  :is(#rsp#rsp#rsp#rsp, html) body .view .panel .table-wrap > table:not(.erp-table) > tbody,
  :is(#rsp#rsp#rsp#rsp, html) body .view .panel .table-wrap > table:not(.erp-table) > tfoot,
  :is(#rsp#rsp#rsp#rsp, html) body .view .panel .table-wrap > table:not(.erp-table) > tbody > tr,
  :is(#rsp#rsp#rsp#rsp, html) body .view .panel .table-wrap > table:not(.erp-table) > tfoot > tr { display: block !important; width: 100% !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .view .panel .table-wrap > table:not(.erp-table) > thead { display: none !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .view .panel .table-wrap > table:not(.erp-table) > tbody > tr { padding: 12px 14px !important; border-bottom: 1px solid var(--line) !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .view .panel .table-wrap > table:not(.erp-table) > tbody > tr:last-child { border-bottom: 0 !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .view .panel .table-wrap > table:not(.erp-table) td,
  :is(#rsp#rsp#rsp#rsp, html) body .view .panel .table-wrap > table:not(.erp-table) th {
    display: flex !important; align-items: baseline; justify-content: flex-start; gap: 8px;
    width: auto !important; padding: 3px 0 !important; border: 0 !important; text-align: left !important; white-space: normal !important;
  }
  :is(#rsp#rsp#rsp#rsp, html) body .view .panel .table-wrap > table:not(.erp-table) td::before {
    content: attr(data-label); flex: 0 0 auto; max-width: 46%; font-size: 10.5px; font-weight: 700;
    color: var(--muted); text-transform: uppercase; letter-spacing: .05em;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  :is(#rsp#rsp#rsp#rsp, html) body .view .panel .table-wrap > table:not(.erp-table) td:not([data-label])::before,
  :is(#rsp#rsp#rsp#rsp, html) body .view .panel .table-wrap > table:not(.erp-table) td[data-label=""]::before { content: none; }
  /* The first cell is the card's title; the checkbox and the row actions sit on their own line */
  :is(#c9#c9#c9#c9#c9#c9#c9#c9#c9, html) body .view .panel .table-wrap > table:not(.erp-table) td:first-child { font-size: 15px !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .view .panel .table-wrap > table:not(.erp-table) td.select-cell { position: absolute; right: 14px; padding: 0 !important; }
  :is(#rsp#rsp#rsp#rsp, html) body .view .panel .table-wrap > table:not(.erp-table) > tbody > tr { position: relative; }
  :is(#rsp#rsp#rsp#rsp, html) body .view .panel .table-wrap > table:not(.erp-table) .row-actions { justify-content: flex-start !important; margin-top: 6px; }
  :is(#rsp#rsp#rsp#rsp, html) body .view .panel .table-wrap > table:not(.erp-table) > tfoot > tr { padding: 12px 14px !important; border-top: 1px solid var(--line) !important; }
}
