/* ═══════════════════════════════════════════════════════════════════════════
 * LUXORIA telefonivaade (Jimmy 13.10.2026) — Google Stitchi „Nordic Workshop Paper"
 * mobiiliekraanid (projekt „Luxoria — tootmise ERP", 14 ekraani: Rohkem-leht, Tootmine,
 * Ladu, Müük/arved, Artiklid, Tootearendus, Sisseost, Finants, Minu töö, Partnerid,
 * vorm, ISO, Seaded, Personal).
 *
 * Kõik reeglid on ≤768 px meedia sees — lauaarvuti vaade ei muutu. Laetakse PÄRAST
 * style.css-i, seega võidab samal spetsiifilisusel. Kest (alumine riba, lehed) tuleb
 * static/js/mobile-shell.js-ist.
 * ═══════════════════════════════════════════════════════════════════════════ */

#mTabbar, #mPealkiri, #mKontoBtn { display: none; }

@media (max-width: 768px) {
    :root {
        --m-paber: #f3ede4; --m-paber2: #faf6f0; --m-kaart: #ffffff; --m-joon: #e8ddd3;
        --m-pruun: #5c4033; --m-messing: #a07c45; --m-tekst: #2c2520; --m-hall: #7a6e64;
        --m-riba: 64px;
    }
    [data-theme="dark"] {
        --m-paber: #1d1814; --m-paber2: #241e19; --m-kaart: #2a221c; --m-joon: #3a3029;
        --m-pruun: #d4a574; --m-messing: #d4a574; --m-tekst: #efe6dd; --m-hall: #b3a597;
    }
    /* clip (mitte hidden): hidden-kasti saab skript siiski külgsuunas kerida, clip-kasti mitte */
    html, body { overflow-x: hidden; overflow-x: clip; }
    body { background: var(--m-paber); font-size: 15px;
           padding-bottom: calc(var(--m-riba) + env(safe-area-inset-bottom, 0px)); }

    /* ── Päis: hele pabeririba, pealkiri serifis (Stitch: LUXORIA · moodul) ── */
    #appScreen > nav {
        position: sticky; top: 0; z-index: 900;
        display: flex; flex-wrap: nowrap; align-items: center; gap: 6px;
        min-height: 56px; padding: 6px 10px 6px 12px;
        background: var(--m-paber2) !important; color: var(--m-tekst);
        border-bottom: 1px solid var(--m-joon); box-shadow: none;
    }
    #appScreen > nav > img { height: 22px !important; filter: none !important; flex: 0 0 auto; }
    #appScreen > nav > h1, #appScreen > nav .hamburger-btn,
    #appScreen > nav .nav-buttons, #luxoriaTooltip { display: none !important; }
    #mPealkiri {
        display: block; flex: 1 1 auto; min-width: 0;
        font-family: var(--font-display, Georgia, serif); font-size: 1.25rem; font-weight: 600;
        color: var(--m-pruun); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    #appScreen > nav .nav-utils { display: flex; align-items: center; gap: 2px; margin: 0; flex: 0 0 auto; }
    #appScreen > nav .nav-utils > * { display: none !important; }
    #appScreen > nav .nav-utils > button[onclick="openSearchModal()"],
    #appScreen > nav .nav-utils > button[onclick="toggleNotifications()"],
    #appScreen > nav .nav-utils > #mKontoBtn {
        display: inline-flex !important; align-items: center; justify-content: center;
        width: 44px !important; height: 44px !important; min-height: 44px; padding: 0 !important;
        border: 0 !important; border-radius: 50% !important; background: transparent !important;
        color: var(--m-pruun) !important; font-size: 1.1rem !important; filter: grayscale(1) contrast(1.4);
    }
    #appScreen > nav .nav-utils > #mKontoBtn { filter: none; }
    #appScreen > nav .nav-utils > *:active { background: rgba(92,64,51,0.08) !important; }
    /* TEST-keskkonnas jääb eristus alles (riba ülal + teal pealkiri) */
    body[data-instance="test"] #mPealkiri { color: #0e7490; }

    /* ── Alumine riba ── */
    #mTabbar {
        display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 950;
        height: calc(var(--m-riba) + env(safe-area-inset-bottom, 0px));
        padding: 6px 6px env(safe-area-inset-bottom, 0px);
        background: var(--m-paber2); border-top: 1px solid var(--m-joon);
        box-shadow: 0 -4px 16px rgba(60,40,30,0.06);
    }
    #mTabbar button {
        flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center;
        justify-content: center; gap: 2px; border: 0; background: transparent; border-radius: 14px;
        color: var(--m-hall); font: 500 0.72rem/1.1 var(--font-body, system-ui, sans-serif); padding: 4px 2px;
    }
    #mTabbar button span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    #mTabbar button.on { background: rgba(160,124,69,0.16); color: var(--m-pruun); font-weight: 600; }
    #mTabbar button:active { transform: scale(0.96); }
    body.m-leht-lahti { overflow: hidden; }

    /* ── Lehed (Rohkem / Konto) ── */
    #mLeht { position: fixed; inset: 0; z-index: 2600; }
    .m-leht-taust { position: absolute; inset: 0; background: rgba(40,28,20,0.42); animation: mHajub .18s ease; }
    .m-leht {
        position: absolute; left: 0; right: 0; bottom: 0; max-height: 88dvh; overflow-y: auto;
        background: var(--m-paber2); color: var(--m-tekst); border-radius: 22px 22px 0 0;
        padding: 8px 16px calc(20px + env(safe-area-inset-bottom, 0px));
        box-shadow: 0 -10px 40px rgba(40,28,20,0.25); animation: mTous .22s cubic-bezier(.2,.8,.2,1);
    }
    .m-leht-kaepide { width: 44px; height: 5px; border-radius: 3px; background: var(--m-joon); margin: 4px auto 12px; }
    .m-leht-pealkiri { font-family: var(--font-display, Georgia, serif); font-size: 1.35rem; color: var(--m-pruun); margin: 0 0 12px; }
    .m-otsi { width: 100%; min-height: 48px; padding: 0 14px; border: 1px solid var(--m-joon); border-radius: 12px;
              background: var(--m-kaart); color: var(--m-tekst); font-size: 16px; margin-bottom: 14px; box-sizing: border-box; }
    .m-plaadid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
    .m-plaat {
        display: flex; flex-direction: column; align-items: flex-start; gap: 10px; min-height: 96px;
        padding: 12px; border: 1px solid var(--m-joon); border-radius: 14px; background: var(--m-kaart);
        color: var(--m-tekst); font: 600 0.82rem/1.2 var(--font-body, system-ui, sans-serif); text-align: left; hyphens: auto;
    }
    .m-plaat-nimi { display: flex; flex-direction: column; gap: 3px; min-width: 0; width: 100%; overflow-wrap: break-word; }
    .m-plaat-nimi small { font-weight: 400; font-size: 0.74rem; color: var(--m-hall); line-height: 1.25;
        display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
    .m-plaat.on { border-color: var(--m-messing); box-shadow: inset 0 0 0 1px var(--m-messing); }
    .m-plaat-ikoon {
        width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
        background: rgba(160,124,69,0.14); color: var(--m-pruun); font-family: var(--font-display, Georgia, serif); font-size: 1.05rem;
    }
    .m-grupp { background: var(--m-kaart); border: 1px solid var(--m-joon); border-radius: 14px; overflow: hidden; margin-bottom: 12px; }
    .m-rida {
        display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%;
        min-height: 52px; padding: 0 16px; border: 0; border-bottom: 1px solid var(--m-joon); background: transparent;
        color: var(--m-tekst); font: 500 0.95rem var(--font-body, system-ui, sans-serif); text-align: left; text-decoration: none; box-sizing: border-box;
    }
    .m-grupp > .m-rida:last-child { border-bottom: 0; }
    .m-leht > .m-rida { border: 1px solid var(--m-joon); border-radius: 14px; background: var(--m-kaart); color: var(--m-pruun); font-weight: 600; }
    .m-rida small { color: var(--m-hall); font-size: 0.8rem; font-weight: 400; }
    .m-rida-valik select { min-height: 40px; border: 1px solid var(--m-joon); border-radius: 10px; padding: 0 10px; background: var(--m-paber2); color: var(--m-tekst); font-size: 16px; }
    @keyframes mTous { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
    @keyframes mHajub { from { opacity: 0; } to { opacity: 1; } }

    /* ── Ujuvad nupud: Konto-lehel, mitte sisu peal ── */
    #stuckBtn, #agentBtn, #luxChatToggle { display: none !important; }
    #scrollTopBtn { bottom: calc(var(--m-riba) + 16px) !important; right: 14px !important; }
    #luxChatWidget { right: 0 !important; bottom: 0 !important; }
    .lux-chat-panel { position: fixed !important; inset: 0 !important; width: auto !important; height: auto !important;
                      max-height: none !important; border-radius: 0 !important; z-index: 2700 !important; }
    #feedbackPanel, #notifPanel, #onlinePanel {
        left: 8px !important; right: 8px !important; width: auto !important; min-width: 0 !important;
        top: 64px !important; max-height: calc(100dvh - 64px - var(--m-riba) - 16px) !important;
    }

    /* ── Sisu ── */
    .container { padding: 0 12px !important; margin: 10px auto !important; }
    /* Mooduli nimi on päises (#mPealkiri) — sisu esimene <h2> (puhas pealkiri) oleks kordus */
    .section > h2:first-of-type { display: none; }
    .section > h2 { font-family: var(--font-display, Georgia, serif); font-size: 1.45rem; margin: 6px 0 10px; }
    .card { border-radius: 14px; padding: 14px; border: 1px solid var(--m-joon); }

    /* Alamvahelehed: ÜKS külgsuunas keritav kiibirida (Stitch), mitte 6 rida murdunud nuppe */
    .tab-bar, .section.active:has(> .tab-bar) > .tab-bar, .prod-subbar {
        display: flex; flex-wrap: nowrap !important; flex-direction: row !important; gap: 6px !important;
        overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; scrollbar-width: none;
        border: 0 !important; border-bottom: 0 !important; background: transparent !important;
        margin: 0 0 12px !important; padding: 4px 0 8px !important; max-height: none !important; max-width: 100%; box-sizing: border-box;
        position: static !important; scroll-snap-type: x proximity;
    }
    .tab-bar::-webkit-scrollbar, .prod-subbar::-webkit-scrollbar { display: none; }
    .tab-bar .tab-btn, .section.active:has(> .tab-bar) > .tab-bar .tab-btn, .prod-subbar button {
        flex: 0 0 auto; white-space: nowrap; min-height: 38px; padding: 0 14px !important;
        border: 1px solid var(--m-joon) !important; border-radius: 999px !important; margin: 0 !important;
        background: var(--m-kaart) !important; color: var(--m-tekst) !important; font-size: 0.9rem !important;
        overflow: visible; text-overflow: clip; scroll-snap-align: start; box-shadow: none !important;
    }
    .tab-bar .tab-btn.active, .section.active:has(> .tab-bar) > .tab-bar .tab-btn.active, .prod-subbar button.active {
        background: var(--m-pruun) !important; border-color: var(--m-pruun) !important; color: #fff !important; font-weight: 600;
    }
    [data-theme="dark"] .tab-bar .tab-btn.active, [data-theme="dark"] .prod-subbar button.active { color: #1d1814 !important; }
    .mb-filter-tabs { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; max-width: 100%; }

    /* Puutealad ≥ 40 px (Stitch: 44 px põhinuppudel) */
    .section .btn, .modal .btn, .section button.btn-primary { min-height: 40px; }
    .section td .btn, .section td button { min-height: 34px; }
    .section input:not([type=checkbox]):not([type=radio]):not([type=range]),
    .section select, .section textarea, .modal input:not([type=checkbox]):not([type=radio]):not([type=range]),
    .modal select, .modal textarea, .cd-content input, .cd-content select, .cd-content textarea {
        min-height: 44px; font-size: 16px !important; /* < 16 px → iOS suumib välja fookusesse */
        max-width: 100%; box-sizing: border-box; border-radius: 10px;
    }
    .section textarea, .modal textarea { min-height: 88px; }
    .section input[type=checkbox], .section input[type=radio], .modal input[type=checkbox], .modal input[type=radio] { width: 20px; height: 20px; }

    /* Vormid: sildid välja kohal, üks veerg */
    .form-row { flex-direction: column; gap: 10px; }
    .form-row label { min-width: 0 !important; width: 100%; font-size: 0.88rem; }
    .form-row > *, .modal .form-row > * { max-width: 100%; min-width: 0 !important; }

    /* Aknad: täiskõrgusega alt avanev leht, kinnitusribaga all (Stitch vorm) */
    .modal-overlay { padding: 0 !important; align-items: flex-end !important; }
    .modal-overlay > .modal {
        max-width: 100% !important; width: 100% !important; min-height: 0; max-height: 100dvh;
        margin: 0 !important; border-radius: 20px 20px 0 0 !important; padding: 18px 16px calc(24px + env(safe-area-inset-bottom, 0px)) !important;
        overflow-y: auto; overflow-x: hidden; box-sizing: border-box; animation: mTous .22s cubic-bezier(.2,.8,.2,1);
    }
    /* Sulgemisnupp: kleepub üles paremale, AGA ei uju (float) — ujuv nupp tegi kogu akna sisu
       ~70 px kitsamaks (13.10, ost/finants agent). Negatiivne alumine marginaal = ei võta rida. */
    .modal-overlay > .modal .modal-close { position: sticky; top: 0; float: none; display: flex; align-items: center;
        justify-content: center; z-index: 3; width: 44px; height: 44px; margin: -6px -6px -38px auto;
        border-radius: 50%; background: var(--m-paber2) !important; }
    .modal-overlay > .modal * { max-width: 100%; }
    .modal-overlay > .modal table { max-width: none; }
    .modal-overlay > .modal .modal-footer, .modal-overlay > .modal .form-actions, .modal-overlay > .modal .modal-actions {
        position: sticky; bottom: calc(-24px - env(safe-area-inset-bottom, 0px)); background: var(--m-kaart);
        padding: 12px 0 calc(12px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--m-joon); z-index: 2;
    }
    .cd-modal { padding: 0 !important; align-items: flex-end !important; }
    .cd-content { max-width: 100% !important; width: 100% !important; border-radius: 20px 20px 0 0 !important;
                  max-height: 92dvh; overflow-y: auto; box-sizing: border-box; }

    /* Laiad tabelid: keritakse oma kastis, leht ise ei keri (vt style.css „table { display:block }") */
    .section table { border-radius: 10px; }
    .section th { position: sticky; top: 0; }
    .section img, .section canvas, .section svg { max-width: 100%; }
    .section canvas { height: auto !important; }
    .section [style*="min-width"] { min-width: 0 !important; }
    .section [style*="grid-template-columns"]:not(table *) { grid-template-columns: 1fr !important; }
    .section [style*="display:flex"]:not(.tab-bar):not(.mb-filter-tabs):not(td *) { flex-wrap: wrap; }

    /* ── Tabel → kaardid (klassi paneb mobile-shell.js, ainult ≥4 veeruga päisega tabelitele) ── */
    table.m-kaardid { display: block !important; overflow: visible !important; width: 100% !important;
                      min-width: 0 !important; border: 0 !important; background: transparent !important; font-size: 0.92rem; }
    table.m-kaardid thead { display: none !important; }
    table.m-kaardid tbody, table.m-kaardid tfoot { display: block; }
    table.m-kaardid tr {
        display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 14px;
        margin: 0 0 10px; padding: 12px 14px; background: var(--m-kaart) !important;
        border: 1px solid var(--m-joon); border-radius: 14px; box-shadow: 0 1px 2px rgba(60,40,30,0.04);
    }
    table.m-kaardid tr[style*="display: none"], table.m-kaardid tr[style*="display:none"] { display: none !important; }
    table.m-kaardid td, table.m-kaardid tfoot th {
        display: block; padding: 0 !important; border: 0 !important; background: transparent !important;
        white-space: normal !important; text-align: left !important; min-width: 0; overflow-wrap: anywhere;
        width: auto !important; max-width: none !important; position: static !important;
    }
    table.m-kaardid td[data-label]::before {
        content: attr(data-label); display: block; font-size: 0.72rem; font-weight: 500; letter-spacing: 0.02em;
        color: var(--m-hall); margin-bottom: 1px;
    }
    table.m-kaardid td:empty, table.m-kaardid td[data-label=""]::before { display: none; }
    table.m-kaardid td.m-pea { grid-column: 1 / -1; order: -1; font-weight: 600; font-size: 1rem; color: var(--m-tekst); }
    table.m-kaardid td.m-pea::before { display: none; }
    table.m-kaardid td.m-valik { order: -2; grid-column: 1 / -1; }
    table.m-kaardid td.m-valik::before { display: none; }
    table.m-kaardid td.m-lai { grid-column: 1 / -1; }
    table.m-kaardid td.m-tegevus { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px;
                                   padding-top: 8px !important; border-top: 1px solid var(--m-joon) !important; }
    table.m-kaardid td.m-tegevus::before { display: none; }
    table.m-kaardid td.m-tegevus .btn, table.m-kaardid td.m-tegevus button { min-height: 40px; }
    table.m-kaardid td input:not([type=checkbox]):not([type=radio]), table.m-kaardid td select { width: 100%; }

    /* ── Nupud (Stitch): üks messingvärvi põhitegevus, ülejäänud valge kaart + hairline ── */
    .section .btn, .modal .btn, .cd-content .btn {
        border-radius: 10px; border: 1px solid var(--m-joon); background: var(--m-kaart); color: var(--m-tekst);
        box-shadow: none; font-weight: 500;
    }
    .section .btn-primary, .modal .btn-primary, .cd-content .btn-primary {
        background: var(--m-messing) !important; border-color: var(--m-messing) !important; color: #fff !important;
        background-image: none !important; font-weight: 600;
    }
    .section .btn-danger, .modal .btn-danger { background: #fff; border-color: #e6b8b1; color: #a33025; }

    /* Pikad sildid murduvad (13.10 audit: Artiklid → Pakendid silt 448 px) */
    .section label { max-width: 100%; white-space: normal; }
    /* Kaardi lingid ja märkeruudud: puuteala (WCAG 2.2 ≥ 24 px; lingid 32 px) */
    table.m-kaardid td a { display: inline-flex; align-items: center; min-height: 32px; }
    table.m-kaardid td input[type=checkbox], table.m-kaardid td input[type=radio] { width: 24px; height: 24px; }

    /* AI-kaaslase riba (dashboard.js aiContextNudge) oli telefonis terve esimene ekraan —
       nüüd 3-realine eelvaade, puudutus avab (mobile-shell.js lülitab .m-lahti) */
    [id^="aiNudgeStrip-"] { position: relative; max-height: 6.2em; overflow: hidden; cursor: pointer; border-radius: 12px !important; padding-bottom: 22px !important; }
    [id^="aiNudgeStrip-"]::after { content: "Näita kõike ▾"; position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 12px 4px;
        text-align: right; font-size: 0.78rem; font-weight: 600; color: #11806a; background: linear-gradient(rgba(234,250,245,0), #eafaf5 60%); }
    [id^="aiNudgeStrip-"].m-lahti { max-height: none; }
    [id^="aiNudgeStrip-"].m-lahti::after { content: "Peida ▴"; position: static; display: block; background: none; padding: 6px 0 0; }
    [data-theme="dark"] [id^="aiNudgeStrip-"]:not(.m-lahti)::after { background: linear-gradient(rgba(0,0,0,0), var(--m-kaart) 60%); }
}
