/* ============================================================
   Aydin Chips — design system
   Inspired by GreenChips (greenchips.com): forest-green primary,
   warm off-white body, dark charcoal footer, moderate radii,
   crisp neutral borders, soft shadows. Chip+leaf decorative
   motifs reinforce the chip-distribution + eco-aware identity.
   ============================================================ */

/* Icons are provided by Bootstrap Icons (web/bootstrap-icons/). Render them
   without the default 3s invisibility window. The .bi base class + per-icon
   ::before glyphs come from bootstrap-icons.min.css; we only nudge the
   font-display here so missing-font never blocks paint. */
@font-face {
    font-family: "bootstrap-icons";
    font-display: swap;
    src: url("../bootstrap-icons/fonts/bootstrap-icons.woff2") format("woff2");
}

:root {
    /* Brand palette — forest green primary */
    --ac-primary:        #16a34a;   /* green-600 */
    --ac-primary-700:    #15803d;   /* green-700 hover */
    --ac-primary-500:    #22c55e;
    --ac-primary-300:    #86efac;
    --ac-primary-100:    #dcfce7;
    --ac-primary-50:     #f0fdf4;
    --ac-accent:         #0ea5e9;   /* chip-industry sky-blue accent */
    --ac-accent-100:     #e0f2fe;
    --ac-leaf:           #4ade80;   /* fresh leaf tint for decorative motifs */

    --ac-bg:             #fafaf9;   /* warm off-white */
    --ac-bg-grad-1:      #f0fdf4;   /* very light green tint */
    --ac-bg-grad-2:      #fafaf9;

    --ac-card-bg:        #ffffff;
    --ac-card-border:    #e7e5e4;   /* warm neutral border */
    --ac-card-shadow:    0 1px 2px rgba(16,16,16,.04), 0 4px 16px rgba(22, 163, 74, .05);
    --ac-card-shadow-hi: 0 2px 6px rgba(16,16,16,.06), 0 12px 32px rgba(22, 163, 74, .08);

    --ac-text:           #18181b;   /* zinc-900 */
    --ac-text-strong:    #09090b;
    --ac-muted:          #71717a;   /* zinc-500 */
    --ac-border:         #e4e4e7;   /* zinc-200 */
    --ac-input-border:   #d4d4d8;   /* zinc-300 */

    --ac-footer-bg:      #18181b;   /* charcoal footer */
    --ac-footer-fg:      #a1a1aa;
    --ac-footer-link:    #e4e4e7;
}

/* ---- Re-tint Tabler primary ---- */
[data-bs-theme="light"],
:root {
    --tblr-primary: var(--ac-primary);
    --tblr-primary-rgb: 22, 163, 74;
    --tblr-primary-darken: var(--ac-primary-700);
    --tblr-primary-lt: var(--ac-primary-100);
    --tblr-primary-fg: #ffffff;
    --tblr-link-color: var(--ac-primary-700);
}

/* ---- Body / app shell ---- */
body {
    background: var(--ac-bg);
    color: var(--ac-text);
    font-feature-settings: 'cv11','ss01','ss03';
    -webkit-font-smoothing: antialiased;
}

/* Subtle circuit-pattern body backdrop (chip industry texture, green-tinted) */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: -1;
    opacity: .28;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 80 80'><g fill='none' stroke='%2386efac' stroke-width='0.5' opacity='0.6'><circle cx='10' cy='10' r='1.5'/><circle cx='70' cy='70' r='1.5'/><circle cx='70' cy='10' r='1.5'/><circle cx='10' cy='70' r='1.5'/><path d='M10 10 L30 10 L30 30 M70 10 L50 10 L50 30 M10 70 L30 70 L30 50 M70 70 L50 70 L50 50'/></g></svg>");
    background-size: 80px 80px;
}

/* ============================================================
   APP CONTAINER — wide layout, small side padding only
   ============================================================ */
.app-container {
    padding-left: 1rem;
    padding-right: 1rem;
    max-width: none;
}
@media (min-width: 1200px) {
    .app-container { padding-left: 1.25rem; padding-right: 1.25rem; }
}

/* ============================================================
   PAGE HEADER (gradient + dot pattern + avatar)
   ============================================================ */
.page-header {
    position: relative;
    overflow: hidden;
    background: linear-gradient(135deg, var(--ac-bg-grad-1) 0%, #ffffff 60%, #ffffff 100%);
    border-radius: 12px;
    border: 1px solid var(--ac-card-border);
    margin: 1rem 0 1.25rem;
    padding: 1.25rem 1.5rem;
}
.page-header::after {
    content: '';
    position: absolute;
    top: 0; right: 0; bottom: 0; width: 55%;
    background-image: radial-gradient(circle, rgba(74, 222, 128, .50) 1.1px, transparent 1.5px);
    background-size: 20px 20px;
    -webkit-mask-image: linear-gradient(to left, black 10%, transparent 95%);
            mask-image: linear-gradient(to left, black 10%, transparent 95%);
    pointer-events: none;
}
/* Inner container must sit above the ::after dot-pattern so title + actions
   are not painted over. Match BOTH old container-xl and new container-fluid. */
.page-header > .container-xl,
.page-header > .container-fluid,
.page-header > .container { position: relative; z-index: 2; }

.page-pretitle {
    color: var(--ac-primary-700);
    font-weight: 600;
    font-size: .72rem;
    letter-spacing: .08em;
    text-transform: uppercase;
}
.page-title {
    font-weight: 700;
    font-size: 1.6rem;
    color: var(--ac-text-strong);
    margin: .15rem 0 .35rem;
    line-height: 1.15;
}
.page-title .badge { font-size: .72rem; font-weight: 600; }

/* avatar block on the left of page-header */
.ph-avatar {
    width: 60px; height: 60px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--ac-primary-100), #fff);
    border: 1px solid var(--ac-card-border);
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--ac-primary-700);
    font-size: 1.8rem;
    box-shadow: inset 0 0 0 3px rgba(255,255,255,.55), 0 2px 8px rgba(22,163,74,.10);
    flex-shrink: 0;
}

/* Audit-meta strip */
.audit-meta-strip {
    color: var(--ac-muted);
    font-size: .8125rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .35rem .6rem;
    margin-top: .25rem;
}
.audit-meta-strip i { color: var(--ac-primary-300); margin-right: .25rem; }
.audit-meta-strip .sep { color: var(--ac-primary-300); }

/* "More actions" button area */
.ph-actions .btn { border-radius: 10px; }
.ph-actions .more-actions {
    background: #fff;
    border: 1px solid var(--ac-card-border);
    box-shadow: 0 1px 2px rgba(0,0,0,.04);
    color: var(--ac-text);
    font-weight: 500;
}
.ph-actions .more-actions:hover {
    background: var(--ac-primary-50);
    color: var(--ac-primary-700);
    border-color: var(--ac-primary-300);
}

/* ============================================================
   NAVBAR (top menu)
   ============================================================ */
.navbar.sticky-top { backdrop-filter: saturate(140%) blur(10px); background: rgba(255,255,255,.85) !important; }
.navbar .navbar-brand .avatar { background: linear-gradient(135deg, var(--ac-primary-100), var(--ac-accent-100)); color: var(--ac-primary-700); font-weight: 700; }
.navbar.navbar-expand-md .navbar-nav .nav-link { padding: .7rem 1rem; font-weight: 500; color: var(--ac-text); }
.navbar .nav-link:hover { color: var(--ac-primary); }
.navbar .nav-link.active { color: var(--ac-primary) !important; }
.dropdown-menu { border: 1px solid var(--ac-card-border); border-radius: 12px; box-shadow: var(--ac-card-shadow); padding: .35rem; }
.dropdown-header { color: var(--ac-primary-700); font-weight: 700; font-size: .7rem; letter-spacing: .06em; text-transform: uppercase; padding: .5rem .75rem .25rem; }
.dropdown-item { border-radius: 8px; padding: .5rem .75rem; }
.dropdown-item:hover, .dropdown-item:focus { background: var(--ac-primary-50); color: var(--ac-primary-700); }
.dropdown-item i { color: var(--ac-primary); }

/* ============================================================
   CARDS
   ============================================================ */
.card {
    background: var(--ac-card-bg);
    border: 1px solid var(--ac-card-border);
    border-radius: 12px;
    box-shadow: var(--ac-card-shadow);
    overflow: hidden;
}
.card-header {
    background: transparent;
    border-bottom: 1px solid var(--ac-border);
    padding: 1rem 1.25rem;
}
.card-body { padding: 1.25rem; }
.card-footer { background: transparent; border-top: 1px solid var(--ac-border); padding: .85rem 1.25rem; }

.card-section {
    position: relative;
    padding: 1.5rem 1.5rem 1.25rem;
    border-bottom: 1px solid var(--ac-border);
}
.card-section:last-child { border-bottom: 0; }
.card-section-title { font-weight: 700; color: var(--ac-text-strong); font-size: 1.05rem; margin-bottom: .1rem; }
.card-section-sub   { color: var(--ac-muted); font-size: .85rem; margin-bottom: 1rem; }

/* Decorative chip illustration in section header (right-aligned, faint) */
.card-section .section-deco {
    position: absolute;
    right: 1rem; top: 1rem;
    width: 110px; height: 80px;
    opacity: .55;
    pointer-events: none;
    background-repeat: no-repeat;
    background-size: contain;
    background-position: right top;
}

/* ============================================================
   TABS (entity update screens) — segmented pills inside a card
   ============================================================ */
.entity-tabs {
    margin-top: 1rem;
}
.entity-tabs > .nav-tabs {
    background: #fff;
    border: 1px solid var(--ac-card-border);
    border-radius: 14px;
    padding: .35rem;
    box-shadow: var(--ac-card-shadow);
    margin-bottom: 1rem;
    gap: .15rem;
}
.entity-tabs > .nav-tabs > .nav-item > .nav-link {
    border: 0;
    border-radius: 10px;
    padding: .65rem 1rem;
    color: var(--ac-muted);
    font-weight: 500;
    transition: background .15s ease, color .15s ease, box-shadow .15s ease;
    position: relative;
}
.entity-tabs > .nav-tabs > .nav-item > .nav-link i { color: var(--ac-primary-300); transition: color .15s ease; }
.entity-tabs > .nav-tabs > .nav-item > .nav-link:hover {
    background: var(--ac-primary-50);
    color: var(--ac-primary-700);
}
.entity-tabs > .nav-tabs > .nav-item > .nav-link:hover i { color: var(--ac-primary); }
.entity-tabs > .nav-tabs > .nav-item > .nav-link.active {
    color: var(--ac-primary-700) !important;
    background: var(--ac-primary-50);
    box-shadow: inset 0 -3px 0 var(--ac-primary);
}
.entity-tabs > .nav-tabs > .nav-item > .nav-link.active i { color: var(--ac-primary); }
.entity-tabs > .tab-content {
    background: transparent;
    border: 0;
    padding: 0;
}

/* Sub-pills used on Master Data + Company role filter row */
.nav-pills .nav-link {
    border-radius: 999px;
    padding: .4rem .85rem;
    color: var(--ac-muted);
    font-weight: 500;
}
.nav-pills .nav-link.active {
    background: var(--ac-primary);
    color: #fff;
    box-shadow: 0 2px 8px rgba(22,163,74,.28);
}
.nav-pills .nav-link:hover:not(.active) { background: var(--ac-primary-50); color: var(--ac-primary-700); }

/* ============================================================
   FORMS — inputs / labels / focus / errors
   ============================================================ */
.form-label {
    color: var(--ac-text-strong);
    font-size: .8125rem;
    font-weight: 600;
    margin-bottom: .3rem;
    letter-spacing: .005em;
}
.form-label.required::after { content: ' *'; color: var(--ac-primary); }
.form-hint { color: var(--ac-muted); font-size: .75rem; margin-top: .25rem; }

.form-control,
.form-select {
    border: 1.5px solid var(--ac-input-border);
    border-radius: 8px;
    padding: .55rem .85rem;
    background: #fff;
    color: var(--ac-text);
    transition: border-color .15s, box-shadow .15s, background .15s;
    box-shadow: none;
}
.form-control::placeholder { color: #a1a1aa; }
.form-control:focus,
.form-select:focus {
    border-color: var(--ac-primary);
    box-shadow: 0 0 0 4px rgba(22,163,74,.14);
    background: #fff;
}
.form-control.is-invalid,
.form-select.is-invalid {
    border-color: #e11d48;
    box-shadow: 0 0 0 4px rgba(225,29,72,.10);
}
.form-control-sm, .form-select-sm { border-radius: 6px; padding: .35rem .6rem; }

textarea.form-control { line-height: 1.45; }

/* Input with leading icon */
.input-icon .input-icon-addon { color: var(--ac-primary-300); }
.input-icon:focus-within .input-icon-addon { color: var(--ac-primary); }

/* Form-switch (toggle) */
.form-switch .form-check-input {
    width: 2.5em; height: 1.35em;
    background-color: var(--ac-input-border);
    border-color: var(--ac-input-border);
}
.form-check-input:checked { background-color: var(--ac-primary); border-color: var(--ac-primary); }
.form-check-input:focus   { box-shadow: 0 0 0 .25rem rgba(22,163,74,.22); }

/* TomSelect (searchable dropdown) — match input style */
.ts-wrapper .ts-control {
    border: 1.5px solid var(--ac-input-border) !important;
    border-radius: 8px !important;
    padding: .45rem .8rem !important;
    background: #fff !important;
    box-shadow: none !important;
    min-height: 42px;
}
.ts-wrapper.focus .ts-control {
    border-color: var(--ac-primary) !important;
    box-shadow: 0 0 0 4px rgba(22,163,74,.14) !important;
}

/* Small-size Tom Select — match form-control-sm height (universal) */
.ts-wrapper.form-control-sm .ts-control,
.ts-wrapper.form-select-sm  .ts-control {
    min-height: 31px !important;
    padding: .2rem .55rem !important;
    font-size: .8125rem !important;
    border-radius: 6px !important;
}
.ts-wrapper.form-control-sm,
.ts-wrapper.form-select-sm { font-size: .8125rem; }

/* Native file inputs — match other small inputs height (universal) */
.form-control[type="file"].form-control-sm { line-height: 1.4; padding: .2rem .55rem; }
.form-control[type="file"] { padding: .35rem .6rem; }
.form-control[type="file"]::file-selector-button {
    margin-right: .75rem; padding: .35rem .85rem;
    background: var(--ac-primary-50); color: var(--ac-primary-700);
    border: 0; border-right: 1px solid var(--ac-card-border);
    border-radius: 6px 0 0 6px;
    cursor: pointer;
}
.form-control[type="file"].form-control-sm::file-selector-button {
    padding: .15rem .65rem; font-size: .8125rem;
}
.ts-dropdown {
    background: #ffffff !important;            /* solid, never see-through */
    border: 1px solid var(--ac-card-border) !important;
    border-radius: 8px !important;
    box-shadow: 0 8px 24px rgba(15,23,42,.12), 0 2px 6px rgba(15,23,42,.06) !important;
    margin-top: 4px !important;
    z-index: 99999 !important;                 /* always above page chrome */
}
.ts-dropdown .ts-dropdown-content { background: #ffffff !important; }
.ts-dropdown .option,
.ts-dropdown .optgroup-header { background: #ffffff !important; }
.modal-open .ts-dropdown   { z-index: 1080 !important; }  /* modal backdrop (1055) sits above */
.modal-dialog .ts-dropdown { z-index: 1080 !important; }  /* when modal hosts the picker */
.ts-dropdown .active { background: var(--ac-primary-50) !important; color: var(--ac-primary-700) !important; }
.ts-wrapper.single .ts-control:after { border-color: var(--ac-primary) transparent transparent transparent !important; }

/* ---- Autocomplete text-input typeahead ---- */
.ac-wrap { position: relative; }
.ac-menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #ffffff !important;          /* always opaque */
    border: 1px solid var(--ac-card-border);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(15,23,42,.12), 0 2px 6px rgba(15,23,42,.06);
    z-index: 99998;                          /* just below ts-dropdown but above page chrome */
    max-height: 280px;
    overflow-y: auto;
    margin-top: 4px;
    padding: .25rem;
    display: none;
}
.ac-item {
    display: block;
    padding: .45rem .65rem;
    border-radius: 6px;
    color: var(--ac-text);
    cursor: pointer;
    text-decoration: none;
    font-size: .875rem;
    line-height: 1.3;
}
.ac-item:hover, .ac-item.active {
    background: var(--ac-primary-50);
    color: var(--ac-primary-700);
}
.ac-item .ac-sub { font-size: .75rem; color: var(--ac-muted); display: block; margin-top: .1rem; }
.ac-loading { display: flex; align-items: center; justify-content: center; padding: 1rem; color: var(--ac-muted); font-size: .85rem; }
.ac-empty { padding: .75rem; color: var(--ac-muted); font-size: .85rem; text-align: center; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    border-radius: 8px;
    font-weight: 600;
    padding: .5rem 1rem;
    transition: transform .08s ease, box-shadow .15s ease, background .15s ease, color .15s ease;
}
.btn-sm { border-radius: 6px; padding: .35rem .65rem; font-weight: 500; }
.btn:active { transform: translateY(1px); }

.btn-primary {
    background: linear-gradient(135deg, var(--ac-primary-500) 0%, var(--ac-primary) 100%);
    border: 0;
    color: #fff;
    box-shadow: 0 2px 8px rgba(22,163,74,.28), inset 0 1px 0 rgba(255,255,255,.16);
}
.btn-primary:hover {
    background: linear-gradient(135deg, var(--ac-primary) 0%, var(--ac-primary-700) 100%);
    box-shadow: 0 4px 14px rgba(22,163,74,.38);
    color: #fff;
}
.btn-primary:disabled { background: var(--ac-primary-300); color: #fff; box-shadow: none; }

.btn-outline-primary {
    color: var(--ac-primary-700);
    border: 1.5px solid var(--ac-primary-300);
    background: #fff;
}
.btn-outline-primary:hover { background: var(--ac-primary-50); color: var(--ac-primary-700); border-color: var(--ac-primary); }

.btn-outline-secondary {
    color: var(--ac-text);
    border: 1.5px solid var(--ac-border);
    background: #fff;
}
.btn-outline-secondary:hover { background: var(--ac-primary-50); color: var(--ac-primary-700); border-color: var(--ac-primary-300); }

.btn-link { color: var(--ac-primary-700); text-decoration: none; font-weight: 500; }
.btn-link:hover { color: var(--ac-primary); text-decoration: none; }

.btn-danger,
.btn-outline-danger { border-radius: 10px; }
.btn-outline-danger {
    border: 1.5px solid #fecaca;
    background: #fff;
    color: #b91c1c;
}
.btn-outline-danger:hover { background: #fef2f2; color: #991b1b; border-color: #fca5a5; }

/* Floating action bar at bottom of forms (sticky-feel) */
.form-action-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #fff;
    border-top: 1px solid var(--ac-border);
    padding: .9rem 1.25rem;
    border-radius: 0 0 16px 16px;
    margin: 1.25rem -1.25rem -1.25rem;
}

/* ============================================================
   BADGES — soft pill style
   ============================================================ */
.badge {
    font-weight: 600;
    padding: .35em .65em;
    border-radius: 999px;
    letter-spacing: .01em;
}
.bg-blue-lt   { background: #dbeafe !important; color: #1d4ed8 !important; }
.bg-green-lt  { background: #d1fae5 !important; color: #047857 !important; }
.bg-red-lt    { background: #fee2e2 !important; color: #b91c1c !important; }
.bg-yellow-lt { background: #fef3c7 !important; color: #b45309 !important; }
.bg-purple-lt { background: var(--ac-primary-100) !important; color: var(--ac-primary-700) !important; }
.bg-cyan-lt   { background: var(--ac-accent-100) !important; color: #0e7490 !important; }
.bg-secondary-lt { background: #f1f5f9 !important; color: #475569 !important; }
.bg-orange-lt { background: #ffedd5 !important; color: #c2410c !important; }
.bg-primary-lt { background: var(--ac-primary-100) !important; color: var(--ac-primary-700) !important; }

/* Bootstrap's built-in .badge.bg-danger inherits body text colour
   (dark grey) which is unreadable on the solid red background. Every
   place we use it — the CANCELLED marker on commission payments,
   advance adjustments, generic error chips — needs white text. Force
   it globally so nobody has to remember `text-white` on every usage. */
.badge.bg-danger,
.bg-danger.badge {
    color: #ffffff !important;
}

/* ============================================================
   GRIDVIEW / TABLES
   ============================================================ */
.grid-view table.table {
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    border-collapse: separate;
    border-spacing: 0;
}
.grid-view table.table thead th {
    background: var(--ac-primary-50);
    color: var(--ac-primary-700);
    border-bottom: 1px solid var(--ac-border);
    font-weight: 700;
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: .75rem 1rem;
    white-space: nowrap;
}
.grid-view table.table tbody tr { transition: background .12s ease; }
.grid-view table.table tbody tr:hover { background: var(--ac-primary-50); }
.grid-view table.table tbody td { padding: .8rem 1rem; vertical-align: middle; border-top: 1px solid var(--ac-border); }
.grid-view .summary { color: var(--ac-muted); font-size: .8125rem; padding-top: .5rem; }
.pagination .page-link {
    border-radius: 8px !important;
    margin: 0 2px;
    color: var(--ac-primary-700);
    border-color: var(--ac-card-border);
}
.pagination .page-item.active .page-link { background: var(--ac-primary); border-color: var(--ac-primary); color: #fff; }

/* ============================================================
   BREADCRUMB
   ============================================================ */
.breadcrumb { background: transparent; padding: 0; font-size: .82rem; }
.breadcrumb-item a { color: var(--ac-primary-700); text-decoration: none; font-weight: 500; }
.breadcrumb-item.active { color: var(--ac-muted); }

/* ============================================================
   MODAL
   ============================================================ */
.modal-content { border: 0; border-radius: 14px; box-shadow: 0 24px 60px rgba(15,23,42,.18); }
.modal-header { border-bottom: 1px solid var(--ac-border); padding: 1rem 1.25rem; }
.modal-title { font-weight: 700; color: var(--ac-text-strong); }
.modal-body { padding: 1.25rem; }
.modal-blur .modal-backdrop { backdrop-filter: blur(4px); background: rgba(46,32,89,.45); }

/* ============================================================
   EMPTY-STATE
   ============================================================ */
.empty { padding: 3rem 1rem; text-align: center; }
.empty-icon { width: 64px; height: 64px; margin: 0 auto 1rem; border-radius: 18px;
    background: var(--ac-primary-50); color: var(--ac-primary);
    display: flex; align-items: center; justify-content: center; font-size: 2rem; }
.empty-title { font-weight: 700; color: var(--ac-text-strong); margin-bottom: .25rem; }
.empty-subtitle { color: var(--ac-muted); margin-bottom: 1rem; }

/* ============================================================
   AUTH PAGE
   ============================================================ */
.auth-page { min-height: 100vh; display: flex; align-items: center;
    background: linear-gradient(135deg, var(--ac-bg-grad-1) 0%, #ffffff 60%, #ffffff 100%); }
.auth-page::before {
    content: '';
    position: absolute; inset: 0; pointer-events: none;
    background-image: radial-gradient(circle, rgba(74,222,128,.45) 1.2px, transparent 1.5px);
    background-size: 28px 28px;
    -webkit-mask-image: radial-gradient(circle at 70% 30%, black 0%, transparent 70%);
            mask-image: radial-gradient(circle at 70% 30%, black 0%, transparent 70%);
}
.auth-page .card { box-shadow: 0 24px 60px rgba(22,163,74,.14); }

/* ============================================================
   HTMX feedback
   ============================================================ */
.htmx-indicator { opacity: 0; transition: opacity 200ms ease-in; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { opacity: 1; }

/* Reusable busy-state for any button that fires an HTMX request.
   Markup pattern:
     <button class="btn btn-primary" hx-...>
       <span class="btn-loading-idle"><i class="bi bi-search me-1"></i>Search</span>
       <span class="btn-loading-spinner">
         <span class="spinner-border spinner-border-sm me-1" role="status"></span>Searching…
       </span>
     </button>
   When HTMX adds .htmx-request to the button (its own request) OR to an
   ancestor (e.g. a wrapping form), we swap the two states and lock the
   button so it can't be double-clicked. */
.btn-loading-spinner { display: none; align-items: center; }
.btn.htmx-request,
.htmx-request .btn-loading-spinner-host { /* host = ancestor that gets .htmx-request */
    cursor: progress;
    pointer-events: none;
}
.btn.htmx-request .btn-loading-idle,
.htmx-request .btn-loading-spinner-host .btn-loading-idle { display: none !important; }
.btn.htmx-request .btn-loading-spinner,
.htmx-request .btn-loading-spinner-host .btn-loading-spinner { display: inline-flex !important; }

/* Toastr position + style */
#toast-container > div { opacity: .98; box-shadow: 0 12px 32px rgba(15,23,42,.18); border-radius: 10px; }
.toast { border-radius: 10px !important; }

/* ============================================================
   UTILITY — alert (info / success / danger) shape
   ============================================================ */
.alert { border-radius: 12px; border: 0; padding: .85rem 1rem; }
.alert-info    { background: var(--ac-primary-50); color: var(--ac-primary-700); }
.alert-success { background: #d1fae5; color: #065f46; }
.alert-warning { background: #fef3c7; color: #92400e; }
.alert-danger  { background: #fee2e2; color: #991b1b; }
.alert i { margin-right: .35rem; }

/* ============================================================
   AVATAR (used in user menu and other places)
   ============================================================ */
.avatar { border-radius: 8px; font-weight: 600; }
.avatar-sm  { width: 32px;  height: 32px;  font-size: .75rem; }
.avatar-md  { width: 48px;  height: 48px;  font-size: 1rem; }
.avatar-xl  { width: 80px;  height: 80px;  font-size: 1.5rem; }

/* ============================================================
   DOCUMENT TOTALS table + side panel (reusable for Req / Quote / PO / SO / INV)
   ============================================================ */
@media (min-width: 992px) {
    .totals-side {
        position: sticky;
        top: 80px;        /* clears the sticky navbar */
        align-self: flex-start;
    }
}
.totals-table { font-size: .9rem; }
.totals-table td { padding: .35rem .5rem; border: 0; }
.totals-table .border-top td { border-top: 1px solid var(--ac-border) !important; padding-top: .55rem; }
.totals-table .grand-total-row td {
    background: var(--ac-primary-50);
    border-top: 2px solid var(--ac-primary) !important;
    padding-top: .65rem;
    padding-bottom: .65rem;
    color: var(--ac-primary-700);
    font-size: .92rem;
}
.totals-table .grand-total-value {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--ac-primary-700);
    letter-spacing: -.01em;
}

/* ============================================================
   FOOTER — dark charcoal, GreenChips style
   ============================================================ */
.footer.footer-transparent {
    background: var(--ac-footer-bg) !important;
    color: var(--ac-footer-fg);
    border-top: 0;
    margin-top: 2rem;
    padding: 1.25rem 0;
    border-radius: 12px 12px 0 0;
}
.footer.footer-transparent a { color: var(--ac-footer-link); text-decoration: none; }
.footer.footer-transparent a:hover { color: var(--ac-primary-300); }
.footer.footer-transparent .list-inline-dots li { color: var(--ac-footer-fg); }
.footer.footer-transparent .list-inline-dots li::after { color: var(--ac-footer-fg); opacity: .4; }

/* ============================================================
   DASHBOARD STAT TILES (GreenChips-style big numbers)
   ============================================================ */
.stat-card {
    background: #fff;
    border: 1px solid var(--ac-card-border);
    border-radius: 12px;
    padding: 1.25rem 1.25rem 1rem;
    box-shadow: var(--ac-card-shadow);
    position: relative;
    overflow: hidden;
}
.stat-card .stat-icon {
    width: 40px; height: 40px;
    border-radius: 10px;
    background: var(--ac-primary-100);
    color: var(--ac-primary-700);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 1.2rem;
    margin-bottom: .85rem;
}
.stat-card .stat-label {
    color: var(--ac-muted);
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    font-weight: 600;
    margin: 0;
}
.stat-card .stat-value {
    color: var(--ac-text-strong);
    font-size: 2rem;
    font-weight: 800;
    line-height: 1.1;
    margin: .25rem 0 .25rem;
    letter-spacing: -.01em;
}
.stat-card .stat-sub { color: var(--ac-muted); font-size: .8rem; }
.stat-card.stat-eco .stat-icon { background: var(--ac-primary-100); color: var(--ac-primary-700); }
.stat-card.stat-blue .stat-icon { background: var(--ac-accent-100); color: #0369a1; }
.stat-card.stat-warn .stat-icon { background: #fef3c7; color: #92400e; }
.stat-card.stat-red  .stat-icon { background: #fee2e2; color: #991b1b; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
    .page-header { padding: 1rem; border-radius: 14px; }
    .page-header::after { width: 35%; }
    .page-title { font-size: 1.3rem; }
    .ph-avatar { width: 52px; height: 52px; font-size: 1.5rem; border-radius: 12px; }
    .entity-tabs > .nav-tabs { padding: .25rem; gap: 0; }
    .entity-tabs > .nav-tabs > .nav-item > .nav-link { padding: .5rem .65rem; font-size: .85rem; }
}

/* ============================================================
   NUMBER INPUTS — keyboard only, no mouse scroll, no spinner arrows
   ------------------------------------------------------------
   Per spec: number-typed inputs (qty, price, etc.) must NOT be
   nudgeable via the spinner buttons or the mouse wheel. Users
   type values; up/down arrows on the keyboard still work.
   The wheel-block lives in web/js/site.js.
   ============================================================ */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type="number"] {
    -moz-appearance: textfield;   /* Firefox */
    appearance: textfield;
}

/* ============================================================
 * Hide every delete UI surface across the system.
 *
 * Business policy is "no delete option at all" — neither hard
 * nor soft. The real enforcement is server-side in
 * BaseController::beforeAction() (blocks every /delete URL
 * with 403). These CSS rules just remove the buttons from
 * the page so users don't see something they can't use.
 *
 * Cancel / uncancel / void / archive flows are NOT delete and
 * are deliberately not matched here.
 * ============================================================ */

/* Forms whose action posts to a URL containing /delete (Yii's
 * Url::to(['delete', ...]) renders differently depending on the
 * pretty-url mode — catch both shapes). */
form[action*="/delete"],
form[action*="%2Fdelete"],
form[action*="r=delete"],
form[action$="/delete"] {
    display: none !important;
}

/* Any "data-confirm" message containing "delete" (case-insensitive
 * via the two common casings). */
[data-confirm*="elete"],
[data-confirm*="ELETE"] {
    display: none !important;
}

/* Direct links to /delete endpoints. */
a[href*="/delete"],
a[href*="%2Fdelete"],
a[href*="r=delete"] {
    display: none !important;
}

/* Trash icons inside any button — hide the icon (then most buttons
 * collapse to empty width and become invisible). Some buttons are
 * trash-icon-only so we can also drop the whole button via :has(). */
.btn .bi-trash,
.btn .bi-trash-fill,
.btn .bi-trash3,
.btn .bi-trash3-fill {
    display: none !important;
}
.btn:has(> .bi-trash):not(:has(> :not(.bi-trash):not(.visually-hidden))),
.btn:has(> .bi-trash-fill):not(:has(> :not(.bi-trash-fill):not(.visually-hidden))) {
    display: none !important;
}

/* ============================================================
   SIDEBAR NAVIGATION — expandable menu items with sub-menus
   ============================================================ */
.sidebar {
    background: #fff;
    border-right: 1px solid var(--ac-border);
    padding: 1rem 0;
    position: relative;
    flex-basis: 240px;
    min-width: 240px;
    max-width: 240px;
    height: calc(100vh - 60px);
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
}

.sidebar-nav .nav {
    padding: 0 0.5rem;
    gap: 0.25rem;
}

.sidebar-nav .nav-item {
    position: relative;
}

.sidebar-nav .nav-link,
.sidebar-nav .nav-toggle {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.875rem;
    border-radius: 8px;
    color: var(--ac-text);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.15s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border: none;
    background: transparent;
    cursor: pointer;
    width: 100%;
    text-align: left;
}

.sidebar-nav .nav-link:hover,
.sidebar-nav .nav-toggle:hover {
    background: var(--ac-primary-50);
    color: var(--ac-primary-700);
}

.sidebar-nav .nav-link.active,
.sidebar-nav .nav-toggle.active {
    background: var(--ac-primary-100);
    color: var(--ac-primary-700);
    font-weight: 600;
    box-shadow: inset -3px 0 0 var(--ac-primary);
}

/* Navigation icons */
.sidebar-nav .nav-icon {
    font-size: 1.1rem;
    color: inherit;
    flex-shrink: 0;
    width: 20px;
    text-align: center;
}

.sidebar-nav .nav-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Chevron icon for toggle buttons */
.sidebar-nav .nav-chevron {
    font-size: 0.75rem;
    margin-left: auto;
    flex-shrink: 0;
    transition: transform 0.2s ease;
    color: var(--ac-muted);
}

.sidebar-nav .nav-toggle[aria-expanded="true"] .nav-chevron {
    transform: rotate(-180deg);
    color: var(--ac-primary);
}

/* Sub-menu styling */
.sidebar-nav .nav-submenu {
    list-style: none;
    padding: 0.35rem 0;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.sidebar-nav .nav-submenu.show {
    max-height: 2000px;
    opacity: 1;
    padding: 0.5rem 0 0.25rem 0;
}

.sidebar-nav .nav-submenu .nav-item {
    margin: 0;
}

.sidebar-nav .nav-submenu .nav-link {
    padding-left: 2.25rem;
    font-size: 0.85rem;
    color: var(--ac-muted);
    font-weight: 400;
}

.sidebar-nav .nav-submenu .nav-link:hover {
    background: var(--ac-primary-50);
    color: var(--ac-primary-700);
}

.sidebar-nav .nav-submenu .nav-link.active {
    background: var(--ac-primary-50);
    color: var(--ac-primary-700);
    box-shadow: inset -3px 0 0 var(--ac-primary);
}

/* Sub-menu bullet indicator */
.sidebar-nav .nav-bullet {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--ac-primary-300);
    margin-right: 0.5rem;
    flex-shrink: 0;
}

.sidebar-nav .nav-submenu .nav-link.active .nav-bullet {
    background: var(--ac-primary);
    box-shadow: 0 0 0 2px var(--ac-primary-100);
}

/* Scrollbar styling for sidebar */
.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--ac-border);
    border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--ac-primary-300);
}

/* ============================================================
   PAGE LAYOUT WITH SIDEBAR
   ============================================================ */
.page {
    display: flex;
}

.page-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 60px);
}

/* Responsive: hide sidebar on small screens */
@media (max-width: 767px) {
    .sidebar {
        display: none !important;
    }

    .page-wrapper {
        min-height: calc(100vh - 56px);
    }
}

/* Tablet size: narrow sidebar */
@media (min-width: 768px) and (max-width: 1024px) {
    .sidebar {
        flex-basis: 200px;
        min-width: 200px;
        max-width: 200px;
    }

    .sidebar-nav .nav-link,
    .sidebar-nav .nav-toggle {
        font-size: 0.8rem;
        padding: 0.55rem 0.75rem;
        gap: 0.6rem;
    }

    .sidebar-nav .nav-submenu .nav-link {
        padding-left: 1.9rem;
    }
}

/* Desktop size: full sidebar */
@media (min-width: 1025px) {
    .sidebar {
        flex-basis: 240px;
        min-width: 240px;
        max-width: 240px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .sidebar {
        background: #1a1a1a;
        border-right-color: #333;
    }

    .sidebar-nav .nav-link,
    .sidebar-nav .nav-toggle {
        color: #e0e0e0;
    }

    .sidebar-nav .nav-link:hover,
    .sidebar-nav .nav-toggle:hover {
        background: rgba(22, 163, 74, 0.1);
        color: var(--ac-primary);
    }

    .sidebar::-webkit-scrollbar-track {
        background: transparent;
    }

    .sidebar::-webkit-scrollbar-thumb {
        background: #333;
    }

    .sidebar::-webkit-scrollbar-thumb:hover {
        background: #444;
    }
}
