@media (max-width: 1100px) {
    .order-shell {
        grid-template-columns: minmax(180px, 240px) minmax(300px, 1fr);
        grid-template-rows: auto auto auto;
        grid-template-areas:
            "products summary"
            "focus summary"
            "calculator summary";
    }

    .calculator-panel {
        grid-template-columns: 1fr;
    }

    .filters {
        grid-template-columns: repeat(3, minmax(150px, 1fr));
    }

    .data-grid {
        grid-template-columns: 1fr;
    }

    .data-filters {
        grid-template-columns: repeat(2, minmax(150px, 1fr)) auto;
    }
}

@media (max-width: 767px) {
    body.order-page {
        height: 100dvh;
        overflow: hidden;
    }

    .topbar {
        min-height: 60px;
        height: 60px;
        align-items: center;
        padding: 6px 10px;
        gap: 8px;
    }

    .brand {
        min-width: 0;
    }

    .brand img {
        width: 36px;
        height: 36px;
        border-radius: 6px;
    }

    .brand-title {
        font-size: 18px;
        line-height: 1;
    }

    .topbar-left {
        gap: 8px;
    }

    .topbar-history-link {
        min-height: 36px;
        padding: 8px 10px;
        font-size: 13px;
    }

    .topbar-user {
        font-size: 13px;
        gap: 6px;
        flex-wrap: nowrap;
        min-width: 0;
        flex: 1 1 auto;
    }

    .privacy-toplink {
        font-size: 12px;
        text-decoration-thickness: 1px;
    }

    .topbar-user span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .topbar-user .ghost-button {
        min-height: 36px;
        padding: 8px 10px;
    }

    .order-shell {
        height: calc(100dvh - 60px);
        min-height: 0;
        padding: 10px;
        grid-template-columns: minmax(0, 4fr) minmax(0, 1fr);
        grid-template-rows: minmax(0, 1fr) 35dvh;
        grid-template-areas:
            "products summary"
            "calculator calculator";
        gap: 10px;
        overflow: hidden;
        transition: grid-template-columns 260ms ease;
    }

    .admin-order-switcher {
        width: auto;
        margin: 8px 10px 0;
        padding: 8px;
    }

    .admin-order-switcher form {
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .admin-order-switcher .secondary-link {
        grid-column: 1 / -1;
        width: 100%;
    }

    .admin-order-switcher + .order-shell {
        height: calc(100dvh - 196px);
    }

    .order-shell.summary-open {
        grid-template-columns: minmax(0, 1fr) minmax(0, 4fr);
    }

    .order-shell.keyboard-collapsed {
        grid-template-rows: minmax(0, 1fr) 58px;
    }

    .focus-panel {
        display: none;
    }

    .product-panel,
    .summary-panel {
        min-width: 0;
        min-height: 0;
        overflow: hidden;
        transition: box-shadow 200ms ease, border-color 200ms ease, background-color 200ms ease;
    }

    .product-panel {
        padding: 10px;
    }

    .summary-panel {
        padding: 10px;
        position: static;
        z-index: auto;
        max-height: none;
    }

    .mobile-panel-tab {
        width: 100%;
        height: 100%;
        min-height: 0;
        border: 0;
        border-radius: 8px;
        background: #fff8a8;
        color: var(--red);
        display: none;
        align-items: center;
        justify-content: center;
        padding: 10px 6px;
        font-weight: 900;
        font-size: clamp(13px, 3.5vw, 16px);
        line-height: 1;
        white-space: nowrap;
        cursor: pointer;
    }

    .mobile-panel-tab span {
        display: block;
        white-space: nowrap;
        transform: rotate(90deg);
    }

    .mobile-panel-tab:hover {
        background: #fff26b;
    }

    .order-shell.summary-open .product-panel .mobile-panel-tab,
    .order-shell:not(.summary-open) .summary-panel .mobile-panel-tab {
        display: flex;
    }

    .order-shell.summary-open .product-panel > :not(.mobile-panel-tab),
    .order-shell:not(.summary-open) .summary-panel > :not(.mobile-panel-tab) {
        display: none;
    }

    .order-shell.summary-open .product-panel,
    .order-shell:not(.summary-open) .summary-panel {
        padding: 6px;
        background: #fffef0;
        display: grid;
        grid-template-rows: 1fr;
    }

    .order-shell:not(.summary-open) .product-panel .mobile-panel-tab,
    .order-shell.summary-open .summary-panel .mobile-panel-tab {
        display: none;
    }

    .order-shell:not(.summary-open) .product-panel,
    .order-shell.summary-open .summary-panel {
        animation: mobilePanelIn 220ms ease both;
    }

    .product-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        overflow: auto;
        padding-right: 2px;
    }

    .product-button {
        min-height: clamp(64px, 14vh, 96px);
        align-items: center;
        justify-content: center;
        font-size: clamp(14px, 3.5vw, 17px);
        padding: 10px 8px;
    }

    .summary-header {
        gap: 10px;
    }

    .summary-header h2 {
        font-size: clamp(24px, 7vw, 34px);
    }

    .summary-panel .empty-state {
        padding: 14px;
    }

    .items-list {
        min-height: 0;
        max-height: none;
        overflow: auto;
    }

    .calculator-panel {
        padding: 8px;
        grid-template-columns: 1fr;
        grid-template-rows: 48px minmax(0, 1fr);
        gap: 6px;
        min-height: 0;
        position: sticky;
        bottom: 0;
        z-index: 8;
    }

    .calculator-panel.keyboard-collapsed {
        padding: 5px 8px;
        grid-template-rows: 1fr;
    }

    .calculator-display {
        min-height: 0;
        height: 48px;
        padding: 5px 8px;
        border-radius: 6px;
        grid-template-columns: 40px minmax(0, 1fr) auto minmax(32px, 0.25fr);
        gap: 6px;
    }

    .calculator-toggle {
        width: 36px;
        height: 36px;
        min-height: 0;
    }

    .calculator-toggle svg {
        width: 20px;
        height: 20px;
    }

    .calculator-controls {
        min-height: 0;
        grid-template-rows: minmax(0, 1fr) 42px;
        gap: 6px;
    }

    .display-product {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 12px;
    }

    .display-unit {
        font-size: 12px;
    }

    .calculator-display strong {
        font-size: 26px;
    }

    .keypad {
        gap: 6px;
        min-height: 0;
    }

    .keypad button {
        min-height: 0;
        height: 100%;
        border-radius: 6px;
        font-size: clamp(20px, 7vw, 28px);
    }

    .calculator-actions {
        gap: 6px;
        min-height: 0;
    }

    .calculator-actions .arrow-button {
        min-height: 0;
        height: 42px;
        border-radius: 6px;
        font-size: 28px;
    }

    .summary-footer .primary-button,
    .summary-footer .secondary-button {
        min-height: 38px;
        padding: 8px 10px;
    }

    .total-row {
        padding: 8px 0;
    }

    @keyframes mobilePanelIn {
        from {
            opacity: 0.82;
            transform: translateY(4px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    .admin-shell {
        padding: 12px;
    }

    .admin-header {
        display: grid;
        align-items: start;
    }

    .stats-grid,
    .filters,
    .data-filters {
        grid-template-columns: 1fr;
    }

    .data-grid {
        grid-template-columns: 1fr;
    }

    .table-wrap {
        overflow: visible;
        border: 0;
        background: transparent;
        box-shadow: none;
    }

    .orders-table {
        min-width: 0;
        display: block;
        background: transparent;
    }

    .orders-table thead {
        display: none;
    }

    .orders-table tbody {
        display: grid;
        gap: 12px;
    }

    .orders-table tr {
        padding: 12px;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px 14px;
        border: 1px solid var(--line);
        border-radius: 8px;
        background: #fff;
        box-shadow: var(--shadow);
    }

    .orders-table td {
        min-width: 0;
        padding: 0;
        display: grid;
        gap: 4px;
        border: 0;
        overflow-wrap: anywhere;
    }

    .orders-table td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 11px;
        font-weight: 900;
        text-transform: uppercase;
    }

    .orders-table td[data-label="Sucursal/Cliente"],
    .orders-table .macro-progress-cell,
    .orders-table .actions-cell,
    .orders-table .table-empty {
        grid-column: 1 / -1;
    }

    .orders-table .actions-cell {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        padding-top: 8px;
        border-top: 1px solid var(--line);
    }

    .orders-table .actions-cell::before {
        grid-column: 1 / -1;
    }

    .actions-cell > *,
    .actions-cell form button {
        width: 100%;
    }

    .orders-table .macro-details-row {
        padding: 0;
        display: block;
        background: transparent;
        box-shadow: none;
    }

    .orders-table .macro-details-row[hidden] {
        display: none;
    }

    .orders-table .macro-details-row > td {
        display: block;
    }

    .orders-table .macro-details-row > td::before {
        display: none;
    }

    .macro-details-shell {
        padding: 0;
    }

    .macro-component-row {
        grid-template-columns: 1fr;
    }

    .macro-component-items {
        margin-left: 0;
        grid-template-columns: 1fr;
    }

    .pagination {
        justify-content: center;
    }

    .settings-header {
        gap: 12px;
    }

    .settings-header .secondary-link {
        width: 100%;
    }

    .settings-nav {
        margin: 0 -12px;
        padding: 0 12px 2px;
    }

    .settings-section-heading {
        padding: 12px;
    }

    .settings-actions {
        padding: 10px 12px;
    }

    .settings-actions .primary-button {
        width: 100%;
    }

    .create-form,
    .user-create-form,
    .admin-account-form {
        padding: 12px;
        grid-template-columns: 1fr;
    }

    .config-card-grid {
        padding: 12px;
        grid-template-columns: 1fr;
    }

    .time-row {
        grid-template-columns: 1fr;
    }

    .login-shell {
        padding: 14px;
    }

    .login-panel {
        padding: 18px;
    }

    .login-logo {
        width: 140px;
        height: 140px;
    }
}

@media (min-width: 768px) {
    body.order-page {
        min-height: 100%;
    }

    body.order-page,
    body.history-page {
        background: var(--yellow);
    }

    body.order-page .topbar,
    body.history-page .topbar {
        width: min(100%, 540px);
        min-height: 60px;
        height: 60px;
        margin: 0 auto;
        padding: 6px 10px;
        gap: 8px;
        background: var(--yellow);
        box-shadow: 0 10px 28px rgba(36, 36, 36, 0.16);
    }

    body.order-page .brand {
        min-width: 0;
    }

    body.order-page .brand img,
    body.history-page .brand img {
        width: 36px;
        height: 36px;
        border-radius: 6px;
    }

    body.order-page .brand-title,
    body.history-page .brand-title {
        font-size: 18px;
        line-height: 1;
    }

    body.order-page .topbar-left,
    body.history-page .topbar-left {
        gap: 8px;
    }

    body.order-page .topbar-history-link,
    body.history-page .topbar-history-link {
        min-height: 36px;
        padding: 8px 10px;
        font-size: 13px;
    }

    body.order-page .topbar-user,
    body.history-page .topbar-user {
        min-width: 0;
        gap: 6px;
        flex-wrap: nowrap;
        font-size: 13px;
        flex: 1 1 auto;
    }

    body.order-page .topbar-user span,
    body.history-page .topbar-user span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    body.order-page .topbar-user .ghost-button,
    body.history-page .topbar-user .ghost-button {
        min-height: 36px;
        padding: 8px 10px;
    }

    body.history-page .history-shell {
        width: min(100%, 540px);
        padding: 10px;
        background: rgba(255, 255, 255, 0.32);
        box-shadow: 0 18px 48px rgba(36, 36, 36, 0.2);
    }

    body.order-page .order-shell {
        width: min(100%, 540px);
        height: min(800px, calc(100dvh - 60px));
        min-height: 0;
        margin: 0 auto;
        padding: 10px;
        grid-template-columns: minmax(0, 4fr) minmax(0, 1fr);
        grid-template-rows: minmax(0, 1fr) minmax(230px, 35%);
        grid-template-areas:
            "products summary"
            "calculator calculator";
        gap: 10px;
        overflow: hidden;
        background: rgba(255, 255, 255, 0.32);
        box-shadow: 0 18px 48px rgba(36, 36, 36, 0.2);
        transition: grid-template-columns 260ms ease;
    }

    body.order-page .admin-order-switcher + .order-shell {
        height: min(800px, calc(100dvh - 150px));
    }

    body.order-page .order-shell.summary-open {
        grid-template-columns: minmax(0, 1fr) minmax(0, 4fr);
    }

    body.order-page .order-shell.keyboard-collapsed {
        grid-template-rows: minmax(0, 1fr) 58px;
    }

    body.order-page .focus-panel {
        display: none;
    }

    body.order-page .product-panel,
    body.order-page .summary-panel {
        min-width: 0;
        min-height: 0;
        overflow: hidden;
        transition: box-shadow 200ms ease, border-color 200ms ease, background-color 200ms ease;
    }

    body.order-page .product-panel {
        padding: 10px;
    }

    body.order-page .summary-panel {
        padding: 10px;
        position: static;
        z-index: auto;
        max-height: none;
    }

    body.order-page .mobile-panel-tab {
        width: 100%;
        height: 100%;
        min-height: 0;
        border: 0;
        border-radius: 8px;
        background: #fff8a8;
        color: var(--red);
        display: none;
        align-items: center;
        justify-content: center;
        padding: 10px 6px;
        font-weight: 900;
        font-size: 15px;
        line-height: 1;
        white-space: nowrap;
        cursor: pointer;
    }

    body.order-page .mobile-panel-tab span {
        display: block;
        white-space: nowrap;
        transform: rotate(90deg);
    }

    body.order-page .mobile-panel-tab:hover {
        background: #fff26b;
    }

    body.order-page .order-shell.summary-open .product-panel .mobile-panel-tab,
    body.order-page .order-shell:not(.summary-open) .summary-panel .mobile-panel-tab {
        display: flex;
    }

    body.order-page .order-shell.summary-open .product-panel > :not(.mobile-panel-tab),
    body.order-page .order-shell:not(.summary-open) .summary-panel > :not(.mobile-panel-tab) {
        display: none;
    }

    body.order-page .order-shell.summary-open .product-panel,
    body.order-page .order-shell:not(.summary-open) .summary-panel {
        padding: 6px;
        background: #fffef0;
        display: grid;
        grid-template-rows: 1fr;
    }

    body.order-page .order-shell:not(.summary-open) .product-panel .mobile-panel-tab,
    body.order-page .order-shell.summary-open .summary-panel .mobile-panel-tab {
        display: none;
    }

    body.order-page .order-shell:not(.summary-open) .product-panel,
    body.order-page .order-shell.summary-open .summary-panel {
        animation: mobilePanelIn 220ms ease both;
    }

    body.order-page .product-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        overflow: auto;
        padding-right: 2px;
    }

    body.order-page .product-button {
        min-height: 76px;
        align-items: center;
        justify-content: center;
        padding: 10px 8px;
        font-size: 15px;
    }

    body.order-page .summary-header {
        gap: 10px;
    }

    body.order-page .summary-header h2 {
        font-size: 28px;
    }

    body.order-page .summary-panel .empty-state {
        padding: 14px;
    }

    body.order-page .items-list {
        min-height: 0;
        max-height: none;
        overflow: auto;
    }

    body.order-page .calculator-panel {
        min-height: 0;
        padding: 8px;
        grid-template-columns: 1fr;
        grid-template-rows: 48px minmax(0, 1fr);
        gap: 6px;
        position: sticky;
        bottom: 0;
        z-index: 8;
    }

    body.order-page .calculator-panel.keyboard-collapsed {
        padding: 5px 8px;
        grid-template-rows: 1fr;
    }

    body.order-page .calculator-display {
        min-height: 0;
        height: 48px;
        padding: 5px 8px;
        border-radius: 6px;
        grid-template-columns: 40px minmax(0, 1fr) auto minmax(32px, 0.25fr);
        gap: 6px;
    }

    body.order-page .calculator-toggle {
        width: 36px;
        height: 36px;
        min-height: 0;
    }

    body.order-page .calculator-toggle svg {
        width: 20px;
        height: 20px;
    }

    body.order-page .calculator-controls {
        min-height: 0;
        grid-template-rows: minmax(0, 1fr) 42px;
        gap: 6px;
    }

    body.order-page .display-product {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 12px;
    }

    body.order-page .display-unit {
        font-size: 12px;
    }

    body.order-page .calculator-display strong {
        font-size: 26px;
    }

    body.order-page .keypad {
        min-height: 0;
        gap: 6px;
    }

    body.order-page .keypad button {
        min-height: 0;
        height: 100%;
        border-radius: 6px;
        font-size: 26px;
    }

    body.order-page .calculator-actions {
        min-height: 0;
        gap: 6px;
    }

    body.order-page .calculator-actions .arrow-button {
        min-height: 0;
        height: 42px;
        border-radius: 6px;
        font-size: 28px;
    }

    body.order-page .summary-footer .primary-button,
    body.order-page .summary-footer .secondary-button {
        min-height: 38px;
        padding: 8px 10px;
    }

    body.order-page .total-row {
        padding: 8px 0;
    }

    @keyframes mobilePanelIn {
        from {
            opacity: 0.82;
            transform: translateY(4px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
}

@media (max-width: 600px) {
    .macro-history-summary {
        grid-template-columns: minmax(0, 1fr) auto !important;
    }

    .macro-history-summary > .macro-progress {
        grid-column: 1 / -1;
        width: 100%;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
    }

    .macro-history-summary .order-segments {
        width: 100%;
    }

    .macro-section-heading {
        align-items: stretch;
        flex-direction: column;
    }

    .macro-section-heading .primary-link {
        width: 100%;
    }
}
