/* ============================================================
   OpsLink — Phone layout
   Applies up to 768px wide, and also on a touch-only screen that is
   short (a phone turned sideways), so rotating a phone never switches it
   to the desktop layout: the phone layout is built for portrait and just
   gets wider. The same query is in js/mobile.js (OPSLINK_MOBILE_QUERY)
   and in each view's own <style> block, so change them together.

   Loaded after index.html's own <style>, so these rules win at equal
   specificity. Outside the query nothing here applies, and the phone
   chrome injected by js/mobile.js (top bar, tab bar, drawer backdrop)
   stays hidden, so the desktop layout is unchanged.
   Page-specific phone rules live in each view's own <style> block,
   because those load later and would otherwise override this file.
   ============================================================ */

.m-topbar, .m-tabbar, .m-backdrop { display: none; }

@media (max-width: 768px), (hover: none) and (pointer: coarse) and (max-height: 540px) {
    /* --m-tabbar-pad: the tab bar takes only part of the home-indicator inset (34px on an
       iPhone), so its buttons sit just above the indicator instead of a full inset above it. */
    :root {
        --m-bar: #2c3e50; --m-tabbar-h: 58px; --m-accent: #2a78d6;
        --m-tabbar-pad: max(env(safe-area-inset-bottom) - 20px, 0px);
    }

    /* Turning the phone sideways must not enlarge the text (iOS does by default). */
    html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
    /* The document scrolls (not .main-content), so the browser bars can collapse. */
    html, body { height: auto; }
    body {
        display: block; overflow: visible;
        min-height: 100vh; min-height: 100dvh;
    }
    .main-content {
        display: block; overflow: visible;
        padding: 8px 8px calc(var(--m-tabbar-h) + 16px + var(--m-tabbar-pad));
    }
    .container { width: 100%; min-height: 0; padding: 10px; gap: 10px; }

    /* iOS zooms into any field under 16px when it's focused. */
    input, select, textarea { font-size: 16px !important; }
    .btn { padding: 7px 12px; }
    h2 { font-size: 1.1rem; }
    th, td { padding: 6px 8px; }
    .filters { flex-wrap: wrap; overflow: visible; row-gap: 8px; }

    /* ── Top bar ─────────────────────────────────────────────── */
    .m-topbar {
        display: flex; align-items: center; gap: 4px;
        position: sticky; top: 0; z-index: 1400;
        padding: env(safe-area-inset-top) 8px 0 4px;
        min-height: calc(48px + env(safe-area-inset-top));
        background: var(--m-bar); color: #fff;
        box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    }
    .m-logo { display: block; height: 28px; width: auto; flex-shrink: 0; margin-right: 6px; }
    .m-title {
        font-size: 1.05rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1;
        padding-left: 10px; border-left: 1px solid rgba(255,255,255,0.25); line-height: 24px;
    }
    .m-title:empty { border-left: none; }
    .m-icon-btn {
        display: inline-flex; align-items: center; justify-content: center;
        width: 44px; height: 44px; border: none; background: none; color: inherit;
        border-radius: 8px; cursor: pointer; padding: 0;
    }
    .m-icon-btn:active { background: rgba(255,255,255,0.12); }
    .m-icon-btn svg { width: 24px; height: 24px; }

    /* ── Sidebar → slide-in drawer (its inline style sets the desktop size) ── */
    .app-sidebar {
        position: fixed !important; top: 0; bottom: 0; left: 0;
        width: min(280px, 82vw) !important; height: 100% !important;
        z-index: 1600; transform: translateX(-105%); transition: transform 0.22s ease;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        box-shadow: 2px 0 12px rgba(0,0,0,0.3);
    }
    body.m-nav-open .app-sidebar { transform: none; }
    .app-sidebar .nav-item, .app-sidebar .nav-group-header { padding-top: 11px; padding-bottom: 11px; }

    .m-backdrop {
        display: block; position: fixed; inset: 0; z-index: 1550;
        background: rgba(0,0,0,0.4); opacity: 0; pointer-events: none; transition: opacity 0.2s;
    }
    body.m-nav-open .m-backdrop { opacity: 1; pointer-events: auto; }
    body.m-nav-open { overflow: hidden; }

    /* ── Bottom tab bar ──────────────────────────────────────── */
    .m-tabbar {
        display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1400;
        height: calc(var(--m-tabbar-h) + var(--m-tabbar-pad));
        padding-bottom: var(--m-tabbar-pad);
        background: #fff; border-top: 1px solid #dde1e6;
        box-shadow: 0 -1px 6px rgba(0,0,0,0.06);
    }
    .m-tab {
        flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
        border: none; background: none; padding: 0; cursor: pointer;
        color: #6b7480; font: 500 11px/1.1 inherit; text-decoration: none;
        -webkit-tap-highlight-color: transparent;
    }
    .m-tab svg { width: 24px; height: 24px; }
    .m-tab.active { color: var(--m-accent); }

    .ol-toast { bottom: calc(var(--m-tabbar-h) + 14px + var(--m-tabbar-pad)); }

    /* ── Page toolbars: field boxes, icon buttons ─────────────── */
    /* A field box: a small caps label over its value, the whole box one tap target.
       (Above the phone width .ol-field is display: contents — see app.css.) */
    .ol-field {
        display: flex; flex-direction: column; justify-content: center; align-items: stretch; gap: 1px;
        min-width: 0; height: 50px; margin: 0; padding: 5px 10px;
        border: 1px solid #d0d5dd; border-radius: 10px; background: #fff;
        box-sizing: border-box; text-align: left; color: #1f2933; font: inherit;
    }
    .ol-field-row { display: flex; gap: 12px; min-width: 0; }
    .ol-field > label, .ol-field .ol-field-label {
        margin: 0; font-size: 11px !important; font-weight: 600; line-height: 1.2;
        letter-spacing: 0.04em; text-transform: uppercase; color: #8a929c; white-space: nowrap;
    }
    .ol-field .ol-field-value {
        display: block; font-size: 16px; font-weight: 500; line-height: 24px;
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .ol-field select, .ol-field input {
        -webkit-appearance: none; appearance: none;
        height: 24px; line-height: 24px; margin: 0; padding: 0;
        border: none; border-radius: 0; background: transparent; box-shadow: none; outline: none;
        width: 100% !important; min-width: 0; color: #1f2933; font-weight: 500;
    }
    .ol-field select {
        padding-right: 16px;
        background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%236b7480' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 2px center / 10px 6px;
    }
    .ol-field input::-webkit-date-and-time-value { text-align: left; }
    .ol-field:focus-within { border-color: var(--m-accent); }

    .ol-refresh {
        width: 50px; height: 50px; padding: 0; border-radius: 10px; flex-shrink: 0;
    }
    .ol-refresh .ol-ico { display: block; width: 22px; height: 22px; }
    .ol-refresh .ol-btn-text { display: none; }
    .ol-refresh:active .ol-ico { transform: rotate(90deg); transition: transform 0.2s; }

    .ol-phone-hide { display: none !important; }
}
