/* General Styles */
*,
*::before,
*::after {
    box-sizing: border-box;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: #f8f9fa;
    min-height: 100vh;
    position: relative;
    display: flex;
    flex-direction: column;
}

.footer {
    margin-top: auto;
}

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

/* Prevent text/content from forcing horizontal overflow */
h1, h2, h3, h4, h5, h6,
p, small, span, a, li,
.card-title, .card-text, .alert, .dropdown-item, .nav-link,
.btn, .badge {
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* Critical for Bootstrap flex/grid overflow edge cases */
.row > [class*="col-"],
.card,
.card-body,
.navbar,
.navbar .container,
.navbar-collapse,
.navbar-nav,
.nav-item,
.dropdown-menu,
.dropdown-item,
.d-flex > *,
.flex-grow-1,
.flex-shrink-1,
.list-group-item {
    min-width: 0;
}

/* All flex containers: children must be allowed to shrink */
[class*="d-flex"] > * {
    min-width: 0;
}

.container,
.container-fluid {
    max-width: 100%;
}

/* Form Styles */
.form-control:focus {
    border-color: #80bdff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

/* Inputs and selects never exceed their parent */
input, select, textarea {
    max-width: 100%;
}

/* Card Styles */
.card {
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    max-width: 100%;
    border: 1px solid #e9ecef;
    border-radius: 0.5rem;
}

.card-header {
    background-color: #f8f9fa;
    border-bottom: 1px solid rgba(0,0,0,0.125);
}

/* Tables inside cards scroll horizontally rather than blowing out the card */
.card table,
.card .table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Alert Styles */
.alert {
    margin-bottom: 1rem;
    white-space: normal;
}

/* Navigation Styles */
.navbar {
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.navbar-brand {
    font-weight: bold;
    font-size: 1.5rem;
    /* Never let brand text overflow onto toggler */
    max-width: calc(100% - 56px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-link {
    font-weight: 500;
}

.dropdown-item:active {
    background-color: #007bff;
}

.dropdown-menu {
    max-width: min(92vw, 26rem);
}

/* Notification dropdown — never narrower than its content,
   never wider than the viewport. */
.notification-dropdown {
    width: min(350px, calc(100vw - 1rem));
    max-height: min(400px, 70vh);
    overflow-y: auto;
}

/* Notification dropdown header row: title + "Mark all read" button */
.notification-dropdown .dropdown-header {
    white-space: normal;
    flex-wrap: wrap;
    gap: 0.25rem;
}

/* Badge */
.badge {
    font-size: 0.75rem;
}

/* Button Styles */
.btn {
    white-space: normal;
    max-width: 100%;
    border-radius: 0.375rem;
}

.btn-primary {
    background-color: #007bff;
    border-color: #007bff;
}
.btn-primary:hover {
    background-color: #0056b3;
    border-color: #0056b3;
}

.btn-success {
    background-color: #28a745;
    border-color: #28a745;
}
.btn-success:hover {
    background-color: #218838;
    border-color: #1e7e34;
}

.btn-warning {
    background-color: #ffc107;
    border-color: #ffc107;
    color: #212529;
}
.btn-warning:hover {
    background-color: #e0a800;
    border-color: #d39e00;
}

.btn-info {
    background-color: #17a2b8;
    border-color: #17a2b8;
}
.btn-info:hover {
    background-color: #138496;
    border-color: #117a8b;
}

.btn-danger {
    background-color: #dc3545;
    border-color: #dc3545;
}
.btn-danger:hover {
    background-color: #c82333;
    border-color: #bd2130;
}

.btn-secondary {
    background-color: #6c757d;
    border-color: #6c757d;
}
.btn-secondary:hover {
    background-color: #5a6268;
    border-color: #545b62;
}

.btn-outline-primary  { color: #007bff;  border-color: #007bff; }
.btn-outline-primary:hover  { background-color: #007bff;  border-color: #007bff; color: #fff; }

.btn-outline-success  { color: #28a745;  border-color: #28a745; }
.btn-outline-success:hover  { background-color: #28a745;  border-color: #28a745; color: #fff; }

.btn-outline-warning  { color: #ffc107;  border-color: #ffc107; }
.btn-outline-warning:hover  { background-color: #ffc107;  border-color: #ffc107; color: #212529; }

.btn-outline-info     { color: #17a2b8;  border-color: #17a2b8; }
.btn-outline-info:hover     { background-color: #17a2b8;  border-color: #17a2b8; color: #fff; }

.btn-outline-danger   { color: #dc3545;  border-color: #dc3545; }
.btn-outline-danger:hover   { background-color: #dc3545;  border-color: #dc3545; color: #fff; }

.btn-outline-secondary { color: #6c757d; border-color: #6c757d; }
.btn-outline-secondary:hover { background-color: #6c757d; border-color: #6c757d; color: #fff; }

/* Social Login Buttons */
.btn-social {
    position: relative;
    padding-left: 44px;
    text-align: left;
    /* Do not set white-space: nowrap here — it overflows on mobile */
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-social > :first-child {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 32px;
    line-height: 34px;
    font-size: 1.6em;
    text-align: center;
    border-right: 1px solid rgba(0,0,0,0.2);
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: 56px; /* Height of navbar */
    bottom: 0;
    left: 0;
    z-index: 100;
    padding: 0;
    box-shadow: inset -1px 0 0 rgba(0, 0, 0, .1);
}

.sidebar-sticky {
    position: sticky;
    top: 0;
    height: calc(100vh - 56px);
    padding-top: .5rem;
    overflow-x: hidden;
    overflow-y: auto;
}

/* Main content */
.main-content {
    margin-left: 16.666667%; /* col-md-2 width */
    min-width: 0;
}

@media (min-width: 992px) {
    .main-content {
        margin-left: 25%; /* col-lg-3 width */
    }
}

/* ── DENSE NAVBAR: 992–1199px (10+ nav links at this width crowd) ───── */
@media (min-width: 992px) and (max-width: 1199.98px) {
    .navbar-nav .nav-link {
        padding-left: 0.35rem;
        padding-right: 0.35rem;
        font-size: 0.82rem;
    }
    .navbar-brand {
        font-size: 1rem;
    }
}

/* ── RESPONSIVE ADJUSTMENTS ─────────────────────────────────────────── */
@media (max-width: 767.98px) {
    .container,
    .container-fluid {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    h1,
    .h1,
    .display-4 {
        font-size: clamp(1.75rem, 6vw, 2.4rem);
    }

    h2,
    .h2 {
        font-size: clamp(1.4rem, 4.8vw, 2rem);
    }

    /* Full-width large buttons, no horizontal margins */
    .btn.btn-lg {
        width: 100%;
        margin-right: 0 !important;
        margin-left: 0 !important;
    }

    /* Stack sibling btn-lg buttons */
    .btn.btn-lg + .btn.btn-lg,
    .d-grid.gap-2.d-md-block > .btn,
    .card .btn + .btn {
        margin-top: 0.5rem;
    }

    /* Social login buttons: allow text to wrap on mobile */
    .btn-social {
        white-space: normal;
        padding-left: 44px;
    }

    /* Notification dropdown: full available width minus edge gaps */
    .notification-dropdown {
        width: calc(100vw - 1rem) !important;
        max-width: calc(100vw - 1rem);
        right: 0 !important;
        left: auto !important;
    }

    .dropdown-menu,
    .dropdown-menu.show {
        max-width: calc(100vw - 1rem);
    }

    .sidebar {
        position: static;
        height: auto;
    }

    .sidebar .nav-link,
    .admin-nav .nav-link {
        white-space: normal;
    }

    .main-content {
        margin-left: 0;
    }

    /* Vertically centre dismiss button within single-line alerts */
    .alert-dismissible .btn-close {
        top: 50%;
        transform: translateY(-50%);
        padding: 0.5rem;
    }
}

/* ── EXTRA-SMALL (< 480px) ──────────────────────────────────────────── */
@media (max-width: 479.98px) {
    /* Clamp heading sizes even tighter */
    h1, .h1, .display-4 { font-size: clamp(1.5rem, 8vw, 1.9rem); }
    h2, .h2             { font-size: clamp(1.25rem, 6.5vw, 1.6rem); }
    h3, .h3             { font-size: clamp(1.1rem, 5.5vw, 1.35rem); }

    /* Slim horizontal padding on tiniest phones */
    .container,
    .container-fluid {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    /* Card padding tighter */
    .card-body {
        padding: 0.75rem;
    }
}

/* ── BOOTSTRAP 4 → 5 COLOR SHIMS ────────────────────────────────────
   Bootstrap 5 dropped the exact BS4 hex values for bg-* and text-*.
   These restores ensure consistent colour across all templates.       */
.text-muted    { color: #6c757d !important; }
.text-primary  { color: #007bff !important; }
.text-success  { color: #28a745 !important; }
.text-warning  { color: #ffc107 !important; }
.text-info     { color: #17a2b8 !important; }
.text-danger   { color: #dc3545 !important; }
.text-secondary{ color: #6c757d !important; }

.bg-primary    { background-color: #007bff !important; }
.bg-success    { background-color: #28a745 !important; }
.bg-warning    { background-color: #ffc107 !important; }
.bg-info       { background-color: #17a2b8 !important; }
.bg-danger     { background-color: #dc3545 !important; }
.bg-secondary  { background-color: #6c757d !important; }

/* ══════════════════════════════════════════════════════════════════
   DROPDOWN SUBMENU SYSTEM
   Second-level fly-out menus for the authenticated user nav.

   Design intent:
     • Desktop (≥ 992px): panel flies out to the LEFT of the parent
       dropdown.  The user dropdown is right-aligned (dropdown-menu-end)
       near the viewport's right edge; left:100% would push the submenu
       off-screen where overflow-x:clip hides it.  right:100% is safe.
     • Mobile (< 992px): submenus stack vertically inside the collapsed
       drawer — all absolute-positioning is fully reset.
   ══════════════════════════════════════════════════════════════════ */

/* PARENT ITEM — position:relative anchors the absolute submenu panel.
   overflow:visible is explicit so the panel is never clipped by the <li>. */
.dropdown-submenu {
    position: relative;
    overflow: visible;
}

/* SUBMENU PANEL — base/desktop defaults ─────────────────────────── */
.dropdown-submenu .dropdown-submenu-content {
    display: none;
    position: absolute;
    right: 100%;     /* fly out to the LEFT */
    left: auto;
    top: 0;
    margin-right: 5px;
    margin-left: 0;
    min-width: 200px;
    max-width: min(280px, 90vw);
    white-space: nowrap;    /* keep items on one line; panel grows to fit */
    background-color: #fff;
    border: 1px solid rgba(0,0,0,.15);
    border-radius: 0.375rem;
    box-shadow: 0 0.5rem 1rem rgba(0,0,0,.175);
    z-index: 1060;          /* above Bootstrap dropdown (1000) and navbar (1030) */
    padding: 0.5rem 0;
    list-style: none;
    overflow: visible;      /* never clip child elements or further nested panels */
}

/* HOVER BRIDGE — invisible pseudo-element on the panel's right edge.
   The submenu panel is separated from its parent <li> by margin-right:5px.
   As the cursor crosses that gap it briefly leaves the .dropdown-submenu DOM
   subtree, deactivating :hover and making the panel disappear before the
   cursor reaches it.  This ::before element fills the gap so the cursor
   stays over a descendant of .dropdown-submenu throughout the traversal. */
.dropdown-submenu .dropdown-submenu-content::before {
    content: '';
    position: absolute;
    right: -8px;     /* margin-right is 5px; 8px gives a small safety margin  */
    top: 0;
    bottom: 0;
    width: 8px;
    background: transparent;
    pointer-events: auto;
}

/* Show: CSS hover path */
.dropdown-submenu:hover > .dropdown-submenu-content,
.dropdown-submenu.active > .dropdown-submenu-content {
    display: block !important;
}

/* Show: more-specific selector used when Bootstrap .show is present */
.dropdown-menu.show .dropdown-submenu:hover > .dropdown-submenu-content {
    display: block !important;
}

.dropdown-submenu .dropdown-toggle {
    cursor: pointer;
}

/* Arrow: ► conventional right-pointing chevron for submenus */
.dropdown-submenu .dropdown-toggle::after {
    content: "►";
    margin-left: 0.5rem;
    float: right;
    border: none;
    font-size: 0.7em;
    line-height: inherit;
    vertical-align: middle;
}

/* PARENT DROPDOWN MENU — overflow:visible ensures the submenu panel
   is never clipped by the parent dropdown's own box. */
#userDropdownMenu {
    min-width: min(260px, 92vw);
    overflow: visible;
}

#userDropdownMenu .dropdown-submenu-content {
    pointer-events: auto;
    min-width: min(220px, 90vw);
}

/* ── DESKTOP GUARD (≥ 992px) ────────────────────────────────────────
   Belt-and-suspenders: re-assert the fly-out positioning with
   !important so no lower-specificity rule can override it on desktop. */
@media (min-width: 992px) {
    .dropdown-submenu .dropdown-submenu-content {
        position: absolute !important;
        right: 100% !important;
        left: auto !important;
        top: 0 !important;
        margin-right: 5px !important;
        margin-left: 0 !important;
        min-width: 200px !important;
        white-space: nowrap !important;
        border: 1px solid rgba(0,0,0,.15) !important;
        border-radius: 0.375rem !important;
        box-shadow: 0 0.5rem 1rem rgba(0,0,0,.175) !important;
        z-index: 1060 !important;
    }

    .dropdown-submenu .dropdown-toggle::after {
        content: "►";
        float: right;
        margin-left: 0.5rem;
    }
}

/* ── MOBILE (< 992px) — stack vertically in collapsed drawer ────────
   position:static removes all offset properties (right/left/top are
   ignored on static elements).  Every desktop value is explicitly
   reset with !important to win any specificity battle. */
@media (max-width: 991.98px) {
    .dropdown-submenu .dropdown-submenu-content {
        position: static !important;
        right: auto !important;
        left: auto !important;
        top: auto !important;
        margin-right: 0 !important;
        margin-left: 0 !important;
        margin-top: 0.25rem;
        min-width: 100% !important;
        max-width: 100% !important;
        white-space: normal !important;
        border: 0 !important;
        border-left: 2px solid rgba(0, 0, 0, 0.08) !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        z-index: auto !important;
        overflow: visible;
    }

    .dropdown-submenu .dropdown-toggle::after {
        content: "▼";   /* down-arrow for vertical-stack mobile view */
        float: none;
        margin-left: 0.35rem;
    }
}