/* ============================================================
   CTA [24/06/2026], INTRANET-TORRIBAS, look & feel Business Central (Fluent).
   Re-themes the validated mockup to BC: Segoe UI, Fluent palette, app bar,
   command bar, dense list view, FactBox-style cards, 2px radii, subtle shadows.
   Class names kept from the mockup so migrated Twig views work unchanged.
   Tokens approximate Dynamics 365 BC; replace with Marc's official pantones when provided.
   ============================================================ */

:root {
    --bc-blue: #00188F;          /* deep Dynamics blue — app bar / brand */
    --bc-accent: #0078D4;        /* Fluent communication blue — primary actions, links, active */
    --bc-accent-hover: #106EBE;
    --bc-bg: #FAF9F8;            /* app background */
    --bc-surface: #FFFFFF;       /* cards, lists */
    --bc-border: #EDEBE9;        /* separators */
    --bc-border-strong: #C8C6C4;
    --bc-row-hover: #F3F2F1;
    --bc-text: #201F1E;
    --bc-text-sec: #605E5C;
    --bc-pos: #107C10;          /* green: positive / done */
    --bc-pos-bg: #DFF6DD;
    --bc-neg: #A4262C;          /* red: negative / error */
    --bc-neg-bg: #FDE7E9;
    --bc-warn: #FFB900;
    --bc-warn-bg: #FFF4CE;
    --bc-info-bg: #EFF6FC;
    --radius: 2px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
    font-family: "Segoe UI", "Segoe UI Web (West European)", -apple-system, system-ui, Roboto, Helvetica, Arial, sans-serif;
    background: var(--bc-bg);
    color: var(--bc-text);
    min-height: 100vh;
    font-size: 14px;
    font-variant-numeric: tabular-nums;
}

/* Optional demo bar — only shown when body has class .is-demo */
.demo-bar { display: none; }
body.is-demo .demo-bar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 9999;
    background: var(--bc-warn); color: #3b2f00; height: 26px;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 1rem; font-size: 0.75rem; font-weight: 600; letter-spacing: 1px;
}
body.is-demo { padding-top: 26px; }

.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; flex-direction: column; }

/* ==================== APP BAR (BC) ==================== */
.header {
    background: var(--bc-blue);
    color: #fff; padding: 0 1rem; min-height: 48px;
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: 0.5rem;
}
.header-left { display: flex; align-items: center; gap: 0.6rem; }
.header-left .logo-small { height: 24px; }
.header-left .back-btn {
    background: transparent; border: none; color: #fff;
    width: 40px; height: 40px; font-size: 1.2rem; cursor: pointer;
    display: flex; align-items: center; justify-content: center; text-decoration: none;
    border-radius: var(--radius);
}
.header-left .back-btn:hover { background: rgba(255,255,255,0.15); }
.header h1 { font-size: 1rem; font-weight: 600; }
.header .warehouse-badge {
    background: rgba(255,255,255,0.18); padding: 0.2rem 0.6rem;
    border-radius: var(--radius); font-size: 0.75rem; font-weight: 600;
}
.header-right { display: flex; align-items: center; gap: 0.8rem; }
.brand-torribas { height: 22px; opacity: 0.95; }
.user-menu { font-size: 0.8rem; color: rgba(255,255,255,0.9); display: flex; align-items: center; gap: 0.6rem; }
.user-menu a { color: #fff; text-decoration: none; opacity: 0.85; }
.user-menu a:hover { opacity: 1; text-decoration: underline; }

.date-picker-wrapper {
    display: flex; align-items: center; gap: 0.4rem;
    background: rgba(255,255,255,0.15); padding: 0.3rem 0.6rem; border-radius: var(--radius);
}
.date-picker-wrapper label { font-size: 0.75rem; opacity: 0.85; color: #fff; }
.date-picker-wrapper input[type="date"] {
    background: transparent; border: none; color: #fff;
    font-size: 0.9rem; font-family: inherit; cursor: pointer; outline: none;
}
.date-picker-wrapper input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1); cursor: pointer; }

/* ==================== COMMAND BAR (ribbon-lite) ==================== */
.command-bar {
    display: flex; align-items: center; gap: 0.25rem; flex-wrap: wrap;
    background: var(--bc-surface); border-bottom: 1px solid var(--bc-border);
    padding: 0.25rem 1rem; min-height: 40px;
}
.command-bar .cmd {
    display: inline-flex; align-items: center; gap: 0.35rem;
    background: transparent; border: none; color: var(--bc-text);
    padding: 0.35rem 0.7rem; font-size: 0.85rem; cursor: pointer; border-radius: var(--radius);
    font-family: inherit; text-decoration: none;
}
.command-bar .cmd:hover { background: var(--bc-row-hover); }
.command-bar .cmd.primary { color: var(--bc-accent); font-weight: 600; }

/* ==================== LANDING (warehouse / mode select) ==================== */
#screen-warehouse, #screen-mode {
    justify-content: center; align-items: center; background: var(--bc-bg); color: var(--bc-text);
}
.warehouse-selector { text-align: center; padding: 2rem; max-width: 760px; }
.warehouse-selector .logo { height: 40px; margin-bottom: 1.25rem; }
.warehouse-selector h1 { font-size: 1.6rem; margin-bottom: 0.4rem; font-weight: 600; color: var(--bc-blue); }
.warehouse-selector p { font-size: 0.95rem; color: var(--bc-text-sec); margin-bottom: 2rem; }
.warehouse-cards, .mode-cards { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; }
.warehouse-card, .mode-card {
    background: var(--bc-surface); border: 1px solid var(--bc-border);
    border-top: 3px solid var(--bc-accent);
    border-radius: var(--radius); padding: 1.5rem 2rem; cursor: pointer;
    transition: box-shadow 0.15s, transform 0.15s; min-width: 190px;
    text-decoration: none; color: var(--bc-text); display: block;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
.warehouse-card:hover, .mode-card:hover { box-shadow: 0 3px 10px rgba(0,0,0,0.14); transform: translateY(-2px); }
.warehouse-card .icon, .mode-card .icon { font-size: 2rem; margin-bottom: 0.5rem; }
.warehouse-card .name, .mode-card .name { font-size: 1.05rem; font-weight: 600; margin-bottom: 0.15rem; color: var(--bc-blue); }
.warehouse-card .code, .mode-card .code { font-size: 0.75rem; color: var(--bc-text-sec); }

/* ==================== CONTENT ==================== */
.content { flex: 1; padding: 1rem 1.25rem; max-width: 1200px; margin: 0 auto; width: 100%; }
.content-title { font-size: 0.85rem; color: var(--bc-text-sec); margin-bottom: 0.75rem; }
.content-title strong { color: var(--bc-blue); }

/* Card grid (touch-friendly list, BC-themed) */
.reception-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 0.75rem; }
.reception-card, .transfer-card {
    background: var(--bc-surface); border: 1px solid var(--bc-border);
    border-left: 3px solid var(--bc-warn); border-radius: var(--radius);
    padding: 0.9rem 1rem; cursor: pointer; position: relative; min-height: 90px;
    text-decoration: none; color: var(--bc-text); display: block;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06); transition: box-shadow 0.15s;
}
.reception-card:hover, .transfer-card:hover { box-shadow: 0 3px 10px rgba(0,0,0,0.12); }
.reception-card.completed, .transfer-card.transfer-sent { border-left-color: var(--bc-pos); }
.transfer-card { border-left-color: var(--bc-accent); margin-bottom: 0.6rem; }
.reception-card .supplier-name, .transfer-card .supplier-name {
    font-size: 0.95rem; font-weight: 600; color: var(--bc-blue); margin-bottom: 0.3rem; padding-right: 80px;
}
.reception-card .order-number, .transfer-card .order-number { font-size: 0.78rem; color: var(--bc-text-sec); margin-bottom: 0.45rem; }
.reception-card .card-details, .transfer-card .card-details { display: flex; gap: 1rem; font-size: 0.82rem; color: var(--bc-text-sec); flex-wrap: wrap; }
.status-badge {
    position: absolute; top: 0.8rem; right: 0.8rem;
    padding: 0.15rem 0.5rem; border-radius: var(--radius);
    font-size: 0.68rem; font-weight: 600; text-transform: uppercase;
}
.status-badge.pending { background: var(--bc-warn-bg); color: #8a6d00; }
.status-badge.done { background: var(--bc-pos-bg); color: var(--bc-pos); }
.status-badge.partial, .status-badge.sent { background: var(--bc-info-bg); color: var(--bc-accent); }

/* ==================== DETAIL ==================== */
.detail-header {
    background: var(--bc-surface); padding: 0.8rem 1.25rem; border-bottom: 1px solid var(--bc-border);
    display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.8rem;
}
.detail-info { display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap; }
.detail-info .info-block { display: flex; flex-direction: column; }
.detail-info .info-block small { font-size: 0.68rem; color: var(--bc-text-sec); text-transform: uppercase; letter-spacing: 0.4px; }
.detail-info .info-block strong { font-size: 0.9rem; color: var(--bc-blue); }

.truck-input {
    display: flex; align-items: center; gap: 0.5rem;
    background: var(--bc-warn-bg); border: 1px solid var(--bc-warn); border-radius: var(--radius); padding: 0.4rem 0.8rem;
}
.truck-input label { font-size: 0.82rem; font-weight: 600; color: #8a6d00; white-space: nowrap; }
.truck-input input {
    border: none; background: transparent; font-size: 1.1rem; font-weight: 600;
    width: 180px; outline: none; text-transform: uppercase;
    font-family: "Consolas", "Courier New", monospace; letter-spacing: 1px;
}

/* ==================== LIST VIEW (BC table) ==================== */
.lines-table-wrapper { padding: 0.75rem 1.25rem; flex: 1; overflow-x: auto; }
.lines-table { width: 100%; border-collapse: collapse; background: var(--bc-surface); }
.lines-table thead th {
    text-align: left; padding: 0.5rem 0.7rem; font-size: 0.72rem;
    color: var(--bc-text-sec); font-weight: 600; background: var(--bc-bg);
    border-bottom: 1px solid var(--bc-border-strong); white-space: nowrap;
}
.lines-table tbody tr { border-bottom: 1px solid var(--bc-border); transition: background 0.1s; }
.lines-table tbody tr:hover { background: var(--bc-row-hover); }
.lines-table tbody tr.registered { background: var(--bc-pos-bg); }
.lines-table tbody tr.pending-line { background: var(--bc-warn-bg); }
.lines-table tbody td { padding: 0.5rem 0.7rem; vertical-align: middle; }

.line-status-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.line-status-dot.green { background: var(--bc-pos); }
.line-status-dot.orange { background: var(--bc-warn); }

.product-ref { font-weight: 600; color: var(--bc-blue); font-size: 0.88rem; }
.product-desc { color: var(--bc-text-sec); font-size: 0.85rem; }
.qty-cell { font-weight: 600; font-size: 0.95rem; text-align: right; }
.qty-registered { color: var(--bc-pos); }

.lot-input, .qty-input-field {
    border: 1px solid var(--bc-border-strong); border-radius: var(--radius); padding: 0.4rem 0.5rem;
    font-size: 0.85rem; width: 130px; transition: border-color 0.15s; font-family: inherit; background: #fff;
}
.lot-input:focus, .qty-input-field:focus { border-color: var(--bc-accent); outline: 1px solid var(--bc-accent); }
.lot-input:disabled { background: var(--bc-pos-bg); border-color: var(--bc-pos); color: var(--bc-pos); font-weight: 600; }
.qty-input-field { width: 90px; text-align: right; font-weight: 600; }

/* ==================== BUTTONS (BC) ==================== */
.btn-register, .btn-transfer, .btn-new-transfer, .popup-actions .btn-confirm {
    background: var(--bc-accent); color: #fff; border: 1px solid var(--bc-accent);
    padding: 0.5rem 1rem; border-radius: var(--radius); font-size: 0.85rem; font-weight: 600;
    cursor: pointer; white-space: nowrap; min-height: 40px; font-family: inherit;
    transition: background 0.15s; text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
}
.btn-register:hover, .btn-transfer:hover, .btn-new-transfer:hover, .popup-actions .btn-confirm:hover { background: var(--bc-accent-hover); }
.btn-register:disabled, .btn-transfer:disabled { background: #C8C6C4; border-color: #C8C6C4; cursor: not-allowed; }
.btn-registered {
    background: var(--bc-pos-bg); color: var(--bc-pos); border: 1px solid var(--bc-pos);
    padding: 0.5rem 1rem; border-radius: var(--radius); font-size: 0.85rem; font-weight: 600;
    cursor: default; white-space: nowrap; min-height: 40px;
}
.btn-transfer { padding: 0.6rem 2rem; min-height: 44px; font-size: 0.95rem; }
.btn-new-transfer { margin-bottom: 1rem; }

.nav-buttons { display: flex; justify-content: space-between; padding: 0.6rem 1.25rem; background: var(--bc-bg); border-top: 1px solid var(--bc-border); }
.nav-btn {
    display: inline-flex; align-items: center; gap: 0.4rem; background: var(--bc-surface);
    border: 1px solid var(--bc-border-strong); padding: 0.5rem 1.1rem; border-radius: var(--radius);
    font-size: 0.88rem; cursor: pointer; font-family: inherit; color: var(--bc-text); min-height: 40px; text-decoration: none;
}
.nav-btn:hover { border-color: var(--bc-accent); color: var(--bc-accent); }
.nav-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ==================== CATALOG ==================== */
.catalog-section { padding: 1rem 1.25rem; max-width: 1200px; margin: 0 auto; width: 100%; flex: 1; overflow-y: auto; }
.catalog-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 0.6rem; }
.catalog-item {
    background: var(--bc-surface); border: 1px solid var(--bc-border); border-radius: var(--radius); padding: 0.8rem;
    display: flex; align-items: center; gap: 0.8rem; transition: border-color 0.15s;
}
.catalog-item.selected { border-color: var(--bc-accent); background: var(--bc-info-bg); }
.catalog-item .cat-info { flex: 1; }
.catalog-item .cat-ref { font-weight: 600; color: var(--bc-blue); font-size: 0.82rem; }
.catalog-item .cat-desc { color: var(--bc-text-sec); font-size: 0.85rem; margin-top: 0.1rem; }
.catalog-item .cat-unit { font-size: 0.72rem; color: var(--bc-text-sec); }
.catalog-item .cat-qty { display: flex; align-items: center; gap: 0.4rem; }
.catalog-item .cat-qty input {
    width: 80px; text-align: right; border: 1px solid var(--bc-border-strong); border-radius: var(--radius);
    padding: 0.35rem; font-size: 0.9rem; font-weight: 600; font-family: inherit;
}
.catalog-item .cat-qty input:focus { border-color: var(--bc-accent); outline: none; }

.transfer-footer { background: var(--bc-surface); border-top: 1px solid var(--bc-border); padding: 0.8rem 1.25rem; display: flex; align-items: center; justify-content: space-between; }
.transfer-summary { font-size: 0.9rem; color: var(--bc-text-sec); }
.transfer-summary strong { color: var(--bc-blue); font-size: 1rem; }

/* ==================== FORMS / SELECTS ==================== */
select, .form-input {
    padding: 0.45rem 0.6rem; border: 1px solid var(--bc-border-strong); border-radius: var(--radius);
    font-size: 0.9rem; font-family: inherit; background: #fff; color: var(--bc-text);
}
select:focus, .form-input:focus { border-color: var(--bc-accent); outline: 1px solid var(--bc-accent); }
label.field-label { font-weight: 600; color: var(--bc-text); font-size: 0.85rem; }
/* CTA [01/07/2026], INTRANET-TORRIBAS, marca de camp invàlid (validació al client de codis contra la llista). */
.form-input.invalid, select.invalid, input.invalid { border-color: var(--bc-neg); background: var(--bc-neg-bg); }

/* ==================== POPUPS ==================== */
.overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 1000; justify-content: center; align-items: center; }
.overlay.active { display: flex; }
.popup { background: var(--bc-surface); border-radius: var(--radius); padding: 1.5rem; max-width: 460px; width: 92%; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,0.25); border-top: 3px solid var(--bc-accent); }
.popup .popup-icon { width: 52px; height: 52px; border-radius: 50%; background: var(--bc-pos-bg); color: var(--bc-pos); font-size: 1.8rem; display: flex; align-items: center; justify-content: center; margin: 0 auto 1rem; }
.popup h2 { font-size: 1.1rem; color: var(--bc-blue); margin-bottom: 0.7rem; }
.popup .popup-details { text-align: left; background: var(--bc-bg); border: 1px solid var(--bc-border); border-radius: var(--radius); padding: 0.8rem; margin-bottom: 1rem; }
.popup .popup-details .detail-row { display: flex; justify-content: space-between; padding: 0.3rem 0; font-size: 0.85rem; }
.popup .popup-details .detail-row:not(:last-child) { border-bottom: 1px solid var(--bc-border); }
.popup .popup-details .detail-row .label { color: var(--bc-text-sec); }
.popup .popup-details .detail-row .value { font-weight: 600; }
.popup-actions { display: flex; gap: 0.6rem; justify-content: center; flex-wrap: wrap; }
.popup-actions .btn-cancel { background: var(--bc-surface); color: var(--bc-text); border: 1px solid var(--bc-border-strong); padding: 0.5rem 1.2rem; border-radius: var(--radius); font-size: 0.85rem; cursor: pointer; font-family: inherit; min-height: 40px; }
.popup-actions .btn-cancel:hover { background: var(--bc-row-hover); }

/* ==================== TOAST (confirmation Q32) ==================== */
.toast-host { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); z-index: 2000; display: flex; flex-direction: column; gap: 0.5rem; }
.toast { background: var(--bc-pos); color: #fff; padding: 0.6rem 1.1rem; border-radius: var(--radius); font-size: 0.85rem; box-shadow: 0 4px 16px rgba(0,0,0,0.25); animation: toastIn 0.2s ease; }
.toast.error { background: var(--bc-neg); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ==================== LOGIN ==================== */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bc-bg); }
.login-card { background: var(--bc-surface); border: 1px solid var(--bc-border); border-top: 3px solid var(--bc-blue); border-radius: var(--radius); padding: 2rem; width: 360px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.login-card .logos { display: flex; align-items: center; justify-content: center; gap: 0.8rem; margin-bottom: 1.25rem; }
.login-card h1 { font-size: 1.1rem; color: var(--bc-blue); text-align: center; margin-bottom: 1.25rem; }
.login-card label { display: block; font-size: 0.8rem; color: var(--bc-text-sec); margin: 0.6rem 0 0.2rem; }
.login-card input { width: 100%; padding: 0.55rem 0.6rem; border: 1px solid var(--bc-border-strong); border-radius: var(--radius); font-size: 0.95rem; font-family: inherit; }
.login-card input:focus { border-color: var(--bc-accent); outline: 1px solid var(--bc-accent); }
.login-card .btn-login { width: 100%; margin-top: 1.1rem; background: var(--bc-accent); color: #fff; border: none; padding: 0.6rem; border-radius: var(--radius); font-size: 0.95rem; font-weight: 600; cursor: pointer; }
.login-card .btn-login:hover { background: var(--bc-accent-hover); }
.login-error { background: var(--bc-neg-bg); color: var(--bc-neg); border: 1px solid var(--bc-neg); border-radius: var(--radius); padding: 0.5rem 0.7rem; font-size: 0.85rem; margin-bottom: 0.8rem; }

/* ==================== UTIL ==================== */
.pos { color: var(--bc-pos); }
.neg { color: var(--bc-neg); }
.unit { font-size: 0.72rem; color: var(--bc-text-sec); font-weight: normal; }
.empty-state { text-align: center; padding: 2.5rem; color: var(--bc-text-sec); }
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: 0.8rem; }

/* ==================== RESPONSIVE ==================== */
@media (max-width: 900px) {
    .warehouse-cards, .mode-cards { flex-direction: column; align-items: center; }
    .warehouse-card, .mode-card { width: 80%; max-width: 300px; }
    .detail-header { flex-direction: column; align-items: flex-start; }
    .reception-grid, .catalog-grid { grid-template-columns: 1fr; }
    .lines-table-wrapper, .content, .catalog-section { padding: 0.7rem; }
    .transfer-footer { flex-direction: column; gap: 0.7rem; text-align: center; }
}

/* CTA [26/06/2026], INTRANET-TORRIBAS, breakpoint de telefon: sense scroll horitzontal de pagina,
   inputs a amplada completa (sobreescriu els min-width inline), taules de linies amb scroll propi. */
@media (max-width: 600px) {
    html, body { max-width: 100%; overflow-x: hidden; }
    body { font-size: 13px; }
    .header { padding: 0 0.5rem; min-height: 44px; }
    .header-left { gap: 0.4rem; }
    .header h1 { font-size: 0.92rem; }
    .header-right { gap: 0.4rem; flex-wrap: wrap; justify-content: flex-end; }
    .user-menu { font-size: 0.72rem; }
    .content, .catalog-section { padding: 0.6rem; }

    /* Inputs i selects amplada completa; anul·la els min-width inline que desborden */
    .form-input, select { min-width: 0 !important; width: 100%; max-width: 100%; }
    #vendor-input { min-width: 0 !important; width: 100%; }
    .command-bar { padding: 0.4rem 0.6rem; gap: 0.4rem; }
    .command-bar .field-label { width: 100%; }

    /* Botons d'accio a tota l'amplada */
    .btn-transfer, .command-bar .cmd.primary { width: 100%; justify-content: center; }

    /* Targetes a una columna i sense reservar espai pel badge */
    .reception-card .supplier-name, .transfer-card .supplier-name { padding-right: 0; }

    .login-card { width: 92%; }
}

/* ============================================================
   CTA [01/07/2026], INTRANET-TORRIBAS, capa mobile-first polida (iPhone/Safari iOS + Android).
   Prioritat: pantalla de Compras de gerencia. Objectius:
     1) Evitar el zoom automatic d'iOS en enfocar inputs (font >= 16px).
     2) Convertir les taules de linies (.lines-table) en targetes apilades al telefon.
     3) Respectar les safe-area (notch) i fer objectius tactils >= 44px (Apple HIG).
   ============================================================ */

/* Safe-area en elements fixos (nomes te efecte en dispositius amb notch). */
@supports (padding: env(safe-area-inset-bottom)) {
    .toast-host { bottom: calc(1rem + env(safe-area-inset-bottom)); }
    body.is-demo .demo-bar {
        padding-left: calc(1rem + env(safe-area-inset-left));
        padding-right: calc(1rem + env(safe-area-inset-right));
    }
}

/* Scroll amb inercia a iOS per als contenidors que encara facin scroll horitzontal. */
.lines-table-wrapper { -webkit-overflow-scrolling: touch; }

@media (max-width: 600px) {
    /* iOS fa zoom automatic quan l'input enfocat te font < 16px. Ho evitem globalment. */
    input, select, textarea,
    .form-input, .lot-input, .qty-input-field, .price-input,
    .login-card input, .truck-input input, .catalog-item .cat-qty input {
        font-size: 16px !important;
    }

    /* Objectius tactils comodes. */
    .back-btn, .nav-btn, .cmd, .btn-register, .btn-registered,
    .btn-transfer, .popup-actions .btn-cancel, .popup-actions .btn-confirm {
        min-height: 44px;
    }

    /* Padding lateral segur en apaisat (notch a l'esquerra/dreta). */
    .header, .content, .catalog-section, .command-bar,
    .detail-header, .lines-table-wrapper, .nav-buttons, .transfer-footer {
        padding-left: max(0.6rem, env(safe-area-inset-left));
        padding-right: max(0.6rem, env(safe-area-inset-right));
    }

    /* Capcalera: header-left i header-right en files separades, sense desbordar. */
    .header { flex-wrap: wrap; align-items: flex-start; }
    .header-left { flex: 1 1 100%; min-width: 0; }
    .header-left h1 { white-space: normal; overflow-wrap: anywhere; }
    .header-right { flex: 1 1 100%; justify-content: flex-start; flex-wrap: wrap; }

    /* ---- Taules de linies -> targetes apilades ---- */
    .lines-table-wrapper { overflow-x: visible; }
    .lines-table { min-width: 0 !important; }

    /* Amaga la capçalera de la taula (el data-label de cada cel·la la substitueix). */
    .lines-table thead {
        position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
        overflow: hidden; clip: rect(0 0 0 0); border: 0;
    }

    .lines-table, .lines-table tbody, .lines-table tr, .lines-table td { display: block; width: 100%; }

    .lines-table tbody tr {
        background: var(--bc-surface);
        border: 1px solid var(--bc-border); border-left: 3px solid var(--bc-accent);
        border-radius: var(--radius); padding: 0.6rem 0.8rem; margin-bottom: 0.6rem;
        box-shadow: 0 1px 2px rgba(0,0,0,0.06);
    }
    .lines-table tbody tr.registered { border-left-color: var(--bc-pos); background: var(--bc-surface); }
    .lines-table tbody tr.pending-line { border-left-color: var(--bc-warn); background: var(--bc-surface); }
    .lines-table tbody tr:hover { background: var(--bc-surface); }

    /* Pila vertical: etiqueta (bloc) a dalt, valor/control (bloc) a sota a tota l'amplada.
       Sense flex ni space-between -> impossible que desbordi a qualsevol amplada de telefon. */
    .lines-table tbody td {
        display: block; padding: 0.4rem 0; border: 0;
        text-align: left; overflow-wrap: anywhere; word-break: break-word;
    }
    .lines-table tbody td:not(:last-child) { border-bottom: 1px solid var(--bc-border); }
    .lines-table tbody td[data-label]::before {
        content: attr(data-label); display: block; margin-bottom: 0.15rem;
        font-size: 0.68rem; font-weight: 600; text-transform: uppercase;
        letter-spacing: 0.3px; color: var(--bc-text-sec);
    }

    /* Cel·la del semafor: el color de la vora esquerra ja informa; l'amaguem. */
    .lines-table tbody td.line-flag { display: none; }

    /* Cel·la d'accio (boto): a tota l'amplada, sense etiqueta. */
    .lines-table tbody td.line-actions { padding-top: 0.6rem; }

    /* Inputs, selects i botons dins la targeta: bloc a tota l'amplada (anul·la widths inline del JS). */
    .lines-table tbody td .lot-input,
    .lines-table tbody td .qty-input-field,
    .lines-table tbody td .price-input,
    .lines-table tbody td .lot-select,
    .lines-table tbody td .form-input,
    .lines-table tbody td .btn-register,
    .lines-table tbody td .btn-registered,
    .lines-table tbody td .cmd {
        display: block; width: 100% !important; max-width: 100%; min-width: 0 !important;
        box-sizing: border-box; margin: 0; text-align: left;
    }
    .lines-table tbody td .qty-input-field,
    .lines-table tbody td .price-input { text-align: right; }
    .lines-table tbody td .btn-register,
    .lines-table tbody td .btn-registered { text-align: center; }

    /* Caixa de matricula del camio: a tota l'amplada (l'input tenia 180px fixos). */
    .truck-input { width: 100%; flex-wrap: wrap; }
    .truck-input input { flex: 1 1 8rem; min-width: 0; width: auto; }

    /* Peu d'accio enganxat a baix (p. ex. "CREAR PEDIDO") sempre a l'abast del dit. */
    .transfer-footer {
        position: sticky; bottom: 0; z-index: 10;
        flex-direction: column; gap: 0.6rem;
        padding-bottom: calc(0.8rem + env(safe-area-inset-bottom));
        box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
    }
}
