form[data-app-busy="true"] { opacity: .82; }
form[data-app-busy="true"] [type="submit"] { cursor: wait; }
[data-app-region] { scroll-margin-top: 5rem; }
.scan-input {
    border: 2px solid #cfd8dc;
    border-radius: 12px;
    background: #fff;
    padding: 14px;
    margin-bottom: 1rem;
}
.scan-heading { font-size: 1rem; margin-bottom: 9px; }
.scan-identity { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.scan-identity > div { background: #f4f6f8; border-radius: 8px; padding: 8px 10px; }
.scan-identity span { display: block; color: #68737d; font-size: .72rem; text-transform: uppercase; }
.scan-identity strong { display: block; overflow-wrap: anywhere; }
.scan-actions { display: grid; grid-template-columns: minmax(120px, .4fr) 1fr; gap: 9px; }
.scan-manual-wrap { display: flex; min-width: 0; }
.scan-manual-wrap .form-control { min-height: 50px; border-radius: 8px 0 0 8px; font-size: 1rem; }
.scan-manual-wrap .btn { border-radius: 0 8px 8px 0; }
.scan-touch { min-height: 50px; min-width: 50px; font-weight: 700; }
.scan-camera-region { width: 100%; overflow: hidden; border-radius: 9px; background: #111; margin-top: 10px; }
.scan-feedback { width: 100%; padding: 12px 14px; margin-top: 10px; border-radius: 8px; color: #fff; font-weight: 800; text-align: center; }
.scan-feedback-success { background: #198754; }
.scan-feedback-error { background: #c92a3a; }
.scan-hid-hint { display: block; color: #68737d; margin-top: 8px; }
@media (max-width: 575px) {
    .scan-actions, .scan-identity { grid-template-columns: 1fr; }
}
:root {
    --navbar-h:      56px;
    --sidebar-w:     230px;
    --bottom-nav-h:  64px;

    --primary:       #1a2332;
    --primary-mid:   #243044;
    --accent:        #3b82f6;
    --accent-dark:   #2563eb;
    --success:       #22c55e;
    --warning:       #f59e0b;
    --danger:        #ef4444;
    --muted:         #64748b;

    --bg:            #f0f2f5;
    --card-bg:       #ffffff;
    --border:        #e2e8f0;

    --shadow-sm:     0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md:     0 4px 16px rgba(0,0,0,0.10);
    --shadow-lg:     0 8px 32px rgba(0,0,0,0.14);

    --radius-sm:     6px;
    --radius-md:     12px;
    --radius-lg:     18px;
    --radius-pill:   999px;

    /* Legacy compat */
    --primary-color:    #1a2332;
    --secondary-color:  #3b82f6;
    --success-color:    #22c55e;
    --warning-color:    #f59e0b;
    --danger-color:     #ef4444;
}

*, *::before, *::after { box-sizing: border-box; }

html {
    width: 100%;
    max-width: 100%;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: var(--bg);
    color: #1e293b;
    margin: 0;
    padding: 0;
    width: 100%;
    max-width: 100%;
}

img, video, canvas, svg {
    max-width: 100%;
}

.app-navbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--navbar-h);
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-mid) 100%);
    box-shadow: 0 2px 12px rgba(0,0,0,0.25);
    z-index: 1000;
    transition: transform 0.28s ease;
}

.app-navbar.navbar-hidden {
    transform: translateY(-100%);
}

.nav-inner {
    display: flex;
    align-items: center;
    height: 100%;
    padding: 0 12px;
    gap: 8px;
}

/* Brand */
.app-brand {
    display: flex;
    align-items: center;
    gap: 7px;
    text-decoration: none;
    color: #fff;
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: -0.3px;
    white-space: nowrap;
    flex-shrink: 0;
}
.brand-icon { font-size: 1.2rem; line-height: 1; }
.brand-text  { color: #fff; }

/* Icon buttons (hamburger, search toggle) */
.nav-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(255,255,255,0.12);
    border-radius: var(--radius-sm);
    color: #fff;
    font-size: 1.25rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s;
}
.nav-icon-btn:hover { background: rgba(255,255,255,0.22); }
.hamburger-btn { margin-right: 2px; }

/* Desktop search */
.desktop-search-wrap {
    flex: 1;
    max-width: 420px;
    position: relative;
    display: none;         /* shown via media query */
}

.search-pill-wrap {
    display: flex;
    align-items: center;
    background: rgba(255,255,255,0.14);
    border: 1px solid rgba(255,255,255,0.22);
    border-radius: var(--radius-pill);
    padding: 0 14px;
    height: 38px;
    transition: background 0.2s, border-color 0.2s;
}
.search-pill-wrap:focus-within {
    background: rgba(255,255,255,0.22);
    border-color: rgba(255,255,255,0.45);
}

.search-pill-icon {
    color: rgba(255,255,255,0.7);
    font-size: 0.9rem;
    margin-right: 8px;
    flex-shrink: 0;
}

.search-pill-input {
    flex: 1;
    border: none;
    background: transparent;
    color: #fff;
    font-size: 0.9rem;
    outline: none;
    min-width: 0;
}
.search-pill-input::placeholder { color: rgba(255,255,255,0.55); }

/* Right controls */
.nav-right {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}

/* Desktop inline username + logout */
.nav-username {
    color: rgba(255,255,255,0.88);
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
}
.nav-username i { opacity: 0.8; margin-right: 2px; }

.nav-logout-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 34px;
    padding: 0 14px;
    border-radius: var(--radius-pill);
    border: 1px solid rgba(255,255,255,0.3);
    color: #fff;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.15s;
    white-space: nowrap;
}
.nav-logout-btn:hover {
    background: rgba(255,255,255,0.18);
    color: #fff;
}

/* User chip (mobile only) */
.user-chip-wrap { position: relative; }

.user-chip {
    display: flex;
    align-items: center;
    gap: 7px;
    height: 38px;
    padding: 0 10px;
    border: none;
    border-radius: var(--radius-pill);
    background: rgba(255,255,255,0.14);
    color: #fff;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.15s;
}
.user-chip:hover { background: rgba(255,255,255,0.24); }

.user-initials {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.user-name  { font-weight: 500; }
.chevron    { font-size: 0.7rem; opacity: 0.7; }

/* User dropdown */
.user-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 200px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 1060;
    overflow: hidden;
}
.user-dropdown.show { display: block; }

.user-dropdown-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
}
.user-initials-lg {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    flex-shrink: 0;
}

.user-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 16px;
    color: #334155;
    text-decoration: none;
    font-size: 0.9rem;
    transition: background 0.12s;
}
.user-dropdown-item:hover { background: #f1f5f9; color: #334155; }
.user-dropdown-item.text-danger:hover { background: #fef2f2; }

.user-dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: 2px 0;
}

.mobile-search-bar {
    position: fixed;
    top: var(--navbar-h);
    left: 0; right: 0;
    background: rgba(26, 35, 50, 0.92);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 10px 12px;
    z-index: 999;
    transform: translateY(-110%);
    transition: transform 0.25s ease, opacity 0.25s ease;
    opacity: 0;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
.mobile-search-bar.open {
    transform: translateY(0);
    opacity: 1;
}
.mobile-search-bar.navbar-hidden {
    transform: translateY(calc(-100% - var(--navbar-h)));
}

.mobile-search-inner {
    display: flex;
    align-items: center;
    background: rgba(255,255,255,0.13);
    border: 1px solid rgba(255,255,255,0.22);
    border-radius: var(--radius-pill);
    padding: 0 12px;
    height: 42px;
    gap: 8px;
}
.mobile-search-icon { color: rgba(255,255,255,0.6); font-size: 0.95rem; }

.mobile-search-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: #fff;
    font-size: 1rem;
    min-width: 0;
}
.mobile-search-input::placeholder { color: rgba(255,255,255,0.5); }

.mobile-search-close {
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    font-size: 0.95rem;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
}

.mobile-results {
    margin-top: 6px;
    max-height: 55vh;
    overflow-y: auto;
}

.search-results-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 9999;
    max-height: 340px;
    overflow-y: auto;
    display: none;
}
.search-results-dropdown.show { display: block; }

.search-group-header {
    padding: 6px 14px;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
}
.search-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    color: #1e293b;
    text-decoration: none;
    border-bottom: 1px solid #f1f5f9;
    font-size: 0.875rem;
    transition: background 0.1s;
}
.search-item:hover { background: #eff6ff; color: #1e293b; }
.search-item:last-child { border-bottom: none; }
.search-no-results {
    padding: 16px;
    text-align: center;
    color: var(--muted);
    font-size: 0.875rem;
}

.sidebar {
    position: fixed;
    top: var(--navbar-h);
    left: 0;
    bottom: 0;
    width: var(--sidebar-w);
    background: #fff;
    border-right: 1px solid var(--border);
    z-index: 100;
    overflow-y: auto;
    padding: 0;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-mid) 100%);
    flex-shrink: 0;
}
.sidebar-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-username {
    color: #fff;
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-role { font-size: 0.7rem; margin-top: 2px; }

.sidebar-close-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    border-radius: var(--radius-sm);
    color: rgba(255,255,255,0.85);
    width: 30px;
    height: 30px;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    cursor: pointer;
    flex-shrink: 0;
}

.sidebar-nav { flex: 1; padding: 8px 0; }

.sidebar-nav .nav-section {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #94a3b8;
    padding: 14px 16px 4px;
    list-style: none;
}

.sidebar-nav .nav-link {
    font-size: 0.92rem;
    font-weight: 500;
    color: #475569;
    padding: 11px 16px;
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-radius: 0;
    transition: background 0.12s, color 0.12s;
    border-left: 3px solid transparent;
    text-decoration: none;
}
.sidebar-nav .nav-link:hover {
    background: #f1f5f9;
    color: var(--accent);
}
.sidebar-nav .nav-link.active {
    background: #eff6ff;
    color: var(--accent);
    border-left-color: var(--accent);
    font-weight: 600;
}
.sidebar-nav .nav-link i {
    width: 18px;
    text-align: center;
    font-size: 1rem;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1040;
}
.sidebar-overlay.show { display: block; }

.main-content {
    margin-left: var(--sidebar-w);
    margin-top: var(--navbar-h);
    padding: 24px;
    min-height: calc(100vh - var(--navbar-h));
    min-width: 0;
    max-width: calc(100vw - var(--sidebar-w));
}

/* Prevent intrinsic widths (notably fieldsets and editable tables) from
   propagating to the page viewport. Wide tables scroll in their own wrapper. */
.main-content > *,
.main-content form,
.main-content fieldset,
.main-content .container,
.main-content .container-fluid,
.main-content .row,
.main-content .row > *,
.main-content [class*="col-"],
.main-content .d-flex,
.main-content .input-group,
.main-content .list-group-item,
.main-content .card,
.main-content .card-header,
.main-content .card-body {
    min-width: 0;
    max-width: 100%;
}

.main-content fieldset {
    width: 100%;
    min-inline-size: 0;
}

.main-content .d-flex > * {
    min-width: 0;
}

.main-content .alert,
.main-content .card-header,
.main-content .card-body,
.main-content .breadcrumb-item,
.main-content h1,
.main-content h2,
.main-content h3,
.main-content h4,
.main-content h5,
.main-content p,
.main-content a {
    overflow-wrap: anywhere;
}

.main-content .alert,
.main-content .badge,
.main-content .form-check-label,
.main-content .list-group-item,
.main-content td {
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.login-wrap {
    margin-top: var(--navbar-h);
    padding: 20px;
}

/* ── Breadcrumbs ── */
.crumb-bar {
    margin-bottom: 14px;
}
.crumb-bar .breadcrumb {
    font-size: 0.82rem;
    background: transparent;
    padding: 0;
    flex-wrap: wrap;
}
.crumb-bar .breadcrumb-item a {
    color: var(--muted);
    text-decoration: none;
}
.crumb-bar .breadcrumb-item a:hover { color: var(--accent); }
.crumb-bar .breadcrumb-item.active { color: #334155; font-weight: 600; }
.crumb-bar .breadcrumb-item + .breadcrumb-item::before { color: #cbd5e1; }

/* ── Section sub-navigation tabs ── */
.section-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0;
}
.section-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 14px;
    font-size: 0.88rem;
    font-weight: 500;
    color: #475569;
    text-decoration: none;
    border-radius: 8px 8px 0 0;
    border-bottom: 2px solid transparent;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
    min-height: 40px;
    min-width: 0;
    overflow-wrap: anywhere;
}
.section-tab:hover {
    background: #f1f5f9;
    color: var(--accent);
}
.section-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: 600;
}
.section-tab i { font-size: 1rem; }

/* ── "More" hub tiles ── */
.more-tile { transition: box-shadow 0.15s, transform 0.15s; }
.more-tile:hover { box-shadow: 0 4px 20px rgba(0,0,0,0.12); transform: translateY(-2px); }
.more-tile .card-body { padding: 22px 12px; }
.more-tile i { font-size: 2rem; display: block; margin-bottom: 10px; }
.more-tile-label { font-weight: 600; color: #334155; font-size: 0.9rem; }

.card {
    background: var(--card-bg);
    border: none;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
    transition: box-shadow 0.2s;
}
.card:hover { box-shadow: 0 4px 20px rgba(0,0,0,0.10); }

.card-header {
    background: #fff;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    border-radius: var(--radius-md) var(--radius-md) 0 0 !important;
    padding: 14px 18px;
}
.card-body { padding: 18px; }
.card-body.p-0 { padding: 0; }

.table-responsive {
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    contain: inline-size;
}

.table-responsive > .table {
    margin-bottom: 0;
}

.purchase-lines-scroll > .table {
    min-width: 1120px;
}

.document-upload,
.prep-wizard,
.quick-pick-page,
.prep-edit-form {
    width: 100%;
    min-width: 0;
}

.ocr-error-message {
    white-space: pre-wrap;
}

.traceability-chain > *,
.product-choice,
.product-choice label,
.scanner-result,
.scanner-result .alert,
#overlayContent {
    min-width: 0;
    max-width: 100%;
}

.scanner-result {
    overflow-x: auto;
    overscroll-behavior-x: contain;
}

.scanner-result .table {
    min-width: 320px;
}

#reader,
#reader > *,
#reader video,
#reader canvas {
    min-width: 0 !important;
    max-width: 100% !important;
}

#reader {
    overflow: hidden;
}

.traceability-chain .badge,
.traceability-chain a,
.product-choice label {
    overflow-wrap: anywhere;
    white-space: normal;
}

.scanner-result-table {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
}

.scanner-result-table > table {
    min-width: 360px;
}

.btn {
    border-radius: 8px;
    font-weight: 500;
    transition: all 0.15s;
    max-width: 100%;
    white-space: normal;
}
.btn-primary {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
    border-color: var(--accent-dark);
}
.btn-primary:hover {
    background: linear-gradient(135deg, var(--accent-dark) 0%, #1d4ed8 100%);
    border-color: #1d4ed8;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59,130,246,0.4);
}

/* Back button — used on all inner pages */
.btn-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 50%;
    background: #fff;
    border: 1px solid var(--border);
    color: #475569;
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
    text-decoration: none;
    transition: all 0.15s;
    font-size: 1rem;
}
.btn-back:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    box-shadow: 0 4px 12px rgba(59,130,246,0.35);
    transform: translateY(-1px);
}

/* Keep outline buttons looking clean */
.btn-outline-secondary { border-color: var(--border); }

.table {
    margin-bottom: 0;
}
.table thead th {
    font-weight: 600;
    background: #f8fafc;
    border-bottom: 2px solid var(--border);
    vertical-align: middle;
    white-space: nowrap;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}
.table td, .table th {
    vertical-align: middle;
    padding: 0.75rem;
}
.table-hover tbody tr:hover { background: #f8fafc; }
.allocation-table tr.expired    { background: #fef2f2; }
.allocation-table tr.expiring-soon { background: #fefce8; }

.form-control, .form-select {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    transition: border-color 0.15s, box-shadow 0.15s;
    min-width: 0;
    max-width: 100%;
}

.input-group {
    min-width: 0;
    max-width: 100%;
}

.input-group > .form-control,
.input-group > .form-select {
    min-width: 0;
}

input[type="file"] {
    max-width: 100%;
}
.form-control:focus, .form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
.form-label {
    font-weight: 500;
    font-size: 0.85rem;
    color: #475569;
    margin-bottom: 4px;
}

.mobile-bottom-nav {
    display: none;
}

.toast-stack {
    position: fixed;
    top: calc(var(--navbar-h) + 14px);
    right: 16px;
    z-index: 11000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 360px;
    width: calc(100vw - 32px);
}

.app-toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    font-size: 0.9rem;
    font-weight: 500;
    opacity: 0;
    transform: translateX(20px);
    transition: opacity 0.25s ease, transform 0.25s ease;
}
.app-toast.show { opacity: 1; transform: translateX(0); }
.app-toast i { font-size: 1.1rem; flex-shrink: 0; }

.app-toast-success  { background: #dcfce7; color: #166534; }
.app-toast-danger   { background: #fee2e2; color: #991b1b; }
.app-toast-warning  { background: #fef9c3; color: #854d0e; }
.app-toast-info     { background: #dbeafe; color: #1e40af; }

.toast-x {
    margin-left: auto;
    background: none;
    border: none;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    opacity: 0.6;
    flex-shrink: 0;
}
.toast-x:hover { opacity: 1; }

.page-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.page-header h2 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    flex: 1;
}
.page-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* Backward-compat with existing d-flex.justify-content-between pattern */
.d-flex.justify-content-between.align-items-center {
    margin-bottom: 20px;
    gap: 8px;
    flex-wrap: wrap;
}

.badge-status-planned    { background: #94a3b8; }
.badge-status-in_progress { background: var(--accent); }
.badge-status-completed  { background: var(--success); }
.badge-status-canceled   { background: var(--danger); }

.inventory-indicator {
    width: 10px; height: 10px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 5px;
}
.inventory-indicator.ok  { background: var(--success); }
.inventory-indicator.low { background: var(--danger); }

.temp-ok      { color: var(--success); }
.temp-warning { color: var(--danger); font-weight: bold; }

.alert-card           { border-left: 4px solid; }
.alert-card.low-stock { border-left-color: var(--danger); }
.alert-card.expiring  { border-left-color: var(--warning); }

.step-list {
    list-style: none;
    padding: 0;
}
.step-list li {
    padding: 10px 15px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.step-list li.completed    { background: #dcfce7; }
.step-list li.required::before {
    content: "*";
    color: var(--danger);
    margin-right: 5px;
}

.login-container {
    max-width: 400px;
    margin: 60px auto;
}
.login-card   { padding: 30px; }
.login-logo   { text-align: center; margin-bottom: 30px; }
.login-logo h1 { color: var(--primary); font-weight: 700; }

.print-only { display: none; }

@media print {
    .sidebar, .app-navbar, .mobile-bottom-nav, .no-print { display: none !important; }
    .main-content { margin: 0; padding: 0; }
    .print-only   { display: block; }
}

.priority-strip {
    background: #fffbf0;
    border: 1px solid #f0e8c0;
    border-radius: var(--radius-md);
    padding: 12px 16px;
}
.priority-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 14px;
    border-radius: var(--radius-pill);
    font-size: 0.82rem;
    font-weight: 500;
    text-decoration: none;
    transition: opacity 0.15s;
}
.priority-pill:hover { opacity: 0.85; }
.pill-red    { background: #fde8e8; color: #c0392b; border: 1px solid #f5b8b8; }
.pill-blue   { background: #e8f3ff; color: #1a6fb5; border: 1px solid #b8d4f5; }
.pill-orange { background: #fff3e0; color: #b7570a; border: 1px solid #f5d8b0; }

.quick-action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 14px 10px;
    font-size: 0.82rem;
    line-height: 1.3;
    min-height: 80px;
    border-radius: var(--radius-md);
    font-weight: 500;
}
.quick-actions-grid {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.weekly-rhythm {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 50px;
}
.rhythm-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 2px;
}
.rhythm-bar {
    width: 100%;
    background: var(--accent);
    border-radius: 2px 2px 0 0;
    min-height: 2px;
    transition: height 0.3s;
}
.rhythm-col.today .rhythm-bar { background: var(--success); }
.rhythm-label { font-size: 0.65rem; color: #999; text-align: center; }
.rhythm-col.today .rhythm-label { color: var(--success); font-weight: 700; }

.stock-traffic-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 6px;
}
.stock-item {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    overflow: hidden;
}
.stock-item.red    { background: #fde8e8; }
.stock-item.yellow { background: #fef9e7; }
.stock-item.green  { background: #eafaf1; }
.traffic-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.traffic-dot.red    { background: var(--danger); }
.traffic-dot.yellow { background: var(--warning); }
.traffic-dot.green  { background: var(--success); }
.stock-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.stock-qty { font-weight: 600; font-size: 0.78rem; flex-shrink: 0; }

@media (min-width: 992px) {
    .hamburger-btn        { display: none !important; }
    .sidebar-close-btn    { display: none !important; }
    .sidebar-overlay      { display: none !important; }
    .desktop-search-wrap  { display: block; }
    .sidebar-header       { display: flex; }

    .app-brand {
        /* On desktop, brand left-aligned, no absolute centering needed */
        position: static;
        transform: none;
        margin-right: 16px;
    }
}

@media (max-width: 991px) {

    /* Navbar: brand centered */
    .app-brand {
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        font-size: 1rem;
    }
    .brand-icon { display: none; }

    /* Sidebar flies in from left */
    .sidebar {
        top: 0;
        width: 280px;
        left: -290px;
        z-index: 1050;
        transition: left 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        padding-top: 0;
    }
    .sidebar.show { left: 0; }
    .sidebar-close-btn { display: flex; }

    /* Main content uses full width */
    .main-content {
        margin-left: 0;
        padding: 14px 14px calc(var(--bottom-nav-h) + 14px);
        width: 100%;
        max-width: 100vw;
    }

    /* Bottom nav visible */
    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        height: var(--bottom-nav-h);
        background: #fff;
        border-top: 1px solid var(--border);
        box-shadow: 0 -2px 12px rgba(0,0,0,0.08);
        z-index: 1030;
        justify-content: space-around;
        align-items: stretch;
        width: 100%;
        max-width: 100vw;
        min-width: 0;
        overflow: hidden;
    }

    .bottom-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        flex: 1;
        color: var(--muted);
        text-decoration: none;
        font-size: 0.65rem;
        gap: 3px;
        padding-bottom: env(safe-area-inset-bottom, 0px);
        transition: color 0.15s;
        position: relative;
        min-width: 0;
        max-width: 20%;
        overflow: hidden;
    }
    .bottom-nav-item i { font-size: 1.35rem; }
    .bottom-nav-item span {
        display: block;
        width: 100%;
        line-height: 1;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        text-align: center;
    }
    .bottom-nav-item.active { color: var(--accent); }
    .bottom-nav-item.active::before {
        content: '';
        position: absolute;
        top: 0; left: 20%; right: 20%;
        height: 3px;
        background: var(--accent);
        border-radius: 0 0 3px 3px;
    }

    /* Toast above bottom nav */
    .toast-stack {
        top: auto;
        bottom: calc(var(--bottom-nav-h) + 10px);
        right: 12px;
        max-width: calc(100vw - 24px);
    }

    /* Touch targets */
    .btn { min-height: 44px; }
    .btn-sm { min-height: 38px; width: auto !important; }
    .table .btn-sm, td .btn-sm { min-height: 36px; width: auto !important; flex: none !important; }
    .form-control, .form-select { min-height: 46px; font-size: 16px; }

    /* Legacy table fallback: when an older template has not opted into
       .table-responsive yet, keep any overflow inside its card container
       instead of allowing the whole page viewport to expand. */
    .card-body { overflow-x: auto; }
    .card-body.p-0 { overflow-x: auto; }

    /* Responsive stacked-card tables (mobile — list tables without form inputs) */
    .table-mobile-cards { width: 100%; display: block; overflow-x: visible; }
    .table-mobile-cards thead { display: none; }
    .table-mobile-cards tbody { display: block; width: 100%; }

    .table-mobile-cards tbody tr {
        display: block;
        background: #fff;
        border: 1px solid var(--border);
        border-radius: var(--radius-md);
        margin-bottom: 10px;
        padding: 6px 14px;
        box-shadow: var(--shadow-sm);
    }
    .table-mobile-cards tbody tr.expired       { background: #fef2f2; border-color: #fca5a5; }
    .table-mobile-cards tbody tr.expiring-soon { background: #fefce8; border-color: #fde68a; }

    .table-mobile-cards tbody td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        padding: 7px 0;
        border: none;
        border-bottom: 1px solid #f1f5f9;
        font-size: 0.875rem;
        min-height: 0;
        text-align: right;
        min-width: 0 !important;
        overflow-wrap: anywhere;
    }
    .table-mobile-cards tbody td > * { min-width: 0; max-width: 100%; }
    .table-mobile-cards tbody td:last-child {
        border-bottom: none;
        padding-top: 10px;
    }

    .table-mobile-cards tbody td::before {
        content: attr(data-label);
        font-size: 0.70rem;
        font-weight: 700;
        color: var(--muted);
        text-transform: uppercase;
        letter-spacing: 0.05em;
        text-align: left;
        flex-shrink: 0;
        min-width: 80px;
    }
    .table-mobile-cards tbody td[data-label=""]::before { display: none; }
    .table-mobile-cards tbody td[data-label=""] {
        justify-content: flex-end;
        flex-wrap: wrap;
        gap: 8px;
    }
    /* Glove-friendly tap targets: Bootstrap's .btn-sm (~30px) is too small to
       hit reliably wearing work gloves, so every action button in a mobile
       card row gets a wider hit area regardless of its desktop size class. */
    .table-mobile-cards tbody td[data-label=""] .btn {
        min-height: 44px;
        min-width: 44px;
        padding: 0.5rem 0.9rem;
        font-size: 0.9rem;
    }

    .table-mobile-cards tbody td[colspan] {
        display: block;
        text-align: center;
        border-bottom: none;
    }
    .table-mobile-cards tbody td[colspan]::before { display: none; }

    .table td, .table th { padding: 0.5rem; font-size: 0.875rem; }

    /* Page headers keep as flex-row */
    .d-flex.justify-content-between.align-items-center {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
        margin-bottom: 16px;
    }
    .d-flex.justify-content-between.align-items-center > a.btn,
    .d-flex.justify-content-between.align-items-center > button.btn,
    .d-flex.justify-content-between.align-items-center > div.d-flex {
        flex-shrink: 1;
        max-width: 100%;
    }

    h2 { font-size: 1.3rem; }

    /* Step list */
    .step-list li {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .step-list li form { width: 100%; }
    .step-list li form .d-flex { flex-wrap: wrap; }

    /* Row spacing */
    .row > [class*='col-'] { margin-bottom: 14px; }

    /* Login */
    .login-container { margin: 20px auto; padding: 0 15px; }

    /* Dashboard */
    .stock-traffic-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
    .quick-action-btn   { min-height: 65px; font-size: 0.78rem; }

    /* Mobile card views */
    .card-mobile { display: none; }
    .mobile-card-view .table { display: none; }
    .mobile-card-view .card-mobile { display: block; }

    .mobile-item-card {
        background: #fff;
        border-radius: var(--radius-md);
        padding: 14px;
        margin-bottom: 10px;
        box-shadow: var(--shadow-sm);
    }
    .mobile-item-card .item-title {
        font-weight: 600;
        font-size: 1rem;
        margin-bottom: 6px;
        color: var(--primary);
    }
    .mobile-item-card .item-details { font-size: 0.88rem; color: #64748b; }
    .mobile-item-card .item-details span { display: block; margin-bottom: 3px; }
    .mobile-item-card .item-actions {
        margin-top: 10px;
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }
    .mobile-item-card .item-actions .btn { flex: 1; min-width: 80px; }

    /* Table responsive */
    .table-responsive-mobile {
        display: block;
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .scanner-result-table > table {
        min-width: 320px;
    }
}

@media (max-width: 430px) {
    .main-content {
        padding-left: 10px;
        padding-right: 10px;
    }

    .card-header,
    .card-body {
        padding-left: 14px;
        padding-right: 14px;
    }
    .card-body.p-0 { padding-left: 0; padding-right: 0; }

    .main-content h2 { font-size: 1.2rem; }
    .main-content .display-4 { font-size: 2rem; }

    .document-page-header,
    .supplier-order-header,
    .scanner-page-header,
    .prep-report-header,
    .traceability-header {
        align-items: stretch !important;
        flex-direction: column;
    }

    .document-actions,
    .prep-detail-actions,
    .prep-list-actions,
    .supplier-order-actions,
    .scanner-page-actions,
    .prep-edit-actions {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }

    .document-actions > *,
    .document-actions form,
    .document-actions .btn,
    .prep-detail-actions > *,
    .prep-detail-actions form,
    .prep-detail-actions .btn,
    .prep-list-actions > *,
    .prep-list-actions .btn,
    .supplier-order-actions > *,
    .supplier-order-actions .btn,
    .scanner-page-actions > *,
    .scanner-page-actions .btn,
    .prep-edit-actions > *,
    .prep-edit-actions .btn,
    .document-list-add {
        width: 100% !important;
    }

    .scanner-page-header > h2,
    .prep-report-header > h2,
    .traceability-header > h2,
    .scanner-page-header > .btn:not(.btn-back),
    .prep-report-header > .btn,
    .traceability-header > .btn,
    .document-review-save,
    .document-post-button {
        width: 100% !important;
    }

    .scanner-page-header > .btn-back {
        display: none;
    }

    .purchase-filter-actions,
    .prep-upload-form,
    .wizard-actions,
    .scanner-scale-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .purchase-filter-actions > *,
    .prep-upload-form > *,
    .wizard-actions > *,
    .scanner-scale-actions > * {
        width: 100% !important;
        flex: 1 1 auto !important;
    }

    .prep-report-filter > [class*="col-"] {
        flex: 0 0 100%;
        width: 100%;
    }

    .traceability-chain {
        align-items: stretch !important;
        flex-direction: column;
    }
    .traceability-chain > .bi-arrow-right {
        transform: rotate(90deg);
        align-self: center;
    }
    .traceability-chain .badge {
        width: 100%;
        text-align: left;
    }

    .prep-inline-form > [class*="col-"],
    .prep-detail-grid > [class*="col-"] {
        flex: 0 0 100%;
        width: 100%;
    }

    .prep-status-toolbar .ms-auto {
        display: none;
    }

    .prep-card-actions {
        flex-wrap: wrap;
    }
    .prep-card-actions .btn {
        flex: 1 1 120px !important;
    }

    .purchase-lines-scroll > .table {
        min-width: 1080px;
    }
}
