/* Keep the desktop layout intact; adapt navigation and content for touch. */
.admin-mobile-header,
.mobile-menu-backdrop,
.mobile-menu-close,
.pos-mobile-bar { display: none; }
.mobile-create-panel__summary { display: block; list-style: none; pointer-events: none; }
.mobile-create-panel__summary::-webkit-details-marker { display: none; }
#employeePaymentBtn[hidden] { display: none; }
.admin-main,
.pos-products,
.pos-main,
.pos-layout { min-width: 0; min-height: 0; }

@media (max-width: 900px) {
    .admin-page,
    .admin-layout,
    .pos-page { height: 100vh; height: 100dvh; }
    .admin-layout { flex-direction: column; }
    .admin-mobile-header {
        display: flex;
        align-items: center;
        gap: 12px;
        flex-shrink: 0;
        padding: calc(8px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
        background: var(--surface);
        border-bottom: 1px solid var(--border);
    }
    .admin-mobile-header__title {
        flex: 1;
        min-width: 0;
        font-size: 15px;
        font-weight: 750;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .mobile-menu-button {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        flex-shrink: 0;
        border: 1px solid var(--border);
        border-radius: 12px;
        background: var(--bg);
        color: var(--text);
        cursor: pointer;
    }
    .mobile-menu-button svg,
    .pos-mobile-bar svg {
        width: 20px;
        height: 20px;
        fill: none;
        stroke: currentColor;
        stroke-width: 1.8;
        stroke-linecap: round;
        stroke-linejoin: round;
        flex-shrink: 0;
    }
    .admin-sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(300px, calc(100vw - 44px));
        z-index: 1200;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        overflow-y: auto;
        overscroll-behavior: contain;
        transform: translateX(-105%);
        visibility: hidden;
        transition: transform .2s ease, visibility .2s;
    }
    .mobile-menu-open .admin-sidebar { transform: none; visibility: visible; }
    .mobile-menu-open .mobile-menu-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1100;
        background: rgba(15, 23, 42, .45);
        border: 0;
    }
    .sidebar-logo { justify-content: space-between; padding: 16px; }
    .sidebar-logo__img { width: 135px; }
    .sidebar-logo span:last-child { display: inline; }
    .mobile-menu-close { color: #e2e8f0; border-color: #334155; background: #1e293b; }
    .sidebar-nav { flex: 1 0 auto; list-style: none; }
    .sidebar-link { font-size: 15px; justify-content: flex-start; min-height: 46px; padding: 10px 14px; }
    .admin-main { padding: 20px max(14px, env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); }
    .admin-cols { grid-template-columns: minmax(0, 1fr); }
    .admin-header { gap: 14px; flex-wrap: wrap; align-items: flex-start; margin-bottom: 20px; }
    .admin-header > div { min-width: 0; max-width: 100%; }
    .admin-title { overflow-wrap: anywhere; }
    .admin-section,
    .admin-panel { min-width: 0; }
    .form-input,
    .search-box__input,
    .to-order-qty__input { font-size: 16px; min-width: 0; max-width: 100%; }
    .btn,
    .qty-btn,
    .toggle-btn,
    .stock-switch,
    .profit-period-switcher__btn { min-height: 44px; }
    .form-group { min-width: 0; }
    .table-wrap { max-width: 100%; }
    #flash-messages { top: calc(12px + env(safe-area-inset-top)); left: 12px; right: 12px; max-width: none; }
    .modal-overlay { padding: 16px; }
    .modal { padding: 28px 20px; width: 100%; max-height: calc(100dvh - 48px); overflow-y: auto; }
    .order-date-modal__dialog { max-height: calc(100dvh - 40px); overflow-y: auto; }
    .to-order-grid { grid-template-columns: minmax(0, 1fr); }
    .to-order-card__body,
    .to-order-card__name { min-width: 0; overflow-wrap: anywhere; }
    .to-order-main { padding-bottom: calc(210px + env(safe-area-inset-bottom)); }
    .to-order-bottom-bar { left: 0; padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
}

@media (max-width: 640px) {
    .admin-section { padding: 16px; margin-bottom: 14px; border-radius: 14px; }
    .admin-title { font-size: 21px; }
    .admin-subtitle { font-size: 13px; }
    .admin-header > div[style] { gap: 10px !important; }
    .admin-header > div[style] img { width: 56px !important; height: 56px !important; }
    .admin-header .stock-status { align-items: flex-start; }
    .stats-grid,
    .stock-kpi-strip,
    .stock-metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .stat-card,
    .stock-kpi,
    .stock-metric { padding: 14px; min-width: 0; }
    .stat-card__value,
    .stock-kpi strong,
    .stock-metric strong { font-size: 22px; overflow-wrap: anywhere; }
    .kpi-card { padding: 18px; }
    .kpi-card__value { font-size: 32px; }
    .inline-form { gap: 10px; }
    .inline-form > .form-input,
    .inline-form > .form-group,
    .inline-form > .btn { width: 100% !important; min-width: 0 !important; flex: 1 1 100% !important; }
    .form-row:not(.form-row--flags) { flex-direction: column; gap: 0; }
    .form-row .form-group { width: 100%; min-width: 0; flex: auto !important; }
    .form-row--flags .form-input { flex-basis: 100% !important; width: 100%; }
    .form-row--flags .btn { width: 100%; }
    .checkbox-label { min-height: 40px; }
    .mobile-create-panel__summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; cursor: pointer; pointer-events: auto; }
    .mobile-create-panel__summary::-webkit-details-marker { display: none; }
    .mobile-create-panel__summary .admin-section__title { margin-bottom: 0; }
    .mobile-create-panel__summary::after { content: '+'; color: var(--primary); font-size: 24px; flex-shrink: 0; }
    .mobile-create-panel[open] > summary { margin-bottom: 16px; }
    .mobile-create-panel[open] > summary::after { content: '-'; }
    .shake-card__header { flex-direction: column; }
    .shake-card__prices { width: 100%; }
    .shake-card__prices .toggle-btn { margin-left: auto; }
    .price-editor__grid,
    .price-editor__grid--sale,
    .price-editor__grid--three,
    .price-editor__grid--two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .price-field .form-input { width: 100%; padding: 12px 10px; }
    .price-field > span { min-height: 30px; }
    .stock-detail-topbar__actions { flex-wrap: wrap; }
    .stock-detail-topbar__actions .btn { width: auto; flex: 1; }
    .stock-detail-title .admin-title { font-size: 22px; }
    .stock-danger-action { flex-wrap: wrap; }
    .stock-danger-action .btn { width: 100%; }
    .stock-toolbar .stock-search { width: 100%; }
    .stock-create-panel > summary,
    .stock-secondary-panel > summary,
    .stock-collapsible__summary { padding: 16px; }

    /* Preserve the data and actions of each row without sideways scrolling. */
    .mobile-cards,
    .mobile-cards tbody { display: block; width: 100%; }
    .mobile-cards thead { display: none; }
    .mobile-cards tbody tr {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px;
        padding: 16px 0;
        border-bottom: 1px solid var(--border);
        min-width: 0;
    }
    .mobile-cards tbody tr:last-child { border-bottom: 0; }
    .mobile-cards td {
        display: block;
        width: auto !important;
        min-width: 0;
        padding: 0;
        border: 0;
        text-align: left;
        overflow-wrap: anywhere;
        white-space: normal;
    }
    .mobile-cards td::before {
        display: block;
        margin-bottom: 5px;
        content: attr(data-mobile-label);
        color: var(--text-muted);
        font-size: 11px;
        font-weight: 600;
    }
    .mobile-cards td:first-child,
    .mobile-cards td:last-child,
    .mobile-cards td[colspan] { grid-column: 1 / -1; }
    .mobile-cards td:first-child::before,
    .mobile-cards td[colspan]::before { display: none; }
    .mobile-cards td:first-child { font-weight: 600; font-size: 15px; }
    .mobile-cards td:last-child { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
    .mobile-cards td:last-child::before { align-self: center; margin-right: auto; }
    .mobile-cards td[colspan] { justify-content: center; }
    .mobile-cards tr:hover td,
    .mobile-cards .row--warning td { background: transparent !important; }
    .mobile-cards .row--warning { border-left: 3px solid var(--warn); padding-left: 12px; }
    .stock-table-wrap { padding: 0 16px; }
    .stock-level { min-width: 0; width: 100%; }
    .stock-level__head { flex-wrap: wrap; }
    .stock-row-actions { justify-content: flex-start; }
    .mobile-cards .cell-actions,
    .mobile-cards .stock-pos-tags { flex-wrap: wrap; }
    .info-table td:first-child { width: 100px; }

    .order-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; padding: 14px; }
    .order-date-form,
    .order-row__content { grid-column: 1 / -1; min-width: 0; }
    .order-row__person { flex: auto; }
    .order-row__chips { justify-content: flex-start; }
    .order-row__total { min-width: 0; text-align: right; }
    .order-row__actions { grid-column: 1 / -1; justify-content: flex-end; padding-top: 10px; border-top: 1px solid var(--border-light); }
    .order-action-form { width: auto; }
    .order-action-btn { width: auto; min-height: 44px; }
    .order-action-btn--icon { width: 44px; }
    .order-date-form__fields { grid-template-columns: minmax(0, 1fr) 108px; }
    .order-item-chip { display: block; overflow-wrap: anywhere; white-space: normal; }
    .order-item-chip small { flex-shrink: 0; }
    .order-date-modal__grid { gap: 4px; }
    .order-date-modal__day { min-height: 38px; }
    .to-order-toolbar { flex-direction: column; align-items: stretch; }
    .to-order-toolbar__right { flex-wrap: wrap; }
    .search-box { min-width: 0; max-width: 100%; }
    .to-order-card { padding: 14px; gap: 10px; }
    .to-order-card__foot { flex-wrap: wrap; gap: 12px; }
    .ordered-card__head { flex-wrap: wrap; gap: 12px; }
}

@media (max-width: 900px) {
    .pos-topbar {
        height: auto;
        padding: calc(8px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 12px max(12px, env(safe-area-inset-left));
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 10px;
    }
    .pos-topbar__left { min-width: 0; gap: 8px; font-size: 15px; }
    .pos-topbar__logo { height: 18px; }
    .pos-topbar__right { grid-column: 2; grid-row: 1; min-width: 0; gap: 6px; }
    .pos-topbar__right .btn { min-height: 40px; padding: 6px 10px; font-size: 12px; }
    .pos-user { display: none; }
    .pos-topbar__center { grid-column: 1 / -1; grid-row: 2; display: flex; flex-direction: column; align-items: stretch; gap: 10px; overflow: visible; min-width: 0; }
    .category-tabs { gap: 6px; padding: 0; }
    .cat-tab { flex: 1; min-width: 0; min-height: 42px; padding: 8px 6px; font-size: 13px; }
    .pos-search { flex: auto; min-width: 0; }
    .pos-search input { font-size: 16px; min-height: 44px; padding: 10px 44px 10px 14px; border-radius: 12px; background: var(--bg); }
    .pos-search__clear { width: 34px; height: 34px; }
    .pos-main { flex-direction: column; }
    .pos-products { width: 100%; padding: 12px max(12px, env(safe-area-inset-right)) 16px max(12px, env(safe-area-inset-left)); overscroll-behavior-y: contain; }
    .pos-grid,
    .pos-grid--shake,
    .product-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .pos-grid--protein { grid-template-columns: minmax(0, 1fr); }
    .pos-card { min-width: 0; padding: 12px; border-radius: 12px; }
    #sectionZbozi .pos-grid { grid-template-columns: minmax(0, 1fr); }
    .pos-card--stock { min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 90px; grid-template-rows: auto auto auto; gap: 4px 10px; }
    .pos-card--stock .pos-card__name { grid-column: 1; display: block; min-height: 0; font-size: 13px; overflow: visible; }
    .pos-card--stock .pos-card__pack,
    .pos-card--stock .pos-card__deal { grid-column: 1; justify-self: start; }
    .pos-card--stock .pos-card__footer { grid-column: 2; grid-row: 1 / span 3; display: flex; flex-direction: column-reverse; justify-content: center; align-items: flex-end; gap: 8px; }
    .pos-card--stock .pos-card__meta { flex: none; justify-content: flex-end; font-size: 11px; gap: 4px; }
    .pos-card--stock .pos-card__price-badge { font-size: 14px; padding: 5px 8px; }
    .pos-card__name { font-size: 13px; overflow-wrap: anywhere; }
    .pos-card__pack { overflow-wrap: anywhere; }
    .pos-card__top { gap: 6px; }
    .pos-card__avatar { width: 30px; height: 30px; border-radius: 9px; font-size: 14px; }
    .pos-card__price-badge { font-size: 12px; padding: 5px 7px; white-space: nowrap; }
    .pos-card__footer { flex-wrap: wrap; gap: 6px; }
    .pos-card__deal { white-space: normal; }
    .pos-card__qty .qty-btn { width: 44px; height: 44px; }
    .pos-card__qty .btn { min-height: 44px; }
    .section-label { font-size: 13px; }
    .pos-cart { display: none; width: 100%; min-width: 0; max-height: none; flex: 1; border: 0; overflow-y: auto; overscroll-behavior-y: contain; }
    .pos-show-cart .pos-products { display: none; }
    .pos-show-cart .pos-cart { display: flex; }
    .pos-show-cart .pos-topbar__center { display: none; }
    .customer-panel { padding: 14px; flex-shrink: 0; }
    .customer-search-wrap input { width: 100%; min-height: 46px; font-size: 16px; }
    .customer-dropdown { max-height: 240px; max-height: min(240px, 40dvh); }
    .customer-option { min-height: 48px; }
    .customer-selected__info { min-width: 0; }
    .customer-selected__name { overflow-wrap: anywhere; }
    .cart-header { padding: 12px 14px; flex-shrink: 0; }
    .cart-items { flex: 1 0 auto; overflow: visible; padding: 12px; }
    .cart-item { gap: 10px; padding: 12px; }
    .cart-item__info { min-width: 0; }
    .cart-item__name { overflow-wrap: anywhere; }
    .cart-item__qty { flex-shrink: 0; gap: 5px; }
    .cart-item__qty .qty-btn { width: 40px; height: 40px; }
    .cart-footer { padding: 14px; flex-shrink: 0; }
    .discount-row { flex-wrap: wrap; gap: 8px; }
    .discount-btns { flex-wrap: wrap; }
    .disc-btn { min-width: 38px; min-height: 38px; }
    .payment-btns { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .btn--credit { grid-column: auto; }
    .btn--pay { font-size: 13px; padding: 14px 4px; min-height: 50px; }
    .pos-mobile-bar {
        display: grid;
        grid-template-columns: minmax(0, .8fr) minmax(0, 1.6fr);
        gap: 10px;
        flex-shrink: 0;
        padding: 10px max(12px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
        background: var(--surface);
        border-top: 1px solid var(--border);
    }
    .pos-mobile-bar button { display: flex; align-items: center; justify-content: center; gap: 8px; min-width: 0; min-height: 50px; border-radius: 12px; border: 1px solid var(--border); font: inherit; font-size: 14px; font-weight: 650; cursor: pointer; }
    .pos-mobile-bar__products { color: var(--text-muted); background: var(--bg); }
    .pos-mobile-bar__products[aria-pressed="true"] { color: var(--primary-dark); background: var(--primary-light); border-color: var(--primary-light); }
    .pos-mobile-bar .pos-mobile-bar__cart { color: #fff; background: var(--primary); border-color: var(--primary); padding: 10px 12px; justify-content: space-between; }
    .pos-mobile-bar__cart > span { display: inline-flex; align-items: center; gap: 6px; }
    .pos-mobile-bar__cart strong { margin-left: auto; white-space: nowrap; }
    .pos-mobile-bar__count { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px; padding: 0 5px; font-size: 12px; border-radius: 7px; background: rgba(255, 255, 255, .2); }
    .login-page { min-height: 100dvh; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
    .login-wrapper { padding: 20px; }
    .login-card { padding: 32px 24px; }
}

@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
    .pos-topbar__center { flex-direction: row; }
    .category-tabs { flex: 1; }
    .pos-search { flex: 1; }
    .pos-grid,
    .pos-grid--shake { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

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