/* Variables */
:root {
    --bg: #f2f4f7;
    --panel: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --line: #c2c4c7;
    --brand: #0f766e;
    --danger: #b91c1c;
    --warning: #b45309;
    --ok: #166534;
    --table-head-bg: #c8d4ec;
    --table-head-text: #19386f;
    --table-row-hover: #f6f9ff;
    --table-head-radius: 12px;
    --table-float-line: #cfd8eb;
    --table-float-shadow: 0 4px 14px rgba(35, 58, 115, 0.08);
    --table-row-border: #dfe6f5;
    /* Dashboard primary CTA + bar/line charts (navy, matches --table-head-text) */
    --dashboard-accent: #19386f;
    --dashboard-accent-hover: #142a52;
    --dashboard-chart-area-start: rgba(25, 56, 111, 0.18);
    --dashboard-chart-area-end: rgba(25, 56, 111, 0);
    --layout-sidebar-expanded-width: var(--ims-sidebar-expanded-width, 250px);
    --layout-sidebar-collapsed-width: var(--ims-sidebar-collapsed-width, 76px);
    --layout-sidebar-motion: var(--ims-sidebar-motion, 0.4s ease);
    /* Global slim scrollbars */
    --scrollbar-size: 6px;
    --scrollbar-track: #eef2f7;
    --scrollbar-thumb: #9ca3af;
    --scrollbar-thumb-hover: #6b7280;
}

/* Chromium, Safari, Edge, Opera — any element with overflow scroll */
*::-webkit-scrollbar {
    width: var(--scrollbar-size);
    height: var(--scrollbar-size);
}

*::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
    border-radius: 999px;
}

*::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 999px;
}

*::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

*::-webkit-scrollbar-corner {
    background: transparent;
}

*::-webkit-scrollbar-button {
    display: none;
    width: 0;
    height: 0;
}

* {
    box-sizing: border-box;
    /* Firefox / standard — applies to every scrollable element */
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
}

.container {
    width: min(1200px, 92vw);
    margin: 0 auto;
}
body.has-sidebar .container {
    width: 100%;
    max-width: none;
    margin: 0;
    padding-left: 24px;
    padding-right: 24px;
}

.app-main {
    padding: 20px 0 24px;
    transition: margin-left var(--layout-sidebar-motion), width var(--layout-sidebar-motion);
    will-change: margin-left, width;
}
html.ims-sidebar-preload body.has-sidebar .app-main {
    transition: none !important;
}
.app-main-guest {
    padding: 0;
}

/* AJAX in-app nav: instant feedback while fetch + fragment scripts run */
#ims-app-content.ims-content-navigating {
    opacity: 0.55;
    pointer-events: none;
    transition: opacity 0.12s ease;
}

body.has-sidebar .app-main {
    margin-left: var(--layout-sidebar-expanded-width);
    width: calc(100% - var(--layout-sidebar-expanded-width));
}
html.ims-sidebar-collapsed body.has-sidebar .app-main {
    margin-left: var(--layout-sidebar-collapsed-width);
    width: calc(100% - var(--layout-sidebar-collapsed-width));
}

/*  Panels  */
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
    overflow-x: auto;
}
.grid      { display: grid; gap: 16px; }
.grid-2    { grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); }
.grid-4    { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.kpi {
    background: #f8fafc;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px;
}
.kpi .label {
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.kpi .value {
    margin-top: 5px;
    font-size: 27px;
    font-weight: 700;
}

/*  Table  */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    min-width: 740px;
    background: #ffffff;
    border: 1px solid var(--table-float-line);
    border-radius: 14px;
    box-shadow: var(--table-float-shadow);
}
th, td {
    padding: 14px 14px;
    vertical-align: top;
    text-align: left;
    font-size: 14px;
}
th {
    font-size: 14px;
    text-transform: none;
    color: var(--table-head-text);
    letter-spacing: 0;
    background: var(--table-head-bg);
    border: 0;
    font-weight: 700;
}
thead th:first-child {
    border-top-left-radius: var(--table-head-radius);
    border-bottom-left-radius: var(--table-head-radius);
}
thead th:last-child {
    border-top-right-radius: var(--table-head-radius);
    border-bottom-right-radius: var(--table-head-radius);
}
tbody td {
    border: 0;
    background: #ffffff;
    transition: background 0.2s ease;
}
tbody tr + tr td {
    border-top: 1px solid var(--table-row-border);
}
tbody tr:hover td {
    background: var(--table-row-hover);
}
tbody td.muted[colspan] {
    border-top: 0;
    background: transparent;
    text-align: center;
}
.panel-table {
    background: transparent;
    border: 0;
    border-radius: 0;
    padding: 0;
    overflow-x: auto;
    overflow-y: visible;
    box-shadow: none;
}
.panel-table > :not(table) + table { margin-top: 10px; }
.panel-table tbody tr:last-child td:first-child { border-bottom-left-radius: 12px; }
.panel-table tbody tr:last-child td:last-child  { border-bottom-right-radius: 12px; }
.panel-table .btn-row { margin-top: 10px; }

/*
 * Dashboard + Transactions: tx-table header and shell use the same theme tokens as :root.
 * Extra specificity beats Bootstrap / fragment-only loads where generic `table` can lose the fight.
 */
.db-wrap table.tx-table,
.panel.panel-table table.tx-table {
    border: 1px solid var(--table-float-line);
    border-radius: 14px;
    box-shadow: var(--table-float-shadow);
    background: #fff;
}
.db-wrap table.tx-table thead th,
.panel.panel-table table.tx-table thead th {
    background: var(--table-head-bg);
    color: var(--table-head-text);
    font-weight: 700;
    font-size: 14px;
}
.db-wrap table.tx-table thead th:first-child,
.panel.panel-table table.tx-table thead th:first-child {
    border-top-left-radius: var(--table-head-radius);
    border-bottom-left-radius: var(--table-head-radius);
}
.db-wrap table.tx-table thead th:last-child,
.panel.panel-table table.tx-table thead th:last-child {
    border-top-right-radius: var(--table-head-radius);
    border-bottom-right-radius: var(--table-head-radius);
}
.db-wrap table.tx-table tbody tr + tr td,
.panel.panel-table table.tx-table tbody tr + tr td {
    border-top: 1px solid var(--table-row-border);
}
.db-wrap table.tx-table tbody tr:hover td,
.panel.panel-table table.tx-table tbody tr:hover td {
    background: var(--table-row-hover);
}

/*  Badges */
.badge {
    display: inline-block;
    border-radius: 999px;
    padding: 2px 10px;
    font-size: 12px;
    border: 1px solid var(--line);
    background: #fff;
}
.badge-pending   { color: #92400e; border-color: #f59e0b; background: #fffbeb; }
.badge-issued    { color: #065f46; border-color: #34d399; background: #ecfdf5; }
.badge-rejected  { color: #9f1239; border-color: #fb7185; background: #fff1f2; }
.badge-cancelled { color: #374151; border-color: #9ca3af; background: #f3f4f6; }
.badge-low       { color: #991b1b; border-color: #ef4444; background: #fef2f2; }
.badge-ok        { color: #166534; border-color: #22c55e; background: #f0fdf4; }

/* Solid status badges */
.badge-solid {
    display: inline-block;
    padding: 4px 14px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border: none;
    color: #fff;
}
.badge-complete      { background: #15803d; }
.badge-complete-done { background: #4f46e5; }
.badge-approved      { background: #2563eb; }
.badge-pending-s     { background: #eab308; color: #1f2937; }
.badge-for-receiving { background: #0a9632; color: #fff; }
.badge-partial       { background: #f59e0b; color: #1f2937; }
.badge-cancel-s      { background: #6b7280; }
.badge-reject-s      { background: #e11d48; }

/* ── Forms ── */
label {
    font-size: 13px;
    color: var(--muted);
    display: block;
    margin-bottom: 4px;
}
input, select, textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: #fff;
    color: var(--text);
}
textarea { resize: vertical; min-height: 72px; }

/* Unified filter select style across modules */
.btn-row select:not(.ims-rows-filter-select),
.db-table-toolbar select:not(.ims-rows-filter-select),
.ap-toolbar select:not(.ims-rows-filter-select),
.ap-filter-bar select:not(.ims-rows-filter-select),
.at-input-group select:not(.ims-rows-filter-select) {
    width: auto;
    min-height: 44px;
    border: 1px solid #c9d8ef;
    border-radius: 12px;
    padding: 0 40px 0 14px;
    font-size: 14px;
    font-weight: 600;
    color: #1e3a8a;
    background-color: #fff;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'%3E%3Cpath d='M5 7l5 5 5-5' stroke='%231f3b74' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 13px center;
    background-size: 14px;
}
.ims-filter-select {
    width: auto;
    min-height: 44px;
    border: 1px solid #c9d8ef;
    border-radius: 12px;
    padding: 0 40px 0 14px;
    font-size: 14px;
    font-weight: 600;
    color: #1e3a8a;
    background-color: #fff;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'%3E%3Cpath d='M5 7l5 5 5-5' stroke='%231f3b74' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 13px center;
    background-size: 14px;
}
.ims-filter-select:focus {
    outline: none;
    border-color: #9fb8e6;
    box-shadow: 0 0 0 3px rgba(147, 175, 224, 0.2);
}
.ims-rows-filter {
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    min-height: 42px;
    min-width: 145px;
    padding: 0 12px;
    border: 1px solid #c9d8ef;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.ims-rows-filter-icon {
    color: #64748b;
    font-size: 17px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.ims-rows-filter-select {
    border: 0 !important;
    border-radius: 0 !important;
    outline: none;
    background: transparent !important;
    color: #1f3b74;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    padding: 0;
    min-height: 38px;
    width: 100%;
    min-width: 0;
    appearance: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    background-image: none;
    cursor: pointer;
    box-shadow: none !important;
}
.ims-rows-filter-select::-ms-expand {
    display: none;
}
.ims-rows-filter-select:focus {
    outline: none;
    box-shadow: none;
}
.btn-row select:not(.ims-rows-filter-select):focus,
.db-table-toolbar select:not(.ims-rows-filter-select):focus,
.ap-toolbar select:not(.ims-rows-filter-select):focus,
.ap-filter-bar select:not(.ims-rows-filter-select):focus,
.at-input-group select:not(.ims-rows-filter-select):focus {
    outline: none;
    border-color: #9fb8e6;
    box-shadow: 0 0 0 3px rgba(147, 175, 224, 0.2);
}

/*  Buttons  */
.btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}
.btn {
    border-radius: 8px;
    border: 1px solid transparent;
    padding: 8px 12px;
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-danger  { background: #dc2626; color: #fff; }
.btn-muted   { background: #fff; border-color: var(--line); color: var(--text); }
.ims-page-btn {
    border-color: #c9d8ef;
    color: #2f3c7e;
    font-weight: 600;
}
.ims-page-btn:hover {
    background: #2f3c7e;
    border-color: #2f3c7e;
    color: #fff;
}

.btn-dark {
    background: #1f2937;
    color: #fff;
    border: 1px solid #1f2937;
    border-radius: 8px;
    padding: 9px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn-dark:hover { background: #374151; }
.btn-outline {
    background: #fff;
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 9px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}
.btn-outline:hover { background: #f9fafb; }

/* Flash messages */
.flash {
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 12px;
    border: 1px solid var(--line);
}
.flash-success { background: #f0fdf4; border-color: #4ade80; color: var(--ok); }
.flash-error   { background: #fef2f2; border-color: #f87171; color: var(--danger); }

.muted { color: var(--muted); font-size: 13px; }

/* Inventory header */
.inv-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}
.inv-header h1 { font-size: 28px; font-weight: 800; margin: 0; }
.inv-actions   { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ── Search bar ── */
.search-wrapper {
    position: relative;
    width: 100%;
    max-width: 360px;
}
.search-wrapper input {
    width: 100%;
    padding: 10px 40px 10px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 14px;
    background: #fff;
}
.search-wrapper .search-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    pointer-events: none;   
}

/*  Table action buttons  */
.table-action-group {
    display: flex;
    flex-direction: row;
    align-items: center;
    flex-wrap: nowrap;
    justify-content: center;
    gap: 4px;
    min-width: 0;
}
.table-col-action {
    width: 1%;
    white-space: nowrap;
    text-align: center;
    position: relative;
}
.table-action-form { margin: 0; }
.table-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 7px;
    border: 1px solid #9db8f1;
    background: #eef4ff;
    color: #2b56b9;
    text-decoration: none;
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
}
.table-action-btn:hover { background: #e2ecff; }
.table-action-btn.table-action-approve { border-color: #86efac; background: #ecfdf3; color: #166534; }
.table-action-btn.table-action-approve:hover { background: #dcfce7; }
.table-action-btn.table-action-reject  { border-color: #fecaca; background: #fef2f2; color: #b91c1c; }
.table-action-btn.table-action-reject:hover  { background: #fee2e2; }

/*   Approval review dropdown   */
.approval-review { position: relative; display: inline-block; }
.approval-review > summary { list-style: none; }
.approval-review > summary::-webkit-details-marker { display: none; }
.approval-review-toggle { border-color: #8cb2f3; background: #ecf3ff; color: #1d4fb7; }
.approval-review-toggle::after { content: "▾"; font-size: 10px; margin-left: 2px; transform: translateY(-1px); }
.approval-review[open] > .approval-review-toggle::after { content: "▴"; }
.approval-review-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    width: min(92vw, 520px);
    max-height: min(74vh, 520px);
    overflow: auto;
    background: #ffffff;
    border: 1px solid #d7e2f8;
    border-radius: 12px;
    box-shadow: 0 12px 28px rgba(25, 56, 111, 0.18);
    padding: 12px;
    z-index: 1200;
    text-align: left;
    white-space: normal;
}
.approval-review-panel label { text-align: left; }
.approval-table-panel { overflow: visible; }
.approval-review-grid-2 { display: grid; gap: 8px; grid-template-columns: repeat(2, minmax(130px, 1fr)); }
.approval-review-grid-3 { display: grid; gap: 8px; grid-template-columns: repeat(3, minmax(120px, 1fr)); margin-top: 8px; }
.approval-review-note { margin-top: 8px; }
.approval-review-note textarea { min-height: 56px; }
.approval-review-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.approval-review-actions .btn { padding: 6px 10px; font-size: 12px; }

/* Kebab action menu */
.kebab-wrapper { position: relative; display: inline-block; }
.kebab-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    font-size: 18px;
    color: var(--text);
    letter-spacing: 2px;
    line-height: 1;
    border-radius: 6px;
}
.kebab-btn:hover { background: #f3f4f6; }
.kebab-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.10);
    min-width: 140px;
    z-index: 50;
    overflow: hidden;
}
.kebab-dropdown.open { display: block; }
.kebab-dropdown a,
.kebab-dropdown button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 14px;
    font-size: 13px;
    color: var(--text);
    text-decoration: none;
    background: none;
    border: none;
    cursor: pointer;
}
.kebab-dropdown a:hover,
.kebab-dropdown button:hover { background: #f3f4f6; }
.kebab-dropdown .danger { color: #dc2626; }

/*  Modal  */
.inv-modal {
    display: none;
    position: fixed;
    z-index: 9999;
    left: 0; top: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.45);
}
.inv-modal.open { display: flex; align-items: center; justify-content: center; }
.inv-modal-content {
    background: #fff;
    width: 400px;
    max-width: 92vw;
    max-height: 90vh;
    overflow-y: auto;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.18);
    animation: modalIn 0.2s ease-out;
}
@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95); }
    to   { opacity: 1; transform: scale(1); }
}
.inv-modal-close {
    float: right;
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: var(--muted);
    line-height: 1;
}

/*  Responsive  */
@media (max-width: 720px) {
    .topbar .container { flex-direction: column; align-items: flex-start; }
}
@media (max-width: 992px) {
    /* Sidebar is a transform-based overlay on mobile — content stays at collapsed offset only */
    body.has-sidebar .app-main {
        margin-left: var(--layout-sidebar-collapsed-width);
        width: calc(100% - var(--layout-sidebar-collapsed-width));
    }
    html.ims-sidebar-expanded body.has-sidebar .app-main {
        margin-left: var(--layout-sidebar-collapsed-width);
        width: calc(100% - var(--layout-sidebar-collapsed-width));
    }
    .inv-header { flex-direction: column; }
}
@media (max-width: 700px) {
    .approval-review-panel { right: auto; left: 0; width: min(92vw, 420px); }
    .approval-review-grid-2,
    .approval-review-grid-3 { grid-template-columns: 1fr; }
}

