/* ── Ladu: telefonikujundus (Stitch m3 „Lao ülevaade" — tooraine kaardid) ──
   Kõik ≤768 px ja skoobitud #warehouse-ga; lauaarvuti vaade ei muutu.
   Tabelid jäävad mobile-shell.js kaartideks (m-kaardid); siin ainult kaardi sisemine paigutus
   (grid-template-areas veergude järjekorra järgi) + riba/kiibid, mille lisab mobile-ladu.js. */
@media (max-width: 768px) {
    #warehouse { --ml-savi: #b0694c; --ml-salvei: #7c8a6a; --ml-tellis: #c0392b; --ml-info: #2c6b9c; }

    /* KPI-plokid (.stats): 2 veergu, kompaktsemad */
    #warehouse .tab-content > .stats { display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px !important; }
    #warehouse .tab-content > .stats .stat-card { padding: 12px 10px !important; margin: 0 !important; min-width: 0 !important; border-radius: 12px; }
    #warehouse .tab-content > .stats .stat-card .number { font-size: 1.4rem !important; line-height: 1.15; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
    #warehouse .tab-content > .stats .stat-card .label { font-size: 0.78rem !important; }

    /* Ühised kaardi tükid */
    #warehouse .m-ladu-kiip {
        display: inline-block; margin: 0 0 0 6px; padding: 1px 7px; border-radius: 6px; font-size: 0.72rem; font-weight: 600;
        font-family: var(--font-body, inherit); letter-spacing: 0; vertical-align: 2px; white-space: nowrap;
        border: 1px solid var(--m-joon); background: var(--m-paber2); color: var(--m-hall);
    }
    #warehouse .m-ladu-kiip.m-ladu-hoiatus { border-color: #ebcfc3; background: #fbefe9; color: var(--ml-savi); }
    #warehouse td.m-ladu-riba { grid-area: riba; padding-top: 2px !important; }
    #warehouse td.m-ladu-riba-tyhi { display: none !important; }
    #warehouse td.m-ladu-riba > span { position: relative; display: block; height: 8px; border-radius: 999px; background: var(--m-joon); overflow: hidden; }
    #warehouse td.m-ladu-riba > span > i { display: block; height: 100%; border-radius: 999px; background: #4f5e3f; }
    #warehouse td.m-ladu-riba > span.m-madal > i { background: var(--ml-savi); }
    /* märk = miinimum (riba täis = 2 × miinimum) */
    #warehouse td.m-ladu-riba > span::after { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; background: var(--m-kaart); }
    #warehouse tr.m-ladu-madal { border-color: #d9a690 !important; box-shadow: 0 0 0 1px #ecc9b9 inset !important; }

    /* ── Tooraine (renderRawMaterials): Kood | Koostisosa | INCI | Tarnija | Ühik | Laoseis | Miinimum | Hind/ü | nupud ── */
    #warehouse #rmBody > tr.rm-row {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto !important; gap: 6px 12px !important;
        grid-template-areas: "kood kood laos" "nimi nimi min" "riba riba riba" "inci inci inci" "tarn tarn hind" "teg teg teg";
        color: var(--m-tekst) !important; font-weight: 400 !important; padding: 14px 16px !important;
    }
    #warehouse #rmBody > tr.rm-row > td:nth-child(1) { grid-area: kood; font-size: 0.8rem !important; font-weight: 600; letter-spacing: 0.06em; color: var(--m-hall) !important; }
    #warehouse #rmBody > tr.rm-row > td:nth-child(1) strong { font-weight: 600; }
    #warehouse #rmBody > tr.rm-row > td:nth-child(2) { grid-area: nimi; font-family: var(--font-display, Georgia, serif); font-size: 1.15rem; line-height: 1.25; }
    #warehouse #rmBody > tr.rm-row > td:nth-child(2) strong { font-weight: 600; }
    #warehouse #rmBody > tr.rm-row > td:nth-child(2)::before,
    #warehouse #rmBody > tr.rm-row > td:nth-child(6)::before { display: none; }
    #warehouse #rmBody > tr.rm-row > td:nth-child(3) { grid-area: inci; font-size: 0.82rem !important; color: var(--m-hall); }
    #warehouse #rmBody > tr.rm-row > td:nth-child(3):empty { display: none; }
    #warehouse #rmBody > tr.rm-row > td:nth-child(4) { grid-area: tarn; font-size: 0.85rem; }
    #warehouse #rmBody > tr.rm-row > td:nth-child(5) { display: none !important; }
    #warehouse #rmBody > tr.rm-row > td:nth-child(6) { grid-area: laos; text-align: right !important; font-size: 1.2rem; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap !important; align-self: end; }
    #warehouse #rmBody > tr.rm-row > td:nth-child(7) { grid-area: min; text-align: right !important; font-size: 0.8rem; color: var(--m-hall); font-variant-numeric: tabular-nums; white-space: nowrap !important; }
    #warehouse #rmBody > tr.rm-row > td:nth-child(7)::before { content: "min "; display: inline; font-size: inherit; letter-spacing: 0; }
    #warehouse #rmBody > tr.rm-row > td:nth-child(8) { grid-area: hind; text-align: right !important; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
    #warehouse #rmBody > tr.rm-row > td:nth-child(9) { grid-area: teg; justify-content: flex-end; }
    #warehouse #rmBody > tr.rm-row.m-ladu-madal > td:nth-child(6),
    #warehouse #rmBody > tr.rm-row.m-ladu-madal > td:nth-child(7) { color: var(--ml-savi) !important; }
    /* LOT-ide leht (toggleRmLots): kompaktsed partiikaardid kaardi all */
    #warehouse #rmBody > tr[id^="rmLots_"] { padding: 8px !important; background: var(--m-paber2) !important; margin-top: -6px; }
    #warehouse #rmBody > tr[id^="rmLots_"] > td::before { display: none; }
    #warehouse #rmBody > tr[id^="rmLots_"] > td > div { background: transparent !important; padding: 0 !important; border: 0 !important; }
    #warehouse #rmBody > tr[id^="rmLots_"] table.m-kaardid tr { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 8px; padding: 10px 12px; }

    /* ── Pakendid (renderPkgStock): Kood | Nimetus | Tüüp | Materjal | Maht | Tarnija | Laoseis | Miinimum | nupud ── */
    #warehouse #pkgStockBody > tr.m-ladu-pkg {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto !important; gap: 6px 12px !important;
        grid-template-areas: "kood kood laos" "nimi nimi min" "riba riba riba" "tyyp mat maht" "tarn tarn tarn" "teg teg teg";
        color: var(--m-tekst) !important; font-weight: 400 !important; padding: 14px 16px !important;
    }
    #warehouse #pkgStockBody > tr.m-ladu-pkg > td:nth-child(1) { grid-area: kood; font-size: 0.8rem !important; letter-spacing: 0.06em; color: var(--m-hall) !important; }
    #warehouse #pkgStockBody > tr.m-ladu-pkg > td:nth-child(1) strong { font-weight: 600; }
    #warehouse #pkgStockBody > tr.m-ladu-pkg > td:nth-child(2) { grid-area: nimi; font-family: var(--font-display, Georgia, serif); font-size: 1.12rem; font-weight: 600; line-height: 1.25; }
    #warehouse #pkgStockBody > tr.m-ladu-pkg > td:nth-child(2)::before,
    #warehouse #pkgStockBody > tr.m-ladu-pkg > td:nth-child(7)::before { display: none; }
    #warehouse #pkgStockBody > tr.m-ladu-pkg > td:nth-child(3) { grid-area: tyyp; }
    #warehouse #pkgStockBody > tr.m-ladu-pkg > td:nth-child(4) { grid-area: mat; }
    #warehouse #pkgStockBody > tr.m-ladu-pkg > td:nth-child(5) { grid-area: maht; text-align: right !important; }
    #warehouse #pkgStockBody > tr.m-ladu-pkg > td:nth-child(3),
    #warehouse #pkgStockBody > tr.m-ladu-pkg > td:nth-child(4),
    #warehouse #pkgStockBody > tr.m-ladu-pkg > td:nth-child(5),
    #warehouse #pkgStockBody > tr.m-ladu-pkg > td:nth-child(6) { font-size: 0.85rem; }
    #warehouse #pkgStockBody > tr.m-ladu-pkg > td:nth-child(6) { grid-area: tarn; }
    #warehouse #pkgStockBody > tr.m-ladu-pkg > td:nth-child(7) { grid-area: laos; text-align: right !important; font-size: 1.2rem; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap !important; align-self: end; }
    #warehouse #pkgStockBody > tr.m-ladu-pkg > td:nth-child(8) { grid-area: min; text-align: right !important; font-size: 0.8rem; color: var(--m-hall); font-variant-numeric: tabular-nums; white-space: nowrap !important; }
    #warehouse #pkgStockBody > tr.m-ladu-pkg > td:nth-child(8)::before { content: "min "; display: inline; font-size: inherit; letter-spacing: 0; }
    #warehouse #pkgStockBody > tr.m-ladu-pkg > td:nth-child(9) { grid-area: teg; justify-content: flex-end; }
    #warehouse #pkgStockBody > tr.m-ladu-pkg.m-ladu-madal > td:nth-child(7),
    #warehouse #pkgStockBody > tr.m-ladu-pkg.m-ladu-madal > td:nth-child(8) { color: var(--ml-savi) !important; }
    /* Filtrid: otsing täislaiuses, valikud kahes veerus */
    #warehouse #whPackaging .card > div:first-child { display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px !important; }
    #warehouse #whPackaging #whPkgSearch { grid-column: 1 / -1; }
    #warehouse #whPackaging .card > div:first-child select { width: 100%; font-size: 16px !important; padding: 0.4rem 0.5rem !important; }

    /* ── Valmistooted (renderWarehouse): Kood | Toode | Luxoria | Directo VT | Vahe | Broneeritud | Saadaval | Partiid | Riiul | nupud ──
       Numbrid tulevad renderdajast muutmata (Luxoria = stock_qty, Directo VT = directo_stock — kaks eri veergu). */
    #warehouse #whBody > tr.lv-rida {
        grid-template-columns: repeat(4, minmax(0, 1fr)) !important; gap: 6px 10px !important;
        grid-template-areas: "kood kood kood lux" "nimi nimi nimi lux" "dir vahe bron saad" "part part riiul riiul" "teg teg teg teg";
        padding: 14px 16px !important;
    }
    #warehouse #whBody > tr.lv-rida > td:nth-child(1) { grid-area: kood; font-size: 0.82rem !important; letter-spacing: 0.05em; color: var(--m-hall); }
    #warehouse #whBody > tr.lv-rida > td:nth-child(2) { grid-area: nimi; }
    #warehouse #whBody > tr.lv-rida > td:nth-child(2)::before { display: none; }
    #warehouse #whBody > tr.lv-rida > td:nth-child(2) .so-klient { font-family: var(--font-display, Georgia, serif); font-size: 1.1rem; font-weight: 600; line-height: 1.25; }
    #warehouse #whBody > tr.lv-rida > td:nth-child(3) { grid-area: lux; text-align: right !important; font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap !important; }
    #warehouse #whBody > tr.lv-rida > td:nth-child(4) { grid-area: dir; }
    #warehouse #whBody > tr.lv-rida > td:nth-child(5) { grid-area: vahe; }
    #warehouse #whBody > tr.lv-rida > td:nth-child(6) { grid-area: bron; }
    #warehouse #whBody > tr.lv-rida > td:nth-child(7) { grid-area: saad; text-align: right !important; }
    #warehouse #whBody > tr.lv-rida > td:nth-child(4),
    #warehouse #whBody > tr.lv-rida > td:nth-child(5),
    #warehouse #whBody > tr.lv-rida > td:nth-child(6),
    #warehouse #whBody > tr.lv-rida > td:nth-child(7) { font-variant-numeric: tabular-nums; padding-top: 8px !important; border-top: 1px solid var(--m-joon) !important; }
    #warehouse #whBody > tr.lv-rida > td:nth-child(8) { grid-area: part; }
    #warehouse #whBody > tr.lv-rida > td:nth-child(9) { grid-area: riiul; text-align: right !important; }
    #warehouse #whBody > tr.lv-rida > td:nth-child(10) { grid-area: teg; justify-content: flex-end; }
    #warehouse #whBody > tr.lv-rida.lv-otsas > td:nth-child(3),
    #warehouse #whBody > tr.lv-rida.lv-madal > td:nth-child(3) { color: var(--ml-savi); }

    /* ── Inventuur (renderInventoryTable): Kood | Nimetus | Süsteemis | Loetud kogus | Vahe | Mahakandmine ── */
    #warehouse #invBody > tr:has(> td:nth-child(6)) {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
        grid-template-areas: "kood kood" "nimi nimi" "sys vahe" "loe loe" "teg teg";
    }
    #warehouse #invBody > tr > td:nth-child(1) { grid-area: kood; font-size: 0.82rem !important; color: var(--m-hall); }
    #warehouse #invBody > tr > td:nth-child(2) { grid-area: nimi; font-family: var(--font-display, Georgia, serif); font-size: 1.08rem; font-weight: 600; line-height: 1.25; }
    #warehouse #invBody > tr > td:nth-child(2)::before { display: none; }
    #warehouse #invBody > tr > td:nth-child(3) { grid-area: sys; font-variant-numeric: tabular-nums; }
    #warehouse #invBody > tr > td:nth-child(4) { grid-area: loe; display: flex !important; align-items: center; flex-wrap: wrap; gap: 4px 8px; }
    #warehouse #invBody > tr > td:nth-child(4)::before { flex: 0 0 100%; }
    #warehouse #invBody > tr > td:nth-child(4) input { flex: 1 1 auto; width: auto !important; min-width: 0; text-align: right; }
    #warehouse #invBody > tr > td:nth-child(5) { grid-area: vahe; text-align: right !important; font-variant-numeric: tabular-nums; }
    #warehouse #invBody > tr > td:nth-child(6) { grid-area: teg; justify-content: flex-end; }
    #warehouse #whInventory > .card:first-child > div > div:last-child { flex-direction: column; width: 100%; }
    #warehouse #whInventory > .card:first-child select, #warehouse #whInventory #inventorySearch { width: 100%; }
    #warehouse #whInventory .card:nth-child(2) > div:first-child { flex-wrap: wrap; gap: 8px; }

    /* ── Noppimisleht (renderPickingList) ── */
    #warehouse #whPickingList > .card:first-child > div > div:last-child { display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px !important; width: 100%; }
    #warehouse #whPickingList > .card:first-child > div > div:last-child .btn { margin: 0 !important; min-height: 44px; }
    #warehouse #pickingListContent > .card > div:first-child { flex-wrap: wrap; gap: 4px 12px !important; }
    #warehouse #pickingListContent > .card > div:first-child > label { flex: 1 1 100%; min-height: 44px; }
    #warehouse #pickingListContent > .card > div:first-child > label input { width: 24px !important; height: 24px !important; }
    /* rida: Kood | EAN | Toode | Asukoht | Kogus | Laos | OK */
    #warehouse #pickingListContent tbody > tr:has(> td:nth-child(7)) {
        grid-template-columns: minmax(0, 1fr) auto !important; gap: 4px 12px !important;
        grid-template-areas: "kood ok" "nimi kogus" "ean laos" "koht koht"; padding: 12px 14px !important;
    }
    #warehouse #pickingListContent tbody > tr > td:nth-child(1) { grid-area: kood; }
    #warehouse #pickingListContent tbody > tr > td:nth-child(2) { grid-area: ean; }
    #warehouse #pickingListContent tbody > tr > td:nth-child(3) { grid-area: nimi; font-weight: 600; }
    #warehouse #pickingListContent tbody > tr > td:nth-child(3)::before { display: none; }
    #warehouse #pickingListContent tbody > tr > td:nth-child(4) { grid-area: koht; }
    #warehouse #pickingListContent tbody > tr > td:nth-child(4) span { font-size: 0.9rem !important; padding: 3px 8px !important; border-radius: 6px !important; }
    #warehouse #pickingListContent tbody > tr > td:nth-child(5) { grid-area: kogus; text-align: right !important; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
    #warehouse #pickingListContent tbody > tr > td:nth-child(6) { grid-area: laos; text-align: right !important; font-variant-numeric: tabular-nums; }
    #warehouse #pickingListContent tbody > tr > td:nth-child(7) { grid-area: ok; text-align: right !important; font-size: 1.1rem; }
    #warehouse #pickingListContent tbody > tr > td:nth-child(7)::before { display: none; }

    /* ── Mahakandmised ── */
    #warehouse #whWriteoffs label:has(> input.wo-reason-chk) {
        min-height: 44px; padding: 0 12px; border: 1px solid var(--m-joon); border-radius: 999px; background: var(--m-kaart);
    }
    #warehouse #whWriteoffs label:has(> input.wo-reason-chk:checked) { border-color: var(--m-messing); background: #f7efe2; }
    #warehouse #whWriteoffs label:has(> input.wo-reason-chk) > input { width: 20px; height: 20px; }
    /* logi: Kuupäev | Ladu | Kood | Nimetus | Kogus | Põhjus | Konto | Tegija | Storno */
    #warehouse #woLogBody > tr:has(> td:nth-child(9)) {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
        grid-template-areas: "kp kogus" "nimi nimi" "ladu kood" "pohj pohj" "konto tegija" "teg teg";
    }
    #warehouse #woLogBody > tr > td:nth-child(1) { grid-area: kp; }
    #warehouse #woLogBody > tr > td:nth-child(2) { grid-area: ladu; }
    #warehouse #woLogBody > tr > td:nth-child(3) { grid-area: kood; }
    #warehouse #woLogBody > tr > td:nth-child(4) { grid-area: nimi; font-weight: 600; }
    #warehouse #woLogBody > tr > td:nth-child(4)::before { display: none; }
    #warehouse #woLogBody > tr > td:nth-child(5) { grid-area: kogus; text-align: right !important; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
    #warehouse #woLogBody > tr > td:nth-child(5)::before { display: none; }
    #warehouse #woLogBody > tr > td:nth-child(6) { grid-area: pohj; }
    #warehouse #woLogBody > tr > td:nth-child(7) { grid-area: konto; }
    #warehouse #woLogBody > tr > td:nth-child(8) { grid-area: tegija; }
    #warehouse #woLogBody > tr > td:nth-child(9) { grid-area: teg; }

    /* ── Raportid: varude bilansilise maksumuse plokid (flex:1;min-width:150px) — kaks reas, mitte kuus kitsast ── */
    #warehouse #inventoryValueReport [style*="flex-wrap:wrap"] > [style*="min-width:150px"] { flex: 1 1 calc(50% - 0.7rem) !important; }
    #warehouse #whReports #stockAsOfDate { min-width: 0; width: 11rem; }

    /* ── Visuaaliaudit 14.11.2026 L14: põhitegevuse roheline tagasi. mobile.css `.section .btn` (0,2,0)
       võttis `.btn-success` (0,1,0) taustavärvi → „Võta lattu“ / „Vabasta“ olid valged kontuurnupud,
       sama moodi nagu „Lükka tagasi“. Ainult värv; nth-child paigutusreeglid ei muutu. */
    #warehouse .btn.btn-success { background: #4f5e3f !important; border-color: #4f5e3f !important; color: #fff !important; background-image: none !important; font-weight: 600; }
    #warehouse table.m-kaardid td .btn.btn-success { min-height: 44px; padding-inline: 18px; }

    /* ── L9: Komplekteerimise skännirida üksteise alla — skänniväli täislaiuses, kohatäide ei lõigu ── */
    #warehouse .kt-skann > div:first-child { flex-direction: column; align-items: stretch !important; gap: 10px !important; }
    #warehouse .kt-skann > div:first-child > div { flex: none !important; min-width: 0 !important; width: 100%; }
    #warehouse .kt-skann .kt-valik, #warehouse .kt-skann .kt-ean { width: 100%; }

/* ── 3. etapp 2. voor L5: logid telefonil tihedate ridadena, mitte täiskaartidena (500 kirjet × ~200 px).
   Rida 1: toode/tooraine | kogus; rida 2 hallis: aeg · komplekteerija · partii/lot · tellimus/segamispartii (· retsept).
   Lahtrid leitakse klassi järgi (picking-log.js, .wh-l-*), mitte nth-child'iga; lahtrite arv/järjekord muutmata. */
    #warehouse table.wh-logi-tabel > tbody > tr {
        display: flex !important; flex-wrap: wrap; align-items: baseline; gap: 2px 8px !important;
        margin: 0 !important; padding: 9px 4px !important; border: 0 !important; border-bottom: 1px solid var(--m-joon) !important;
        border-radius: 0 !important; box-shadow: none !important; background: transparent !important;
    }
    #warehouse table.wh-logi-tabel > tbody > tr::after { content: ""; order: 2; flex: 0 0 100%; height: 0; }
    #warehouse table.wh-logi-tabel > tbody > tr > td { order: 3; flex: 0 0 auto; font-size: 0.78rem; color: var(--m-hall); font-weight: 400;
        white-space: nowrap !important; overflow-wrap: normal; }
    #warehouse table.wh-logi-tabel > tbody > tr > td::before { content: none !important; display: none !important; }
    #warehouse table.wh-logi-tabel > tbody > tr > td.wh-l-toode { order: 0; flex: 1 1 0; min-width: 0; font-size: 0.92rem; font-weight: 600; color: var(--m-tekst);
        white-space: normal !important; overflow-wrap: anywhere; }
    #warehouse table.wh-logi-tabel > tbody > tr > td.wh-l-toode .wh-kood { font-weight: 600; }
    #warehouse table.wh-logi-tabel > tbody > tr > td.wh-l-kogus { order: 1; font-size: 0.98rem; font-weight: 700; color: var(--m-tekst); text-align: right !important; font-variant-numeric: tabular-nums; }
    #warehouse table.wh-logi-tabel > tbody > tr > td.wh-l-kes::before,
    #warehouse table.wh-logi-tabel > tbody > tr > td.wh-l-partii::before,
    #warehouse table.wh-logi-tabel > tbody > tr > td.wh-l-tellimus::before,
    #warehouse table.wh-logi-tabel > tbody > tr > td.wh-l-retsept::before { content: "· " !important; display: inline !important; font-size: inherit; color: inherit; margin: 0; letter-spacing: 0; }
    #warehouse table.wh-logi-tabel > tbody > tr > td.wh-l-bb { display: none !important; }
    #warehouse table.wh-logi-tabel > tbody > tr > td.wh-l-retsept { white-space: normal !important; }
    #warehouse table.wh-logi-tabel > tbody > tr > td:empty { display: none !important; }

    /* L5 logide filtririda: kuupäevavahemik mahub ekraanile (enne lõikus teine kalendri-ikoon ära) */
    #warehouse .wh-logifiltrid .wh-kp-grupp { flex: 1 1 100%; min-width: 0; }
    #warehouse .wh-logifiltrid .wh-kp-grupp > input { flex: 1 1 0; min-width: 0 !important; width: auto !important; }
}
