:root {
    --bg: #1f2b5c;
    --bg-soft: #2d3a73;
    --bg-softer: #364582;
    --bg-header: #071330;
    --text: #ffffff;
    --text-soft: rgba(255,255,255,0.85);
    --border: rgba(255,255,255,0.08);
    --btn: #0d1638;
    --btn-hover: #16214f;
    --card-shadow: 0 8px 20px rgba(0,0,0,0.18);
    --pending: #9b7b1e;
    --transit: #1e6c9b;
    --today: #a76418;
    --overdue: #a1283e;
    --received: #207548;
}

html[data-theme="light"] {
    --bg: #eef3ff;
    --bg-soft: #ffffff;
    --bg-softer: #f5f7fd;
    --bg-header: #dbe5ff;
    --text: #0f172a;
    --text-soft: rgba(15,23,42,0.80);
    --border: rgba(15,23,42,0.08);
    --btn: #dbe5ff;
    --btn-hover: #c8d8ff;
    --card-shadow: 0 8px 20px rgba(15,23,42,0.08);
    --pending: #d1a321;
    --transit: #2d86b9;
    --today: #d77e19;
    --overdue: #cc425f;
    --received: #2f915c;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: inherit; text-decoration: none; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 260px;
    background: var(--bg-header);
    color: var(--text);
    display: flex;
    flex-direction: column;
    padding: 20px 16px;
    border-right: 1px solid var(--border);
    position: sticky;
    top: 0;
    height: 100vh;
}
.sidebar-brand { margin-bottom: 24px; }
.brand-title { font-size: 22px; font-weight: 800; }
.brand-subtitle { font-size: 13px; color: var(--text-soft); margin-top: 4px; }
.sidebar-nav { display: flex; flex-direction: column; gap: 8px; }
.nav-link { padding: 12px 14px; border-radius: 12px; background: transparent; font-weight: 700; transition: 0.2s ease; }
.nav-link:hover, .nav-link.active { background: rgba(255,255,255,0.08); }
.sidebar-footer { margin-top: auto; padding-top: 20px; }

.theme-toggle-btn, .menu-btn, .btn {
    display: inline-block;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--btn);
    color: var(--text);
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
}
.theme-toggle-btn:hover, .menu-btn:hover, .btn:hover { background: var(--btn-hover); }

.main-content { flex: 1; padding: 20px; min-width: 0; }
.mobile-topbar { display: none; align-items: center; gap: 12px; margin-bottom: 18px; }
.mobile-title { font-size: 20px; font-weight: 800; }

.page { padding: 0; }
.title { font-size: 28px; font-weight: 700; }
.small { font-size: 12px; color: var(--text-soft); }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.top-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.card, .hero-card, .filters, .table-card {
    background: var(--bg-soft);
    color: var(--text);
    border-radius: 16px;
    padding: 18px;
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border);
}
.card-title { font-size: 18px; font-weight: 700; margin-bottom: 14px; }
.hero-grid, .cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.hero-card .label, .card .label { font-size: 13px; font-weight: 700; margin-bottom: 8px; }
.hero-card .value, .card .value { font-size: 28px; font-weight: 800; }

.filters { margin-bottom: 18px; }
.filters form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    align-items: end;
}
label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 700; }

input[type="text"],
input[type="password"],
input[type="date"],
input[type="file"],
select {
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    outline: none;
    background: var(--bg-softer);
    color: var(--text);
    font-size: 14px;
}

.flash {
    background: var(--btn);
    padding: 12px;
    border-radius: 10px;
    margin-bottom: 10px;
    border-left: 4px solid #6aa5ff;
}

.table-container { overflow: auto; max-height: 75vh; border-radius: 16px; position: relative; }
table { width: max-content; min-width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; }
th, td { padding: 14px 16px; text-align: left; border-bottom: 1px solid var(--border); }
thead { position: sticky; top: 0; z-index: 50; }
thead tr { background: var(--bg-header); }
th { position: sticky; top: 0; z-index: 60; background: var(--bg-header); white-space: nowrap; font-weight: 700; }
td { background: var(--bg-softer); }
tr:nth-child(even) td { filter: brightness(0.98); }

th
.supplier-wrap { display: flex; align-items: center; gap: 8px; min-width: 0; }
.supplier-name { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }

.currency-badge,
.status-badge,
.badge,
.action-badge {
    display: inline-block;
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    background: rgba(127,127,127,0.16);
}
.pending-eta, .grn-pending { background: var(--pending); }
.in-transit, .grn-partly, .badge-dept { background: var(--transit); }
.arriving-today { background: var(--today); }
.overdue-badge, .badge-admin { background: var(--overdue); }
.received-badge, .grn-full, .badge-department { background: var(--received); }
.badge-all { background: #5f4b9a; }

.overdue-row td, .overdue-row .received-row td, .received-row 
.right { text-align: right; }
.layout { display: grid; grid-template-columns: 360px 1fr; gap: 18px; }
.chart-wrap { position: relative; width: 100%; height: 340px; }
.chart-wrap.small { height: 300px; }

@media (max-width: 980px) {
    .sidebar { position: fixed; left: -280px; z-index: 1000; transition: 0.25s ease; }
    .sidebar.show { left: 0; }
    .mobile-topbar { display: flex; }
    .layout { grid-template-columns: 1fr; }
    .title { font-size: 22px; }
    }

@media print {
    .sidebar, .mobile-topbar, .theme-toggle-btn, .btn { display: none !important; }
    .main-content { padding: 0; }
    body { background: white; color: black; }
    .card, .hero-card, .filters, .table-card { box-shadow: none; border: 1px solid #ccc; }
}


/* Tighter column sizing */
th:nth-child(4), td:nth-child(4) { width: 140px; min-width: 140px; max-width: 140px; }
th:nth-child(5), td:nth-child(5) { width: 260px; min-width: 260px; max-width: 260px; }
th:nth-child(6), td:nth-child(6) { width: 90px; min-width: 90px; max-width: 90px; }
th:nth-child(7), td:nth-child(7) { width: 90px; min-width: 90px; max-width: 90px; }
th:nth-child(8), td:nth-child(8) { width: 120px; min-width: 120px; max-width: 120px; }
th:nth-child(9), td:nth-child(9) { width: 120px; min-width: 120px; max-width: 120px; }
th:nth-child(10), td:nth-child(10) { width: 150px; min-width: 150px; max-width: 150px; }
th:nth-child(11), td:nth-child(11) { width: 130px; min-width: 130px; max-width: 130px; }
th:nth-child(12), td:nth-child(12) { width: 180px; min-width: 180px; max-width: 180px; }
th:nth-child(13), td:nth-child(13) { width: 120px; min-width: 120px; max-width: 120px; }
th:nth-child(14), td:nth-child(14) { width: 150px; min-width: 150px; max-width: 150px; }

.supplier-name { max-width: 250px; }

@media (max-width: 980px) {
    table { table-layout: auto; }
}


/* Resizable columns */
.resizable-table th {
    position: sticky;
    overflow: visible;
}

.resizable-table th,
.resizable-table td {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.col-resizer {
    position: absolute;
    top: 0;
    right: -3px;
    width: 8px;
    height: 100%;
    cursor: col-resize;
    z-index: 120;
}

.col-resizer:hover,
body.is-resizing-columns .col-resizer {
    background: rgba(106, 165, 255, 0.25);
}

body.is-resizing-columns {
    user-select: none;
    cursor: col-resize;
}

#autoFitColumnsBtn,
#resetColumnsBtn {
    margin-right: 8px;
}


.overdue-row td { background: rgba(161,40,62,0.22) !important; }
.received-row td { background: rgba(32,117,72,0.22) !important; }

/* v5 non-frozen columns */
.resizable-table th,
.resizable-table td {
    position: relative;
}
