/*
 * Hero mobile and dashboard hardening.
 * Loaded after the base theme so phone navigation, dashboard layouts, forms,
 * tables and interactive controls remain usable in both LTR and RTL.
 */

:root {
    --hero-mobile-header: #003c8f;
    --hero-mobile-header-strong: #002d6b;
    --hero-mobile-overlay: rgba(15, 23, 42, .56);
    --hero-mobile-shadow: 0 24px 60px rgba(15, 23, 42, .24);
}

html {
    max-width: 100%;
    overflow-x: hidden;
}

body {
    max-width: 100%;
    overflow-x: clip;
}

img,
svg,
video,
canvas,
iframe {
    max-width: 100%;
}

/* Prevent Bootstrap/grid children from forcing the page wider than the viewport. */
.container,
.container-fluid,
.row,
[class*="col-"] {
    min-width: 0;
}

/* Accessible focus states for the controls introduced/fixed here. */
.ec-header a:focus-visible,
.ec-header button:focus-visible,
.dashboard-mobile-menu-button:focus-visible,
.notification-filters a:focus-visible,
.notification-filters button:focus-visible {
    outline: 3px solid rgba(255, 255, 255, .72);
    outline-offset: 2px;
}

/* Mobile site-menu overlay. */
.ec-mobile-menu-overlay {
    position: fixed;
    inset: 0;
    z-index: 9997;
    display: block;
    visibility: hidden;
    border: 0;
    background: var(--hero-mobile-overlay);
    opacity: 0;
    transition: opacity .22s ease, visibility 0s linear .22s;
}

.ec-mobile-menu-overlay.is-visible {
    visibility: visible;
    opacity: 1;
    transition-delay: 0s;
}

body.hero-mobile-menu-open,
body.hero-dashboard-menu-open {
    overflow: hidden !important;
    touch-action: none;
}

#ec-mobile-menu {
    z-index: 9998;
    width: min(88vw, 360px);
    max-width: 100%;
    box-shadow: var(--hero-mobile-shadow);
}

#ec-mobile-menu .ec-menu-title {
    min-height: 64px;
    align-items: center;
    padding: 14px 18px;
    background: var(--hero-mobile-header);
}

#ec-mobile-menu .ec-menu-title .menu_title,
#ec-mobile-menu .ec-menu-title .ec-close {
    color: #fff !important;
}

#ec-mobile-menu .ec-menu-title .ec-close {
    width: 42px;
    height: 42px;
    display: inline-grid;
    place-items: center;
    flex: 0 0 42px;
    margin: 0;
    border: 1px solid rgba(255, 255, 255, .24);
    border-radius: 12px;
    background: rgba(255, 255, 255, .10);
    font-size: 28px;
    line-height: 1;
}

#ec-mobile-menu .ec-menu-inner {
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

#ec-mobile-menu .ec-menu-content > ul,
#ec-mobile-menu .ec-menu-content ul {
    max-width: 100%;
}

#ec-mobile-menu .ec-menu-content a {
    overflow-wrap: anywhere;
}

/* Dashboard shell: desktop geometry and overflow safety. */
.hero-dashboard-page .ec-page-content {
    overflow: visible;
}

.notification-page-wrapper {
    width: 100%;
    max-width: 1420px;
    grid-template-columns: minmax(240px, 280px) minmax(0, 1fr);
    box-sizing: border-box;
}

.notification-sidebar,
.notification-stream-container,
.notification-stream-container > *,
.notification-stream-container .ha-page,
.notification-stream-container .hero-account,
.notification-stream-container .ha-shell {
    min-width: 0;
    max-width: 100%;
}

.notification-sidebar-overlay,
.dashboard-mobile-toolbar {
    display: none;
}

.notification-filters .nav-treeview {
    display: none;
    margin: 4px 0 8px;
    padding: 4px 0 4px 24px;
    border-inline-start: 1px solid #dce5ef;
    list-style: none;
}

.notification-filters .nav-treeview.is-open,
.notification-filters .filter-group.is-open > .nav-treeview {
    display: block;
}

.notification-filters .filter-link {
    border: 0;
    text-decoration: none;
}

.notification-filters button.filter-link {
    font-family: inherit;
}

.notification-filters .dashboard-submenu-chevron {
    margin-inline-start: auto;
    transition: transform .18s ease;
}

.notification-filters .filter-group.is-open > .filter-link .dashboard-submenu-chevron {
    transform: rotate(180deg);
}

.notification-filters .nav-treeview .nav-link {
    min-height: 40px;
    display: flex;
    align-items: center;
    gap: 9px;
    margin: 2px 0;
    padding: 8px 10px;
    border-radius: 9px;
    color: var(--notif-text-muted, #64748b);
    font-size: 13px;
    text-decoration: none;
}

.notification-filters .nav-treeview .nav-link:hover,
.notification-filters .nav-treeview .nav-link.active {
    background: #eef4fb;
    color: var(--notif-primary, #003c8f);
}

/* Generic dashboard content hardening for module-provided screens. */
.notification-stream-container input,
.notification-stream-container select,
.notification-stream-container textarea,
.notification-stream-container .form-control,
.notification-stream-container .form-select,
.notification-stream-container .input-group,
.notification-stream-container form {
    max-width: 100%;
}

.notification-stream-container textarea {
    resize: vertical;
}

.notification-stream-container .card,
.notification-stream-container .ha-card,
.notification-stream-container .hero-account .ha-card,
.notification-stream-container .modal-content {
    max-width: 100%;
}

.notification-stream-container .table-responsive,
.notification-stream-container .ha-table-scroll,
.notification-stream-container .ec-table-responsive {
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
}

.notification-stream-container table {
    max-width: 100%;
}

.notification-stream-container pre,
.notification-stream-container code,
.notification-stream-container .ha-provider-meta,
.notification-stream-container .ha-card-meta,
.notification-stream-container .ha-page-subtitle,
.notification-stream-container .ha-section-copy {
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* Preserve phone inputs as LTR in Arabic dashboards. */
.notification-stream-container input[type="tel"],
.notification-stream-container .iti,
.notification-stream-container .intl-tel-input,
.notification-stream-container .phone-input,
.notification-stream-container .phone-input-container {
    direction: ltr !important;
    text-align: left !important;
}

@media (max-width: 991.98px) {
    /* Blue mobile action bar with readable white controls. */
    .ec-header .header-top {
        position: relative;
        z-index: 1000;
        padding: 8px 0;
        border-bottom: 0;
        color: #fff;
        background: linear-gradient(135deg, var(--hero-mobile-header), var(--hero-mobile-header-strong));
    }

    .ec-header .header-top .row {
        flex-wrap: nowrap;
        gap: 8px;
    }

    .ec-header .header-top-center {
        min-width: 0;
        text-align: start !important;
    }

    .ec-header .header-top-message,
    .ec-header .header-top-message span {
        color: #fff !important;
    }

    .ec-header .header-top-message {
        overflow: hidden;
        font-size: 12px;
        line-height: 1.35;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .ec-header .header-top .ec-header-bottons {
        position: static;
        min-width: max-content;
        align-items: center;
        justify-content: flex-end;
        gap: 4px;
    }

    .ec-header .header-top .ec-header-bottons > * + * {
        margin: 0;
        padding: 0;
    }

    .ec-header .header-top .ec-header-user,
    .ec-header .header-top .ec-header-btn,
    .ec-header .header-top .ec-header-user .dropdown-toggle {
        position: relative !important;
        inset: auto !important;
        width: 42px;
        height: 42px;
        min-width: 42px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        margin: 0 !important;
        padding: 0 !important;
        border: 1px solid rgba(255, 255, 255, .18);
        border-radius: 12px;
        color: #fff !important;
        background: rgba(255, 255, 255, .08);
    }

    .ec-header .header-top .ec-header-user .dropdown-toggle:hover,
    .ec-header .header-top .ec-header-btn:hover,
    .ec-header .header-top .ec-header-user .dropdown-toggle:focus,
    .ec-header .header-top .ec-header-btn:focus {
        color: #fff !important;
        background: rgba(255, 255, 255, .18);
    }

    .ec-header .header-top .ec-header-bottons i,
    .ec-header .header-top .ec-header-btn i,
    .ec-header .header-top .header-icon i,
    .ec-header .header-top .ec-header-user .dropdown-toggle i {
        color: #fff !important;
        font-size: 22px;
    }

    .ec-header .header-top .ec-header-count {
        top: -4px;
        right: -4px;
        bottom: auto;
        min-width: 18px;
        height: 18px;
        padding: 0 4px;
        border: 2px solid var(--hero-mobile-header);
        background: #ef4444;
        font-size: 10px;
        line-height: 14px;
    }

    [dir="rtl"] .ec-header .header-top .ec-header-count {
        right: auto;
        left: -4px;
    }

    .ec-header .header-top .ec-header-user .dropdown-menu {
        top: calc(100% + 8px) !important;
        right: 0 !important;
        left: auto !important;
        min-width: 180px;
        border: 1px solid #e2e8f0;
        border-radius: 12px;
        box-shadow: 0 16px 38px rgba(15, 23, 42, .18);
        transform: none !important;
    }

    [dir="rtl"] .ec-header .header-top .ec-header-user .dropdown-menu {
        right: auto !important;
        left: 0 !important;
    }

    .ec-header .ec-header-bottom.d-lg-none {
        padding: 16px 0 12px;
        background: #fff;
    }

    .ec-header .ec-header-bottom.d-lg-none .header-logo img {
        width: auto;
        max-width: min(180px, 100%);
        max-height: 58px;
        object-fit: contain;
    }

    .ec-header .ec-header-bottom.d-lg-none .header-search,
    .ec-header .ec-header-bottom.d-lg-none .header-search form {
        width: 100%;
        min-width: 0;
    }

    .ec-header .ec-header-bottom.d-lg-none .location-selector-btn {
        min-height: 46px;
        text-align: start;
    }

    /* Dashboard becomes a content-first page with an accessible drawer. */
    .hero-dashboard-page .ec-page-content {
        padding-top: 20px;
    }

    .hero-dashboard-page .ec-page-content > .container {
        max-width: 100%;
        padding-inline: 14px;
    }

    .notification-page-wrapper {
        display: block;
        margin: 0 auto 28px;
        padding: 0;
    }

    .dashboard-mobile-toolbar {
        min-height: 56px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        margin-bottom: 14px;
        padding: 10px 12px;
        border: 1px solid #dfe7f1;
        border-radius: 14px;
        background: #fff;
        box-shadow: 0 8px 24px rgba(15, 36, 74, .06);
    }

    .dashboard-mobile-toolbar-copy {
        min-width: 0;
    }

    .dashboard-mobile-toolbar-copy strong,
    .dashboard-mobile-toolbar-copy span {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .dashboard-mobile-toolbar-copy strong {
        color: #1e293b;
        font-size: 14px;
    }

    .dashboard-mobile-toolbar-copy span {
        margin-top: 2px;
        color: #64748b;
        font-size: 11px;
    }

    .dashboard-mobile-menu-button {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        flex: 0 0 auto;
        padding: 9px 13px;
        border: 0;
        border-radius: 11px;
        background: var(--notif-primary, #003c8f);
        color: #fff;
        font: inherit;
        font-size: 13px;
        font-weight: 750;
        cursor: pointer;
    }

    .notification-sidebar {
        position: fixed;
        z-index: 10002;
        inset-block: 0;
        inset-inline-start: 0;
        top: 0;
        width: min(88vw, 340px);
        max-width: 100%;
        overflow-y: auto;
        overscroll-behavior: contain;
        padding: 22px 16px 28px;
        background: #fff;
        box-shadow: var(--hero-mobile-shadow);
        transform: translateX(-105%);
        transition: transform .24s ease;
        -webkit-overflow-scrolling: touch;
    }

    [dir="rtl"] .notification-sidebar {
        transform: translateX(105%);
    }

    .notification-sidebar.is-open,
    [dir="rtl"] .notification-sidebar.is-open {
        transform: translateX(0);
    }

    .notification-sidebar-overlay {
        position: fixed;
        z-index: 10001;
        inset: 0;
        display: block;
        visibility: hidden;
        border: 0;
        background: var(--hero-mobile-overlay);
        opacity: 0;
        transition: opacity .22s ease, visibility 0s linear .22s;
    }

    .notification-sidebar-overlay.is-visible {
        visibility: visible;
        opacity: 1;
        transition-delay: 0s;
    }

    .notification-sidebar .sidebar-header {
        margin-bottom: 14px;
    }

    .notification-sidebar .profile-card {
        padding-bottom: 16px;
        margin-bottom: 16px;
    }

    .notification-filters {
        flex-direction: column;
        overflow: visible;
        padding-bottom: 0;
    }

    .notification-filters .filter-link {
        width: 100%;
        min-height: 44px;
        white-space: normal;
    }

    .notification-stream-container {
        width: 100%;
        gap: 14px;
    }

    .notification-stream-container .ha-security-hero,
    .notification-stream-container .ha-account-layout,
    .notification-stream-container .ha-setup-grid,
    .notification-stream-container .hero-account .ha-grid,
    .notification-stream-container .hero-account .ha-link-builder {
        grid-template-columns: minmax(0, 1fr);
    }

    .notification-stream-container .hero-account .ha-summary {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 767.98px) {
    .section-space-p,
    .ec-page-content.section-space-p {
        padding-top: 18px;
        padding-bottom: 34px;
    }

    .notification-stream-container .row {
        margin-inline: -6px;
    }

    .notification-stream-container .row > [class*="col-"] {
        padding-inline: 6px;
    }

    .notification-stream-container .ha-topbar,
    .notification-stream-container .ha-card-head,
    .notification-stream-container .ha-provider,
    .notification-stream-container .ha-notification-head,
    .notification-stream-container .hero-account .ha-toolbar,
    .notification-stream-container .hero-account .ha-hero,
    .notification-stream-container .hero-account .ha-form-head,
    .notification-stream-container .hero-account .ha-card-head,
    .notification-stream-container .hero-account .ha-card-foot {
        align-items: stretch;
        flex-direction: column;
    }

    .notification-stream-container .ha-card-head,
    .notification-stream-container .ha-card-body,
    .notification-stream-container .ha-security-hero,
    .notification-stream-container .hero-account .ha-card-body,
    .notification-stream-container .hero-account .ha-form-body {
        padding-inline: 16px;
    }

    .notification-stream-container .ha-stat-grid,
    .notification-stream-container .ha-form-grid,
    .notification-stream-container .ha-stepper {
        grid-template-columns: minmax(0, 1fr);
    }

    .notification-stream-container .ha-inline-actions,
    .notification-stream-container .ha-card-actions,
    .notification-stream-container .hero-account .ha-inline-actions,
    .notification-stream-container .hero-account .ha-toolbar-actions,
    .notification-stream-container .hero-account .ha-actions {
        width: 100%;
    }

    .notification-stream-container .ha-inline-actions > .ha-btn,
    .notification-stream-container .ha-card-actions > .ha-btn,
    .notification-stream-container .hero-account .ha-inline-actions > .ha-btn,
    .notification-stream-container .hero-account .ha-toolbar-actions > .ha-btn {
        flex: 1 1 150px;
    }

    .notification-stream-container .card-body,
    .notification-stream-container .ha-card-body {
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .notification-stream-container .table:not(.ha-table-responsive-cards),
    .notification-stream-container table.ha-table:not(.ha-table-responsive-cards) {
        width: 100%;
        min-width: 620px;
    }

    .notification-stream-container .hero-account .ha-table-responsive-cards {
        min-width: 0 !important;
    }

    .notification-stream-container .notification-card {
        padding: 16px;
    }

    .notification-stream-container .card-headline-row {
        align-items: flex-start;
        flex-direction: column;
        gap: 4px;
    }

    .notification-stream-container .timestamp {
        white-space: normal;
    }

    .notification-stream-container .ha-session {
        grid-template-columns: 42px minmax(0, 1fr);
    }

    .notification-stream-container .ha-session-actions {
        grid-column: 1 / -1;
    }
}

@media (max-width: 575.98px) {
    .ec-header .header-top .container {
        padding-inline: 10px;
    }

    .ec-header .header-top-center {
        display: none;
    }

    .ec-header .header-top .col.d-lg-none {
        width: 100%;
        flex: 1 1 100%;
    }

    .ec-header .header-top .ec-header-bottons {
        width: 100%;
        justify-content: space-between;
    }

    .ec-header .header-top .ec-header-user,
    .ec-header .header-top .ec-header-btn,
    .ec-header .header-top .ec-header-user .dropdown-toggle {
        width: 46px;
        height: 46px;
        min-width: 46px;
    }

    .ec-header .ec-header-bottom.d-lg-none .row.align-items-center.mb-3 {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: 12px;
        margin-bottom: 12px !important;
    }

    .ec-header .ec-header-bottom.d-lg-none .row.align-items-center.mb-3 > .col {
        width: 100%;
        padding-inline: 12px;
    }

    .ec-header .ec-header-bottom.d-lg-none .header-logo {
        text-align: center;
    }

    .dashboard-mobile-toolbar {
        position: sticky;
        z-index: 20;
        top: 8px;
    }

    .dashboard-mobile-menu-button span {
        display: none;
    }

    .notification-stream-container .ha-card,
    .notification-stream-container .hero-account .ha-shell,
    .notification-stream-container .hero-account .ha-card,
    .notification-stream-container .hero-account .ha-form-panel {
        border-radius: 14px;
    }

    .notification-stream-container .ha-card-head,
    .notification-stream-container .ha-card-body,
    .notification-stream-container .ha-security-hero,
    .notification-stream-container .hero-account .ha-card-body,
    .notification-stream-container .hero-account .ha-form-body,
    .notification-stream-container .hero-account .ha-body,
    .notification-stream-container .hero-account .ha-hero {
        padding-inline: 14px;
    }

    .notification-stream-container .ha-inline-actions,
    .notification-stream-container .ha-card-actions,
    .notification-stream-container .hero-account .ha-inline-actions,
    .notification-stream-container .hero-account .ha-toolbar-actions,
    .notification-stream-container .hero-account .ha-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .notification-stream-container .ha-inline-actions > .ha-btn,
    .notification-stream-container .ha-card-actions > .ha-btn,
    .notification-stream-container .hero-account .ha-inline-actions > .ha-btn,
    .notification-stream-container .hero-account .ha-toolbar-actions > .ha-btn,
    .notification-stream-container .hero-account .ha-actions > .ha-btn,
    .notification-stream-container form > .btn,
    .notification-stream-container form > button[type="submit"] {
        width: 100%;
    }

    .notification-stream-container .hero-account .ha-summary {
        grid-template-columns: minmax(0, 1fr);
    }

    .notification-stream-container .ha-otp {
        gap: 4px;
    }

    .notification-stream-container .ha-otp input {
        min-width: 0;
        height: 44px;
        font-size: 18px;
    }

    .notification-card {
        flex-direction: column;
    }

    .card-status-indicator {
        top: 0;
        right: 16px;
        bottom: auto;
        left: 16px;
        width: auto;
        height: 4px;
        border-radius: 0 0 4px 4px;
    }
}

@media (prefers-reduced-motion: reduce) {
    #ec-mobile-menu,
    .ec-mobile-menu-overlay,
    .notification-sidebar,
    .notification-sidebar-overlay,
    .dashboard-submenu-chevron {
        transition: none !important;
    }
}
