/* =====================================================================
   RZ Chemicals East Africa LTD — Stock Management System
   Design tokens — Blue theme
   - Display/UI face:  Montserrat        (headings, nav, buttons, labels)
   - Data/ledger face: IBM Plex Mono     (quantities, stat numbers, badges)
   - Signature motif:  a single hazard-stripe rule under the top bar —
     a nod to warehouse/drum signage, used exactly once, nowhere else.
   ===================================================================== */

:root {
    --rz-ink:          #0f2438;   /* deep navy ink, text & nav */
    --rz-ink-soft:      #46617a;
    --rz-primary:      #1361b0;   /* brand blue - primary actions / stock in */
    --rz-primary-dark: #0d4680;
    --rz-steel:        #0f8b9e;   /* teal-blue - informational / pail badge */
    --rz-rust:         #a8452c;   /* stock out / danger, kept warm for contrast */
    --rz-rust-dark:    #7e3220;
    --rz-amber:        #e2992f;   /* hazard amber - warnings / low stock */
    --rz-bg:           #f2f5f8;
    --rz-surface:      #ffffff;
    --rz-border:       #dde4ea;
}

/* ---------------------------------------------------------------------
   Base type
   --------------------------------------------------------------------- */
body {
    background-color: var(--rz-bg);
    color: var(--rz-ink);
    font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, sans-serif;
    font-weight: 400;
}

h1, h2, h3, h4, h5, h6,
.navbar-brand, .card-header, .btn, .form-label, label,
.dropdown-menu, .nav-link {
    font-family: 'Montserrat', sans-serif;
}

h1, h2, h3, h4, h5, h6 { font-weight: 700; letter-spacing: -0.01em; }
.card-header { font-weight: 600; }
.form-label { font-weight: 600; font-size: .85rem; color: var(--rz-ink-soft); }

/* Ledger / data face — numbers should read like a manifest, not prose */
.stat-number,
.badge,
table.dataTable td.text-end,
table td.text-end,
code {
    font-family: 'IBM Plex Mono', 'SFMono-Regular', Consolas, monospace;
}

/* ---------------------------------------------------------------------
   Layout shell: fixed top bar + vertical sticky sidebar + main content
   --------------------------------------------------------------------- */
:root {
    --rz-topbar-h: 58px;
    --rz-sidebar-w: 232px;
}

* { box-sizing: border-box; }
html, body { overflow-x: hidden; }

/* ---- Top bar : brand + hamburger on the left, user menu pinned far right ---- */
.app-topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--rz-topbar-h);
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 0 1rem;
    background: linear-gradient(90deg, var(--rz-ink), var(--rz-primary-dark));
    box-shadow: 0 1px 0 rgba(0,0,0,.08);
    z-index: 1040;
}
.sidebar-toggle-btn {
    background: transparent;
    border: 1px solid rgba(255,255,255,.25);
    color: #fff;
    font-size: 1.25rem;
    line-height: 1;
    width: 40px; height: 40px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    flex: 0 0 auto;
}
.sidebar-toggle-btn:hover { background: rgba(255,255,255,.12); }

.app-brand {
    display: flex;
    align-items: center;
    gap: .5rem;
    color: #fff;
    font-weight: 800;
    letter-spacing: .01em;
    text-decoration: none;
    white-space: nowrap;
}
.app-brand:hover { color: #fff; }
.app-brand .fw-light { opacity: .75; font-weight: 400; }
.app-brand-text { font-size: 1.02rem; }

.topbar-spacer { flex: 1 1 auto; }

/* Logged-in user block: always the right-most element of the top bar */
.app-user-menu { flex: 0 0 auto; margin-left: auto; }
.app-user-btn {
    display: flex;
    align-items: center;
    gap: .55rem;
    color: #fff !important;
    border: 1px solid rgba(255,255,255,.25);
    border-radius: 24px;
    padding: .3rem .7rem .3rem .3rem;
    background: rgba(255,255,255,.06);
}
.app-user-btn:hover, .app-user-btn:focus { background: rgba(255,255,255,.16); color: #fff; }
.app-user-avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    background: var(--rz-amber);
    color: var(--rz-ink);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .85rem;
    flex: 0 0 auto;
}
.app-user-name { font-weight: 600; font-size: .9rem; }

/* ---- Sidebar : vertical + sticky (fixed) on desktop, off-canvas on mobile ---- */
.app-sidebar {
    position: fixed;
    top: var(--rz-topbar-h);
    left: 0;
    bottom: 0;
    width: var(--rz-sidebar-w);
    background: var(--rz-ink);
    overflow-y: auto;
    z-index: 1035;
    display: flex;
    flex-direction: column;
    transition: transform .22s ease;
}
.app-sidebar .hazard-stripe { height: 4px; flex: 0 0 auto; }

.sidebar-nav {
    list-style: none;
    margin: 0;
    padding: .6rem 0;
    flex: 1 1 auto;
}
.sidebar-group-label {
    font-family: 'Montserrat', sans-serif;
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: rgba(255,255,255,.45);
    padding: .9rem 1.1rem .3rem;
}
.sidebar-link {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .65rem 1.1rem;
    color: rgba(255,255,255,.82);
    font-weight: 500;
    font-size: .92rem;
    text-decoration: none;
    border-left: 3px solid transparent;
}
.sidebar-link i { font-size: 1.05rem; width: 1.1rem; text-align: center; }
.sidebar-link.sidebar-sublink { padding-left: 1.6rem; font-size: .87rem; }
.sidebar-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-link.active {
    background: rgba(255,255,255,.09);
    color: #fff;
    font-weight: 600;
    border-left-color: var(--rz-amber);
}
.sidebar-footer {
    padding: .8rem 1.1rem;
    font-size: .7rem;
    color: rgba(255,255,255,.4);
    border-top: 1px solid rgba(255,255,255,.08);
}
.sidebar-logout-link {
    display: flex;
    align-items: center;
    gap: .6rem;
    color: rgba(255,255,255,.75);
    text-decoration: none;
    font-weight: 600;
    font-size: .82rem;
}
.sidebar-logout-link i { font-size: 1.05rem; }
.sidebar-logout-link:hover { color: #fff; }

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    top: var(--rz-topbar-h);
    background: rgba(18,36,29,.45);
    z-index: 1030;
}

/* ---- Main content area, offset for the fixed top bar + sidebar ---- */
.app-main {
    margin-top: var(--rz-topbar-h);
    margin-left: var(--rz-sidebar-w);
    min-height: calc(100vh - var(--rz-topbar-h));
}
.app-content-inner {
    padding: 1.5rem 1.5rem 2.5rem;
}

/* ---- Desktop-collapsible / mobile off-canvas behaviour ---- */
@media (max-width: 991.98px) {
    .app-sidebar {
        transform: translateX(-100%);
        width: min(var(--rz-sidebar-w), 82vw);
        box-shadow: 4px 0 18px rgba(0,0,0,.25);
    }
    .app-sidebar.show { transform: translateX(0); }
    .sidebar-backdrop.show { display: block; }
    .app-main { margin-left: 0; }
    .app-content-inner { padding: 1.1rem 1rem 2rem; }

    /* Mobile top bar: full company name pinned left, menu icon pinned right */
    .app-brand { order: 1; }
    .topbar-spacer { order: 2; }
    .app-user-menu { display: none; }
    .sidebar-toggle-btn { order: 3; }
    .app-brand-text {
        display: inline-block;
        font-size: .8rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: calc(100vw - 130px);
    }
}

@media (min-width: 992px) {
    /* Desktop: hamburger doubles as a collapse toggle, in case the user
       wants extra width for wide report tables. */
    body.sidebar-open .app-sidebar,
    .app-sidebar { transform: translateX(0); }
}

/* The single signature element: a repeating hazard-stripe rule. */
.hazard-stripe {
    height: 5px;
    background-image: repeating-linear-gradient(
        45deg,
        var(--rz-ink) 0, var(--rz-ink) 10px,
        var(--rz-amber) 10px, var(--rz-amber) 20px
    );
}

/* ---------------------------------------------------------------------
   Stat cards (dashboard + reports)
   --------------------------------------------------------------------- */
.stat-card {
    background: var(--rz-surface);
    border: 1px solid var(--rz-border);
    border-radius: 12px;
    border-top: 4px solid var(--rz-border);
    box-shadow: 0 1px 3px rgba(18,36,29,.05);
    padding: 1.25rem 1.35rem 1.4rem;
    height: 100%;
    transition: box-shadow .15s ease, transform .15s ease;
}
.stat-card:hover { box-shadow: 0 6px 18px rgba(18,36,29,.09); transform: translateY(-1px); }

.stat-card.card-green  { border-top-color: var(--rz-primary); }
.stat-card.card-blue   { border-top-color: var(--rz-steel); }
.stat-card.card-orange { border-top-color: var(--rz-amber); }
.stat-card.card-red    { border-top-color: var(--rz-rust); }

.stat-icon {
    width: 42px; height: 42px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem; color: #fff;
    margin-bottom: .85rem;
}
.stat-icon.icon-green  { background: var(--rz-primary); }
.stat-icon.icon-blue   { background: var(--rz-steel); }
.stat-icon.icon-orange { background: var(--rz-amber); }
.stat-icon.icon-red    { background: var(--rz-rust); }

.stat-label {
    font-size: .74rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--rz-ink-soft);
    margin-bottom: .15rem;
}
.stat-number {
    font-size: 1.9rem;
    font-weight: 600;
    color: var(--rz-ink);
    line-height: 1.1;
}

/* Legacy class names still used inline in a few pages — keep them mapped
   to the new token-based look so every card matches without touching markup. */
.card-stat { border: none; border-radius: 14px; box-shadow: 0 2px 10px rgba(0,0,0,.06); color: #fff; overflow: hidden; }
.card-stat .card-body { position: relative; z-index: 2; }
.card-stat i.bg-icon { position: absolute; right: -10px; bottom: -10px; font-size: 5rem; opacity: .16; z-index: 1; }
.card-stat.bg-green   { background: linear-gradient(135deg, var(--rz-primary), var(--rz-primary-dark)); }
.card-stat.bg-blue    { background: linear-gradient(135deg, var(--rz-steel), #1d3f54); }
.card-stat.bg-orange  { background: linear-gradient(135deg, var(--rz-amber), #b87a1e); }
.card-stat.bg-red     { background: linear-gradient(135deg, var(--rz-rust), var(--rz-rust-dark)); }
.card-stat .stat-label { opacity: .92; }

/* ---------------------------------------------------------------------
   Cards, tables, forms
   --------------------------------------------------------------------- */
.card {
    border: 1px solid var(--rz-border);
    border-radius: 12px;
}
.card-header {
    background: var(--rz-surface);
    border-bottom: 1px solid var(--rz-border);
}

.table thead th {
    font-family: 'Montserrat', sans-serif;
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--rz-ink-soft);
    background-color: #f8f9f6;
    border-bottom: 2px solid var(--rz-border);
}

.badge-pail { background-color: var(--rz-steel); }
.badge-drum { background-color: var(--rz-primary); }

.btn { font-weight: 600; border-radius: 8px; letter-spacing: .01em; }

.btn-success {
    background-color: var(--rz-primary);
    border-color: var(--rz-primary);
}
.btn-success:hover, .btn-success:focus {
    background-color: var(--rz-primary-dark);
    border-color: var(--rz-primary-dark);
}
.btn-danger {
    background-color: var(--rz-rust);
    border-color: var(--rz-rust);
}
.btn-danger:hover, .btn-danger:focus {
    background-color: var(--rz-rust-dark);
    border-color: var(--rz-rust-dark);
}
.btn-outline-secondary {
    color: var(--rz-ink-soft);
    border-color: var(--rz-border);
}
.btn-outline-secondary:hover {
    background-color: var(--rz-ink);
    border-color: var(--rz-ink);
}

.form-control:focus, .form-select:focus {
    border-color: var(--rz-primary);
    box-shadow: 0 0 0 .2rem rgba(14,107,69,.15);
}

/* ---------------------------------------------------------------------
   Product photos
   --------------------------------------------------------------------- */
.product-photo-thumb {
    width: 48px; height: 48px; object-fit: cover; border-radius: 8px; border: 1px solid var(--rz-border);
}
.product-photo-preview {
    width: 140px; height: 140px; object-fit: cover; border-radius: 10px; border: 1px solid var(--rz-border);
}

/* ---------------------------------------------------------------------
   Signature pads
   --------------------------------------------------------------------- */
.signature-pad-wrapper {
    border: 2px dashed #b7bfb2;
    border-radius: 10px;
    background: #fff;
    touch-action: none;
}
.signature-pad-wrapper canvas {
    width: 100%;
    height: 180px;
    display: block;
    border-radius: 8px;
    cursor: crosshair;
}

.table-signature-img {
    max-width: 110px;
    max-height: 50px;
    border: 1px solid var(--rz-border);
    border-radius: 4px;
    background: #fff;
}

/* ---------------------------------------------------------------------
   Mobile-friendliness touch-ups shared across every page
   --------------------------------------------------------------------- */
@media (max-width: 575.98px) {
    h4 { font-size: 1.15rem; }
    .stat-number { font-size: 1.5rem; }
    .card-body { padding: 1rem; }
    .btn { font-size: .88rem; }
    table.dataTable { font-size: .82rem; }
}

/* Any plain (non-DataTables) table on a narrow screen scrolls horizontally
   instead of squashing/breaking the layout. */
@media (max-width: 767.98px) {
    .table-responsive-mobile { display: block; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* Signature canvases stay comfortably tappable on small screens */
@media (max-width: 575.98px) {
    .signature-pad-wrapper canvas { height: 150px; }
}

/* ---------------------------------------------------------------------
   Floating "scroll to top" button — present on every page
   --------------------------------------------------------------------- */
.scroll-top-btn {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    width: 46px;
    height: 46px;
    border: none;
    border-radius: 50%;
    background: var(--rz-primary);
    color: #fff;
    font-size: 1.15rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 16px rgba(15,36,56,.28);
    opacity: 0;
    visibility: hidden;
    transform: translateY(12px);
    transition: opacity .2s ease, transform .2s ease, visibility .2s;
    z-index: 1045;
}
.scroll-top-btn.show { opacity: 1; visibility: visible; transform: translateY(0); }
.scroll-top-btn:hover, .scroll-top-btn:focus { background: var(--rz-primary-dark); color: #fff; }

/* ---------------------------------------------------------------------
   Print
   --------------------------------------------------------------------- */
/* Zero page margin is the standard trick that stops browsers (Chrome/Edge)
   from reserving — and therefore printing — their own header/footer strip
   (page URL, title, date, page number) at the top/bottom of every printed
   page. Visual spacing is restored via padding on the content itself below,
   so this applies to every printed page in the app, not just this block. */
@page {
    margin: 0;
}

@media print {
    .app-topbar, .app-sidebar, .sidebar-backdrop, .hazard-stripe,
    .no-print, footer, .scroll-top-btn, .dtsp-searchPanes, .dt-buttons,
    .dataTables_filter, .dataTables_length, .dataTables_paginate, .dataTables_info { display: none !important; }
    .app-main { margin: 0 !important; }
    .app-content-inner { padding: 12mm 10mm !important; }
    body { background: #fff; }
    /* Never let the horizontal-scroll wrapper clip table columns on paper —
       every column must be visible in the printed report. */
    .table-responsive { overflow: visible !important; width: auto !important; }
    table.dataTable { font-size: .72rem; }
}

/* ---------------------------------------------------------------------
   Standalone printable documents (Stock In / Stock Out slips) —
   deliberately outside the app shell entirely, so printing or saving
   as PDF never includes the top bar, sidebar or site footer, and the
   page can be shared as a clean, self-contained document.
   --------------------------------------------------------------------- */
.doc-page {
    max-width: 780px;
    margin: 2rem auto;
    background: #fff;
    padding: 2rem 2.25rem;
}
.doc-toolbar {
    max-width: 780px;
    margin: 1rem auto 0;
    padding: 0 2.25rem;
    display: flex;
    gap: .5rem;
    justify-content: flex-end;
}
.doc-letterhead {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 3px solid var(--rz-ink);
    padding-bottom: 1rem;
    margin-bottom: 1.25rem;
}
.doc-letterhead h2 { margin: 0; font-size: 1.1rem; }
.doc-letterhead .doc-type {
    text-align: right;
    font-size: .8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--rz-ink-soft);
}
.doc-meta-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .35rem 2rem;
    font-size: .8rem;
    margin-bottom: 1.1rem;
}
.doc-meta-grid dt { color: var(--rz-ink-soft); font-weight: 600; }
.doc-meta-grid dd { margin: 0 0 .4rem; }

/* Inline vertical-rule divider used to combine two related fields
   (Product | Quantity, Vehicle | Driver) onto a single line. */
.doc-vline {
    display: inline-block;
    width: 1px;
    height: 1em;
    background: var(--rz-border);
    margin: 0 .65rem;
    vertical-align: middle;
}

/* Notes text on the printable slip is supporting detail, not the main
   record — keep it visually secondary/smaller. */
.doc-notes-text {
    font-size: .72rem;
    color: var(--rz-ink-soft);
    margin: 0;
}
.doc-section-title {
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--rz-ink-soft);
    border-bottom: 1px solid var(--rz-border);
    padding-bottom: .25rem;
    margin: 1.1rem 0 .5rem;
}
.doc-sign-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    margin-top: .85rem;
}
.doc-sign-box { text-align: center; font-size: .8rem; }
.doc-sign-box img { max-width: 200px; max-height: 80px; border-bottom: 1px solid var(--rz-ink); padding-bottom: .25rem; }
.doc-sign-box .doc-sign-name { margin-top: .35rem; font-weight: 600; }
.doc-sign-box .doc-sign-role { font-size: .7rem; color: var(--rz-ink-soft); }
.doc-footer { text-align: center; font-size: .7rem; }

/* Below this width the on-screen view stacks into a single column for
   comfortable reading on a phone. This is purely a *screen* convenience —
   both the printed page and the "Print / Save as PDF" button (which
   renders at a fixed desktop-equivalent width even on mobile, see
   stock_in_print.php / stock_out_print.php) always use the two/three
   column layout below, so the document looks identical on every device. */
@media screen and (max-width: 575.98px) {
    .doc-page { margin: 0; padding: 1.1rem; }
    .doc-toolbar { padding: 0 1.1rem; margin-top: .75rem; }
    .doc-meta-grid, .doc-sign-grid { grid-template-columns: 1fr; }
    .doc-letterhead { flex-direction: column; align-items: flex-start; gap: .5rem; }
    .doc-letterhead .doc-type { text-align: left; }
}

@media print {
    body { background: #fff; }
    .doc-toolbar { display: none !important; }
    .doc-page { margin: 0; max-width: none; padding: .3in .3in; font-size: .8rem; }
    /* Always keep the multi-column layout when printing, regardless of the
       physical screen size the print/PDF was triggered from. */
    .doc-meta-grid { grid-template-columns: 1fr 1fr !important; }
    .doc-sign-grid { grid-template-columns: repeat(3, 1fr) !important; }
    .doc-letterhead { flex-direction: row !important; align-items: center !important; }
    .doc-letterhead .doc-type { text-align: right !important; }
}
