/* Screen-only rules keep invoice, cheque and PDF print dimensions intact. */
@media screen {
    body[data-layout] { min-width: 0; }
    body[data-layout="app"], body[data-layout="admin"] { height: 100dvh; }
    main, main .flex > *, main .grid > * { min-width: 0; }
    main .flex-col, .app-workspace { min-height: 0; }
    main input:not([type="checkbox"]):not([type="radio"]), main select, main textarea { max-width: 100%; }
    main img, main video, main canvas { max-width: 100%; }
    main textarea { resize: vertical; }
    .responsive-table-scroll { max-width: 100%; overflow: auto; overscroll-behavior-x: contain; }
    [data-responsive-scroll] { overscroll-behavior-x: contain; }
    [data-responsive-scroll]:focus-visible { outline: 2px solid #2563eb; outline-offset: -2px; }
    .responsive-toolbar { flex-wrap: wrap; }
    #mobile-menu-container { max-height: min(65dvh, 32rem); overflow-y: auto; }
    #public-mobile-nav { max-height: calc(100dvh - 4rem); overflow-y: auto; }
    #public-mobile-nav a { display: flex; align-items: center; min-height: 44px; padding: .5rem; border-radius: .375rem; }
    #public-mobile-nav a:hover { background: #f1f5f9; }
    #right-sidebar, #left-sidebar { overscroll-behavior: contain; }
    #admin-sidebar { overflow-y: auto; }
    .admin-menu-toggle { display: none; }
    .responsive-backdrop { position: fixed; inset: 0; z-index: 60; background: rgb(15 23 42 / .5); }
    .responsive-backdrop[hidden], #public-mobile-nav[hidden] { display: none; }
    #ba-copilot-panel { max-height: calc(100dvh - 2rem); }
    #shortcut-bar { padding-bottom: max(.25rem, env(safe-area-inset-bottom)); overflow-x: auto; }
    #shortcut-bar > * { flex-shrink: 0; }
    :where(button, a, input, select, textarea, summary):focus-visible { outline: 2px solid #2563eb; outline-offset: 2px; }
}

@media screen and (max-width: 1279px) {
    #right-sidebar { z-index: 70; max-width: calc(100vw - 2rem); max-height: 100dvh; }
    #sidebar-backdrop { z-index: 60; }
    #sidebar-mobile-toggle { bottom: calc(5rem + env(safe-area-inset-bottom)); }
    #app-header #global-search-trigger { padding-inline: .5rem; }
    #app-header #global-search-trigger kbd { display: none; }
}

@media screen and (max-width: 1023px) {
    #left-sidebar.ls-active.ls-drawer-open { z-index: 70; width: min(18rem, calc(100vw - 2rem)) !important; }
    #left-sidebar.ls-drawer-open .ls-label, #left-sidebar.ls-drawer-open .ls-caret { display: inline; }
    #left-sidebar.ls-drawer-open .ls-parent, #left-sidebar.ls-drawer-open .ls-leaf { justify-content: flex-start; }
    #left-sidebar.ls-drawer-open #ls-collapse-toggle { display: none; }
    #left-sidebar-backdrop { z-index: 60; }
    #left-sidebar-mobile-toggle { bottom: calc(5rem + env(safe-area-inset-bottom)); }
    #admin-sidebar { position: fixed; inset: 0 auto 0 0; z-index: 70; width: min(18rem, calc(100vw - 2rem)); transform: translateX(-100%); visibility: hidden; }
    #admin-sidebar[data-open="true"] { transform: translateX(0); visibility: visible; }
    .admin-menu-toggle { display: flex; align-items: center; gap: .5rem; position: fixed; top: .5rem; left: 1rem; z-index: 50; min-height: 44px; padding: .5rem 1rem; background: #0f172a; color: white; border-radius: .5rem; }
    body[data-layout="admin"] main { padding-top: 4rem; }
    #pos-workspace .pos-columns { flex: none; }
    #pos-items { max-height: 45dvh; min-height: 12rem; }
    #cart-rows { max-height: 45dvh; min-height: 8rem; }
    #pos-workspace { padding-bottom: 6rem; }
}

@media screen and (max-width: 639px) {
    #app-header { min-height: 56px; height: auto; padding-block: .25rem; }
    #context-bar { height: auto; min-height: 64px; gap: .5rem; padding-block: .5rem; }
    #context-bar > div:first-child { flex: 1; }
    #context-bar > div:first-child > div:first-child { flex: 1; gap: .5rem; }
    #context-bar [title="Change company"] { flex: 1; min-width: 0; }
    #context-bar [title="Change company"] span { max-width: 100%; }
    #mode-text-blinkaudit, #mode-text-browser { display: none !important; }
    #context-bar > div:last-child { align-self: flex-start; padding-top: .5rem; }
    #app-main > .overflow-y-auto { padding-bottom: calc(7rem + env(safe-area-inset-bottom)); }
    main > .p-6, main > .p-8 { padding-inline: .75rem; padding-top: 1rem; }
    main .p-6 { padding: 1rem; }
    main .responsive-toolbar { gap: .5rem; }
    main .responsive-toolbar > .flex { flex-wrap: wrap; max-width: 100%; }
    main .subscription-notice { flex-wrap: nowrap; padding: .5rem .75rem; }
    main .subscription-notice > span { flex: 1; }
    [data-export-cols] .exp-cols-panel { left: 0; right: auto; }
    main .responsive-grid { grid-template-columns: minmax(0, 1fr); }
    main .responsive-grid > [class*="col-span-"] { grid-column: auto; }
    main input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
    main select, main textarea { font-size: 16px; min-height: 44px; }
    #top-chrome button, #mobile-menu-container button, #right-sidebar button,
    #right-sidebar a, #left-sidebar a, main button:not([role="switch"]), main a[class*="rounded"] { min-height: 44px; }
    #report-filter-form { max-height: 45dvh; overflow-y: auto; }
    #report-filter-strip { flex-wrap: wrap; }
    #report-filter-strip > span { white-space: normal; overflow-wrap: anywhere; }
    #ba-copilot-toggle { bottom: calc(.75rem + env(safe-area-inset-bottom)); right: .75rem; }
    #ba-copilot-panel { bottom: max(.5rem, env(safe-area-inset-bottom)); right: .5rem; max-width: calc(100vw - 1rem); max-height: calc(100dvh - 1rem); }
    body[data-layout="app"] > .fixed.inset-0 .flex.justify-between,
    body[data-layout="app"] > .fixed.inset-0 .flex.justify-between > .flex { flex-wrap: wrap; gap: .5rem; }
    body[data-layout="app"] > .fixed.inset-0 input:not([type="checkbox"]),
    body[data-layout="app"] > .fixed.inset-0 select { min-height: 44px; font-size: 16px; }
    body[data-layout="app"] > .fixed.inset-0 { padding: .75rem; overflow-y: auto; }
    body[data-layout="app"] > .fixed.inset-0 > div { max-width: 100%; max-height: calc(100dvh - 1.5rem); overflow-y: auto; }
}

@media (prefers-reduced-motion: reduce) {
    body[data-layout] *, body[data-layout] *::before, body[data-layout] *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

@media screen {
    body[data-layout="document"] { margin: clamp(.5rem, 3vw, 2rem); }
    body[data-layout="document"] .toolbar { display: flex; flex-wrap: wrap; gap: .5rem; }
    body[data-layout="document"] .btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; }
    body[data-layout="document"] .responsive-table-scroll { width: 100%; }
}
@media screen and (max-width: 639px) {
    body[data-layout="document"] .doc, body[data-layout="document"] .page { width: 100%; padding: 1rem; margin-block: 1rem; }
    body[data-layout="document"] .grid2 { grid-template-columns: minmax(0, 1fr); }
    body[data-layout="document"] .cell + .cell { border-left: 0; }
    body[data-layout="document"] .doc-head, body[data-layout="document"] .parties, body[data-layout="document"] .below { flex-direction: column; gap: 1rem; }
    body[data-layout="document"] .totals { flex-basis: auto; width: 100%; }
    body[data-layout="document"] .header, body[data-layout="document"] .header-left, body[data-layout="document"] .header-right,
    body[data-layout="document"] .grid, body[data-layout="document"] .cell { display: block; width: 100%; text-align: left; }
    body[data-layout="document"] input { font-size: 16px; min-height: 44px; }
    body[data-layout="document"] .email-box .field { min-width: 0; }
}

@media screen {
    .responsive-entry-sheet > * { min-width: 40rem; }
}
@media screen and (max-width: 639px) {
    main .voucher-ledger-grid { min-width: 0; }
    .voucher-ledger-grid > div:first-child { display: none; }
    #entries-rows-container > div { display: grid; grid-template-columns: 4rem minmax(0, 1fr); height: auto; padding: .5rem; gap: .5rem; }
    #entries-rows-container > div > div { width: auto; min-height: 44px; border: 1px solid #cbd5e1; border-radius: .25rem; }
    #entries-rows-container > div > div:last-child { grid-column: 1 / -1; padding-left: .5rem; }
    #entries-rows-container > div > div:last-child::before { content: 'Amount'; font-size: .75rem; color: #475569; }
    #entries-rows-container button { opacity: 1; width: 44px; }
    #entries-rows-container input[name$="[amount]"] { padding-right: 44px; }
    .voucher-ledger-grid > .h-10 { height: auto; min-height: 44px; }
}

@media screen and (max-width: 639px) {
    #cart-list > div { flex-wrap: wrap; }
    #cart-list > div > div:first-child { flex-basis: 100%; }
    #cart-list .cart-del { min-width: 44px; }
    #pos-items .pos-item > div:first-child { white-space: normal; overflow-wrap: anywhere; }
    #payment-bill-splits > div { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
    #payment-bill-splits input:first-child { grid-column: 1 / -1; }
    #payment-bill-splits input { width: 100%; }
}
