html, body {
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
}

.agrumy-topbar {
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

.agrumy-main {
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
}

.agrumy-user {
    max-width: 12rem;
}

/* Same box for every state: the Disabled badge's border and longest label set the size. */
.device-status-badge {
    min-width: 7.5em;
    border: var(--bs-border-width) solid transparent;
}

/* GitHub, Local and Custom share one width, sized by the longest label. */
.fw-source-badge {
    min-width: 5.5em;
}

/* Lucide SVGs as masks so they take currentColor and the 1em box of a bootstrap-icons glyph. */
.ag-icon {
    display: inline-block;
    width: 1em;
    height: 1em;
    vertical-align: -0.125em;
    background-color: currentColor;
    -webkit-mask: var(--ag-icon) center / contain no-repeat;
    mask: var(--ag-icon) center / contain no-repeat;
}

.ag-icon-apple {
    --ag-icon: url("../lib/lucide-static/icons/apple.svg");
}

.ag-icon-sprout {
    --ag-icon: url("../lib/lucide-static/icons/sprout.svg");
}

.ag-icon-wheat {
    --ag-icon: url("../lib/lucide-static/icons/wheat.svg");
}

.agrumy-stat {
    font-size: 1.25rem;
    font-weight: 600;
}

#blazor-error-ui,
#components-reconnect-modal {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1090;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
    color: var(--bs-warning-text-emphasis);
    background: var(--bs-warning-bg-subtle);
    border-top: 1px solid var(--bs-warning-border-subtle);
}

#components-reconnect-modal .reconnect-state {
    display: none;
}

#components-reconnect-modal.components-reconnect-show,
#components-reconnect-modal.components-reconnect-retrying,
#components-reconnect-modal.components-reconnect-failed,
#components-reconnect-modal.components-reconnect-paused,
#components-reconnect-modal.components-reconnect-resume-failed,
#components-reconnect-modal.components-reconnect-rejected {
    display: flex;
}

#components-reconnect-modal.components-reconnect-show .reconnect-connecting,
#components-reconnect-modal.components-reconnect-retrying .reconnect-connecting,
#components-reconnect-modal.components-reconnect-failed .reconnect-failed,
#components-reconnect-modal.components-reconnect-paused .reconnect-failed,
#components-reconnect-modal.components-reconnect-resume-failed .reconnect-rejected,
#components-reconnect-modal.components-reconnect-rejected .reconnect-rejected {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.agrumy-sidebar-toggle,
.agrumy-sidebar-brand .btn {
    min-width: 44px;
    min-height: 44px;
}

.agrumy-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1020;
    display: flex;
    padding-bottom: env(safe-area-inset-bottom);
}

.agrumy-bottom-nav a {
    flex: 1 1 0;
    min-width: 0;
    min-height: 3.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    color: var(--bs-secondary-color);
    text-decoration: none;
}

.agrumy-bottom-nav a .bi {
    font-size: 1.25rem;
}

.agrumy-bottom-nav a span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.agrumy-bottom-nav a.active {
    color: var(--bs-success-text-emphasis);
    font-weight: 600;
}

.agrumy-user-menu {
    min-width: 16rem;
    max-height: calc(100dvh - 4.5rem);
    overflow-y: auto;
}

/* Overflow "..." menu: absolute so it never widens a card header or table cell. */
.agrumy-action-menu {
    position: relative;
}

.agrumy-action-menu .dropdown-menu.show {
    display: block;
    position: absolute;
    right: 0;
    left: auto;
    top: 100%;
    z-index: 1050;
}

.agrumy-action-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1040;
}

.agrumy-shell {
    display: flex;
    min-height: 100vh;
    min-height: 100dvh;
}

.agrumy-sidebar {
    flex: 0 0 16rem;
    width: 16rem;
    display: flex;
    flex-direction: column;
    background: #1f2d27;
    color: #cfd8d3;
    overflow-y: auto;
    padding-top: env(safe-area-inset-top);
}

.agrumy-sidebar-footer {
    margin-top: auto;
    padding: 0.5rem 0.5rem calc(0.5rem + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.agrumy-sidebar-brand {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    padding: 0 0.5rem 0 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.agrumy-sidebar-nav {
    flex: 1 0 auto;
    padding: 0.5rem;
}

.agrumy-sidebar .nav-link {
    color: #cfd8d3;
    border-radius: 0.375rem;
}

.agrumy-sidebar .nav-link:hover,
.agrumy-sidebar .nav-link.active {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

.agrumy-content {
    flex: 1 1 auto;
    min-width: 0;
}

.agrumy-sidebar-backdrop {
    display: none;
}

.agrumy-sidebar-toggle {
    display: none;
}

.agrumy-header .dropdown-menu.show {
    display: block;
    position: absolute;
}

.agrumy-header .dropdown-menu-end.show {
    right: 0;
    left: auto;
}

.agrumy-sidebar-brand,
.agrumy-header {
    box-sizing: border-box;
    height: 3.5rem;
}

.agrumy-header {
    padding-top: 0;
    padding-bottom: 0;
}

@media (max-width: 991.98px) {
    .agrumy-sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 1040;
        transform: translateX(-100%);
        transition: transform 0.2s ease-in-out;
    }

    .sidebar-open .agrumy-sidebar {
        transform: none;
    }

    .sidebar-open .agrumy-sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1030;
        background: rgba(0, 0, 0, 0.4);
    }

    .agrumy-sidebar-toggle {
        display: inline-block;
    }
}

@media (max-width: 767.98px) {
    /* Bottom sheet on phones: a table-responsive wrapper would clip an absolute menu. */
    .agrumy-action-menu .dropdown-menu.show {
        position: fixed;
        top: auto;
        left: 0.5rem;
        right: 0.5rem;
        bottom: calc(0.5rem + env(safe-area-inset-bottom));
        max-height: 70dvh;
        overflow-y: auto;
    }

    .agrumy-tab-panel {
        border-top: var(--bs-border-width) solid var(--bs-border-color) !important;
        border-radius: var(--bs-border-radius) !important;
    }

    .agrumy-app:has(.has-bottom-nav) > footer {
        padding-bottom: calc(4rem + env(safe-area-inset-bottom)) !important;
    }

    .agrumy-main .form-control,
    .agrumy-main .form-select {
        max-width: 100%;
    }

    /* Tables not already in a .table-responsive wrapper scroll sideways instead of widening the page. */
    .agrumy-main :not(.table-responsive) > table.table:not([style*="table-layout"]) {
        display: block;
        max-width: 100%;
        overflow-x: auto;
    }
}

/* The parcel wizard's header, steps and footer stay on screen with the map: no page scroll. */
.ag-wizard-map {
    height: calc(100vh - 27rem);
    min-height: 16rem;
}

/* Rule editor: full width on phones, nesting indents by depth, natural widths from 576px up. */
.ag-rule-text {
    min-width: 0;
}

.ag-rule-children {
    margin-left: 0.5rem;
}

.ag-rule-children > .ag-rule-child {
    min-width: 0;
}

@media (min-width: 576px) {
    .ag-rule-autofit {
        width: auto;
        min-width: 18rem;
    }

    .ag-rule-children {
        margin-left: 1.5rem;
    }

    .ag-rule-children.flex-row > .ag-rule-child {
        flex: 1 1 16rem;
        min-width: 14rem;
    }

    .ag-rule-duration {
        max-width: 16rem;
    }
}

@media (min-width: 992px) {
    .ag-wizard-side {
        max-height: calc(100vh - 25rem);
        overflow-y: auto;
    }
}

@media (max-width: 575.98px) {
    .agrumy-widget-grid {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    .agrumy-touch,
    .agrumy-actions .btn {
        min-width: 44px;
    }

    .agrumy-touch,
    .agrumy-actions .btn,
    .agrumy-action-menu .dropdown-item {
        min-height: 44px;
    }

    .agrumy-action-menu .dropdown-item {
        display: flex;
        align-items: center;
    }
}

.agrumy-toasts {
    z-index: 1090;
    padding-top: calc(env(safe-area-inset-top) + 1rem) !important;
}

@media (max-width: 575.98px) {
    .agrumy-toasts {
        left: 0;
        right: 0;
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }

    .agrumy-toasts .toast {
        width: 100%;
    }
}

.form-control[aria-invalid="true"],
.form-select[aria-invalid="true"] {
    border-color: var(--bs-form-invalid-border-color);
}

.form-control[aria-invalid="true"]:focus,
.form-select[aria-invalid="true"]:focus {
    border-color: var(--bs-form-invalid-border-color);
    box-shadow: 0 0 0 .25rem rgba(var(--bs-danger-rgb), .25);
}
