/* ============================================================
   AdminLTE 4 + OptiMach-style orange theme overrides
   Brand primary: #FF4500  (hover #E63E00, light #FF6B35)
   Loaded AFTER bootstrap + adminlte so it wins.
   ============================================================ */

:root,
[data-bs-theme="light"] {
    --bs-primary: #FF4500;
    --bs-primary-rgb: 255, 69, 0;
    --bs-primary-text-emphasis: #b83100;
    --bs-primary-bg-subtle: #ffe8df;
    --bs-primary-border-subtle: #ffc9b8;
    --bs-link-color: #FF4500;
    --bs-link-color-rgb: 255, 69, 0;
    --bs-link-hover-color: #E63E00;
    --bs-link-hover-color-rgb: 230, 62, 0;

    --brand: #FF4500;
    --brand-hover: #E63E00;
    --brand-light: #FF6B35;
}

/* ---- Buttons ---- */
.btn-primary {
    --bs-btn-bg: #FF4500;
    --bs-btn-border-color: #FF4500;
    --bs-btn-hover-bg: #E63E00;
    --bs-btn-hover-border-color: #E63E00;
    --bs-btn-active-bg: #cc3700;
    --bs-btn-active-border-color: #cc3700;
    --bs-btn-disabled-bg: #FF4500;
    --bs-btn-disabled-border-color: #FF4500;
}

.btn-outline-primary {
    --bs-btn-color: #FF4500;
    --bs-btn-border-color: #FF4500;
    --bs-btn-hover-bg: #FF4500;
    --bs-btn-hover-border-color: #FF4500;
    --bs-btn-active-bg: #E63E00;
    --bs-btn-active-border-color: #E63E00;
}

.text-primary { color: #FF4500 !important; }
.bg-primary { background-color: #FF4500 !important; }
.border-primary { border-color: #FF4500 !important; }
.link-primary { color: #FF4500 !important; }

/* Focus rings / form controls */
.form-control:focus,
.form-select:focus,
.form-check-input:focus {
    border-color: #ffa07a;
    box-shadow: 0 0 0 0.25rem rgba(255, 69, 0, 0.20);
}
.form-check-input:checked {
    background-color: #FF4500;
    border-color: #FF4500;
}

/* ---- App shell base ---- */
/* Flex-truncation helper (Bootstrap 5 has no min-w utility): allows text-truncate
   to work inside flex rows where a child would otherwise refuse to shrink. */
.min-w-0 {
    min-width: 0 !important;
}

/* Sticky table header: add `.table-sticky` to a scroll wrapper (it already carries
   overflow via .table-responsive). The header row pins to the top of that region
   while the rows scroll under it, and it still scrolls horizontally. `min-height:0`
   isn't needed here because the wrapper's own max-height creates the scroll context. */
.table-sticky {
    max-height: 68vh;
    overflow: auto;
}

.table-sticky thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    /* keep a crisp divider under the pinned header (its own border scrolls away) */
    box-shadow: inset 0 -1px 0 var(--bs-border-color);
}

/* Fixed app shell: bind the grid wrapper to the viewport so the header, sidebar
   and footer stay put and ONLY the main content area scrolls. AdminLTE already
   sets `.app-header{position:sticky}` but its wrapper is only `min-height:100vh`,
   so with tall content the whole document scrolls and drags the header with it.
   `min-height:0` on the 1fr grid item is what lets `.app-main`'s overflow scroll
   internally instead of expanding the page. */
html, body {
    height: 100%;
}

body.layout-fixed .app-wrapper {
    height: 100vh;
    overflow: hidden;
}

body.layout-fixed .app-main {
    min-height: 0;
    overflow-y: auto;
}

body {
    font-family: 'Source Sans 3', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Sidebar (dark) brand + active accent */
.app-sidebar .sidebar-brand {
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.app-sidebar .brand-text { font-weight: 700; letter-spacing: -0.01em; }

.sidebar-menu .nav-link.active,
.sidebar-menu .nav-item > .nav-link.active {
    background-color: #FF4500 !important;
    color: #fff !important;
    box-shadow: 0 2px 8px rgba(255, 69, 0, 0.35);
}
.sidebar-menu .nav-treeview .nav-link.active {
    background-color: rgba(255, 69, 0, 0.85) !important;
    color: #fff !important;
}
.sidebar-menu .nav-link:hover {
    background-color: rgba(255, 255, 255, 0.06);
}
.sidebar-menu .nav-treeview .nav-link:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

/* Section headers inside sidebar */
.app-sidebar .nav-header {
    color: rgba(255, 255, 255, 0.45);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 11px;
    font-weight: 700;
}

/* ---- Cards ---- */
.card {
    border: 1px solid var(--bs-border-color);
    border-radius: 0.65rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
}
.card-primary.card-outline { border-top: 3px solid #FF4500; }

/* Small brand accent used by page headers */
.brand-accent { color: #FF4500; }

/* Selection */
::selection { background: #FF4500; color: #fff; }

/* Tables: subtle header + hover */
.table > thead { background-color: var(--bs-tertiary-bg); }
.table-hover > tbody > tr:hover > * { background-color: rgba(255, 69, 0, 0.05); }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* Notification badge dot on navbar */
.navbar-badge {
    font-size: 0.6rem;
    font-weight: 600;
    padding: 2px 5px;
    background-color: #FF4500 !important;
}

/* ---- DataTables (Bootstrap 5) tuning ---- */
.dataTables_wrapper .dt-buttons .btn { margin-right: .35rem; }
div.dt-container .dt-search input { min-width: 220px; }
table.dataTable thead tr.dt-filter-row th { padding: .25rem .35rem; }
table.dataTable thead tr.dt-filter-row .form-control-sm { font-weight: 400; }
table.dataTable thead th { white-space: nowrap; }
div.dt-container .dt-paging .pagination { margin-bottom: 0; }
.page-item.active .page-link { background-color: #FF4500; border-color: #FF4500; }
.page-link { color: #FF4500; }
.page-link:hover { color: #cc3700; }

/* Card that holds a data table: let the table breathe */
.card > .card-body > .dataTables_wrapper,
.card > .card-body > div.dt-container { margin-top: -.25rem; }

/* Theme switcher active check */
[data-theme-value].active { color: #FF4500; }

/* Dark-mode: keep the orange sidebar accents readable */
[data-bs-theme="dark"] .card {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

/* ===== AppGrid opt-in sticky header (set MaxHeight on <AppGrid>) =====
   Header + filter rows stay pinned while only the body scrolls. Sticky on the
   whole <thead> auto-handles multi-line headers. (Must live here — the app loads
   adminlte-custom.css, NOT erp-theme.css.) */
.app-grid-scroll { position: relative; }
.app-grid-sticky thead {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    z-index: 3;
}
.app-grid-sticky thead th {
    background: var(--bs-body-bg, #fff);
    box-shadow: inset 0 -1px 0 var(--bs-border-color, #dee2e6);
}

/* =====================================================================
   MOBILE / RESPONSIVE  (loaded by BOTH shells — Blazor App.razor and the
   MVC _Layout — so these rules reach every page in the app.)
   AdminLTE 4 + Bootstrap 5 are responsive already; these rules fix the
   app-specific things that break on a phone: wide data tables, toolbars
   that refuse to wrap, and padding that eats the small screen.
   ===================================================================== */

/* NOTE: do NOT put `overflow-x: hidden` on html/body here. This shell is
   AdminLTE `layout-fixed`, where scrolling belongs to .app-main; forcing an
   overflow on html/body flips their computed overflow-y to `auto`, creating a
   second scroll container (double/janky scrolling) and it can also break
   `position: sticky`. Wide content is contained by the table rules below,
   which scroll inside their own wrapper instead. */

/* Any table wrapped in .table-responsive scrolls smoothly on touch. */
.table-responsive {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
}

/* `.app-wrapper` is a CSS GRID whose areas are named (lte-app-header/-sidebar/-main/
   -footer). Only those four classes carry a `grid-area`, so ANY other direct child —
   like our `.sidebar-overlay` backdrop — gets auto-placed into its own cell and
   shifts the entire layout, on desktop as well. AdminLTE ships no base rule for the
   overlay, so we keep it out of the grid until it is actually needed; when the mobile
   sidebar opens AdminLTE gives it `position:absolute; inset:0`, which takes it out of
   grid flow anyway. */
.sidebar-overlay { display: none; }

@media (max-width: 991.98px) {
    body.sidebar-open .sidebar-overlay { display: block; }

    /* The off-canvas sidebar must sit above the sticky header when open. */
    .app-sidebar { z-index: 1038; }
}

@media (max-width: 767.98px) {
    /* Reclaim horizontal space: the shell's gutters are generous for desktop. */
    .app-content > .container-fluid,
    .app-content-header > .container-fluid { padding-left: .75rem; padding-right: .75rem; }
    .app-content { padding-top: .5rem; }
    .card-body { padding: .75rem; }

    /* Page headings scale down so a title + button row still fits one line. */
    h1, .h1 { font-size: 1.35rem; }
    h2, .h2 { font-size: 1.2rem; }
    h3, .h3, h4, .h4 { font-size: 1.05rem; }

    /* Header / toolbar rows: allow wrapping instead of overflowing. */
    .d-flex.justify-content-between { flex-wrap: wrap; }

    /* Filter bars stack; controls become comfortably tappable. */
    .form-control, .form-select { font-size: 16px; }   /* 16px stops iOS zoom-on-focus */
    .form-control-sm, .form-select-sm { font-size: 15px; }

    /* Tables stay readable but compact, and always scroll rather than squeeze. */
    .table > :not(caption) > * > * { padding: .35rem .4rem; }
    .table-responsive > table { min-width: 640px; }

    /* Button groups wrap and stretch a little for touch. */
    .btn-group, .btn-toolbar { flex-wrap: wrap; }
    .btn { --bs-btn-padding-y: .35rem; }

    /* Breadcrumb/footer are decorative — hide the noisy parts. */
    .app-content-header .breadcrumb { display: none; }
    .app-footer { font-size: .8rem; text-align: center; }
    .app-footer .float-end { float: none !important; display: block; }

    /* Dropdown menus (notifications/user) must not run off-screen. */
    .app-header .dropdown-menu { max-width: 92vw; }
}

@media (max-width: 575.98px) {
    /* Stack summary/KPI cards full width on the smallest phones. */
    .row > [class*="col-"] { margin-bottom: .25rem; }
    .card-body { padding: .6rem; }
    .table-responsive > table { min-width: 560px; }
}

/* Print: the sidebar/header never belong on paper. */
@media print {
    .app-sidebar, .app-header, .app-footer, .sidebar-overlay, .no-print { display: none !important; }
    .app-main { margin-left: 0 !important; }
}

/* ===== AppGrid on small screens =====
   AppGrid backs most Blazor list pages, so these rules carry across the app.
   The grid keeps its columns and scrolls horizontally — squeezing 10+ columns
   into 375px makes them unreadable, scrolling keeps them intact. */
@media (max-width: 767.98px) {
    /* Search takes the full second line instead of being squashed beside the buttons. */
    .app-grid-toolbar .app-grid-search { max-width: 100% !important; width: 100%; }
    .app-grid-toolbar > div { flex: 0 0 auto; }

    /* Compact, still tappable. */
    .app-grid table.table { font-size: 13px; }
    .app-grid table.table th,
    .app-grid table.table td { white-space: nowrap; }

    /* Per-column filter inputs stay usable without dominating the row. */
    .app-grid .dt-filter-row .form-control { min-width: 90px; font-size: 13px; }

    /* Paging strip wraps and centres. */
    .app-grid .pagination { flex-wrap: wrap; }
    .app-grid .d-flex.justify-content-between:last-child { justify-content: center !important; gap: .5rem; }
}

/* ===== Bare tables (no .table-responsive wrapper) =====
   ~20 legacy MVC views and one Blazor page drop a <table> straight into a card.
   On a phone those would stretch the page sideways, so below md we turn the table
   itself into its own scroller. Scoped to DIRECT children of the card so it can
   never touch a DataTables-managed table (those live inside .dt-container). */
@media (max-width: 767.98px) {
    .card-body > table.table,
    .card > table.table,
    .app-content > .container-fluid > table.table {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }

    /* DataTables' own wrapper scrolls instead of overflowing. */
    .dt-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* ---------------------------------------------------------------------------
   3D icon tile (client, 2026-09-29: "3D icons like this dashboards also need").
   The desktop's tile (HRMS.UI.Controls/Theme/HrmsIcon3D.cs) in CSS: a rounded
   square lit from above - lighter top, a gloss over the upper half, a darker
   rim, a soft shadow - with the icon in white. Colour by what it is about, as
   on the desktop ribbon: people blue, pay green, time orange, reports purple,
   papers teal, fleet indigo, settings slate, leaving / warnings red.
   Use:  <span class="icon-3d icon-3d-blue" style="width:42px;height:42px"><i class="bi bi-people"></i></span>
   --------------------------------------------------------------------------- */
.icon-3d { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; position: relative;
           color: #fff; border-radius: 26%; background: linear-gradient(180deg, var(--t1, #4caf6e), var(--t2, #177a33));
           box-shadow: 0 2px 3px rgba(0,0,0,.26), 0 1px 0 rgba(0,0,0,.08), inset 0 -1.5px 0 rgba(0,0,0,.18); }
.icon-3d::before { content: ""; position: absolute; left: 7%; right: 7%; top: 4%; height: 46%; border-radius: 22% 22% 14% 14%;
                   background: linear-gradient(180deg, rgba(255,255,255,.42), rgba(255,255,255,0)); pointer-events: none; }
.icon-3d > i { position: relative; line-height: 1; text-shadow: 0 1px 0 rgba(0,0,0,.25); }
.icon-3d-green  { --t1: #4caf6e; --t2: #177a33; }
.icon-3d-blue   { --t1: #4b93f0; --t2: #1560c9; }
.icon-3d-orange { --t1: #f5a73a; --t2: #cf7700; }
.icon-3d-purple { --t1: #9a66d6; --t2: #6533a8; }
.icon-3d-teal   { --t1: #35a99c; --t2: #00776b; }
.icon-3d-indigo { --t1: #6b79cf; --t2: #2e3d99; }
.icon-3d-slate  { --t1: #7a929c; --t2: #465c66; }
.icon-3d-red    { --t1: #ea5d52; --t2: #b8241b; }
.icon-3d-pink   { --t1: #ea5b8f; --t2: #b3134f; }

/* Every table's words centred both ways and a long text wrapped onto further lines rather than cut (client, 2026-11-03:
   "Apply proper text wrapping, auto row height ... Center-align all column headers and cell contents horizontally and
   vertically"). A row grows with its text, as a table row does. */
.table > :not(caption) > * > th,
.table > :not(caption) > * > td {
    text-align: center !important;
    vertical-align: middle !important;
    white-space: normal !important;
    overflow-wrap: break-word;
}
