/* ============================================================
   LactisOne — Design System Layer (v1.0)  "Spruce & Butterfat"
   Loaded LAST, after metronic + lactisone-v9 + lactis-enterprise.
   This is the canonical token + utility layer. Future pages should
   pull from the --lo-* tokens and the .lo-* / .lactis-* utilities.
   ============================================================ */
:root {
    /* Spruce — primary */
    --spruce-50:#ECF5F2; --spruce-100:#D2E8E1; --spruce-200:#A6D2C5; --spruce-300:#71B5A3;
    --spruce-400:#429683; --spruce-500:#1F7A66; --spruce-600:#136150; --spruce-700:#0E4D40;
    --spruce-800:#0B3D33; --spruce-900:#082E27;
    /* Butterfat — accent */
    --gold-50:#FBF4E4; --gold-100:#F5E6C2; --gold-200:#EBCF8C; --gold-300:#DDB456;
    --gold-400:#CC9C33; --gold-500:#B5842A; --gold-600:#946A23; --gold-700:#73521E;
    /* Slate — neutral */
    --slate-50:#F6F8F7; --slate-100:#ECF0EF; --slate-200:#DCE3E1; --slate-300:#C2CCC9;
    --slate-400:#98A5A2; --slate-500:#6E7B78; --slate-600:#515D5A; --slate-700:#3B4543;
    --slate-800:#262E2C; --slate-900:#161D1B;
    /* Semantic */
    --lo-success:#2E9E5B; --lo-success-bg:#E6F4EC; --lo-success-fg:#1E6B3D;
    --lo-warning:#C8820E; --lo-warning-bg:#FBF0D9; --lo-warning-fg:#8A5A09;
    --lo-danger:#C8453B;  --lo-danger-bg:#FBE7E5;  --lo-danger-fg:#8E2E27;
    --lo-info:#2D6FB0;    --lo-info-bg:#E4EFF8;    --lo-info-fg:#1F4E7D;
    /* Brand roles */
    --lo-primary:var(--spruce-600); --lo-accent:var(--gold-500);
    --lo-rail-top:#0E4D40; --lo-rail-bottom:#082E27;
    --lo-rail-text:#CFE0DA; --lo-rail-text-dim:#85A79C;
    /* Chart palette (categorical, colour-blind aware) */
    --lo-chart-1:#136150; --lo-chart-2:#B5842A; --lo-chart-3:#2D6FB0;
    --lo-chart-4:#71B5A3; --lo-chart-5:#C8453B; --lo-chart-6:#946A23;
    /* Type + geometry */
    --font-display:"Hanken Grotesk","Inter",system-ui,sans-serif;
    --font-mono:"IBM Plex Mono",ui-monospace,SFMono-Regular,monospace;
    --lo-shadow-sm:0 1px 2px rgba(11,40,33,.06),0 1px 3px rgba(11,40,33,.05);
    --lo-shadow-md:0 4px 12px rgba(11,40,33,.08),0 2px 4px rgba(11,40,33,.05);
    --lo-shadow-lg:0 12px 32px rgba(11,40,33,.12),0 4px 8px rgba(11,40,33,.06);
}

/* ---- Dark-mode token + chart re-mapping ---- */
.dark {
    --lo-success-bg:#10271B; --lo-success-fg:#62C089;
    --lo-warning-bg:#2A2008; --lo-warning-fg:#E0A93E;
    --lo-danger-bg:#2C1311;  --lo-danger-fg:#E08178;
    --lo-info-bg:#0F1F2E;    --lo-info-fg:#6FA6D9;
    --lo-primary:#3FA890; --lo-accent:#DDB456;
    --lo-rail-top:#0A1614; --lo-rail-bottom:#06100E;
    --lo-rail-text:#C4D4CE; --lo-rail-text-dim:#6F857E;
    --lo-chart-1:#3FA890; --lo-chart-2:#DDB456; --lo-chart-3:#6FA6D9;
    --lo-chart-4:#A6D2C5; --lo-chart-5:#E08178; --lo-chart-6:#C99A45;
    --lo-shadow-sm:0 1px 2px rgba(0,0,0,.35);
    --lo-shadow-md:0 4px 14px rgba(0,0,0,.45);
    --lo-shadow-lg:0 16px 40px rgba(0,0,0,.55);
}

/* ============================================================
   Typography — display face for headings, mono for figures
   ============================================================ */
.lactis-page-title,
.lactis-login-brand h1,
.lactis-chart-card__head h3,
.lactis-rail-card__head h3,
.lactis-shell .kt-card-title {
    font-family: var(--font-display);
    letter-spacing: -0.015em;
}

/* Financial / quantitative figures use tabular mono */
.lactis-kpi__val,
.lactis-delta,
.lactis-reg-table .r,
.lactis-dash-table .r,
.lactis-shell table.w-full td.text-end,
.lactis-pager-btn {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
}
.lactis-kpi__val { font-weight: 600; letter-spacing: -0.01em; }

/* ============================================================
   Signature sidebar — deep Spruce rail in BOTH themes
   (decoupled from --primary so dark mode keeps a deep rail)
   ============================================================ */
.lactis-shell .lactis-sidebar,
.lactis-shell #sidebar.lactis-sidebar,
.lactis-shell .kt-drawer.lactis-sidebar {
    background: linear-gradient(180deg, var(--lo-rail-top) 0%, var(--lo-rail-bottom) 100%);
}

/* Spruce-tinted sidebar text (replaces legacy blue tints) */
.lactis-nav-item { color: var(--lo-rail-text); }
.lactis-nav-group-h { color: var(--lo-rail-text-dim); }
.lactis-brand-sub,
.lactis-side-foot-txt span,
.lactis-sidebar-collapse,
.lactis-tenant-sidebar-trigger .lactis-tenant-type,
.lactis-tenant-sidebar-trigger .lactis-tenant-chevron { color: var(--lo-rail-text-dim); }
.lactis-side-foot-avatar,
.lactis-tenant-sidebar-trigger .lactis-tenant-logo { color: var(--spruce-700); }

/* Active item: butterfat accent marker (the signature touch) */
.lactis-nav-item.active::before { background: var(--gold-300); }
.lactis-nav-badge { background: var(--gold-300); color: var(--spruce-900); }

/* ============================================================
   Dark-mode contrast fixes for filled spruce controls
   (keep deep bg + light text so AA holds on dark surfaces)
   ============================================================ */
.dark .lactis-shell .kt-btn-primary,
.dark .lactis-shell .kt-btn.kt-btn-primary,
.dark .lactis-pager-btn--active {
    background: #15564A;
    border-color: #15564A;
    color: #EAF6F2;
}
.dark .lactis-shell .kt-btn-primary:hover,
.dark .lactis-shell .kt-btn.kt-btn-primary:hover {
    background: #0E4D40;
    border-color: #0E4D40;
}

/* Login CTA → brand spruce (was success green) */
.lactis-login-submit { background: var(--lo-primary); color: #EAF6F2; }
.lactis-login-submit:hover { filter: none; background: var(--spruce-700); }

/* Hero metric — the single most important number wears butterfat */
.lactis-kpi--gold .lactis-kpi__val { color: var(--gold-600); }
.dark .lactis-kpi--gold .lactis-kpi__val { color: var(--gold-300); }

/* ============================================================
   Collection Pipeline — the LactisOne signature component.
   Shows where today's milk & value sit in the chain:
   Collected -> Received -> Quality -> Reconciled -> Paid.
   Usage:
     <div class="lo-pipeline">
       <div class="lo-pstep lo-pstep--done"><span class="lo-pc">..</span>
            <span class="lo-pl"><b>Collected</b><span>12,480 L</span></span></div>
       <span class="lo-pconn lo-pconn--done"></span>
       <div class="lo-pstep lo-pstep--now"> ... </div>
       <span class="lo-pconn"></span>
       <div class="lo-pstep lo-pstep--todo"> ... </div>
     </div>
   ============================================================ */
.lo-pipeline {
    display: flex;
    align-items: center;
    gap: 0;
    background: var(--lactis-surface);
    border: 1px solid var(--lactis-line);
    border-radius: var(--lactis-r-md);
    box-shadow: var(--lactis-shadow-card);
    padding: 14px 18px;
    overflow-x: auto;
}
.lo-pstep { display: flex; align-items: center; gap: 9px; flex: none; }
.lo-pc {
    width: 30px; height: 30px; border-radius: 50%;
    display: grid; place-items: center;
    font-family: var(--font-mono); font-size: 13px; font-weight: 600;
}
.lo-pl { font-size: 11.5px; line-height: 1.2; color: var(--lactis-muted-2); }
.lo-pl b { display: block; font-family: var(--font-display); font-size: 13px; color: var(--lactis-ink); font-weight: 600; }
.lo-pconn { height: 2px; width: 34px; background: var(--lactis-line); margin: 0 6px; flex: none; }
.lo-pconn--done { background: var(--spruce-400); }
.lo-pstep--done .lo-pc { background: var(--spruce-600); color: #fff; }
.lo-pstep--now  .lo-pc { background: var(--gold-300); color: var(--spruce-900); box-shadow: 0 0 0 4px var(--gold-50); }
.lo-pstep--todo .lo-pc { background: var(--lactis-milk); color: var(--lactis-muted-2); border: 1.5px solid var(--lactis-line); }
.dark .lo-pstep--now .lo-pc { box-shadow: 0 0 0 4px rgba(221,180,86,.16); }

/* Enhance the existing flow widget to the same visual language */
.lactis-flow-step--done .lactis-flow-step__icon { background: var(--spruce-600); color: #fff; }
.lactis-flow-step--now  .lactis-flow-step__icon { background: var(--gold-300); color: var(--spruce-900); box-shadow: 0 0 0 4px var(--gold-50); }
.lactis-flow-step--todo .lactis-flow-step__icon { background: var(--lactis-milk); color: var(--lactis-muted-2); border: 1.5px solid var(--lactis-line); }

/* QC grade chips (extend the existing .lactis-chip set) */
.lactis-chip--grade-a { background: var(--lo-success-bg); color: var(--lo-success-fg); }
.lactis-chip--grade-b { background: var(--lo-warning-bg); color: var(--lo-warning-fg); }
.lactis-chip--grade-c { background: var(--lo-danger-bg);  color: var(--lo-danger-fg); }
.lactis-chip--priority { background: var(--gold-100); color: var(--gold-700); }

/* ============================================================
   Sidebar collapse toggle (custom LactisOne system)
   - Button stays visible when collapsed (no longer a label)
   - Icon rotates 180deg: points in (collapse) <-> out (expand)
   - Desktop-only control; hidden in the mobile drawer
   ============================================================ */
.lactis-sidebar-collapse i {
    transition: transform 0.25s ease;
}
html.lactis-sidebar-collapsed .lactis-sidebar-collapse i {
    transform: rotate(180deg);
}
@media (max-width: 1023.98px) {
    .lactis-sidebar-collapse {
        display: none !important;
    }
}

/* ============================================================
   Sidebar rail HARDENING (safe, bulletproof)
   Guarantees the rail can never render white — and therefore can
   never hide its light nav text/icons — regardless of KTUI drawer
   state, re-init/relocation, or stale CSS. Background + the rail's
   *default* text colour are forced; per-item state colours (active
   #fff, group header dim, gold badge) are intentionally NOT forced,
   so they keep working via their own (more specific) rules.
   ============================================================ */
:root {
    --lactis-sidebar-bg: linear-gradient(180deg, #0E4D40 0%, #082E27 100%);
    --lactis-sidebar-text: #CFE0DA;
}
.dark {
    --lactis-sidebar-bg: linear-gradient(180deg, #0A1614 0%, #06100E 100%);
    --lactis-sidebar-text: #C4D4CE;
}

/* 1 — Force the spruce rail in every state (solid #0B3D33 fallback).
   Anchored on the #sidebar ID (not the class) so the rail survives even
   if KTUI strips the lactis-sidebar class from the element. */
#sidebar,
aside#sidebar,
.lactis-shell #sidebar,
#sidebar.lactis-sidebar,
.kt-drawer.lactis-sidebar,
.lactis-sidebar {
    background: var(--lactis-sidebar-bg, #0B3D33) !important;
    color: var(--lactis-sidebar-text, #CFE0DA) !important;
}

/* 2 — Keep dividers subtle on the dark rail (scoped, not global *) */
#sidebar .lactis-sidebar-brand,
#sidebar .lactis-side-foot {
    border-color: rgba(255, 255, 255, 0.08);
}

/* 3 — Icon-visibility safeguard ONLY (expanded + collapsed states).
   Per-item COLOUR is deliberately left to the existing rules so active
   (#fff), group headers (dim) and gold badges keep their states. The
   forced container colour above is the legibility safety net; icons use
   currentColor so they always follow the (light) text colour. */
#sidebar .lactis-nav-item i {
    color: currentColor;
    display: inline-flex !important;
}

/* 4 — Anchor the fixed rail to full viewport height even if KTUI strips
   the top-0 / bottom-0 utility classes (they were shared with the drawer
   attribute). Keeps the scrollable nav area from collapsing. */
#sidebar {
    top: 0 !important;
    bottom: 0 !important;
}

/* ============================================================
   App shell width fix.
   .lactis-shell is a flex child of <body> with no width, so it
   shrink-wraps to its content's intrinsic width. List pages have
   full-width tables that fill the viewport (hiding this), but the
   dashboard's content (KPI grid + fixed 300px rail) is intrinsically
   narrower, so the shell shrank and left a gap on the right.
   Forcing the shell to fill the viewport makes every page consistent
   (.lactis-page stretches fluidly across the main content area).
   ============================================================ */
.lactis-shell {
    width: 100%;
}

/* ============================================================
   Sidebar collapse toggle — Metronic-style square icon button.
   Converts the old full-width "Collapse" text row into a small
   square icon-only button that sits on the sidebar/content divider
   at header height and slides with the rail when collapsed.
   Custom collapse logic (lactisOne.toggleSidebarCollapse) is kept;
   only the button's appearance/position changes. CSS-only -> live
   on refresh, no rebuild.
   position:fixed escapes the rail's overflow:hidden, so the button
   can straddle the divider; `left` tracks --sidebar-width so it
   follows the rail in both expanded (264px) and collapsed (76px).
   ============================================================ */
.lactis-sidebar-collapse {
    position: fixed;
    top: 16px;
    left: calc(var(--sidebar-width, 264px) - 16px);
    z-index: 40;
    width: 32px;
    height: 32px;
    padding: 0;
    gap: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #A3B0AB;
    border-radius: 9px;
    background: #ffffff;
    color: var(--spruce-600, #136150);
    box-shadow: 0 0 0 1px rgba(11, 61, 51, 0.05), 0 2px 7px rgba(11, 61, 51, 0.16);
    cursor: pointer;
    transition: left 0.18s ease, background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.lactis-sidebar-collapse:hover {
    background: var(--spruce-50, #ECF5F2);
    color: var(--spruce-700, #0E4D40);
    box-shadow: 0 2px 9px rgba(11, 61, 51, 0.16);
}
.lactis-sidebar-collapse span {
    display: none;   /* icon-only, like Metronic */
}
.lactis-sidebar-collapse i {
    font-size: 16px;
    line-height: 1;
}
/* Keep it square + icon-only in the collapsed state too */
html.lactis-sidebar-collapsed .lactis-sidebar-collapse {
    padding: 0;
    justify-content: center;
}
/* Dark mode: dark surface chip instead of white */
.dark .lactis-sidebar-collapse {
    background: var(--lactis-surface, #121C1A);
    border-color: var(--lactis-border, #283733);
    color: var(--lo-rail-text, #CFE0DA);
}
.dark .lactis-sidebar-collapse:hover {
    background: var(--spruce-800, #0B3D33);
    color: #ffffff;
}

/* ============================================================
   Sidebar collapse toggle — stacking fix.
   The toggle straddles the sidebar/content divider, so its right
   half sits over the sticky topbar (z-index:30). The button itself
   is z-index:40 but lives inside the <aside> (z-index:20), so that
   40 is trapped inside the aside's stacking context and the topbar
   painted on top of it — hiding the button's right half + border
   and stealing clicks. Raising the aside above the topbar on
   desktop lets the whole button (and its border) render on top.
   Desktop-only so the mobile drawer's KTDrawer-managed z-index is
   left alone.
   ============================================================ */
@media (min-width: 1024px) {
    #sidebar {
        z-index: 35;
    }
}

/* ============================================================
   Login password field
   ============================================================ */

.lactis-login-password {
    display: flex;
    align-items: center;
    width: 100%;
    border: 1px solid var(--lactis-line);
    border-radius: 9px;
    background: var(--lactis-surface);
    overflow: hidden;
}

    .lactis-login-password:focus-within {
        border-color: var(--spruce-600);
        box-shadow: 0 0 0 3px rgba(19, 97, 80, 0.12);
    }

    .lactis-login-password .lactis-login-input {
        flex: 1;
        border: 0 !important;
        outline: 0 !important;
        box-shadow: none !important;
        background: transparent;
        padding: 10px 12px;
        margin: 0;
    }

    .lactis-login-password button {
        width: 44px;
        height: 44px;
        flex-shrink: 0;
        border: 0;
        background: transparent;
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--lactis-muted);
        cursor: pointer;
    }

        .lactis-login-password button:hover {
            color: var(--spruce-600);
            background: var(--spruce-50);
        }