/* ============================================================
   EMIS — Main Stylesheet
   Aesthetic: Industrial utilitarian — dark steel, amber accents,
   monospaced data, tight grids. Designed for shop & field use.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=Sora:wght@300;400;600&display=swap');

/* ---- Variables ---- */
:root {
    --bg:        #0f1012;
    --bottom-nav-h: 52px;
    --bg2:       #161719;
    --surface:   #1c1e21;
    --surface2:  #23262a;
    --border:    rgba(255,255,255,.09);
    --border2:   rgba(255,255,255,.16);
    --text:      #e2e0d8;
    --muted:     #737068;
    --muted2:    #9a9690;
    --accent:    #e8a020;       /* Amber */
    --accent2:   #c47d10;
    --green:     #3db37a;
    --red:       #e05252;
    --blue:      #4a9fd4;
    --orange:    #e06a30;
    --radius:    3px;
    --radius-lg: 6px;
    --font-body: 'Sora', system-ui, sans-serif;
    --font-mono: 'IBM Plex Mono', 'Courier New', monospace;
    --nav-w:     230px;
    --top-h:     52px;
    --shadow:    0 2px 12px rgba(0,0,0,.5);
}

/* ---- Light Theme ---- */
[data-theme="light"] {
    --bottom-nav-h: 52px;
    --bg:        #f2f0ec;
    --bg2:       #e8e6e0;
    --surface:   #ffffff;
    --surface2:  #f2f0ec;
    --border:    rgba(0,0,0,.10);
    --border2:   rgba(0,0,0,.18);
    --text:      #1a1a16;
    --muted:     #8a8780;
    --muted2:    #6a6760;
    --accent:    #b87310;
    --accent2:   #9a5f0a;
    --green:     #2a8f5c;
    --red:       #c23535;
    --blue:      #3a80b5;
    --orange:    #c05620;
    --shadow:    0 2px 12px rgba(0,0,0,.12);
}

/* ---- System preference auto-switch (if user hasn't manually chosen) ---- */
@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]):not([data-theme="light"]) {
        --bottom-nav-h: 52px;
        --bg:        #f2f0ec;
        --bg2:       #e8e6e0;
        --surface:   #ffffff;
        --surface2:  #f2f0ec;
        --border:    rgba(0,0,0,.10);
        --border2:   rgba(0,0,0,.18);
        --text:      #1a1a16;
        --muted:     #8a8780;
        --muted2:    #6a6760;
        --accent:    #b87310;
        --accent2:   #9a5f0a;
        --green:     #2a8f5c;
        --red:       #c23535;
        --blue:      #3a80b5;
        --orange:    #c05620;
        --shadow:    0 2px 12px rgba(0,0,0,.12);
    }
}

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

html {
    height: 100%;
    scroll-behavior: smooth;
}
body {
    min-height: 100%;
    font-family: var(--font-body);
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--text); }

/* ============================================================
   LAYOUT
   ============================================================ */
.app-layout {
    display: grid;
    grid-template-columns: var(--nav-w) 1fr;
    grid-template-rows: var(--top-h) 1fr;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.app-topbar {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    padding: 0 20px;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    gap: 16px;
    z-index: 100;
}

.app-logo {
    font-family: var(--font-mono);
    font-weight: 500;
    font-size: 15px;
    color: var(--accent);
    letter-spacing: -.5px;
    white-space: nowrap;
    margin-right: 8px;
}

.app-topbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-badge {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px; height: 32px;
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--muted2);
    transition: color .15s, background .15s;
}
.topbar-badge:hover { color: var(--text); background: var(--surface2); }
.topbar-badge .count {
    position: absolute;
    top: -4px; right: -6px;
    min-width: 18px; height: 18px;
    padding: 0 5px;
    background: var(--red);
    border-radius: 9px;
    border: 2px solid var(--bg2);
    font-size: 10px;
    font-weight: 700;
    line-height: 14px;
    color: #fff;
    align-items: center;
    justify-content: center;
    display: flex;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px 4px 4px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background .15s;
    font-size: 12px;
}
.user-chip:hover { background: var(--surface2); }
.user-chip .avatar {
    width: 28px; height: 28px;
    border-radius: var(--radius);
    background: var(--accent2);
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 12px; color: #000;
}

/* ---- Sidebar ---- */
.app-sidebar {
    background: var(--bg2);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 0;
    display: flex;
    flex-direction: column;
}

/* Sidebar backdrop overlay (mobile) */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.55);
    z-index: 150;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease;
    -webkit-tap-highlight-color: transparent;
}
.sidebar-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.nav-section-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--muted);
    padding: 16px 16px 4px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    color: var(--muted2);
    font-size: 13px;
    font-weight: 400;
    border-left: 2px solid transparent;
    transition: color .15s, border-color .15s, background .15s;
    cursor: pointer;
}
.nav-link svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-link:hover { color: var(--text); background: var(--surface); }
.nav-link.active { color: var(--accent); border-left-color: var(--accent); background: rgba(232,160,32,.06); }

/* ---- Sidebar user card ---- */
.sidebar-user {
    padding: 20px 16px 16px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}
.sidebar-user .avatar {
    width: 44px; height: 44px;
    border-radius: var(--radius);
    background: var(--accent2);
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 16px; color: #000;
}
.sidebar-user .avatar.large { width: 48px; height: 48px; font-size: 18px; }
.sidebar-user-name { font-size: 14px; font-weight: 500; color: var(--text); }
.sidebar-user-role { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.sidebar-footer { margin-top: auto; padding: 8px 0; border-top: 1px solid var(--border); }

/* ---- Main content ---- */
.app-main {
    overflow-y: auto;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    min-height: 0;
    height: 100%;
    padding: 24px 28px;
}
.app-main > * + * {
    margin-top: 24px;
}

/* ============================================================
   PAGE HEADER
   ============================================================ */
.page-header {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    flex-wrap: wrap;
}
.page-header-left { flex: 1; min-width: 0; }
.page-title { font-size: 20px; font-weight: 600; color: var(--text); }
.page-sub   { font-size: 12px; color: var(--muted2); margin-top: 2px; font-family: var(--font-mono); }
.page-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ============================================================
   STAT CARDS
   ============================================================ */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: border-color .15s;
}
.stat-card:hover { border-color: var(--border2); }
.stat-label { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); font-weight: 600; }
.stat-value { font-family: var(--font-mono); font-size: 28px; font-weight: 500; color: var(--text); line-height: 1; }
.stat-value.amber { color: var(--accent); }
.stat-value.green { color: var(--green); }
.stat-value.red   { color: var(--red); }
.stat-sub { font-size: 11px; color: var(--muted2); }

/* ============================================================
   TABLES
   ============================================================ */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.table-header {
    display: flex;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
}
.table-title { font-weight: 600; font-size: 13px; }
.table-header .ml-auto { margin-left: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead tr { border-bottom: 1px solid var(--border); }
th {
    text-align: left;
    padding: 10px 16px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--muted);
    white-space: nowrap;
}
td {
    padding: 11px 16px;
    border-bottom: 1px solid rgba(255,255,255,.04);
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }
.asset-code { font-family: var(--font-mono); font-size: 12px; color: var(--accent); }
.eq-name { font-weight: 500; }
.eq-type  { font-size: 11px; color: var(--muted2); }

/* ============================================================
   BADGES / STATUS PILLS
   ============================================================ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 2px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .5px;
    text-transform: uppercase;
    white-space: nowrap;
}
.badge-green  { background: rgba(61,179,122,.15); color: #5cd49e; }
.badge-amber  { background: rgba(232,160,32,.15); color: var(--accent); }
.badge-red    { background: rgba(224,82,82,.15);  color: #f08080; }
.badge-blue   { background: rgba(74,159,212,.15); color: #79c0f0; }
.badge-gray   { background: rgba(255,255,255,.07); color: var(--muted2); }
.badge-orange { background: rgba(224,106,48,.15); color: #f0905a; }

/* Status → badge mapping helpers */
.status-in-service   { --c: var(--green); }
.status-in-shop      { --c: var(--blue); }
.status-out-of-service { --c: var(--red); }

/* ============================================================
   FORMS
   ============================================================ */
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .8px; color: var(--muted2); }
.form-control {
    background: var(--bg2);
    border: 1px solid var(--border2);
    color: var(--text);
    border-radius: var(--radius);
    padding: 9px 12px;
    font-size: 14px;
    font-family: var(--font-body);
    transition: border-color .15s;
    width: 100%;
}
.form-control:focus { outline: none; border-color: var(--accent); }
.form-control::placeholder { color: var(--muted); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

.form-row { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }
.form-row.thirds { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 640px) { .form-row, .form-row.thirds { grid-template-columns: 1fr; } }

.form-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}
.form-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--muted2);
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
    margin-bottom: 2px;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font-body);
    cursor: pointer;
    border: 1px solid transparent;
    transition: all .15s;
    white-space: nowrap;
    line-height: 1;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 14px; height: 14px; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: #f0b030; }
.btn-secondary { background: var(--surface2); color: var(--text); border-color: var(--border2); }
.btn-secondary:hover { border-color: var(--muted); }
.btn-danger { background: rgba(224,82,82,.15); color: var(--red); border-color: rgba(224,82,82,.3); }
.btn-danger:hover { background: rgba(224,82,82,.25); }
.btn-ghost { background: transparent; color: var(--muted2); }
.btn-ghost:hover { color: var(--text); background: var(--surface2); }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-icon { padding: 7px; width: 32px; height: 32px; }
.btn:disabled, .btn.loading { opacity: .55; pointer-events: none; }
.btn.loading::after {
    content: '';
    width: 12px; height: 12px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin .5s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    border-left: 3px solid;
    margin-bottom: 12px;
}
.alert-danger  { background: rgba(224,82,82,.1);   border-color: var(--red);   color: #f08080; }
.alert-success { background: rgba(61,179,122,.1);  border-color: var(--green); color: #6dd9a0; }
.alert-warning { background: rgba(232,160,32,.1);  border-color: var(--accent);color: var(--accent); }
.alert-info    { background: rgba(74,159,212,.1);  border-color: var(--blue);  color: #90d0f0; }

/* ============================================================
   TABS
   ============================================================ */
.tabs { display: flex; border-bottom: 1px solid var(--border); gap: 0; }
.tab {
    padding: 10px 18px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    color: var(--muted2);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color .15s, border-color .15s;
    white-space: nowrap;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab:hover:not(.active) { color: var(--text); }

/* ============================================================
   EQUIPMENT DETAIL CARD
   ============================================================ */
.equip-card {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px;
}
@media (max-width: 600px) { .equip-card { grid-template-columns: 1fr; } }
.equip-photo {
    width: 100%;
    aspect-ratio: 4/3;
    object-fit: cover;
    border-radius: var(--radius);
    background: var(--surface2);
}
.equip-meta { display: flex; flex-direction: column; gap: 12px; }
.equip-meta-row { display: flex; flex-wrap: wrap; gap: 6px 20px; }
.meta-item { min-width: 120px; }
.meta-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); }
.meta-value { font-size: 13px; color: var(--text); }
.meta-value.mono { font-family: var(--font-mono); }

/* ============================================================
   TIMELINE / LOG
   ============================================================ */
.timeline { display: flex; flex-direction: column; gap: 0; }
.timeline-item {
    display: grid;
    grid-template-columns: 36px 1fr;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255,255,255,.04);
}
.timeline-item:last-child { border-bottom: none; }
.timeline-icon {
    width: 32px; height: 32px;
    border-radius: var(--radius);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.timeline-icon svg { width: 15px; height: 15px; }
.ti-insp  { background: rgba(74,159,212,.15);  color: var(--blue); }
.ti-repair{ background: rgba(224,82,82,.15);   color: var(--red); }
.ti-pm    { background: rgba(61,179,122,.15);  color: var(--green); }
.ti-comm  { background: rgba(255,255,255,.06); color: var(--muted2); }
.ti-down  { background: rgba(232,160,32,.15);  color: var(--accent); }

.timeline-content { flex: 1; min-width: 0; }
.timeline-title { font-weight: 500; font-size: 13px; color: var(--text); }
.timeline-meta  { font-size: 11px; color: var(--muted2); margin-top: 2px; }
.timeline-desc  { font-size: 12px; color: var(--muted2); margin-top: 4px; }

/* ============================================================
   QR code display area (for print)
   ============================================================ */
.qr-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px;
    background: #fff;
    border-radius: var(--radius);
    color: #000;
    width: fit-content;
}
.qr-wrap img { width: 140px; height: 140px; }
.qr-asset-code { font-family: var(--font-mono); font-size: 11px; font-weight: 500; }

/* ============================================================
   UTILITY
   ============================================================ */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.ml-auto { margin-left: auto; }
.text-muted { color: var(--muted2); font-size: 12px; }
.text-mono { font-family: var(--font-mono); }
.text-sm { font-size: 12px; }
.text-amber { color: var(--accent); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.w-full { width: 100%; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.p-0 { padding: 0; }
.hidden { display: none !important; }

/* Mobile-only elements: hidden on desktop by default */
.app-bottom-nav, .bnav-quick-btn, .bnav-quick-menu, .fab, .fab-menu, .fab-overlay { display: none; }

/* Responsive split grid (used on dashboard) */
.responsive-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* ---- Search bar ---- */
.search-bar {
    display: flex;
    align-items: center;
    background: var(--bg2);
    border: 1px solid var(--border2);
    border-radius: var(--radius);
    padding: 0 10px;
    gap: 6px;
    min-width: 220px;
}
.search-bar svg { color: var(--muted); width: 14px; height: 14px; flex-shrink: 0; }
.search-bar input {
    background: none;
    border: none;
    color: var(--text);
    font-size: 13px;
    padding: 7px 0;
    outline: none;
    width: 100%;
}
.search-bar input::placeholder { color: var(--muted); }

/* ============================================================
   MOBILE-SPECIFIC OVERRIDES (QR scan UX)
   ============================================================ */
@media (max-width: 768px) {
    /* Eliminate 300ms tap delay on all interactive elements */
    a, button, input, select, textarea, label, .btn, .nav-link, .bnav-item, .tab, .badge,
    .topbar-badge, .user-chip, .fab, .bnav-quick-btn, .mobile-action-btn,
    .setting-row .actions button, .event-actions button { touch-action: manipulation; }

    .app-layout {
        grid-template-columns: 1fr;
        grid-template-rows: var(--top-h) 1fr;
    }
    .app-sidebar {
        position: fixed;
        top: var(--top-h);
        left: -100%;
        width: 280px;
        height: calc(100vh - var(--top-h));
        z-index: 200;
        transition: left .25s cubic-bezier(.16,1,.3,1);
        box-shadow: var(--shadow);
    }
    .app-sidebar.open { left: 0; }
    .app-sidebar .sidebar-user { padding: 16px; }
    .app-main {
        padding: 16px 16px 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .form-row { grid-template-columns: 1fr; }
    .equip-card { grid-template-columns: 1fr; }
    .stat-grid { grid-template-columns: 1fr 1fr; }
    .responsive-split { grid-template-columns: 1fr !important; }

    /* Table horizontal scroll */
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table-wrap table { min-width: 540px; }

    /* Card-style table rows */
    .table-wrap.card-table { overflow-x: visible; }
    .table-wrap.card-table table,
    .table-wrap.card-table thead,
    .table-wrap.card-table tbody,
    .table-wrap.card-table tr,
    .table-wrap.card-table td,
    .table-wrap.card-table th { display: block; }
    .table-wrap.card-table thead { display: none; }
    .table-wrap.card-table tr {
        padding: 14px 16px;
        border-bottom: 1px solid var(--border);
        margin: 0;
    }
    .table-wrap.card-table td {
        border: none;
        padding: 3px 0;
        font-size: 13px;
        display: flex;
        align-items: center;
        gap: 6px;
    }
    .table-wrap.card-table td:empty { display: none; }

    /* Hide desktop search bar on mobile */
    .search-bar { display: none; }

    /* Big tap targets for mobile */
    .nav-link { padding: 12px 16px; min-height: 44px; }
    .nav-section-label { padding-top: 20px; padding-bottom: 6px; }
    .topbar-badge { width: 40px; height: 40px; }
    .user-chip { min-height: 40px; }
    .form-control { padding: 11px 14px; font-size: 16px; }
    .btn { min-height: 40px; }
    .btn-sm { min-height: 32px; }
    select.form-control { font-size: 16px; }
    .tab { padding: 12px 14px; }
    input[type="checkbox"] { width: 20px; height: 20px; min-width: 20px; }
    label { min-height: 28px; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

    .mobile-action-btn {
        display: flex;
        align-items: center;
        gap: 12px;
        width: 100%;
        padding: 16px 18px;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius-lg);
        color: var(--text);
        font-size: 15px;
        font-weight: 500;
        cursor: pointer;
        transition: background .15s, border-color .15s;
        text-align: left;
        -webkit-tap-highlight-color: transparent;
    }
    .mobile-action-btn:hover { background: var(--surface2); border-color: var(--border2); }
    .mobile-action-btn:active { background: var(--surface); transform: scale(.98); }
    .mobile-action-btn .mab-icon {
        width: 40px; height: 40px;
        border-radius: var(--radius);
        display: flex; align-items: center; justify-content: center;
        flex-shrink: 0;
    }

    /* Page actions stack on mobile */
    .page-actions { width: 100%; }
    .page-header { flex-direction: column; }

    /* ---- Bottom Tab Bar ---- */
    .app-main {
        padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
        scroll-padding-bottom: 80px;
    }
    .app-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        height: 52px;
        background: var(--bg2);
        border-top: 1px solid var(--border);
        z-index: 150;
        padding-bottom: env(safe-area-inset-bottom);
    }
    .bnav-quick-btn { display: flex; }
    .bnav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 1px;
        color: var(--muted);
        font-size: 8px;
        font-weight: 600;
        letter-spacing: .5px;
        text-transform: uppercase;
        text-decoration: none;
        -webkit-tap-highlight-color: transparent;
        padding: 2px 0;
        transition: color .15s;
        min-height: 44px;
    }
    .bnav-item svg { width: 18px; height: 18px; }
    .bnav-item:active { opacity: .7; }
    .bnav-item.active { color: var(--accent); }
    .bnav-quick-btn {
        position: fixed;
        bottom: calc(52px + env(safe-area-inset-bottom,0px) - 4px);
        left: 50%;
        transform: translateX(-50%);
        width: 52px;
        height: 52px;
        border-radius: 50%;
        background: var(--accent);
        color: #fff;
        border: 3px solid var(--bg);
        box-shadow: 0 2px 12px rgba(232,160,32,.35);
        cursor: pointer;
        z-index: 151;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: transform .15s, box-shadow .15s;
        -webkit-tap-highlight-color: transparent;
        padding: 0;
    }
    .bnav-quick-btn:active { transform: translateX(-50%) scale(.92); }
    .bnav-quick-btn svg { width: 22px; height: 22px; }

    /* ---- Bottom Nav Quick Action Sheet ---- */
    .bnav-quick-menu { display:none;position:fixed;inset:0;z-index:300;align-items:flex-end;justify-content:center }
    .bnav-quick-menu.open { display:flex }
    .bnav-quick-overlay { position:absolute;inset:0;background:rgba(0,0,0,.5) }
    .bnav-quick-sheet {
        position:relative;
        width:100%;
        max-width:420px;
        background:var(--surface);
        border-radius:var(--radius-lg) var(--radius-lg) 0 0;
        padding:8px 20px calc(52px + env(safe-area-inset-bottom,0px) + 12px);
        animation:slideUp .25s cubic-bezier(.16,1,.3,1);
        max-height:70vh;
        overflow-y:auto;
    }
    @keyframes slideUp { from{transform:translateY(100%)} to{transform:translateY(0)} }
    .bnav-quick-handle {
        width:32px;height:4px;border-radius:2px;background:var(--border2);
        margin:8px auto 12px;
    }
    .bnav-quick-title { font-size:14px;font-weight:600;color:var(--text);margin-bottom:12px;text-align:center }
    .bnav-quick-item {
        display:flex;align-items:center;gap:12px;
        padding:14px 12px;margin:0 -12px;
        border-radius:var(--radius);
        color:var(--text);
        font-size:14px;font-weight:500;
        transition:background .15s;
        -webkit-tap-highlight-color:transparent;
    }
    .bnav-quick-item:hover,
    .bnav-quick-item:active { background:var(--surface2); text-decoration:none; color:var(--text) }
    .bnav-quick-item svg { width:20px;height:20px;color:var(--accent);flex-shrink:0 }

    /* ---- Floating Action Button (QR scan) ---- */
    .fab {
        position: fixed;
        bottom: calc(52px + 16px);
        right: 16px;
        width: 56px; height: 56px;
        border-radius: 50%;
        background: var(--accent);
        color: #fff;
        border: none;
        box-shadow: 0 4px 16px rgba(232,160,32,.4);
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 160;
        transition: transform .2s, box-shadow .2s;
        -webkit-tap-highlight-color: transparent;
    }
    .fab:active { transform: scale(.92); }
    .fab svg { width: 24px; height: 24px; }
    .fab-menu {
        position: fixed;
        bottom: calc(52px + 80px);
        right: 16px;
        display: flex;
        flex-direction: column;
        gap: 8px;
        z-index: 159;
        pointer-events: none;
        opacity: 0;
        transform: translateY(12px);
        transition: opacity .2s, transform .2s;
    }
    .fab-menu.open {
        pointer-events: auto;
        opacity: 1;
        transform: translateY(0);
    }
    .fab-menu-item {
        display: flex;
        align-items: center;
        gap: 8px;
        background: var(--surface);
        border: 1px solid var(--border2);
        border-radius: var(--radius-lg);
        padding: 10px 14px;
        color: var(--text);
        font-size: 13px;
        font-weight: 500;
        text-decoration: none;
        white-space: nowrap;
        box-shadow: var(--shadow);
        -webkit-tap-highlight-color: transparent;
    }
    .fab-menu-item:active { background: var(--surface2); }
    .fab-overlay {
        position: fixed; inset: 0;
        z-index: 158;
        display: none;
    }
    .fab-overlay.open { display: block; }

    /* ---- Toggle Button Group (inspection pass/fail) ---- */
    .toggle-group {
        display: flex;
        gap: 6px;
        margin-top: 8px;
    }
    .toggle-group label {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 4px;
        padding: 10px;
        border-radius: var(--radius);
        border: 1px solid var(--border2);
        background: var(--bg2);
        cursor: pointer;
        font-size: 12px;
        font-weight: 500;
        text-transform: uppercase;
        letter-spacing: .5px;
        transition: background .15s, border-color .15s, color .15s;
        min-height: 44px;
        -webkit-tap-highlight-color: transparent;
        user-select: none;
    }
    .toggle-group label:active { transform: scale(.97); }
    .toggle-group input[type="radio"] { display: none; }
    .toggle-group input[type="radio"]:checked + .tg-pass { background: rgba(61,179,122,.15); border-color: var(--green); color: var(--green); }
    .toggle-group input[type="radio"]:checked + .tg-fail { background: rgba(224,82,82,.15); border-color: var(--red); color: var(--red); }
    .toggle-group input[type="radio"]:checked + .tg-na    { background: rgba(255,255,255,.06); border-color: var(--muted); color: var(--muted2); }
    .toggle-group input[type="radio"]:checked + .tg-yes   { background: rgba(61,179,122,.15); border-color: var(--green); color: var(--green); }
    .toggle-group input[type="radio"]:checked + .tg-no    { background: rgba(224,82,82,.15); border-color: var(--red); color: var(--red); }
    .tg-pass { color: var(--muted2); }
    .tg-fail { color: var(--muted2); }
    .tg-na   { color: var(--muted2); }
    .tg-yes  { color: var(--muted2); }
    .tg-no   { color: var(--muted2); }

    /* ---- Pull-to-Refresh indicator ---- */
    .ptr-indicator {
        text-align: center;
        padding: 12px;
        font-size: 12px;
        color: var(--muted);
        display: none;
    }
    .ptr-indicator.visible { display: block; }
    .ptr-indicator .ptr-spinner {
        display: inline-block;
        width: 18px; height: 18px;
        border: 2px solid var(--border2);
        border-top-color: var(--accent);
        border-radius: 50%;
        animation: ptr-spin .5s linear infinite;
        margin-right: 8px;
        vertical-align: middle;
    }
    @keyframes ptr-spin { to { transform: rotate(360deg); } }

    /* ---- All tables use card layout on mobile ---- */
    .table-wrap table,
    .table-wrap thead,
    .table-wrap tbody,
    .table-wrap tr,
    .table-wrap td,
    .table-wrap th { display: block; }
    .table-wrap thead { display: none; }
    .table-wrap tr {
        padding: 12px 14px;
        border-bottom: 1px solid var(--border);
    }
    .table-wrap td {
        border: none;
        padding: 3px 0;
        font-size: 13px;
        display: flex;
        align-items: center;
        gap: 6px;
    }
    .table-wrap td:empty { display: none; }
    .table-wrap td:last-child { border-bottom: none; }

    /* ---- Recently Viewed on Dashboard ---- */
    .recent-chip {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        padding: 10px 14px;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius-lg);
        text-decoration: none;
        color: var(--text);
        font-size: 13px;
        transition: border-color .15s;
        min-height: 44px;
        -webkit-tap-highlight-color: transparent;
    }
    .recent-chip:active { border-color: var(--border2); }
    .recent-chip .rc-code { font-family: var(--font-mono); font-size: 11px; color: var(--accent); }
}

@media (max-width: 480px) {
    .stat-grid { grid-template-columns: 1fr; }
    .app-main { padding: 12px 12px calc(80px + env(safe-area-inset-bottom, 0px)); }
    .form-section { padding: 16px; }
    .page-title { font-size: 18px; }
    .app-topbar { padding: 0 12px; gap: 6px; }
    .app-logo { font-size: 13px; }
}

/* ============================================================
   PRINT — QR label sheet
   ============================================================ */
@media print {
    body { background: #fff; color: #000; }
    .app-topbar, .app-sidebar { display: none; }
    .app-main { padding: 0; }
    .no-print { display: none !important; }
    .qr-label-sheet {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 8mm;
        padding: 8mm;
    }
    .qr-label {
        border: 1px solid #ccc;
        border-radius: 4px;
        padding: 6mm;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 4px;
        break-inside: avoid;
        font-family: 'IBM Plex Mono', monospace;
        font-size: 9pt;
    }
}

/* ---- Voice Input (Web Speech API) ---- */
.vi-wrapper {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    width: 100%;
}
.vi-wrapper textarea, .vi-wrapper input[type="text"] {
    flex: 1;
}
.vi-btn {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    margin-top: 1px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--muted2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, border-color .15s, color .15s;
    -webkit-tap-highlight-color: transparent;
}
.vi-btn:hover { border-color: var(--border2); color: var(--text); }
.vi-btn:active { background: var(--surface2); }
.vi-btn.recording {
    background: rgba(224,82,82,.15);
    border-color: var(--red);
    color: var(--red);
    animation: vi-pulse .8s ease-in-out infinite;
}
@keyframes vi-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(224,82,82,.3); }
    50% { box-shadow: 0 0 0 6px rgba(224,82,82,0); }
}
.vi-btn svg { width: 16px; height: 16px; }
.vi-indicator {
    display: none;
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
    align-self: center;
    flex-shrink: 0;
}
.vi-indicator:not(:empty) { display: inline; }


