:root {
    color-scheme: light;
    --ds-bg: #f4f7fb;
    --ds-bg-top: #edf5ff;
    --ds-surface: rgba(255, 255, 255, 0.9);
    --ds-surface-solid: #ffffff;
    --ds-surface-soft: #f7f9fc;
    --ds-text: #111827;
    --ds-muted: #667085;
    --ds-border: rgba(17, 24, 39, 0.1);
    --ds-border-strong: rgba(17, 24, 39, 0.16);
    --ds-primary: #1473e6;
    --ds-primary-strong: #0f5fc2;
    --ds-primary-soft: rgba(20, 115, 230, 0.1);
    --ds-teal: #16a394;
    --ds-success: #138a5b;
    --ds-success-soft: #e9f8f1;
    --ds-warning: #b86b08;
    --ds-warning-soft: #fff5df;
    --ds-danger: #d94045;
    --ds-danger-soft: #fff0f1;
    --ds-shadow-sm: 0 8px 24px rgba(15, 23, 42, 0.06);
    --ds-shadow-md: 0 18px 46px rgba(15, 23, 42, 0.1);
    --ds-shadow-lg: 0 28px 80px rgba(15, 23, 42, 0.16);
    --ds-radius-sm: 12px;
    --ds-radius-md: 16px;
    --ds-radius-lg: 22px;
    --ds-control-height: 44px;
}

html {
    min-width: 320px;
    background: var(--ds-bg);
    scrollbar-gutter: stable;
}

body {
    min-height: 100vh;
    margin: 0;
    overflow-x: hidden;
    background: linear-gradient(180deg, var(--ds-bg-top) 0, var(--ds-bg) 320px, var(--ds-bg) 100%);
    color: var(--ds-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.45;
    letter-spacing: 0;
    -webkit-font-smoothing: antialiased;
}

body::before {
    content: "";
    position: fixed;
    inset: 0 0 auto;
    z-index: -1;
    height: 260px;
    background: linear-gradient(110deg, rgba(20, 115, 230, 0.09), rgba(22, 163, 148, 0.07));
    pointer-events: none;
}

button,
input,
select,
textarea {
    font: inherit;
    letter-spacing: 0;
}

button,
.link-button,
.header-logout-card {
    -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
.link-button:focus-visible,
.header-logout-card:focus-visible,
.header-brand-card:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid rgba(20, 115, 230, 0.22) !important;
    outline-offset: 2px;
}

/* App shell */
.pretty-app-header {
    position: relative;
    z-index: 30;
    width: min(1480px, calc(100% - 32px));
    min-height: 84px;
    margin: 16px auto 0;
    padding: 12px 14px !important;
    display: grid !important;
    grid-template-columns: minmax(150px, 1fr) auto minmax(150px, 1fr) !important;
    align-items: center !important;
    gap: 14px !important;
    border: 1px solid var(--ds-border) !important;
    border-radius: var(--ds-radius-lg) !important;
    background: var(--ds-surface) !important;
    color: var(--ds-text) !important;
    box-shadow: var(--ds-shadow-md) !important;
    backdrop-filter: blur(22px);
    -webkit-backdrop-filter: blur(22px);
}

.header-user-card,
.header-brand-card,
.header-actions-card,
.header-logout-card,
.theme-toggle-button {
    box-sizing: border-box !important;
}

.header-user-card {
    min-width: 0 !important;
    width: max-content !important;
    max-width: 100% !important;
    padding: 8px 12px !important;
    border: 0 !important;
    border-radius: var(--ds-radius-sm) !important;
    background: var(--ds-surface-soft) !important;
    box-shadow: none !important;
}

.header-user-label {
    margin: 0 0 2px !important;
    color: var(--ds-muted) !important;
    font-size: 11px !important;
    font-weight: 650 !important;
    line-height: 1.2 !important;
    text-transform: uppercase;
}

.header-user-name {
    overflow: hidden;
    color: var(--ds-text) !important;
    font-size: 14px !important;
    font-weight: 720 !important;
    line-height: 1.2 !important;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-user-role {
    margin-top: 2px !important;
    color: var(--ds-muted) !important;
    font-size: 11px !important;
    line-height: 1.2 !important;
}

.header-brand-card {
    width: auto !important;
    min-width: 222px !important;
    min-height: 58px !important;
    margin: 0 !important;
    padding: 7px 14px 7px 8px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 11px !important;
    border: 0 !important;
    border-radius: var(--ds-radius-md) !important;
    background: transparent !important;
    box-shadow: none !important;
    color: var(--ds-text) !important;
    cursor: pointer;
    transition: background-color 160ms ease, transform 160ms ease !important;
}

.header-brand-card:hover {
    background: var(--ds-primary-soft) !important;
}

.header-brand-card:active {
    transform: scale(0.985) !important;
}

.header-brand-icon,
.login-brand-icon {
    width: 46px;
    height: 46px;
    flex: 0 0 46px;
    display: grid;
    place-items: center;
    border-radius: 15px;
    color: #ffffff;
    background: linear-gradient(145deg, var(--ds-primary), #20b9a5);
    box-shadow: 0 12px 24px rgba(20, 115, 230, 0.24);
}

.header-brand-icon svg,
.login-brand-icon svg {
    width: 23px;
    height: 23px;
    display: block;
}

.header-brand-copy {
    min-width: 0;
    display: grid;
    gap: 2px;
    text-align: left;
}

.header-brand-kicker {
    margin: 0 !important;
    color: var(--ds-text) !important;
    font-size: 20px !important;
    font-weight: 780 !important;
    line-height: 1.05 !important;
    text-transform: none !important;
}

.header-brand-subtitle {
    color: var(--ds-muted);
    font-size: 12px;
    font-weight: 560;
    line-height: 1.2;
}

.header-actions-card {
    justify-self: end !important;
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    padding: 0 !important;
    border: 0 !important;
    background: transparent !important;
}

.theme-toggle-button,
.header-logout-card {
    height: 42px !important;
    min-height: 42px !important;
    margin: 0 !important;
    border: 1px solid var(--ds-border) !important;
    border-radius: 13px !important;
    background: var(--ds-surface-solid) !important;
    color: var(--ds-text) !important;
    box-shadow: none !important;
}

.theme-toggle-button {
    width: 56px !important;
    min-width: 56px !important;
}

.header-logout-card {
    min-width: 76px !important;
    padding: 0 15px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    text-decoration: none !important;
    font-size: 14px !important;
    font-weight: 680 !important;
}

.theme-toggle-button:hover,
.header-logout-card:hover {
    border-color: rgba(20, 115, 230, 0.32) !important;
    background: var(--ds-primary-soft) !important;
    color: var(--ds-primary) !important;
}

.top-nav {
    position: sticky !important;
    top: 0 !important;
    z-index: 25 !important;
    width: min(1480px, calc(100% - 32px)) !important;
    min-height: 64px !important;
    margin: 12px auto 0 !important;
    padding: 10px 12px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border: 1px solid var(--ds-border) !important;
    border-radius: 18px !important;
    background: rgba(255, 255, 255, 0.9) !important;
    box-shadow: var(--ds-shadow-sm) !important;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    overflow: hidden !important;
}

.top-nav > label {
    display: none !important;
}

.top-nav .nav-buttons {
    width: 100%;
    min-height: 42px !important;
    margin: 0 !important;
    display: flex !important;
    flex-wrap: nowrap !important;
    justify-content: center !important;
    align-items: center !important;
    gap: 6px !important;
    contain: layout style !important;
}

.top-nav .nav-buttons > button,
.top-nav button[onclick^="showPage"] {
    height: 42px !important;
    min-height: 42px !important;
    max-height: 42px !important;
    margin: 0 !important;
    padding: 0 15px !important;
    border: 1px solid transparent !important;
    border-radius: 13px !important;
    background: transparent !important;
    color: var(--ds-muted) !important;
    box-shadow: none !important;
    font-size: 14px !important;
    font-weight: 670 !important;
    line-height: 1 !important;
    white-space: nowrap !important;
    transform: none !important;
    transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease !important;
}

.top-nav .nav-buttons > button:hover {
    background: var(--ds-primary-soft) !important;
    color: var(--ds-primary) !important;
}

.top-nav .nav-buttons > button.active,
.top-nav .nav-buttons > button.active-nav-button {
    border-color: rgba(20, 115, 230, 0.18) !important;
    background: var(--ds-primary) !important;
    color: #ffffff !important;
}

main {
    width: min(1480px, 100%) !important;
    max-width: 1480px !important;
    margin: 0 auto !important;
    padding: 22px 16px 54px !important;
}

/* Content surfaces */
.card,
section.card,
.settings-card,
.search-card,
.selected-product-info,
.top-stock-stats-date-picker,
.independent-folder-panel {
    border: 1px solid var(--ds-border) !important;
    border-radius: var(--ds-radius-md) !important;
    background: var(--ds-surface-solid) !important;
    color: var(--ds-text) !important;
    box-shadow: var(--ds-shadow-sm) !important;
}

.card,
section.card {
    margin-bottom: 16px !important;
    padding: 20px !important;
}

.scanner-card {
    border-color: rgba(20, 115, 230, 0.2) !important;
}

.search-card,
.selected-product-info,
.top-stock-stats-date-picker,
.independent-folder-panel {
    padding: 14px !important;
}

h1,
h2,
h3,
h4 {
    color: var(--ds-text);
    letter-spacing: 0;
}

.card > h2:first-child,
section.card > h2:first-child,
.settings-root-card > h2:first-child,
.history-page-card > h2:first-child {
    margin: 0 0 16px !important;
    font-size: 22px !important;
    font-weight: 760 !important;
    line-height: 1.18 !important;
}

h3 {
    font-size: 17px;
    line-height: 1.25;
}

p,
.history-page-subtitle,
.settings-home-subtitle,
.extra-menu-subtitle,
.labels-note {
    color: var(--ds-muted);
}

label {
    margin: 10px 0 5px !important;
    color: #344054 !important;
    font-size: 13px !important;
    font-weight: 650 !important;
    line-height: 1.3 !important;
}

input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
    width: 100% !important;
    min-height: var(--ds-control-height) !important;
    padding: 9px 12px !important;
    border: 1px solid var(--ds-border-strong) !important;
    border-radius: var(--ds-radius-sm) !important;
    background: var(--ds-surface-solid) !important;
    color: var(--ds-text) !important;
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.02) !important;
    font-size: 14px !important;
    line-height: 1.35 !important;
    transition: border-color 150ms ease, box-shadow 150ms ease, background-color 150ms ease !important;
}

textarea {
    min-height: 82px !important;
    resize: vertical;
}

input::placeholder,
textarea::placeholder {
    color: #98a2b3 !important;
    opacity: 1;
}

input:not([type="checkbox"]):not([type="radio"]):hover,
select:hover,
textarea:hover {
    border-color: rgba(20, 115, 230, 0.32) !important;
}

input:not([type="checkbox"]):not([type="radio"]):focus,
select:focus,
textarea:focus {
    border-color: var(--ds-primary) !important;
    outline: 0 !important;
    box-shadow: 0 0 0 3px rgba(20, 115, 230, 0.12) !important;
}

input[type="checkbox"],
input[type="radio"] {
    accent-color: var(--ds-primary);
}

.row,
.action-buttons,
.modal-actions,
.inventory-log-controls,
.history-controls,
.independent-barcodes-actions,
.independent-barcodes-toolbar {
    gap: 8px !important;
}

.row {
    align-items: flex-end;
}

button,
.link-button {
    min-height: 42px !important;
    margin-top: 10px !important;
    padding: 0 15px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 7px !important;
    border: 1px solid transparent !important;
    border-radius: 13px !important;
    background: var(--ds-primary) !important;
    color: #ffffff !important;
    box-shadow: none !important;
    font-size: 14px !important;
    font-weight: 680 !important;
    line-height: 1.15 !important;
    text-decoration: none !important;
    cursor: pointer;
    transition: transform 150ms ease, background-color 150ms ease, border-color 150ms ease !important;
}

button:hover,
.link-button:hover {
    background: var(--ds-primary-strong) !important;
}

button:active,
.link-button:active {
    transform: scale(0.985) !important;
}

button:disabled,
.link-button:disabled {
    opacity: 0.48 !important;
    cursor: not-allowed !important;
    transform: none !important;
}

.small-btn {
    min-height: 36px !important;
    padding: 0 12px !important;
    font-size: 13px !important;
}

.secondary-btn,
button.secondary-btn,
.link-button.secondary-btn {
    border-color: var(--ds-border) !important;
    background: var(--ds-surface-soft) !important;
    color: #344054 !important;
}

.secondary-btn:hover,
button.secondary-btn:hover {
    border-color: rgba(20, 115, 230, 0.24) !important;
    background: var(--ds-primary-soft) !important;
    color: var(--ds-primary) !important;
}

.danger-btn,
button.danger-btn {
    background: var(--ds-danger) !important;
    color: #ffffff !important;
}

.danger-btn:hover,
button.danger-btn:hover {
    background: #c93439 !important;
}

.ui-btn-green-final,
.ds-target-green {
    background: var(--ds-success) !important;
}

.ui-btn-yellow-final,
.ds-target-yellow {
    background: #d78a13 !important;
    color: #ffffff !important;
}

/* Data tables */
table {
    width: 100%;
    margin-top: 12px !important;
    border-collapse: separate !important;
    border-spacing: 0 !important;
    color: var(--ds-text) !important;
}

th,
td {
    padding: 11px 12px !important;
    border: 0 !important;
    border-bottom: 1px solid var(--ds-border) !important;
    background: transparent;
    color: inherit;
    font-size: 13px !important;
    line-height: 1.35 !important;
    vertical-align: middle !important;
}

th {
    position: relative;
    background: var(--ds-surface-soft) !important;
    color: #475467 !important;
    font-size: 12px !important;
    font-weight: 720 !important;
    text-transform: none !important;
}

thead tr:first-child th:first-child {
    border-top-left-radius: 10px;
}

thead tr:first-child th:last-child {
    border-top-right-radius: 10px;
}

tbody tr {
    transition: background-color 130ms ease;
}

tbody tr:hover > td {
    background: rgba(20, 115, 230, 0.035) !important;
}

.stock-ok,
.good {
    color: var(--ds-success) !important;
}

.stock-low,
.bad {
    color: var(--ds-danger) !important;
}

.warehouse-stock-chip,
.order-priority-high,
.order-priority-medium,
.order-priority-low {
    border-radius: 8px !important;
}

/* Menus and settings */
.extra-menu-grid-final,
.settings-tiles-grid {
    gap: 12px !important;
}

.extra-menu-tile-final,
.settings-card {
    min-height: 94px !important;
    padding: 15px !important;
    border: 1px solid var(--ds-border) !important;
    border-radius: var(--ds-radius-md) !important;
    background: var(--ds-surface-solid) !important;
    box-shadow: none !important;
    transition: transform 150ms ease, border-color 150ms ease, box-shadow 150ms ease !important;
}

.extra-menu-tile-final:hover,
.settings-card:hover {
    border-color: rgba(20, 115, 230, 0.3) !important;
    box-shadow: var(--ds-shadow-sm) !important;
    transform: translateY(-1px);
}

.extra-menu-tile-final button,
.settings-card button {
    margin-top: 8px !important;
}

.independent-folder-tabs {
    gap: 7px !important;
}

.independent-folder-tabs button {
    min-height: 36px !important;
    margin: 0 !important;
    border-color: var(--ds-border) !important;
    background: var(--ds-surface-soft) !important;
    color: #475467 !important;
}

.independent-folder-tabs button.active,
.independent-folder-tabs button[aria-selected="true"] {
    border-color: rgba(20, 115, 230, 0.2) !important;
    background: var(--ds-primary) !important;
    color: #ffffff !important;
}

/* Modals */
.modal,
.independent-barcode-modal {
    padding: 18px !important;
    background: rgba(15, 23, 42, 0.46) !important;
    backdrop-filter: blur(7px);
    -webkit-backdrop-filter: blur(7px);
}

.modal-card,
.independent-barcode-modal-card,
.inventory-quick-action-menu {
    border: 1px solid var(--ds-border) !important;
    border-radius: 20px !important;
    background: var(--ds-surface-solid) !important;
    color: var(--ds-text) !important;
    box-shadow: var(--ds-shadow-lg) !important;
}

.modal-card,
.independent-barcode-modal-card {
    padding: 20px !important;
}

.modal-card h2,
.independent-barcode-modal-card h2 {
    margin: 0 0 14px !important;
    font-size: 20px !important;
}

.independent-barcode-modal-close,
.inventory-quick-action-close {
    border-color: var(--ds-border) !important;
    background: var(--ds-surface-soft) !important;
    color: var(--ds-muted) !important;
}

/* Status blocks */
.login-error,
.scanner-error,
.inventory-quick-action-error,
.ds-inv-status-not-found-box,
.ds-inv-status-diff-box {
    border: 1px solid rgba(217, 64, 69, 0.24) !important;
    border-radius: var(--ds-radius-sm) !important;
    background: var(--ds-danger-soft) !important;
    color: #a62f34 !important;
    box-shadow: none !important;
}

.inventory-today-status-ok,
.ds-inv-status-ok-box,
.inventory-live-status-ok {
    border: 1px solid rgba(19, 138, 91, 0.2) !important;
    border-radius: var(--ds-radius-sm) !important;
    background: var(--ds-success-soft) !important;
    color: #0f744c !important;
    box-shadow: none !important;
}

.inventory-today-status-warning,
.inventory-submit-progress {
    border: 1px solid rgba(184, 107, 8, 0.2) !important;
    border-radius: var(--ds-radius-sm) !important;
    background: var(--ds-warning-soft) !important;
    color: #925508 !important;
    box-shadow: none !important;
}

/* Login */
.login-body {
    min-height: 100vh !important;
    padding: max(20px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom)) !important;
    display: grid !important;
    place-items: center !important;
    background: linear-gradient(145deg, #f8fbff 0%, var(--ds-bg) 55%, #edf4f8 100%) !important;
}

.login-card {
    width: min(100%, 390px) !important;
    padding: 28px !important;
    border: 1px solid var(--ds-border) !important;
    border-radius: 26px !important;
    background: rgba(255, 255, 255, 0.9) !important;
    color: var(--ds-text) !important;
    box-shadow: var(--ds-shadow-lg) !important;
    backdrop-filter: blur(22px);
    -webkit-backdrop-filter: blur(22px);
    text-align: center;
}

.login-brand-icon {
    width: 60px;
    height: 60px;
    margin: 0 auto 15px;
    border-radius: 20px;
}

.login-brand-icon svg {
    width: 28px;
    height: 28px;
}

.login-card h1 {
    margin: 0 !important;
    font-size: 26px !important;
    font-weight: 780 !important;
    line-height: 1.1 !important;
}

.login-card > p {
    margin: 7px 0 20px !important;
    color: var(--ds-muted) !important;
    font-size: 14px !important;
}

.login-card form {
    text-align: left;
}

.login-card form button {
    width: 100% !important;
    min-height: 46px !important;
    margin-top: 18px !important;
}

.login-error {
    padding: 11px 12px !important;
    text-align: left;
    font-size: 13px !important;
}

/* Dark theme */
body.dark-theme {
    color-scheme: dark;
    --ds-bg: #0b0f16;
    --ds-bg-top: #0d1420;
    --ds-surface: rgba(18, 24, 34, 0.9);
    --ds-surface-solid: #151d29;
    --ds-surface-soft: #1c2634;
    --ds-text: #f5f7fb;
    --ds-muted: #aab6c5;
    --ds-border: rgba(255, 255, 255, 0.1);
    --ds-border-strong: rgba(255, 255, 255, 0.16);
    --ds-primary: #4d9cff;
    --ds-primary-strong: #3988e8;
    --ds-primary-soft: rgba(77, 156, 255, 0.12);
    --ds-success: #49c995;
    --ds-success-soft: rgba(19, 119, 79, 0.28);
    --ds-warning: #f0b34e;
    --ds-warning-soft: rgba(146, 89, 12, 0.3);
    --ds-danger: #ef676c;
    --ds-danger-soft: rgba(145, 38, 43, 0.3);
    --ds-shadow-sm: 0 8px 24px rgba(0, 0, 0, 0.16);
    --ds-shadow-md: 0 20px 50px rgba(0, 0, 0, 0.28);
    --ds-shadow-lg: 0 30px 90px rgba(0, 0, 0, 0.44);
    background: linear-gradient(180deg, var(--ds-bg-top) 0, var(--ds-bg) 360px, var(--ds-bg) 100%) !important;
    color: var(--ds-text) !important;
}

body.dark-theme::before {
    background: linear-gradient(110deg, rgba(20, 115, 230, 0.13), rgba(22, 163, 148, 0.08));
}

body.dark-theme .pretty-app-header,
body.dark-theme .top-nav,
body.dark-theme .card,
body.dark-theme section.card,
body.dark-theme .settings-card,
body.dark-theme .search-card,
body.dark-theme .selected-product-info,
body.dark-theme .top-stock-stats-date-picker,
body.dark-theme .independent-folder-panel,
body.dark-theme .modal-card,
body.dark-theme .independent-barcode-modal-card,
body.dark-theme .inventory-quick-action-menu {
    border-color: var(--ds-border) !important;
    background: var(--ds-surface-solid) !important;
    color: var(--ds-text) !important;
}

body.dark-theme .pretty-app-header,
body.dark-theme .top-nav {
    background: var(--ds-surface) !important;
}

body.dark-theme .header-user-card,
body.dark-theme .theme-toggle-button,
body.dark-theme .header-logout-card,
body.dark-theme .extra-menu-tile-final,
body.dark-theme .settings-card {
    border-color: var(--ds-border) !important;
    background: var(--ds-surface-soft) !important;
    color: var(--ds-text) !important;
}

body.dark-theme .header-user-name,
body.dark-theme .header-brand-kicker,
body.dark-theme h1,
body.dark-theme h2,
body.dark-theme h3,
body.dark-theme h4,
body.dark-theme label {
    color: var(--ds-text) !important;
}

body.dark-theme .header-user-label,
body.dark-theme .header-user-role,
body.dark-theme .header-brand-subtitle,
body.dark-theme p,
body.dark-theme .history-page-subtitle,
body.dark-theme .settings-home-subtitle,
body.dark-theme .extra-menu-subtitle,
body.dark-theme .labels-note {
    color: var(--ds-muted) !important;
}

body.dark-theme input:not([type="checkbox"]):not([type="radio"]),
body.dark-theme select,
body.dark-theme textarea {
    border-color: var(--ds-border-strong) !important;
    background: #101722 !important;
    color: var(--ds-text) !important;
}

body.dark-theme option {
    background: #101722 !important;
    color: var(--ds-text) !important;
}

body.dark-theme th {
    background: var(--ds-surface-soft) !important;
    color: #c9d3df !important;
}

body.dark-theme td {
    border-bottom-color: var(--ds-border) !important;
    color: var(--ds-text) !important;
}

body.dark-theme tbody tr:hover > td {
    background: rgba(77, 156, 255, 0.055) !important;
}

body.dark-theme .secondary-btn,
body.dark-theme button.secondary-btn,
body.dark-theme .independent-folder-tabs button {
    border-color: var(--ds-border) !important;
    background: var(--ds-surface-soft) !important;
    color: #d7e0eb !important;
}

body.dark-theme .ds-inv-status-ok-box,
body.dark-theme .inventory-live-status-ok,
body.dark-theme .inventory-today-status-ok {
    border-color: rgba(73, 201, 149, 0.24) !important;
    background: var(--ds-success-soft) !important;
    color: #baf2d8 !important;
}

body.dark-theme .scanner-error,
body.dark-theme .login-error,
body.dark-theme .ds-inv-status-diff-box,
body.dark-theme .ds-inv-status-not-found-box {
    border-color: rgba(239, 103, 108, 0.28) !important;
    background: var(--ds-danger-soft) !important;
    color: #ffc7ca !important;
}

/* Responsive */
@media (max-width: 900px) {
    .pretty-app-header {
        width: calc(100% - 20px);
        grid-template-columns: 1fr auto !important;
        min-height: 72px;
        margin-top: 10px;
        padding: 8px 10px !important;
    }

    .header-user-card {
        display: none !important;
    }

    .header-brand-card {
        justify-self: start !important;
        min-width: 0 !important;
        padding-right: 8px !important;
    }

    .top-nav {
        width: calc(100% - 20px) !important;
        margin-top: 8px !important;
        padding: 8px !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        overscroll-behavior-inline: contain;
        scrollbar-width: none;
    }

    .top-nav::-webkit-scrollbar {
        display: none;
    }

    .top-nav .nav-buttons {
        width: max-content !important;
        min-width: 100% !important;
        justify-content: flex-start !important;
    }

    main {
        padding: 14px 10px 42px !important;
    }

    .grid {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }

    .row {
        flex-wrap: wrap;
    }

    .row > input,
    .row > select {
        min-width: min(100%, 240px);
        flex: 1 1 240px;
    }

    .row > button {
        flex: 0 1 auto;
    }
}

@media (max-width: 640px) {
    .pretty-app-header {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) auto !important;
        flex-wrap: nowrap !important;
        justify-content: initial !important;
    }

    .header-brand-icon {
        width: 42px;
        height: 42px;
        flex-basis: 42px;
        border-radius: 14px;
    }

    .header-brand-kicker {
        font-size: 18px !important;
    }

    .header-brand-subtitle {
        font-size: 11px;
    }

    .header-actions-card {
        gap: 6px !important;
    }

    .theme-toggle-button {
        width: 48px !important;
        min-width: 48px !important;
    }

    .header-logout-card {
        min-width: 62px !important;
        padding: 0 10px !important;
    }

    .top-nav .nav-buttons > button,
    .top-nav button[onclick^="showPage"] {
        height: 40px !important;
        min-height: 40px !important;
        max-height: 40px !important;
        padding: 0 12px !important;
        font-size: 13px !important;
    }

    .card,
    section.card {
        padding: 15px !important;
        border-radius: 15px !important;
    }

    .card > h2:first-child,
    section.card > h2:first-child {
        font-size: 20px !important;
    }

    .action-buttons,
    .modal-actions,
    .inventory-log-controls,
    .history-controls,
    .independent-barcodes-actions,
    .independent-barcodes-toolbar {
        align-items: stretch !important;
    }

    .action-buttons > button,
    .action-buttons > .link-button,
    .inventory-log-controls > button,
    .history-controls > button {
        flex: 1 1 auto;
    }

    .modal,
    .independent-barcode-modal {
        padding: 10px !important;
    }

    .modal-card,
    .independent-barcode-modal-card {
        max-height: calc(100vh - 20px);
        overflow-y: auto;
        padding: 16px !important;
        border-radius: 17px !important;
    }

    .login-card {
        padding: 22px !important;
        border-radius: 22px !important;
    }
}

/* Layout polish after Safari review. */
html body header.app-header.pretty-app-header,
html body nav.top-nav,
html body main {
    box-sizing: border-box !important;
    width: min(1480px, calc(100% - 32px)) !important;
    max-width: 1480px !important;
    margin-left: auto !important;
    margin-right: auto !important;
}

html body main {
    padding-left: 0 !important;
    padding-right: 0 !important;
}

/* Highlight the complete history row, including both sticky columns. */
html body .history-month-table tbody tr:hover > td,
html body .history-month-table tbody tr:focus-within > td {
    background: #e8f3ff !important;
    background-color: #e8f3ff !important;
    color: #163b66 !important;
}

html body .history-month-table tbody tr:hover > td.history-sticky,
html body .history-month-table tbody tr:focus-within > td.history-sticky {
    background: #e8f3ff !important;
    background-color: #e8f3ff !important;
    color: #163b66 !important;
}

html body.dark-theme .history-month-table tbody tr:hover > td,
html body.dark-theme .history-month-table tbody tr:focus-within > td {
    background: #17304e !important;
    background-color: #17304e !important;
    color: #f4f8ff !important;
}

html body.dark-theme .history-month-table tbody tr:hover > td.history-sticky,
html body.dark-theme .history-month-table tbody tr:focus-within > td.history-sticky {
    background: #17304e !important;
    background-color: #17304e !important;
    color: #f4f8ff !important;
}

/* Warehouse administration rows keep labels, checkboxes and actions in fixed tracks. */
section[data-page="warehouses"] > section.grid:first-child {
    grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr) !important;
    gap: 18px !important;
    align-items: start !important;
}

#warehousesList {
    padding: 8px 14px !important;
    overflow-x: visible !important;
}

html body #warehousesList .warehouse-list-row {
    grid-template-columns: minmax(190px, 1fr) 104px 88px auto !important;
    gap: 10px !important;
    min-width: 0 !important;
    padding: 10px 0 !important;
}

html body #warehousesList .warehouse-list-row > input:not([type="checkbox"]) {
    width: 100% !important;
    min-width: 0 !important;
}

html body #warehousesList .warehouse-inline-flag {
    display: grid !important;
    grid-template-columns: 18px minmax(0, auto) !important;
    align-items: center !important;
    justify-content: start !important;
    gap: 7px !important;
    min-width: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    white-space: nowrap !important;
}

html body #warehousesList .warehouse-inline-flag > input[type="checkbox"] {
    box-sizing: border-box !important;
    width: 18px !important;
    min-width: 18px !important;
    max-width: 18px !important;
    height: 18px !important;
    min-height: 18px !important;
    max-height: 18px !important;
    margin: 0 !important;
    padding: 0 !important;
}

html body #warehousesList .warehouse-inline-flag > span {
    display: block !important;
    min-width: 0 !important;
    color: var(--ds-muted) !important;
    font-size: 13px !important;
    line-height: 1.2 !important;
}

html body #warehousesList .warehouse-list-row > .action-buttons {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(88px, auto)) !important;
    flex-wrap: nowrap !important;
    gap: 8px !important;
    margin: 0 !important;
}

section[data-page="warehouses"] .card.form-block > .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 14px !important;
    margin-bottom: 10px !important;
}

section[data-page="warehouses"] .card.form-block > .grid input,
section[data-page="warehouses"] .card.form-block > .grid select,
#transferScanInput {
    box-sizing: border-box !important;
    width: 100% !important;
    min-width: 0 !important;
}

section[data-page="warehouses"] .card.form-block > .action-buttons {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    flex-wrap: wrap !important;
}

/* Extra menu: no clipped tiles and readable hover contents. */
html body section[data-page="extra"] .extra-menu-page-card {
    width: 100% !important;
    max-width: none !important;
}

html body section[data-page="extra"] .extra-menu-grid-final {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: 14px !important;
}

html body section[data-page="extra"] .extra-menu-grid-final > .extra-menu-tile-final {
    height: auto !important;
    min-height: 150px !important;
    max-height: none !important;
    grid-template-rows: auto 1fr !important;
    overflow: visible !important;
}

html body section[data-page="extra"] .extra-menu-grid-final > .extra-menu-tile-final span {
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
}

html body section[data-page="extra"] .extra-menu-grid-final > .extra-menu-tile-final:hover,
html body section[data-page="extra"] .extra-menu-grid-final > .extra-menu-tile-final:focus-visible {
    border-color: #1473e6 !important;
    background: #1473e6 !important;
    color: #ffffff !important;
}

html body section[data-page="extra"] .extra-menu-grid-final > .extra-menu-tile-final:hover span,
html body section[data-page="extra"] .extra-menu-grid-final > .extra-menu-tile-final:hover small,
html body section[data-page="extra"] .extra-menu-grid-final > .extra-menu-tile-final:focus-visible span,
html body section[data-page="extra"] .extra-menu-grid-final > .extra-menu-tile-final:focus-visible small {
    color: #ffffff !important;
}

/* Child pages start below the return action instead of touching it. */
html body main > .page-section > .extra-subpage-back-button-final {
    position: relative !important;
    inset: auto !important;
    float: none !important;
    display: inline-flex !important;
    margin: 0 0 14px 0 !important;
    vertical-align: top !important;
}

html body main > .page-section > .extra-subpage-back-button-final + .card {
    margin-top: 0 !important;
}

#externalInventoryPage,
#externalInventoryPage .external-inventory-card,
#externalInventoryPage .external-inventory-create-box,
#externalInventoryPage .external-inventory-detail {
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
}

#externalInventoryPage .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
}

#externalInventoryPage .external-inventory-title-row,
#externalInventoryPage .external-inventory-detail-head {
    flex-wrap: wrap !important;
    align-items: flex-start !important;
}

#externalInventoryPage .external-inventory-table-wrap {
    max-width: 100% !important;
    overflow: auto !important;
}

@media (max-width: 1100px) {
    html body section[data-page="extra"] .extra-menu-grid-final {
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    }

    html body #warehousesList .warehouse-list-row {
        grid-template-columns: minmax(170px, 1fr) 96px 84px !important;
    }

    html body #warehousesList .warehouse-list-row > .action-buttons {
        grid-column: 1 / -1 !important;
        justify-content: start !important;
    }
}

@media (max-width: 820px) {
    html body header.app-header.pretty-app-header,
    html body nav.top-nav,
    html body main {
        width: calc(100% - 20px) !important;
    }

    section[data-page="warehouses"] > section.grid:first-child,
    section[data-page="warehouses"] .card.form-block > .grid,
    #externalInventoryPage .grid {
        grid-template-columns: 1fr !important;
    }

    html body section[data-page="extra"] .extra-menu-grid-final {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}

@media (max-width: 560px) {
    html body #warehousesList .warehouse-list-row,
    html body section[data-page="extra"] .extra-menu-grid-final {
        grid-template-columns: 1fr !important;
    }

    html body #warehousesList .warehouse-list-row > .action-buttons {
        grid-column: auto !important;
    }
}

/* A status-colored cell keeps its meaning while the hovered row gets a clear blue frame. */
html body .history-month-table tbody tr:hover > td,
html body .history-month-table tbody tr:focus-within > td {
    box-shadow: inset 0 2px #55a9ff, inset 0 -2px #55a9ff !important;
}

html body .history-month-table tbody tr:hover > td:first-child,
html body .history-month-table tbody tr:focus-within > td:first-child {
    border-left: 2px solid #55a9ff !important;
}

html body .history-month-table tbody tr:hover > td:last-child,
html body .history-month-table tbody tr:focus-within > td:last-child {
    border-right: 2px solid #55a9ff !important;
}

html body.dark-theme .history-month-table tbody tr:hover > td,
html body.dark-theme .history-month-table tbody tr:focus-within > td {
    box-shadow: inset 0 2px #74b9ff, inset 0 -2px #74b9ff !important;
}

/* History controls share one baseline and one control height. */
html body #homeHistoryCopyFromHistoryFinal .history-controls,
html body section[data-page="history"] .history-controls {
    display: grid !important;
    grid-template-columns: minmax(190px, 0.85fr) minmax(190px, 0.85fr) minmax(230px, 1fr) auto auto !important;
    align-items: end !important;
    gap: 12px !important;
}

html body #homeHistoryCopyFromHistoryFinal .history-controls > label,
html body section[data-page="history"] .history-controls > label {
    min-width: 0 !important;
    margin: 0 !important;
}

html body #homeHistoryCopyFromHistoryFinal .history-controls input,
html body #homeHistoryCopyFromHistoryFinal .history-controls select,
html body #homeHistoryCopyFromHistoryFinal .history-controls button,
html body section[data-page="history"] .history-controls input,
html body section[data-page="history"] .history-controls select,
html body section[data-page="history"] .history-controls button {
    box-sizing: border-box !important;
    width: 100% !important;
    height: 44px !important;
    min-height: 44px !important;
    max-height: 44px !important;
    margin: 0 !important;
}

html body #homeHistoryCopyFromHistoryFinal .history-controls button,
html body section[data-page="history"] .history-controls button {
    width: auto !important;
    white-space: nowrap !important;
}

/* The brand header is a full-width application bar; content remains centered below. */
html body header.app-header.pretty-app-header {
    width: 100% !important;
    max-width: none !important;
    margin-top: 0 !important;
    border-left: 0 !important;
    border-right: 0 !important;
    border-top: 0 !important;
    border-radius: 0 0 22px 22px !important;
}

@media (max-width: 980px) {
    html body #homeHistoryCopyFromHistoryFinal .history-controls,
    html body section[data-page="history"] .history-controls {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}

@media (max-width: 560px) {
    html body #homeHistoryCopyFromHistoryFinal .history-controls,
    html body section[data-page="history"] .history-controls {
        grid-template-columns: 1fr !important;
    }

    html body #homeHistoryCopyFromHistoryFinal .history-controls button,
    html body section[data-page="history"] .history-controls button {
        width: 100% !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}

/* Stability and Safari compatibility */
.top-nav {
    position: relative !important;
    top: auto !important;
}

button,
.link-button,
.header-brand-card,
.extra-menu-tile-final,
.settings-card,
.card,
section.card {
    transform: none !important;
    transition-property: background-color, border-color, color, box-shadow !important;
}

button:hover,
button:active,
.link-button:hover,
.link-button:active,
.header-brand-card:hover,
.header-brand-card:active,
.extra-menu-tile-final:hover,
.extra-menu-tile-final:active,
.settings-card:hover,
.settings-card:active {
    transform: none !important;
}

.top-nav .nav-buttons > button:hover,
.top-nav .nav-buttons > button:focus-visible {
    border-color: rgba(20, 115, 230, 0.18) !important;
    background: var(--ds-primary-soft) !important;
    color: var(--ds-primary) !important;
}

.top-nav .nav-buttons > button.active,
.top-nav .nav-buttons > button.active-nav-button,
.top-nav .nav-buttons > button[aria-current="page"],
.top-nav .nav-buttons > button.active:hover,
.top-nav .nav-buttons > button.active-nav-button:hover,
.top-nav .nav-buttons > button[aria-current="page"]:hover,
body.dark-theme .top-nav .nav-buttons > button.active,
body.dark-theme .top-nav .nav-buttons > button.active-nav-button,
body.dark-theme .top-nav .nav-buttons > button[aria-current="page"],
body.dark-theme .top-nav .nav-buttons > button.active:hover,
body.dark-theme .top-nav .nav-buttons > button.active-nav-button:hover,
body.dark-theme .top-nav .nav-buttons > button[aria-current="page"]:hover {
    border-color: var(--ds-primary) !important;
    background: var(--ds-primary) !important;
    color: #ffffff !important;
    box-shadow: none !important;
}

.page-section .grid {
    align-items: start !important;
}

.page-section .grid > div {
    min-width: 0 !important;
}

.page-section select:not([multiple]),
.page-section input[type="date"],
.page-section input[type="month"],
.page-section input[type="datetime-local"],
.page-section input[type="number"],
.page-section input[type="text"],
.page-section input:not([type]) {
    height: var(--ds-control-height) !important;
    min-height: var(--ds-control-height) !important;
    max-height: var(--ds-control-height) !important;
}

.page-section select:not([multiple]) {
    padding-right: 38px !important;
    -webkit-appearance: none !important;
    appearance: none !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 12px center !important;
    background-size: 16px 16px !important;
}

body.dark-theme .page-section select:not([multiple]) {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23aab6c5' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3C/svg%3E") !important;
}

/* Restore the established inventory action colors. */
[data-page="inventory"] button.inventory-action-blue-final,
[data-page="inventory"] #inventorySubmitButton {
    border-color: #1d4ed8 !important;
    background: #2563eb !important;
    color: #ffffff !important;
}

[data-page="inventory"] button.inventory-action-blue-final:hover,
[data-page="inventory"] #inventorySubmitButton:hover {
    background: #1d4ed8 !important;
    color: #ffffff !important;
}

[data-page="inventory"] button.inventory-action-red-final {
    border-color: #b91c1c !important;
    background: #dc2626 !important;
    color: #ffffff !important;
}

[data-page="inventory"] button.inventory-action-red-final:hover {
    background: #b91c1c !important;
    color: #ffffff !important;
}

[data-page="inventory"] button.inventory-action-yellow-final,
[data-page="inventory"] #inventoryReloadPageButton {
    border-color: #e5a400 !important;
    background: #f5b700 !important;
    color: #332500 !important;
}

[data-page="inventory"] button.inventory-action-yellow-final:hover,
[data-page="inventory"] #inventoryReloadPageButton:hover {
    background: #e5a400 !important;
    color: #241a00 !important;
}

[data-page="inventory"] .inventory-autofill-stock-btn,
[data-page="inventory"] button[data-no-inventory-autofocus="1"] {
    border-color: var(--ds-border-strong) !important;
    background: var(--ds-surface-soft) !important;
    color: #344054 !important;
}

body.dark-theme [data-page="inventory"] .inventory-autofill-stock-btn,
body.dark-theme [data-page="inventory"] button[data-no-inventory-autofocus="1"] {
    border-color: var(--ds-border-strong) !important;
    background: var(--ds-surface-soft) !important;
    color: #d7e0eb !important;
}

/* Opaque sticky history columns: prevent scrolled cells leaking through in Safari. */
.history-table-wrap,
.home-history-copy-wrap {
    isolation: isolate !important;
    background: #ffffff !important;
}

.history-month-table {
    position: relative !important;
}

.history-month-table .history-sticky,
.history-month-table th.history-sticky,
.history-month-table td.history-sticky {
    z-index: 20 !important;
    overflow: hidden !important;
    background: #ffffff !important;
    background-color: #ffffff !important;
    background-image: none !important;
    background-clip: padding-box !important;
    box-shadow: 5px 0 0 rgba(148, 163, 184, 0.18) !important;
}

.history-month-table thead .history-sticky,
.history-month-table .history-main-header.history-sticky {
    z-index: 40 !important;
    background: #e2e8f0 !important;
    background-color: #e2e8f0 !important;
}

.history-month-table tbody tr:hover > td.history-sticky,
.history-month-table tbody tr:focus-within > td.history-sticky {
    background: #f3f7fc !important;
    background-color: #f3f7fc !important;
    color: var(--ds-text) !important;
}

.history-month-table .history-sku {
    left: 0 !important;
}

.history-month-table .history-name {
    left: 92px !important;
}

body.dark-theme .history-table-wrap,
body.dark-theme .home-history-copy-wrap {
    background: #0b1220 !important;
}

body.dark-theme .history-month-table .history-sticky,
body.dark-theme .history-month-table th.history-sticky,
body.dark-theme .history-month-table td.history-sticky {
    background: #111b2b !important;
    background-color: #111b2b !important;
    color: var(--ds-text) !important;
    box-shadow: 5px 0 0 rgba(77, 156, 255, 0.16) !important;
}

body.dark-theme .history-month-table thead .history-sticky,
body.dark-theme .history-month-table .history-main-header.history-sticky {
    background: #1c2a3d !important;
    background-color: #1c2a3d !important;
}

body.dark-theme .history-month-table tbody tr:hover > td.history-sticky,
body.dark-theme .history-month-table tbody tr:focus-within > td.history-sticky {
    background: #1b2b42 !important;
    background-color: #1b2b42 !important;
    color: #ffffff !important;
}

@media (max-width: 900px) {
    .top-nav {
        position: relative !important;
        top: auto !important;
    }
}

/* Final navigation geometry: legacy hover rules used different heights and caused jumps. */
html body .top-nav .nav-buttons > button.small-btn {
    height: 42px !important;
    min-height: 42px !important;
    max-height: 42px !important;
    margin: 0 !important;
    padding: 0 15px !important;
    border-width: 1px !important;
    line-height: 1 !important;
    font-size: 14px !important;
    font-weight: 670 !important;
    transform: none !important;
}

html body .top-nav .nav-buttons > button.small-btn:hover:not([aria-current="page"]),
html body .top-nav .nav-buttons > button.small-btn:focus-visible:not([aria-current="page"]) {
    border-color: rgba(20, 115, 230, 0.22) !important;
    background: rgba(20, 115, 230, 0.10) !important;
    color: #1473e6 !important;
}

html body .top-nav .nav-buttons > button.small-btn[aria-current="page"],
html body .top-nav .nav-buttons > button.small-btn.active-nav-button,
html body .top-nav .nav-buttons > button.small-btn.active {
    height: 42px !important;
    min-height: 42px !important;
    max-height: 42px !important;
    border-color: #1473e6 !important;
    background: #1473e6 !important;
    color: #ffffff !important;
}

html body.dark-theme .top-nav .nav-buttons > button.small-btn:hover:not([aria-current="page"]),
html body.dark-theme .top-nav .nav-buttons > button.small-btn:focus-visible:not([aria-current="page"]) {
    border-color: rgba(143, 193, 255, 0.30) !important;
    background: rgba(77, 156, 255, 0.14) !important;
    color: #8fc1ff !important;
}

@media (max-width: 640px) {
    html body .top-nav .nav-buttons > button.small-btn,
    html body .top-nav .nav-buttons > button.small-btn[aria-current="page"],
    html body .top-nav .nav-buttons > button.small-btn.active-nav-button,
    html body .top-nav .nav-buttons > button.small-btn.active {
        height: 40px !important;
        min-height: 40px !important;
        max-height: 40px !important;
    }
}
