/* =====================================================================
   CSS CUSTOM PROPERTIES (Design Tokens)
   ===================================================================== */
:root {
    --primary: #0b6b3a;
    --primary-dark: #08572f;
    --primary-soft: #e8f5ee;
    --accent: #2bb673;
    --text-main: #1f2937;
    --text-soft: #6b7280;
    --border: #e5e7eb;
    --bg: #f6f7f8;
    --card: #ffffff;
    --sidebar: #fff;
    --header-bg: #fff;
    --warning-soft: #fff4cc;
    --warning-text: #7a5a00;
    --blue-btn: #3b82f6;
}

/* =====================================================================
   GLOBAL RESET
   ===================================================================== */
* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    margin: 0;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text-main);
    font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}

/* =====================================================================
   APP SHELL (Desktop – always flex-row)
   ===================================================================== */
.app-shell {
    height: 100vh;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    overflow: hidden;
}

/* =====================================================================
   DESKTOP SIDEBAR
   Exact same design as before – do not touch these values.
   ===================================================================== */
.sidebar {
    width: 210px !important;
    background: var(--sidebar) !important;
    padding: 10px 12px 18px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    box-shadow: 3px 0 6px rgba(0, 0, 0, 0.03);
    scrollbar-width: thin;
    scrollbar-color: #c4c4c4 transparent;
    flex-shrink: 0;
}

    .sidebar::-webkit-scrollbar { width: 5px; }
    .sidebar::-webkit-scrollbar-track { background: transparent; }
    .sidebar::-webkit-scrollbar-thumb { background: #c4c4c4; border-radius: 4px; }
    .sidebar::-webkit-scrollbar-thumb:hover { background: #a8a8a8; }

/* =====================================================================
   BRAND LOGO
   ===================================================================== */
.brand {
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: sans-serif;
    margin: 0;
    color: #212529;
    font-size: 1.5rem;
    font-weight: 600;
    font-style: italic;
    letter-spacing: 1px;
}

/* =====================================================================
   NAV SECTION – BASE STYLES (Desktop + all sizes)

   KEY FIXES:
   1. Force flex-column on the Bootstrap nav-pills container so items
      NEVER flow horizontally at any viewport width.
   2. Give every .nav-link width:100% so it stretches across the sidebar.
   3. Use align-items:stretch on the nav container (not center/start)
      so children fill the available width automatically.
   ===================================================================== */
.nav-section {
    /* Override Bootstrap nav-pills which can allow horizontal item flow */
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;  /* children stretch to full width */
    width: 100%;
}

.nav-section .nav-link {
    /* Layout */
    display: flex !important;          /* always flex – never inline-flex */
    flex-direction: row !important;    /* icon | label | chevron in a row */
    align-items: center !important;
    width: 100% !important;            /* stretch across full sidebar width */
    flex-shrink: 0;

    /* Spacing */
    gap: 10px;
    padding: 10px 12px;
    margin-bottom: 4px;

    /* Typography */
    color: #687281;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.35;
    text-decoration: none;

    /* Shape */
    border-radius: 8px;

    /* Prevent text overflow */
    overflow: hidden;
    word-break: break-word;
    white-space: normal;
    box-sizing: border-box;
}

    /* Chevron <i> inside nav-link – always pinned right, never squished.
       :not(.SideBariconimg) is essential: some entries (Digital Library, Sample
       Collection, Consignment History) use a Bootstrap-Icon <i> as their LEADING
       icon instead of an <img>. Without the exclusion those leading icons also
       picked up margin-left:auto and were pushed toward the middle of the row,
       so those rows looked indented compared with their <img> neighbours. */
    .nav-section .nav-link i:not(.SideBariconimg),
    .nav-section .nav-link .chevron-icon {
        font-size: 14px;
        flex-shrink: 0;
        margin-left: auto;
        /* Override NavMenu.razor.css scoped .bi margin-right which
           conflicts with margin-left:auto chevron alignment */
        margin-right: 0 !important;
    }

    /* Active state */
    .nav-section .nav-link.active {
        background: var(--primary);
        color: #fff;
        box-shadow: 0 4px 12px rgba(11, 107, 58, 0.15);
    }

    /* Hover state */
    .nav-section .nav-link:hover:not(.active) {
        background-color: #f3f4f6;
        color: var(--text-main);
    }

/* =====================================================================
   SIDEBAR ICON  (.SideBariconimg)
   Fixed pixel size – consistent at ALL viewport widths.
   ===================================================================== */
.SideBariconimg {
    width: 20px !important;
    height: 20px !important;
    min-width: 20px;
    flex-shrink: 0;
    object-fit: contain;
    filter: brightness(0);
    display: block;
}

/* Active → white icon */
.nav-link.active .SideBariconimg {
    filter: brightness(0) invert(1);
}

/* =====================================================================
   CHEVRON ICON  (Bootstrap .bi inside parent menus)
   Override the NavMenu.razor.css scoped `.bi` rule which sets
   margin-right: 0.75rem – this would push the chevron left of the
   right edge, breaking the "pinned right" alignment.
   ===================================================================== */
.chevron-icon {
    margin-left: auto !important;
    margin-right: 0 !important;
    flex-shrink: 0;
    font-size: 0.85rem;
    transition: transform 0.3s;
    /* Reset NavMenu.razor.css .bi overrides */
    position: static !important;
    top: auto !important;
    width: auto !important;
    height: auto !important;
    background-size: auto !important;
}

/* =====================================================================
   SETTINGS-MENU-WRAPPER (parent of expandable menus)
   Must be full width so inner nav-link stretches correctly.
   ===================================================================== */
.settings-menu-wrapper {
    width: 100%;
    display: block;
}

/* =====================================================================
   SUBMENU – Tree layout (desktop + responsive)
   ===================================================================== */
.submenu-list {
    list-style: none;
    padding: 0;
    margin: 0 0 16px 28px; /* 28px aligns vertical line with icon center */
    /* NO width:100% – it is added to the 28px left margin, so the list used to
       stick 28px past the sidebar and the longest labels ("Top Ranking
       Wholesaler") were clipped by the sidebar's overflow. As a block element
       the <ul> already fills the width left over after the margin. */
}

/* css/SettingTreeLayout.css loads after this file and re-declares
   `.submenu-list { width: 100% }`. These two selectors are more specific, so the
   list stays inside the sidebar / offcanvas whichever order the files load in. */
.sidebar .submenu-list,
.offcanvas-body .submenu-list {
    width: auto;
}

.submenu-item {
    position: relative;
}

.submenu-link {
    display: flex;
    align-items: center;
    padding: 10px 0 10px 24px;
    color: #6b7280;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    transition: color 0.2s;
    width: 100%;
    white-space: normal;
    word-break: break-word;
    line-height: 1.3;
}

    .submenu-link:hover {
        color: #1f2937;
    }

    .submenu-link.active {
        color: #059669;
        font-weight: 600;
    }

/* =====================================================================
   CONTENT AREA
   ===================================================================== */
.content-wrap {
    flex: 1;
    min-width: 0;
    padding: 0;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* Brand shown inside .topbar on phone only (see phone block below).
   display:none here keeps the desktop topbar pixel-identical. */
.shell-topbar-lead {
    display: none;
}

.topbar {
    height: 64px;
    background: var(--header-bg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 20px;
    margin-bottom: 0;
    box-shadow: 3px 0 6px rgba(0, 0, 0, 0.03);
    flex-shrink: 0;
}

.search-box {
    max-width: 420px;
    width: 100%;
    position: relative;
}

    .search-box .form-control {
        padding-left: 34px;
        height: 38px;
        border-radius: 8px;
        border: none;
        background: #ffffff;
        font-size: 13px;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1) !important;
    }

        .search-box .form-control:focus {
            outline: none;
            box-shadow: 0 2px 6px rgba(0,0,0,0.12) !important;
        }

    .search-box i {
        position: absolute;
        left: 12px;
        top: 50%;
        transform: translateY(-50%);
        color: #9ca3af;
        font-size: 13px;
    }

.top-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}

.icon-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #6b7280;
    background: transparent;
    border: 0;
}

.iconimg {
    width: 100%;
    height: 100%;
}

/* ---------------------------------------------------------------------
   TOP BAR QUICK ACTIONS (Ask SPIC AI + Alerts) - phone and tablet only.
   Desktop (>= 1200px) keeps the original bell button and never renders
   these, so the live desktop bar is unchanged.
   --------------------------------------------------------------------- */
.shell-topbar-quick {
    display: none;
}

@media (max-width: 1199.98px) {

    /* The dead desktop bell is replaced by the /Alerts link below it. */
    .top-actions .shell-topbar-bell-desktop {
        display: none !important;
    }

    .top-actions .shell-topbar-quick {
        display: inline-flex;
        width: var(--tap-min, 44px);
        height: var(--tap-min, 44px);
        min-width: var(--tap-min, 44px);
        flex: 0 0 auto;
        padding: 0;
        text-decoration: none;
    }

    .top-actions .shell-topbar-quick .iconimg {
        width: 24px;
        height: 24px;
    }

    .top-actions .shell-topbar-ai {
        color: #0b6b3a;
    }

        .top-actions .shell-topbar-ai i {
            font-size: 22px;
            line-height: 1;
        }
}

.profile {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, #d1d5db, #9ca3af);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
}

.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px 24px 28px;
    background-color: #f9fff92e;
}

/* =====================================================================
   RESPONSIVE – Grid helpers (page content)
   ===================================================================== */
@media (max-width: 1199.98px) {
    .saved-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* =====================================================================
   RESPONSIVE SHELL - breakpoint contract (see css/tokens.css)
       phone    <= 767.98px
       tablet   768px .. 1199.98px
       desktop  >= 1200px   (NO rules below apply: desktop is unchanged)
   ===================================================================== */

/* =====================================================================
   TABLET  (768 px … 1199.98 px)
   Desktop sidebar is replaced by the 72px NavRail (Components/Shell/NavRail).
   The full menu stays reachable through the #mobileSidebar offcanvas
   (opened by the rail's menu button). Topbar and scrolling main-content
   keep their desktop behaviour.
   ===================================================================== */
@media (min-width: 768px) and (max-width: 1199.98px) {

    .sidebar {
        display: none !important;
    }

    .topbar {
        padding: 0 16px;
    }

    .main-content {
        padding: 16px 16px 24px;
    }
}

/* =====================================================================
   PHONE  (≤ 767.98 px)
   - body scrolls (app-shell/content-wrap lose their 100vh + overflow)
   - sidebar hidden; navigation = BottomTabBar + More sheet + offcanvas
   - .topbar becomes the compact sticky bar: brand | notification | avatar
   - .main-content gets bottom padding = tab bar height + safe area so no
     content is ever hidden behind the fixed tab bar.
   ===================================================================== */
@media (max-width: 767.98px) {

    .app-shell {
        /* Sticky ActionBars and toasts (Feedback components) sit above the bottom tab bar */
        --shell-bottom-offset: calc(var(--shell-tabbar-h, 60px) + var(--safe-bottom, 0px));
        display: flex;
        flex-direction: column;
        height: auto;
        min-height: 100vh;
        min-height: 100svh;
        overflow: visible;
    }

    .sidebar {
        display: none !important;
    }

    .content-wrap {
        height: auto;
        flex: none;
        overflow: visible;
    }

    /* Compact top bar */
    .topbar {
        position: sticky;
        top: 0;
        z-index: var(--z-topbar, 1020);
        height: auto;
        min-height: calc(var(--shell-topbar-h, 56px) + var(--safe-top, 0px));
        padding: var(--safe-top, 0px) calc(8px + var(--safe-right, 0px)) 0 calc(12px + var(--safe-left, 0px));
        gap: 8px;
        align-items: center;
        flex-shrink: 0;
        border-bottom: 1px solid #dfe3e8;
        box-shadow: none;
    }

    .shell-topbar-lead {
        display: flex;
        align-items: center;
        flex: 1 1 auto;
        min-width: 0;
        min-height: var(--tap-min, 44px);
    }

    .shell-topbar-brand {
        display: inline-flex;
        align-items: center;
        min-height: var(--tap-min, 44px);
        text-decoration: none;
        padding: 0 4px;
    }

    /* Same artwork as the app icon (Resources/AppIcon/appiconfg.png). */
    .shell-topbar-logo {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        display: block;
    }

    /* Global search lives in the desktop bar only; phones use in-page search. */
    .topbar .search-box {
        display: none;
    }

    .top-actions {
        justify-content: flex-end;
        gap: 4px;
        flex-shrink: 0;
    }

    /* Notification button grows to a 44px tap target; the glyph stays 24px. */
    .top-actions .icon-btn {
        width: var(--tap-min, 44px);
        height: var(--tap-min, 44px);
    }

    .top-actions .icon-btn .iconimg {
        width: 24px;
        height: 24px;
    }

    .main-content {
        flex: none;
        overflow: visible;
        padding: 12px 12px calc(var(--shell-tabbar-h, 60px) + var(--safe-bottom, 0px) + 16px);
    }

    /* The page-level error card should not sit under the tab bar either. */
    .page-error {
        margin: 24px auto;
    }
}

/* Body scroll lock while the phone "More" sheet is open (MoreSheet.razor.js). */
body.shell-sheet-open {
    overflow: hidden;
}

/* Bootstrap's dismiss glyph on alerts is ~32x40 – below the 44px tap minimum on
   phones. Phone-only, so the live desktop alerts are untouched. */
@media (max-width: 767.98px) {
    .alert-dismissible .btn-close {
        box-sizing: border-box;
        width: var(--tap-min, 44px);
        height: var(--tap-min, 44px);
        background-position: center;
    }
}

/* =====================================================================
   OFFCANVAS MOBILE SIDEBAR
   Applied when nav renders inside Bootstrap's .offcanvas (#mobileSidebar).

   CRITICAL FIXES that solve the two-column layout problem:
   1. Force .nav-section to be a single-column flex container.
   2. Force every .nav-link to width:100% so nothing sits beside another item.
   3. Override Bootstrap nav-pills which allows horizontal item wrapping.
   4. Fix .bi scoped margin-right that breaks chevron alignment.
   ===================================================================== */

/* Offcanvas panel sizing – works on all phones from 320px to 414px+ */
.offcanvas.offcanvas-start {
    width: min(280px, 85vw) !important;
    max-width: 320px;
}

/* Header inside offcanvas */
.offcanvas-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    align-items: center;
}

    /* Bootstrap's close glyph is 40px; the full menu's only close control gets a
       full 44px thumb target on phones. The glyph itself is unchanged. */
    @media (max-width: 767.98px) {
        .offcanvas-header .btn-close {
            box-sizing: border-box; /* Bootstrap uses content-box here */
            width: var(--tap-min, 44px);
            height: var(--tap-min, 44px);
            background-position: center;
        }
    }

/* Scrollable body */
.offcanvas-body {
    padding: 8px 12px 16px;
    overflow-y: auto;
    overflow-x: hidden;  /* prevent horizontal scroll inside offcanvas */
}

/* ── Nav container inside offcanvas ──────────────────────────────────── */
.offcanvas-body .nav-section,
.offcanvas-body .nav.nav-pills,
.offcanvas-body .nav.flex-column {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;  /* items fill the full width */
    width: 100% !important;
    flex-wrap: nowrap !important;
}

/* ── Every nav-link inside offcanvas ─────────────────────────────────── */
.offcanvas-body .nav-section .nav-link,
.offcanvas-body .nav-link {
    /* Single-row layout: [icon] [label text] [chevron] */
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    flex-wrap: nowrap !important;

    /* Full width – prevents two items per row */
    width: 100% !important;
    box-sizing: border-box;

    /* Touch-friendly sizing */
    min-height: 46px;
    padding: 10px 12px;
    gap: 10px;
    margin-bottom: 4px;

    /* Typography */
    font-size: 13px;
    font-weight: 500;
    color: #687281;
    line-height: 1.4;
    text-decoration: none;

    /* Text overflow handling */
    overflow: hidden;
    white-space: normal;
    word-break: break-word;

    /* Shape */
    border-radius: 8px;
}

/* Active state */
.offcanvas-body .nav-section .nav-link.active,
.offcanvas-body .nav-link.active {
    background: var(--primary) !important;
    color: #fff !important;
    box-shadow: 0 4px 12px rgba(11, 107, 58, 0.15);
}

/* Active icon (white) */
.offcanvas-body .nav-link.active .SideBariconimg {
    filter: brightness(0) invert(1) !important;
}

/* Hover state */
.offcanvas-body .nav-link:hover:not(.active) {
    background-color: #f3f4f6;
    color: var(--text-main);
}

/* ── Icon inside offcanvas nav-link ──────────────────────────────────── */
.offcanvas-body .nav-link .SideBariconimg,
.offcanvas-body .SideBariconimg {
    width: 20px !important;
    height: 20px !important;
    min-width: 20px;
    flex-shrink: 0;
    object-fit: contain;
    filter: brightness(0);
    display: block;
}

/* ── Chevron inside offcanvas nav-link ─────────────────────────────────
   :not(.SideBariconimg) keeps Bootstrap-Icon LEADING icons out of this rule –
   margin-left:auto would otherwise shove them to the middle of the row. */
.offcanvas-body .nav-link i:not(.SideBariconimg),
.offcanvas-body .nav-link .chevron-icon {
    /* Pin to right edge */
    margin-left: auto !important;
    margin-right: 0 !important;
    flex-shrink: 0;
    font-size: 0.8rem;
    /* Reset scoped NavMenu.razor.css .bi overrides */
    position: static !important;
    top: auto !important;
    width: auto !important;
    height: auto !important;
    background-size: auto !important;
    background-image: none !important;
}

/* ── Settings-menu-wrapper inside offcanvas ──────────────────────────── */
.offcanvas-body .settings-menu-wrapper {
    width: 100%;
    display: block;
}

/* ── Submenu inside offcanvas ────────────────────────────────────────── */
.offcanvas-body .submenu-list {
    list-style: none;
    padding: 0;
    margin: 0 0 10px 22px;
    /* width:100% + a 22px left margin overflowed the offcanvas and clipped the
       longest submenu labels – the <ul> fills the remaining width on its own. */
}

.offcanvas-body .submenu-item {
    position: relative;
    width: 100%;
}

.offcanvas-body .submenu-link {
    display: flex !important;
    align-items: center;
    width: 100% !important;
    padding: 9px 4px 9px 18px;
    color: #6b7280;
    text-decoration: none;
    font-size: 0.83rem;
    font-weight: 500;
    min-height: 40px;       /* touch-friendly */
    white-space: normal;
    word-break: break-word;
    line-height: 1.3;
    transition: color 0.2s;
}

    .offcanvas-body .submenu-link:hover {
        color: #1f2937;
    }

    .offcanvas-body .submenu-link.active {
        color: #059669;
        font-weight: 600;
    }

/* Scrollbar inside offcanvas body */
.offcanvas-body::-webkit-scrollbar { width: 4px; }
.offcanvas-body::-webkit-scrollbar-track { background: transparent; }
.offcanvas-body::-webkit-scrollbar-thumb { background: #c4c4c4; border-radius: 4px; }

/* Shown by the page-level ErrorBoundary in MainLayout when a page throws */
.page-error {
    max-width: 520px;
    margin: 48px auto;
    padding: 28px 24px;
    background: #fff;
    border: 1px solid #fde2e2;
    border-radius: 12px;
    text-align: center;
    color: #374151;
}

.page-error .bi {
    font-size: 2rem;
    color: #dc2626;
}

.page-error h5 {
    margin: 10px 0 6px;
    font-weight: 700;
}

.page-error-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 14px;
}
