/* ==========================================================================
   Weigh Admin - mobile-first styles
   Phones: top app bar + bottom tab bar.  >= 992px: docked left sidebar.
   ========================================================================== */

:root {
    --wa-primary: #1E4E79;
    --wa-primary-rgb: 30, 78, 121;
    --wa-on-primary: #FFFFFF;
    --wa-bg: #F4F6F9;
    --wa-surface: #FFFFFF;
    --wa-border: #DDE3EA;
    --wa-text: #1B2430;
    --wa-muted: #5B6675;
    --wa-success: #1F7A4D;
    --wa-danger: #B42318;
    --wa-topbar-bg: #1E4E79;
    --wa-topbar-text: #FFFFFF;
    --wa-topbar-border: transparent;
    --wa-topbar-h: 56px;
    --wa-tabbar-h: 64px;
    --wa-sidebar-w: 248px;
    --wa-safe-top: env(safe-area-inset-top, 0px);
    --wa-safe-bottom: env(safe-area-inset-bottom, 0px);
}

[data-bs-theme="dark"] {
    --wa-primary: #6FA8DC;
    --wa-primary-rgb: 111, 168, 220;
    --wa-on-primary: #0B1220;
    --wa-bg: #11161D;
    --wa-surface: #1A212B;
    --wa-border: #2C3644;
    --wa-text: #E6EAF0;
    --wa-muted: #9AA5B4;
    --wa-success: #4CC38A;
    --wa-danger: #F97066;
    --wa-topbar-bg: #1A212B;
    --wa-topbar-text: #E6EAF0;
    --wa-topbar-border: #2C3644;
}

/* Bootstrap primary follows the app colour. */
:root, [data-bs-theme="dark"] {
    --bs-primary: var(--wa-primary);
    --bs-primary-rgb: var(--wa-primary-rgb);
    --bs-body-bg: var(--wa-bg);
    --bs-body-color: var(--wa-text);
    --bs-secondary-color: var(--wa-muted);
    --bs-border-color: var(--wa-border);
    --bs-link-color: var(--wa-primary);
    --bs-link-hover-color: var(--wa-primary);
}

html { -webkit-text-size-adjust: 100%; }

body {
    background: var(--wa-bg);
    color: var(--wa-text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: none;
}

/* 16px inputs stop iOS Safari from zooming into focused fields. */
input, select, textarea, .form-control, .form-select, .e-input-group input.e-input { font-size: 16px !important; }

.btn {
    min-height: 44px;
    border-radius: 10px;
    font-weight: 600;
}
.btn-primary {
    --bs-btn-bg: var(--wa-primary);
    --bs-btn-border-color: var(--wa-primary);
    --bs-btn-color: var(--wa-on-primary);
    --bs-btn-hover-bg: var(--wa-primary);
    --bs-btn-hover-border-color: var(--wa-primary);
    --bs-btn-hover-color: var(--wa-on-primary);
    --bs-btn-active-bg: var(--wa-primary);
    --bs-btn-active-border-color: var(--wa-primary);
    --bs-btn-active-color: var(--wa-on-primary);
    --bs-btn-disabled-bg: var(--wa-primary);
    --bs-btn-disabled-border-color: var(--wa-primary);
    --bs-btn-disabled-color: var(--wa-on-primary);
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-lg { min-height: 52px; }

.form-control, .form-select { min-height: 48px; border-radius: 10px; }
.form-label { font-weight: 600; font-size: .875rem; color: var(--wa-muted); margin-bottom: .35rem; }

/* ── Top app bar ─────────────────────────────────────────────────────────── */
.wa-topbar {
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 1030;
    height: calc(var(--wa-topbar-h) + var(--wa-safe-top));
    padding: var(--wa-safe-top) 8px 0 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--wa-topbar-bg);
    color: var(--wa-topbar-text);
    border-bottom: 1px solid var(--wa-topbar-border);
}
.wa-topbar .wa-title { flex: 1; min-width: 0; line-height: 1.15; }
.wa-topbar h1 { font-size: 1.125rem; font-weight: 700; margin: 0; color: inherit; }
.wa-topbar .wa-subtitle {
    font-size: .8rem; opacity: .85;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block;
}
.wa-icon-btn {
    width: 44px; height: 44px;
    display: inline-grid; place-items: center;
    border: 0; border-radius: 12px;
    background: transparent; color: inherit;
    font-size: 1.35rem;
}
.wa-icon-btn:active { background: rgba(255, 255, 255, .15); }

/* ── Content ─────────────────────────────────────────────────────────────── */
.wa-main {
    padding: calc(var(--wa-topbar-h) + var(--wa-safe-top) + 16px) 16px
             calc(var(--wa-tabbar-h) + var(--wa-safe-bottom) + 24px);
    max-width: 1200px;
    margin: 0 auto;
}
.wa-auth-main { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }

.wa-card {
    background: var(--wa-surface);
    border: 1px solid var(--wa-border);
    border-radius: 16px;
    padding: 16px;
}
.wa-card + .wa-card { margin-top: 16px; }
.wa-section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--wa-muted); font-weight: 700; margin: 0 0 12px; }

.wa-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.wa-toolbar .wa-grow { flex: 1; }
.wa-meta { font-size: .8rem; color: var(--wa-muted); }

.wa-empty { text-align: center; padding: 40px 16px; color: var(--wa-muted); }
.wa-empty i { font-size: 2.5rem; display: block; margin-bottom: 8px; }

/* Form actions pinned above the tab bar on phones, on a solid strip so the form never shows through. */
.wa-sticky-actions {
    position: sticky;
    bottom: calc(var(--wa-tabbar-h) + var(--wa-safe-bottom));
    z-index: 5;
    display: flex; gap: 8px;
    margin: 16px -16px -24px;
    padding: 12px 16px;
    background: var(--wa-bg);
    border-top: 1px solid var(--wa-border);
}
.wa-sticky-actions .btn { flex: 1; }
.wa-sticky-actions .btn-outline-secondary { background: var(--wa-surface); }

/* ── Bottom tab bar (phones) ─────────────────────────────────────────────── */
.wa-tabbar {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 1030;
    height: calc(var(--wa-tabbar-h) + var(--wa-safe-bottom));
    padding-bottom: var(--wa-safe-bottom);
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    background: var(--wa-surface);
    border-top: 1px solid var(--wa-border);
}
.wa-tab {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: var(--wa-muted);
    text-decoration: none;
    font-size: .7rem; font-weight: 600;
    border: 0; background: transparent;
    min-width: 0;
}
.wa-tab i { font-size: 1.35rem; line-height: 1; padding: 4px 16px; border-radius: 16px; }
.wa-tab.active { color: var(--wa-primary); }
.wa-tab.active i { background: rgba(var(--wa-primary-rgb), .14); }
.wa-tab span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* ── "More" bottom sheet ─────────────────────────────────────────────────── */
.wa-sheet.offcanvas-bottom {
    height: auto;
    max-height: 85vh;
    border-radius: 20px 20px 0 0;
    background: var(--wa-surface);
    padding-bottom: var(--wa-safe-bottom);
}
.wa-sheet .wa-grabber { width: 40px; height: 4px; border-radius: 2px; background: var(--wa-border); margin: 8px auto 0; }
.wa-menu { list-style: none; margin: 0; padding: 0; }
.wa-menu a, .wa-menu button {
    display: flex; align-items: center; gap: 14px;
    width: 100%; min-height: 52px; padding: 0 16px;
    color: var(--wa-text); text-decoration: none;
    background: transparent; border: 0; text-align: left; font-size: 1rem;
    border-radius: 12px;
}
.wa-menu a:active, .wa-menu button:active, .wa-menu a.active { background: rgba(var(--wa-primary-rgb), .1); }
.wa-menu a.active { color: var(--wa-primary); font-weight: 600; }
.wa-menu i { font-size: 1.25rem; width: 24px; text-align: center; color: var(--wa-muted); }
.wa-menu a.active i { color: var(--wa-primary); }
.wa-menu .wa-danger, .wa-menu .wa-danger i { color: var(--wa-danger); }
.wa-menu-heading { padding: 16px 16px 4px; font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--wa-muted); }

.wa-profile { display: flex; gap: 12px; align-items: center; padding: 16px; }
.wa-avatar {
    width: 44px; height: 44px; border-radius: 50%; flex: none;
    display: grid; place-items: center;
    background: var(--wa-primary); color: var(--wa-on-primary); font-weight: 700;
}
.wa-kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: .875rem; padding: 0 16px 8px; }
.wa-kv dt { color: var(--wa-muted); font-weight: 500; }
.wa-kv dd { margin: 0; word-break: break-word; }

/* ── Sidebar (desktop) ───────────────────────────────────────────────────── */
.wa-sidebar { display: none; }

@media (min-width: 992px) {
    .wa-tabbar, .wa-more-btn { display: none !important; }
    .wa-sidebar {
        display: flex; flex-direction: column;
        position: fixed; inset: 0 auto 0 0; z-index: 1031;
        width: var(--wa-sidebar-w);
        background: var(--wa-surface);
        border-right: 1px solid var(--wa-border);
        overflow-y: auto;
    }
    .wa-sidebar .wa-brand {
        display: flex; align-items: center; gap: 10px;
        height: var(--wa-topbar-h); padding: 0 16px;
        font-weight: 800; font-size: 1.05rem; color: var(--wa-text); text-decoration: none;
        border-bottom: 1px solid var(--wa-border);
    }
    .wa-sidebar .wa-brand img { width: 32px; height: 32px; }
    .wa-sidebar .wa-menu { padding: 8px; }
    .wa-topbar { left: var(--wa-sidebar-w); }
    .wa-main {
        margin-left: var(--wa-sidebar-w);
        padding: calc(var(--wa-topbar-h) + 24px) 32px 32px;
        max-width: calc(1200px + var(--wa-sidebar-w));
    }
    .wa-sticky-actions { position: static; margin: 16px 0 0; padding: 0; background: none; border: 0; }
    .wa-sticky-actions .btn { flex: 0 0 auto; min-width: 140px; }
}

/* ── Syncfusion tweaks ───────────────────────────────────────────────────── */
.e-grid { border-radius: 12px; overflow: hidden; }
.e-grid .e-rowcell { font-size: .95rem; }
/* Card rows: label on the left (Syncfusion's td::before), value on the right. */
.e-bigger .e-grid.e-row-responsive .e-gridcontent td { padding: 7px 12px 7px 42% !important; min-height: 36px; }
.e-bigger .e-grid.e-row-responsive .e-gridcontent td::before { width: 38%; top: 8px; left: 12px; color: var(--wa-muted); font-weight: 600; }
.e-bigger .e-grid.e-row-responsive .e-gridcontent td.e-rowcell { text-align: left !important; }
/* Vertical (card) rows: give each record breathing room and a clear edge. */
.e-grid.e-row-responsive tr.e-row { border-bottom: 6px solid var(--wa-bg); }
.e-grid .e-row { cursor: pointer; }

.e-toast-container.e-toast-bottom-center { bottom: calc(var(--wa-tabbar-h) + var(--wa-safe-bottom) + 8px) !important; }
@media (min-width: 992px) { .e-toast-container.e-toast-bottom-center { bottom: 16px !important; } }

/* Dialogs fill the screen on phones. */
@media (max-width: 575.98px) {
    .e-dialog.wa-dialog {
        width: 100% !important; max-width: 100% !important;
        max-height: 100% !important; height: 100% !important;
        top: 0 !important; left: 0 !important;
        border-radius: 0;
    }
    .e-dialog.wa-dialog .e-dlg-header-content { padding-top: calc(16px + var(--wa-safe-top)); }
    .e-dialog.wa-dialog .e-footer-content { padding-bottom: calc(12px + var(--wa-safe-bottom)); }
}
.e-dialog.wa-dialog .e-footer-content { display: flex; gap: 8px; }
.e-dialog.wa-dialog .e-footer-content .e-btn { flex: 1; min-height: 48px; font-size: 1rem; margin: 0; }

/* Busy overlay */
.wa-busy {
    position: fixed; inset: 0; z-index: 2000;
    display: none; place-items: center;
    background: rgba(0, 0, 0, .25);
}
.wa-busy.show { display: grid; }
.wa-busy-box { background: var(--wa-surface); border-radius: 16px; padding: 20px 24px; display: flex; align-items: center; gap: 12px; font-weight: 600; }

/* Status pills */
.wa-pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .75rem; font-weight: 700; }
.wa-pill-on  { background: rgba(31, 122, 77, .14); color: var(--wa-success); }
.wa-pill-off { background: rgba(180, 35, 24, .12); color: var(--wa-danger); }
.wa-pill-info { background: rgba(var(--wa-primary-rgb), .14); color: var(--wa-primary); }

/* Selectable list (customer picker) */
.wa-list { list-style: none; padding: 0; margin: 0; }
.wa-list-item {
    display: flex; align-items: center; gap: 12px; width: 100%;
    padding: 14px 16px; min-height: 64px;
    background: var(--wa-surface); border: 1px solid var(--wa-border); border-radius: 14px;
    color: var(--wa-text); text-align: left;
}
.wa-list-item + .wa-list-item, .wa-list li + li { margin-top: 8px; }
.wa-list-item.active { border-color: var(--wa-primary); box-shadow: 0 0 0 1px var(--wa-primary) inset; }
.wa-list-item .wa-grow { flex: 1; min-width: 0; }
.wa-list-item small { color: var(--wa-muted); display: block; }

/* Install hint (iOS) */
.wa-install-hint { font-size: .875rem; color: var(--wa-muted); padding: 0 16px 12px; }

/* ── Admin (desktop-first) ───────────────────────────────────────────────── */
.wa-page-wide { max-width: 1100px; }
.wa-row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.wa-row-actions .btn { min-height: 32px; padding: 4px 10px; border-radius: 8px; font-weight: 500; }
.wa-share-buttons .btn { min-height: 46px; }

/* ── Badges, module pills, device screens ───────────────────────────────── */
.wa-badge {
    display: inline-block; min-width: 22px; padding: 1px 8px; border-radius: 999px;
    background: #D92D20; color: #fff; font-size: .75rem; font-weight: 700; text-align: center;
}
.wa-tab { position: relative; }
.wa-tab-dot { position: absolute; top: 8px; right: calc(50% - 18px); width: 9px; height: 9px; border-radius: 50%; background: #D92D20; }
.wa-pill-warn { background: rgba(245, 184, 61, .22); color: #8A5A00; }
[data-bs-theme="dark"] .wa-pill-warn { color: #F5B83D; }

.wa-module-card .wa-module-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.wa-module-card .wa-module-head h2 { margin: 0; flex: 1; }
.wa-module-card.wa-off .wa-module-body { display: none; }

.wa-pin { letter-spacing: .5em; text-align: center; font-size: 1.5rem !important; font-weight: 700; }
.wa-device-hero { text-align: center; margin-bottom: 24px; }
.wa-device-hero img { width: 72px; height: 72px; border-radius: 18px; }
.wa-device-hero h1 { font-size: 1.35rem; font-weight: 800; margin: 14px 0 4px; }

/* Centre list: one column on phones, more on wide screens */
.wa-centre-grid { display: grid; grid-template-columns: 1fr; gap: 8px; }
@media (min-width: 768px) { .wa-centre-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1200px) { .wa-centre-grid { grid-template-columns: repeat(3, 1fr); } }
.wa-centre {
    display: flex; align-items: center; gap: 12px; width: 100%; min-height: 60px;
    padding: 12px 14px; text-align: left;
    background: var(--wa-surface); color: var(--wa-text);
    border: 1px solid var(--wa-border); border-radius: 14px;
}
.wa-centre:hover { border-color: var(--wa-primary); }
.wa-centre.wa-applied { border-left: 5px solid #0F8B8D; }
.wa-centre .wa-grow { flex: 1; min-width: 0; font-weight: 600; }
.wa-weights { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.wa-weights .wa-pair-title { grid-column: 1 / -1; font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--wa-muted); margin-top: 4px; }
