:root {
    --accent: #cc1a1a;
    --accent-dark: #a81515;
    --sidebar-bg: #f6f6f8;
    --sidebar-border: #e7e7ec;
    --text-muted: #6b7280;
    --green: #1aa260;
    --amber: #d39e00;
    --red: #d6483f;
    --radius: 10px;
}

* { box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #eef0f4;
    color: #1f2430;
    margin: 0;
}

.app-shell {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.app-sidebar {
    width: 230px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    padding: 22px 18px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 30px; }
.brand-mark { position: relative; width: 26px; height: 26px; display: inline-block; }
.brand-mark span {
    position: absolute; width: 13px; height: 13px; border-radius: 50%; opacity: .9;
}
.brand-mark span:nth-child(1) { background: #cc1a1a; top: 0; left: 6px; }
.brand-mark span:nth-child(2) { background: #2a8c3f; top: 6px; left: 13px; }
.brand-mark span:nth-child(3) { background: var(--accent); top: 6px; left: -1px; }
.brand-mark span:nth-child(4) { background: #2a8c3f; top: 12px; left: 6px; }
.brand-name { font-weight: 700; font-size: 19px; letter-spacing: -.02em; color: #2a2f3a; }

.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a, .side-nav .logout-link {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 10px; border-radius: 8px; color: #4b5160;
    text-decoration: none; font-size: 14.5px; font-weight: 500;
    background: none; border: none; width: 100%; text-align: left; cursor: pointer;
}
.side-nav a:hover, .side-nav .logout-link:hover { background: #ebebf2; color: #20232b; }
.side-nav a.active { color: #20232b; font-weight: 600; text-decoration: underline; text-underline-offset: 4px; }
.nav-dot { font-size: 6px; color: #b9bdc8; }
.side-nav a.active .nav-dot { color: var(--accent); }
.side-nav-divider { height: 1px; background: var(--sidebar-border); margin: 14px 4px; }

/* Main */
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 26px; background: #fff; border-bottom: 1px solid #e9eaef;
    position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-weight: 600; font-size: 16px; color: #20232b; }
.topbar-user { display: flex; align-items: center; gap: 10px; }
.factory-chip {
    background: #fdf0f0; color: var(--accent-dark); font-size: 12.5px; font-weight: 600;
    padding: 4px 10px; border-radius: 20px;
}
.user-chip { color: #4b5160; font-size: 14px; }

.app-content { padding: 24px 26px 60px; }

/* Cards */
.card { border: 1px solid #e9eaef; border-radius: var(--radius); }
.card-header { background: #fff; border-bottom: 1px solid #eef0f4; font-weight: 600; }
.panel-card { background: #fff; border: 1px solid #e9eaef; border-radius: var(--radius); padding: 18px 20px; }

.field-box { background: #f4f5f8; border-radius: 8px; padding: 10px 14px; margin-bottom: 12px; }
.field-box label { display: block; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: #8b8f9b; margin-bottom: 3px; }
.field-box .value { font-weight: 600; font-size: 14.5px; color: #20232b; }

/* Status pills */
.status-pill { padding: 3px 11px; border-radius: 20px; font-size: 12px; font-weight: 600; display: inline-block; white-space: nowrap; }
.status-created { background:#eef0f4; color:#5b6170; }
.status-bom_uploaded { background:#e6effe; color:#1d5fd6; }
.status-in_progress { background:#fdf0f0; color:var(--accent); }
.status-stage_1, .status-stage_2, .status-stage_3 { background:#fff2e0; color:#b8730a; }
.status-qc { background:#f3e8fd; color:#8338ce; }
.status-ready_to_pack { background:#e3f8f3; color:#0f9d80; }
.status-packed { background:#e3f7e8; color:#1aa260; }
.status-shipped { background:#1f2430; color:#fff; }
.status-completed { background:#1aa260; color:#fff; }
.status-pending { background:#fdeeee; color:#d6483f; }

.stat-strip { display:flex; gap: 0; border:1px solid #e9eaef; border-radius: var(--radius); overflow:hidden; background:#fff; }
.stat-block { flex:1; padding: 12px 18px; border-right: 1px solid #eef0f4; }
.stat-block:last-child { border-right:none; }
.stat-block .num { font-size: 22px; font-weight: 700; color:#20232b; line-height:1.1;}
.stat-block .lbl { font-size: 11.5px; color:#8b8f9b; text-transform:uppercase; letter-spacing:.04em; }
.stat-block.green .num { color: var(--green); }
.stat-block.amber .num { color: var(--amber); }
.stat-block.red .num { color: var(--red); }

.progress-thin { height: 8px; border-radius: 20px; background:#eef0f4; }
.progress-thin .bar { height:100%; border-radius:20px; background: var(--green); transition: width .3s; }

.box-card { border:1px solid #e9eaef; border-radius:10px; padding:12px 14px; background:#fff; transition: box-shadow .15s, border-color .15s; cursor:pointer; }
.box-card:hover { box-shadow: 0 2px 10px rgba(20,20,40,.06); }
.box-card.flash-green { border-color:#1aa260; box-shadow:0 0 0 3px rgba(26,162,96,.18); }
.box-card.flash-red { border-color:#d6483f; box-shadow:0 0 0 3px rgba(214,72,63,.18); }
.box-card.flash-amber { border-color:#d39e00; box-shadow:0 0 0 3px rgba(211,158,0,.18); }

.scan-box { display:flex; gap:8px; }
.scan-box input { font-size: 15px; }

.auth-wrap { min-height:100vh; display:flex; align-items:center; justify-content:center; background: linear-gradient(160deg,#cc1a1a 0%,#8a0f0f 100%); }
.auth-card { width: 380px; background:#fff; border-radius:14px; padding:34px 32px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }

table.dataTable {
    border-collapse: separate !important;
    border-spacing: 0;
}
table.dataTable thead th {
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: #6b7280;
    font-weight: 700;
    border-bottom: 2px solid #e9eaef !important;
    border-top: none !important;
    padding: 10px 28px 10px 14px !important; /* extra right padding for sort arrow */
    white-space: nowrap;
    background: #f9fafb;
}
table.dataTable thead th.sorting,
table.dataTable thead th.sorting_asc,
table.dataTable thead th.sorting_desc {
    padding-right: 28px !important; /* room for sort icon */
}
table.dataTable tbody td {
    font-size: 14px;
    vertical-align: middle;
    padding: 11px 14px !important;
    border-bottom: 1px solid #f0f1f5 !important;
    border-top: none !important;
    color: #2a2f3a;
    white-space: nowrap; /* prevents all cell text from wrapping */
}
table.dataTable tbody tr:last-child td { border-bottom: none !important; }
table.dataTable tbody tr:hover td { background: #f7f8fb !important; }
table.dataTable tbody tr:hover { background: #f7f8fb; }
/* Prevent action buttons wrapping */
table.dataTable .d-flex { white-space: nowrap; }

/* Search row — enough top padding so sort arrows don't overlap */
.table-search-row th {
    background: #fff !important;
    padding: 6px 14px 8px !important;
    border-bottom: 1px solid #e9eaef !important;
}
.table-search-row input {
    font-size: 13px;
    padding: 5px 10px;
    border-radius: 6px;
    border: 1px solid #dde0e8;
    width: 100%;
    min-width: 80px;
    background: #f4f5f8;
    height: 32px;
    box-sizing: border-box;
}
.table-search-row input:focus { outline: none; border-color: var(--accent); background: #fff; box-shadow: 0 0 0 2px rgba(204,26,26,.12); }
/* Styled horizontal scrollbar — DataTables scrollX + table-responsive */
.dataTables_scrollBody::-webkit-scrollbar,
.dataTables_scroll::-webkit-scrollbar,
.table-responsive::-webkit-scrollbar { height: 5px; }
.dataTables_scrollBody::-webkit-scrollbar-track,
.dataTables_scroll::-webkit-scrollbar-track,
.table-responsive::-webkit-scrollbar-track { background: #f1f1f5; border-radius: 10px; }
.dataTables_scrollBody::-webkit-scrollbar-thumb,
.dataTables_scroll::-webkit-scrollbar-thumb,
.table-responsive::-webkit-scrollbar-thumb { background: #c0c3d4; border-radius: 10px; }
.dataTables_scrollBody::-webkit-scrollbar-thumb:hover,
.dataTables_scroll::-webkit-scrollbar-thumb:hover,
.table-responsive::-webkit-scrollbar-thumb:hover { background: var(--accent); }
.dataTables_wrapper { padding: 0; }
.dataTables_length, .dataTables_filter { padding: 12px 16px; }
.dataTables_info, .dataTables_paginate { padding: 10px 16px; }
.dataTables_length label, .dataTables_filter label { font-size: 13.5px; color: #6b7280; display: flex; align-items: center; gap: 6px; }
.dataTables_length select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    border-radius: 6px;
    border: 1px solid #dde0e8;
    padding: 4px 28px 4px 10px;
    font-size: 13px;
    color: #2a2f3a;
    background-color: #f4f5f8;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 16 16'%3E%3Cpath fill='%236b7280' d='M7.247 11.14L2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    cursor: pointer;
    line-height: 1.4;
    min-width: 60px;
    box-shadow: none;
    outline: none;
}
.dataTables_length select:focus {
    border-color: #cc1a1a;
    background-color: #fff;
    box-shadow: 0 0 0 2px rgba(204,26,26,.1);
}
.dataTables_paginate .paginate_button { border-radius: 6px !important; font-size: 13px !important; }
.dataTables_paginate .paginate_button.current {
    background: var(--accent) !important;
    border-color: var(--accent) !important;
    color: #fff !important;
}
.dataTables_paginate .paginate_button:hover {
    background: #fdf0f0 !important;
    border-color: var(--accent) !important;
    color: var(--accent) !important;
}

@media (max-width: 992px) {
    .app-sidebar { position: fixed; left:-250px; transition:left .2s; z-index: 50; box-shadow: 0 0 0 9999px rgba(0,0,0,0); }
    .app-shell.sidebar-open .app-sidebar { left:0; box-shadow: 0 0 0 9999px rgba(0,0,0,.35); }
    .app-content { padding: 16px; }
}

/* ── Page flash overlay for scan feedback ── */
.scan-flash-overlay {
    position: fixed; inset: 0; pointer-events: none; z-index: 9999;
    opacity: 0; transition: opacity 0.1s ease;
}
.scan-flash-overlay.flash-green  { background: rgba(42,140,63,.22); opacity: 1; }
.scan-flash-overlay.flash-yellow { background: rgba(245,158,11,.22); opacity: 1; }
.scan-flash-overlay.flash-red    { background: rgba(204,26,26,.22); opacity: 1; }

/* ── Bootstrap pagination (orders show, etc.) matched to app accent ── */
.pagination { margin-bottom: 0; }
.pagination .page-link {
    color: var(--accent, #cc1a1a);
    border-color: #e9eaef;
    padding: 6px 12px;
    font-size: 13px;
}
.pagination .page-link:hover {
    background: #fdf0f0;
    border-color: var(--accent, #cc1a1a);
    color: var(--accent, #cc1a1a);
}
.pagination .page-item.active .page-link {
    background: var(--accent, #cc1a1a);
    border-color: var(--accent, #cc1a1a);
    color: #fff;
}
.pagination .page-item.disabled .page-link {
    color: #b7bac2;
    background: #f8f8f9;
    border-color: #e9eaef;
}

/* ── Invoice module ───────────────────────────────────────────── */
.btn-brand { background: #cc1a1a; border-color: #cc1a1a; color: #fff; }
.btn-brand:hover, .btn-brand:focus { background: #a81414; border-color: #a81414; color: #fff; }

/* Sidebar sub-menu (Invoice -> Dashboard, Customers, ...) */
.side-nav .nav-parent .nav-caret { font-size: 11px; color: #8b8f9b; transition: transform .15s; }
.side-nav .nav-parent[aria-expanded="true"] .nav-caret { transform: rotate(180deg); }
.side-nav .nav-parent.open { color: #20232b; font-weight: 600; }
.side-nav .nav-sub { display: flex; flex-direction: column; gap: 1px; padding: 2px 0 4px 22px; }
.side-nav .nav-sub a { padding: 7px 10px; font-size: 13.5px; }

.inv-num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.inv-status { font-size: 12px; font-weight: 600; letter-spacing: .02em; white-space: nowrap; }
.inv-status.paid { color: #1aa260; }
.inv-status.due { color: #3b82f6; }
.inv-status.overdue { color: #f0643c; }

.inv-summary { display: flex; flex-wrap: wrap; border: 1px solid #e9eaef; border-radius: var(--radius); background: #fff; margin-bottom: 16px; overflow: hidden; }
.inv-summary .cell { flex: 1; min-width: 170px; padding: 14px 18px; border-right: 1px solid #eef0f4; }
.inv-summary .cell:last-child { border-right: none; }
.inv-summary .cap { font-size: 12px; color: #8b8f9b; margin-bottom: 2px; }
.inv-summary .val { font-size: 18px; font-weight: 700; color: #20232b; }

.cash-stat { padding: 9px 0; text-align: right; }
.cash-stat .cap { font-size: 13px; color: #6b7080; }
.cash-stat .cap i { width: 10px; height: 10px; display: inline-block; border-radius: 2px; margin-right: 6px; }
.cash-stat .amt { font-size: 18px; color: #20232b; }
