/*
 * App layout styles (UI optimization plan, Phase 1).
 * Loaded after tokens.css and legacy.css (see Element/stylesheets.ctp).
 * Markup: src/Template/Plugin/Croogo/Core/Layout/default.ctp and Element/header.ctp
 */

/* ---------- Header ---------- */

.app-launcher__body {
    background-color: var(--app-surface-muted);
}

.app-topbar__username {
    padding-left: 10px;
    color: #ffffff;
}

/* ---------- Header: tablet & mobile (Metronic's breakpoint) ----------
   Metronic hides the white topbar strip behind the header until the "more"
   toggle slides it down. Here it sat over the brand bar instead, leaving a 10px
   dark strip and a floating bell/avatar. Show one dark bar instead:
   [menu] [launcher] ............ [bell] [avatar]                            */
@media (max-width: 992px) {
    #m_header .m-brand {
        height: 60px;
        padding: 0 12px;
    }

    #m_header .m-brand > .m-stack {
        display: flex;
        align-items: center;
        height: 60px;
    }

    #m_header .m-brand > .m-stack > .m-stack__item {
        display: flex;
        align-items: center;
        width: auto;
        height: 60px;
    }

    #m_header .m-brand .responsive-header-tool {
        order: 1;
        padding: 0;
    }

    #m_header .m-brand .m-topbar__nav-wrapper {
        order: 2;
        margin-left: 6px;
    }

    #m_header .m-brand .m-topbar__nav-wrapper .m-topbar__nav {
        margin: 0;
    }

    /* Hamburger lines: white on the dark bar */
    #m_header .m-brand .m-brand__tools .m-brand__toggler {
        margin: 0;
    }

    #m_header .m-brand .m-brand__tools .m-brand__toggler span,
    #m_header .m-brand .m-brand__tools .m-brand__toggler span::before,
    #m_header .m-brand .m-brand__tools .m-brand__toggler span::after {
        height: 2px;
        background: #ffffff;
    }

    /* Topbar items live in the bar, so the "more" toggle isn't needed */
    #m_aside_header_topbar_mobile_toggle {
        display: none !important;
    }

    #m_header #m_header_topbar {
        position: absolute;
        top: 0 !important;
        right: 0;
        z-index: 2;
        width: auto !important;
        height: 60px !important;
        margin: 0 !important;
        padding: 0 8px;
        background: transparent;
        box-shadow: none;
    }

    #m_header #m_header_topbar .m-topbar__nav-wrapper,
    #m_header #m_header_topbar .m-topbar__nav {
        display: flex;
        align-items: center;
        height: 60px;
        margin: 0;
        float: none;
    }

    #m_header #m_header_topbar .m-topbar__nav > .m-nav__item {
        display: flex;
        align-items: center;
        height: 60px;
    }

    #m_header #m_header_topbar .m-topbar__nav > .m-nav__item > .m-nav__link {
        display: flex;
        align-items: center;
        height: 60px;
    }

    #m_header #m_header_topbar .m-topbar__userpic img {
        width: 34px;
        height: 34px;
        margin: 0;
        object-fit: cover;
    }

    /* Name doesn't fit next to the avatar on small screens */
    #m_header #m_header_topbar .app-topbar__username {
        display: none;
    }

    /* Dropdowns: pin under the bar instead of hanging off the small icons,
       which pushed them off the right edge of the screen */
    #m_header #m_header_topbar .m-dropdown__wrapper {
        position: fixed !important;
        top: 60px !important;
        right: 8px !important;
        left: 8px !important;
        width: auto !important;
        margin: 0 !important;
        padding-top: 6px !important;
    }

    #m_header #m_header_topbar .m-dropdown__arrow {
        display: none !important;
    }

    #m_header #m_header_topbar .m-dropdown__inner {
        border-radius: 8px;
        box-shadow: 0 10px 30px rgba(39, 39, 39, 0.15);
        overflow: hidden;
    }

    /* Profile menu: compact card on the right rather than full width */
    #m_header #m_header_topbar .profile-dropdown-wraper {
        left: auto !important;
        width: 220px !important;
    }

    #m_header #m_header_topbar .notification_list_container .m-scrollable,
    #m_header #m_header_topbar .notification_list_container .m-scrollable .mCustomScrollBox {
        max-height: calc(100vh - 140px) !important;
    }

    /* No divider after the last profile link (Logout) */
    #m_header #m_header_topbar .profile-dropdown-wraper .m-nav--inline .m-nav__item:last-child .m-nav__link {
        border-right: 0 !important;
    }
}

/* ---------- Notification panel (all widths) ----------
   Rows are built by getNotificationList() in webroot/js/custom.js:
   .m-list-timeline__item[.unread_notification] > .m-list-timeline__text + .m-list-timeline__time, then <hr>.
   Styling only; the click/mark-as-read handlers are unchanged. */
.m-topbar__notifications .m-dropdown__inner {
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(39, 39, 39, 0.16);
    overflow: hidden;
}

.app-notif__head {
    padding: 14px 16px;
    font-size: 1rem;
    font-weight: 700;
    color: var(--app-brand-dark);
    background-color: #ffffff;
    border-bottom: 1px solid var(--app-border);
}

.notification_list_container {
    padding: 0 !important;
    background-color: #ffffff;
}

/* Metronic writes an inline 250px max-height from data-max-height onto the
   scroller and its custom-scrollbar box */
.notification_list_container .m-scrollable {
    height: auto !important;
    max-height: 420px !important;
}

.notification_list_container .m-scrollable .mCustomScrollBox {
    max-height: 420px !important;
}

.notification_list_container .m-list-timeline__items {
    padding: 0;
}

.notification_list_container hr {
    display: none;
}

.notification_list_container .m-list-timeline__item {
    display: grid !important;
    grid-template-columns: 36px 1fr 10px;
    grid-template-rows: auto auto;
    column-gap: 12px;
    align-items: center;
    margin: 0;
    padding: 12px 16px !important;
    background-color: #ffffff;
    border-bottom: 1px solid var(--app-border);
    transition: background-color 0.15s ease;
}

.notification_list_container .m-list-timeline__item:hover {
    background-color: var(--app-surface-muted);
}

/* Icon (the :first-child selector beats custom.css, which hides the first row's :before) */
.notification_list_container .m-list-timeline__item::before,
.notification_list_container .m-list-timeline .m-list-timeline__items .m-list-timeline__item:first-child::before {
    content: "";
    display: block !important;
    position: static !important;
    grid-column: 1;
    grid-row: 1 / span 2;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 0 !important;
    background: #eef0f6 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236f727d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M18 8a6 6 0 0 0-12 0c0 7-3 9-3 9h18s-3-2-3-9'/%3E%3Cpath d='M13.73 21a2 2 0 0 1-3.46 0'/%3E%3C/svg%3E") center / 18px 18px no-repeat;
}

/* Full title, wrapped; no line clamp (titles run up to ~130 characters) */
.notification_list_container .m-list-timeline__text {
    display: block !important;
    grid-column: 2;
    grid-row: 1;
    width: auto !important;
    padding: 0 !important;
    white-space: normal;
    overflow-wrap: anywhere;
    font-size: 0.9rem;
    line-height: 1.35;
    color: #575962;
}

.notification_list_container .m-list-timeline__time {
    display: block !important;
    grid-column: 2;
    grid-row: 2;
    width: auto !important;
    margin-top: 3px;
    padding: 0 !important;
    text-align: left !important;
    white-space: nowrap;
    font-size: 0.75rem;
    color: #9699a2;
}

/* Unread: white row, dark bold text, accent icon and a dot matching the badge */
.notification_list_container .m-list-timeline__item.unread_notification {
    background-color: #ffffff;
}

.notification_list_container .m-list-timeline__item.unread_notification .m-list-timeline__text {
    font-weight: 600;
    color: var(--app-brand-dark);
}

.notification_list_container .m-list-timeline__item.unread_notification::before,
.notification_list_container .m-list-timeline .m-list-timeline__items .m-list-timeline__item.unread_notification:first-child::before {
    background-color: #fde8ec;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23f4516c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M18 8a6 6 0 0 0-12 0c0 7-3 9-3 9h18s-3-2-3-9'/%3E%3Cpath d='M13.73 21a2 2 0 0 1-3.46 0'/%3E%3C/svg%3E");
}

.notification_list_container .m-list-timeline__item.unread_notification::after {
    content: "";
    grid-column: 3;
    grid-row: 1 / span 2;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #f4516c;
}

/* Load more */
.notification_list_container .loadMoreNotificationRow {
    padding: 10px 16px 12px;
}

.notification_list_container .loadMoreNotificationRow a {
    display: block;
    padding: 8px 0;
    border: 1px solid var(--app-border);
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--app-brand-dark);
    text-decoration: none;
}

.notification_list_container .loadMoreNotificationRow a:hover {
    background-color: var(--app-surface-muted);
}

@media (min-width: 993px) {
    #m_header_topbar .m-topbar__notifications .m-dropdown__wrapper {
        width: 380px;
        margin-left: -190px;
    }
}

/* ---------- Franchisee sub-header (admin roles only) ---------- */

/* Laid out like the Role list's franchisee picker: a full-width box at the top of the content, lined up with the
   content's 15px padding (m-content m--padding-15), instead of a 380px box on the right of a white bar */
.app-subheader {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    padding: 15px 15px 0;
}

.app-subheader__label {
    display: none !important; /* the box's building icon and its "Select Franchisee" text say what it is */
}

.app-subheader__control {
    flex: 1 1 auto;
    min-width: 0;
}

/* Dashboards, reports and the add/edit toolbar pull themselves up flush under the header (.app-dashboard /
   .app-report: margin-top -15px, -35px for --tight, components.css; .form-top-action, ui/record_toolbar: -15px,
   legacy.css). With the franchisee box shown that pull-up swallowed the gap under it, so the dashboard tabs and the
   Back To List / Save toolbar touched the box. custom.js hides the box with style="display: none"; while it shows,
   no pull-up. */
.app-subheader:not([style*="none"]) ~ .common-wrapper .app-dashboard,
.app-subheader:not([style*="none"]) ~ .common-wrapper .app-report,
.app-subheader:not([style*="none"]) ~ .common-wrapper .app-report.app-report--tight,
.app-subheader:not([style*="none"]) ~ .common-wrapper .form-top-action {
    margin-top: 0;
}

/* Add/edit pages and dashboards run their toolbar, summary card and tab card edge to edge (margin 0 -15px: .row,
   .form-accordion-container, .app-card-bleed) so they hang off the header bar. Below the franchisee box that left
   them 15px wider on each side than the box: line them up with it instead, as the list cards are. */
.app-subheader:not([style*="none"]) ~ .common-wrapper .form-top-action,
.app-subheader:not([style*="none"]) ~ .common-wrapper .form-accordion-container,
.app-subheader:not([style*="none"]) ~ .common-wrapper .m-portlet.app-card-bleed {
    margin-right: 0;
    margin-left: 0;
}

/* Toggle button, styled like the Role list's franchisee picker (components.css, .app-franchisee-select): white
   44px box, building icon, soft shadow. Overrides the 2px square border in custom.css and Metronic's caret, which
   sits inside the text padding and overlaps long names. */
.app-subheader .bootstrap-select.franchisee-select > .btn.dropdown-toggle {
    height: 44px;
    padding: 0 40px 0 42px;
    background: #ffffff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%236f727d' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 21h18M5 21V7l7-4 7 4v14M9 21v-6h6v6M9 10h.01M15 10h.01'/%3E%3C/svg%3E") no-repeat 14px center !important;
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius-lg) !important;
    box-shadow: 0 1px 15px 1px rgba(69, 65, 78, 0.08) !important; /* a legacy .btn rule removes it otherwise */
    color: var(--app-brand-dark) !important;
    font-family: inherit;
    font-size: 14px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.app-subheader .bootstrap-select.franchisee-select > .btn.dropdown-toggle:hover {
    border-color: var(--app-gray-300);
}

.app-subheader .bootstrap-select.franchisee-select > .btn.dropdown-toggle:focus,
.app-subheader .bootstrap-select.btn-group.franchisee-select.show > .btn.dropdown-toggle,
.app-subheader .bootstrap-select.btn-group.franchisee-select.open > .btn.dropdown-toggle {
    border-color: var(--app-brand-dark) !important;
    box-shadow: 0 0 0 3px var(--app-focus-ring) !important;
}

.app-subheader .bootstrap-select.franchisee-select > .btn.dropdown-toggle .filter-option {
    display: block;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
    font-weight: 600;
    line-height: 42px;
    color: inherit;
}

.app-subheader .bootstrap-select.franchisee-select > .btn.dropdown-toggle .bs-caret {
    display: none;
}

/* Chevron drawn with borders: Metronic's LineAwesome glyph sits low in the 38px button */
.app-subheader .bootstrap-select.btn-group.franchisee-select > .dropdown-toggle:after {
    content: "";
    position: absolute;
    top: 50%;
    right: 14px;
    width: 7px;
    height: 7px;
    margin-top: -5px;
    border: 0;
    border-right: 1.5px solid #575962; /* thin, like the Role list picker's caret */
    border-bottom: 1.5px solid #575962;
    font-size: 0;
    transform: rotate(45deg);
    transition: transform 0.15s ease, margin-top 0.15s ease;
}

.app-subheader .bootstrap-select.btn-group.franchisee-select.show > .dropdown-toggle:after,
.app-subheader .bootstrap-select.btn-group.franchisee-select.open > .dropdown-toggle:after {
    margin-top: -1px;
    transform: rotate(-135deg);
}

/* Dropdown panel */
.app-subheader .bootstrap-select.franchisee-select > .dropdown-menu {
    min-width: 100%;
    max-width: 100%;
    margin-top: 6px;
    padding: 0 0 6px;
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius-lg);
    box-shadow: var(--app-shadow);
    overflow: hidden;
}

/* bootstrap-select 1.12 measures row/search heights on a hidden clone (Bootstrap 4
   keeps .dropdown-menu.open at display:none), gets 0px and writes a max-height that
   clips the list. Size the panel with CSS instead of its inline values. */
.app-subheader .bootstrap-select.franchisee-select > .dropdown-menu {
    max-height: none !important;
    min-height: 0 !important;
}

.app-subheader .bootstrap-select.franchisee-select .dropdown-menu.inner {
    max-height: min(360px, calc(100vh - 220px)) !important;
    min-height: 0 !important;
    overflow-y: auto !important;
}

.app-subheader .bootstrap-select.franchisee-select .bs-searchbox {
    padding: 10px 12px 8px;
    border-bottom: 1px solid var(--app-border);
}

.app-subheader .bootstrap-select.franchisee-select .bs-searchbox .form-control {
    height: 38px;
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
}

.app-subheader .bootstrap-select.franchisee-select .bs-searchbox .form-control:focus {
    border-color: var(--app-brand-dark);
    box-shadow: 0 0 0 3px var(--app-focus-ring);
}

.app-subheader .bootstrap-select.franchisee-select .dropdown-menu.inner > li > a {
    padding: 10px 14px;
    font-size: 14px;
    white-space: normal;
}

.app-subheader .bootstrap-select.franchisee-select .dropdown-menu.inner > li > a:hover,
.app-subheader .bootstrap-select.franchisee-select .dropdown-menu.inner > li.active > a {
    background-color: var(--app-gray-100);
}

.app-subheader .bootstrap-select.franchisee-select .dropdown-menu.inner > li > a.parent .text {
    font-weight: 600;
    color: var(--app-brand-dark);
}

/* Child franchisees: indent with a guide line instead of custom.css's margin-left: 2%.
   bootstrap-select 1.12 copies the option class onto the <a>, not the <li>. */
.app-subheader .bootstrap-select.franchisee-select .dropdown-menu.inner > li > a.child {
    margin-left: 0 !important;
    padding-left: 34px;
}

.app-subheader .bootstrap-select.franchisee-select .dropdown-menu.inner > li > a.child::before {
    content: "";
    position: absolute;
    left: 20px;
    top: 0;
    bottom: 0;
    border-left: 1px solid var(--app-border);
}

.app-subheader .bootstrap-select.franchisee-select .dropdown-menu.inner > li > a.child .text {
    font-weight: 400;
    color: #575962;
}

.app-subheader .bootstrap-select.franchisee-select .dropdown-menu.inner > li.selected > a {
    background-color: var(--app-gray-100);
}

.app-subheader .bootstrap-select.franchisee-select .dropdown-menu.inner > li.selected > a .text {
    color: var(--app-brand-dark);
    font-weight: 600;
}
