:root {
    --bg: #f4f5fa;
    --surface: #ffffff;
    --border: #e7e8f0;
    --text: #1c1d2e;
    --text-muted: #7b7d93;
    --primary: #5b5bf0;
    --primary-hover: #4848d9;
    --primary-soft: #eeeeff;
    --danger: #ef4444;
    --danger-soft: #fef2f2;
    --green: #16a34a;
    --green-soft: #ecfdf3;
    --amber: #d97706;
    --amber-soft: #fffbeb;
    --radius-lg: 18px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(20, 20, 43, 0.04);
    --shadow-md: 0 8px 24px rgba(20, 20, 43, 0.06);
    --sidebar-w: 250px;
}

* { box-sizing: border-box; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 14.5px;
    -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; }

h1, h2, h3, h4, h5 { font-weight: 700; letter-spacing: -0.02em; }

.req { color: var(--danger); }

/* ---------------- App Shell ---------------- */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.app-sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1040;
    transition: transform 0.25s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 22px 22px 18px;
}

.brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: #fff;
    border: 1px solid var(--border);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    overflow: hidden;
    flex-shrink: 0;
}

.brand-mark img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 3px;
}

.brand-name { font-weight: 800; font-size: 17px; }

.sidebar-nav {
    padding: 8px 14px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
}

.sidebar-nav .nav-link, .sidebar-footer .nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-weight: 500;
    font-size: 14px;
    transition: background 0.15s, color 0.15s;
}

.sidebar-nav .nav-link i, .sidebar-footer .nav-link i { font-size: 17px; width: 20px; text-align: center; }

.sidebar-nav .nav-link:hover { background: var(--bg); color: var(--text); }

.sidebar-nav .nav-link.active {
    background: var(--primary-soft);
    color: var(--primary);
}

.sidebar-footer { padding: 14px; border-top: 1px solid var(--border); }
.logout-link:hover { background: var(--danger-soft); color: var(--danger); }

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 20, 0.4);
    z-index: 1035;
}

/* ---------------- Main Area ---------------- */
.app-main {
    margin-left: var(--sidebar-w);
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-topbar {
    height: 66px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 1020;
}

.topbar-title { font-size: 17px; margin: 0; flex: 1; }

.topbar-user { display: flex; align-items: center; gap: 10px; }

.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
}

.user-name { font-weight: 600; font-size: 13.5px; }

.btn-icon {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.btn-icon:hover { background: var(--bg); color: var(--text); }

.app-content {
    padding: 24px;
    flex: 1;
}

/* ---------------- Page Head ---------------- */
.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 22px;
    flex-wrap: wrap;
}

.page-head h2 { margin: 0 0 3px; font-size: 22px; }
.page-head p { margin: 0; font-size: 13.5px; }

/* ---------------- Buttons ---------------- */
.btn {
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 14px;
    padding: 9px 18px;
    border: 1px solid transparent;
}

.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover, .btn-primary:focus { background: var(--primary-hover); border-color: var(--primary-hover); }

.btn-light { background: var(--bg); border-color: var(--border); color: var(--text); }
.btn-light:hover { background: #eaeaf2; }

.btn-outline-danger { --bs-btn-color: var(--danger); --bs-btn-border-color: #fecaca; }

/* ---------------- Stat Cards ---------------- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 16px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s, transform 0.2s;
}

.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

.stat-icon {
    width: 46px;
    height: 46px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #fff;
    flex-shrink: 0;
}

.bg-violet { background: linear-gradient(135deg, #7c7cf0, #5b5bf0); }
.bg-blue   { background: linear-gradient(135deg, #4fa8f5, #2f7fe0); }
.bg-teal   { background: linear-gradient(135deg, #2dd4bf, #14b8a6); }
.bg-amber  { background: linear-gradient(135deg, #fbbf24, #d97706); }
.bg-green  { background: linear-gradient(135deg, #4ade80, #16a34a); }

.stat-value { display: block; font-size: 22px; font-weight: 800; line-height: 1.2; }
.stat-label { display: block; font-size: 12.5px; color: var(--text-muted); font-weight: 500; }

/* ---------------- Panels ---------------- */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
}

.panel-head h3 { font-size: 15.5px; margin: 0; }
.panel-body { padding: 20px; }
.link-action { font-size: 13px; font-weight: 600; color: var(--primary); }

.filter-bar { padding: 16px 20px; margin-bottom: 18px; }

/* ---------------- Batch Overview list (dashboard) ---------------- */
.batch-overview-list { display: flex; flex-direction: column; }

.batch-overview-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.batch-overview-item:last-child { border-bottom: none; }

.boi-main { display: flex; flex-direction: column; gap: 3px; }
.boi-name { font-weight: 600; font-size: 14px; }
.boi-time { font-size: 12.5px; color: var(--text-muted); }
.boi-stats { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.boi-chip {
    background: var(--bg);
    border-radius: 20px;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
}

.chip-green {
    background: var(--green-soft);
    color: var(--green);
    border-radius: 20px;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 700;
}

.status-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.status-active { background: var(--green-soft); color: var(--green); }
.status-inactive { background: #f1f2f6; color: var(--text-muted); }

/* ---------------- Tables ---------------- */
.app-table { margin-bottom: 0; }
.app-table thead th {
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-weight: 700;
    padding: 14px 16px;
}
.app-table tbody td { padding: 14px 16px; vertical-align: middle; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.app-table tbody tr:last-child td { border-bottom: none; }
.app-table tbody tr:hover { background: #fafaff; }

.action-btns { display: flex; gap: 6px; justify-content: flex-end; }

/* DataTables tweaks */
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    padding: 6px 10px;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background: var(--primary) !important;
    border-color: var(--primary) !important;
    color: #fff !important;
    border-radius: 6px;
}
.dataTables_wrapper .dataTables_paginate .paginate_button {
    border-radius: 6px !important;
}

/* ---------------- Mobile Cards ---------------- */
.mobile-cards { display: flex; flex-direction: column; gap: 12px; }

.mobile-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    box-shadow: var(--shadow-sm);
}

.mc-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.mc-head h4 { font-size: 15px; margin: 0; }
.mc-row { font-size: 13px; color: var(--text-muted); margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }
.mc-chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.mc-actions { display: flex; gap: 8px; margin-top: 10px; }
.mc-actions .btn { flex: 1; }

/* ---------------- Empty States ---------------- */
.empty-state {
    text-align: center;
    padding: 60px 20px;
}
.empty-state i { font-size: 42px; color: var(--border); }
.empty-state h4 { margin: 14px 0 4px; font-size: 16px; }
.empty-state p { color: var(--text-muted); margin-bottom: 18px; font-size: 13.5px; }

/* ---------------- Forms ---------------- */
.form-label { font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.form-control, .form-select {
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    padding: 9px 12px;
    font-size: 14px;
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.select2-container .select2-selection--single {
    height: calc(1.5em + 1.1rem + 2px) !important;
    border-radius: var(--radius-sm) !important;
    border: 1px solid var(--border) !important;
    display: flex;
    align-items: center;
    padding: 0 6px;
}
.select2-container--default .select2-selection--single .select2-selection__rendered { line-height: normal !important; }
.select2-container--default .select2-selection--single .select2-selection__arrow { height: 100% !important; }

.modal-content { border-radius: var(--radius-lg); border: none; }
.modal-header, .modal-footer { border-color: var(--border); }
.modal-title { font-size: 16px; font-weight: 700; }

/* ---------------- Auth Page ---------------- */
.auth-body {
    background: linear-gradient(160deg, #f4f5fa 0%, #eceeff 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.auth-wrap { width: 100%; max-width: 400px; }
.auth-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 34px 30px;
    box-shadow: var(--shadow-md);
}
.auth-brand { text-align: center; margin-bottom: 26px; }
.auth-brand .brand-mark { margin: 0 auto 14px; width: 52px; height: 52px; font-size: 24px; border-radius: 14px; }
.auth-brand h1 { font-size: 20px; margin-bottom: 4px; }
.auth-brand p { color: var(--text-muted); font-size: 13px; margin: 0; }
.input-icon-group { position: relative; }
.input-icon-group i { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.input-icon-group .form-control { padding-left: 38px; }
.auth-hint { text-align: center; font-size: 12px; color: var(--text-muted); margin: 18px 0 0; }

/* ---------------- Mobile Bottom Nav ---------------- */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 1030;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    box-shadow: 0 -2px 12px rgba(20,20,43,0.06);
}

.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 2px;
    color: var(--text-muted);
    font-size: 10.5px;
    font-weight: 600;
    border-radius: 10px;
}
.bottom-nav-item i { font-size: 19px; }
.bottom-nav-item.active { color: var(--primary); }

/* ---------------- Responsive ---------------- */
@media (max-width: 991.98px) {
    .app-sidebar { transform: translateX(-100%); }
    .app-sidebar.open { transform: translateX(0); box-shadow: 0 0 30px rgba(0,0,0,0.15); }
    .sidebar-backdrop.show { display: block; }
    .app-main { margin-left: 0; }
    .mobile-bottom-nav { display: flex; }
    .app-content { padding: 16px; padding-bottom: 90px; }
    .app-topbar { padding: 0 16px; }
}

@media (min-width: 992px) {
    #sidebarToggle { display: none; }
}

@media (max-width: 575.98px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .stat-card { padding: 14px; }
    .stat-value { font-size: 18px; }
    .page-head { flex-direction: column; align-items: stretch; }
    .page-head .btn { width: 100%; }
}
