:root {
    --ink: #16323b;
    --teal: #0f7a74;
    --teal-dark: #0b4f4c;
    --navy: #123047;
    --saffron: #d97706;
    --peach: #f3d3b5;
    --cream: #f4efe8;
    --paper: #fffcf8;
    --line: #e4d9cc;
    --muted: #6d7c80;
    --sidebar: #10262c;
    --danger: #c2413b;
    --ok: #2f7d57;
    --shadow: 0 14px 36px rgba(18, 48, 71, .08);
    --radius: 18px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body.app-body {
    margin: 0;
    font-family: "Plus Jakarta Sans", sans-serif;
    color: var(--ink);
    background:
        radial-gradient(900px 400px at 110% -10%, rgba(217,119,6,.12), transparent 50%),
        radial-gradient(700px 320px at -10% 110%, rgba(15,122,116,.10), transparent 45%),
        var(--cream);
    overflow-x: hidden;
}

a { color: var(--teal); text-decoration: none; }
.font-display { font-family: Fraunces, serif; }

.app-shell { min-height: 100vh; display: flex; }
.sidebar {
    width: 268px;
    background: linear-gradient(180deg, var(--sidebar) 0%, #0b1c21 100%);
    color: #edf4f4;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: auto;
    flex-shrink: 0;
    padding: 18px 14px 28px;
    z-index: 1040;
    transition: transform .28s ease;
}
.sidebar-close {
    display: none;
    position: absolute; top: 14px; right: 12px;
    width: 36px; height: 36px; border: 0; border-radius: 10px;
    background: rgba(255,255,255,.08); color: #fff;
}
.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 8px 10px 18px;
}
.brand-mark {
    width: 44px; height: 44px; border-radius: 14px;
    background: linear-gradient(135deg, #1aa39a, #d97706);
    display: grid; place-items: center;
    font-family: Fraunces, serif; font-weight: 700; color: white;
    box-shadow: 0 10px 24px rgba(15,122,116,.35);
    flex-shrink: 0;
}
.brand h1 { font-size: 15px; margin: 0; font-family: Fraunces, serif; letter-spacing: .02em; }
.brand small { color: #b7c8c8; font-size: 11px; }

.side-label {
    font-size: 11px; letter-spacing: .16em; text-transform: uppercase;
    color: #8aa0a3; padding: 10px 12px 8px;
}
.side-link {
    display: flex; align-items: center; gap: 10px;
    color: #d5e3e3; padding: 11px 12px; border-radius: 12px;
    margin-bottom: 4px; font-size: 14px; font-weight: 500;
    min-height: 44px;
}
.side-link i { width: 18px; text-align: center; }
.side-link:hover, .side-link.active {
    background: rgba(255,255,255,.08);
    color: #fff;
}
.side-link.active { background: linear-gradient(90deg, rgba(26,163,154,.35), rgba(217,119,6,.18)); }
.badge-dot {
    margin-left: auto; background: var(--saffron); color: #fff;
    font-size: 10px; min-width: 18px; height: 18px; border-radius: 99px;
    display: inline-grid; place-items: center; padding: 0 5px;
}

.sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(16, 38, 44, .45);
    z-index: 1035;
}
.sidebar-backdrop.show { display: block; }

.content-wrap { flex: 1; min-width: 0; }
.topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 16px 28px 10px;
    position: sticky; top: 0; z-index: 30;
    background: color-mix(in srgb, var(--cream) 86%, white);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid transparent;
}
.menu-toggle {
    display: none;
    width: 42px; height: 42px; border-radius: 12px;
    border: 1px solid var(--line); background: var(--paper); color: var(--ink);
    flex-shrink: 0;
}
.page-title { min-width: 0; }
.page-title h2 { margin: 0; font-size: 26px; font-family: Fraunces, serif; line-height: 1.2; }
.page-title p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.user-chip {
    display: flex; align-items: center; gap: 10px;
    background: var(--paper); border: 1px solid var(--line);
    border-radius: 999px; padding: 6px 12px 6px 6px;
}
.user-chip img, .avatar-fallback {
    width: 34px; height: 34px; border-radius: 50%; object-fit: cover;
}
.avatar-fallback {
    background: var(--teal); color: #fff; display: grid; place-items: center; font-weight: 700;
}
.page { padding: 12px 28px 48px; }

.card-soft {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stat-card {
    padding: 18px; position: relative; overflow: hidden;
}
.stat-card .icon {
    width: 42px; height: 42px; border-radius: 14px;
    display: grid; place-items: center; color: #fff; margin-bottom: 14px;
}
.stat-card h3 { margin: 0; font-size: 26px; font-family: Fraunces, serif; word-break: break-word; }
.stat-card span { color: var(--muted); font-size: 13px; }
.stat-card::after {
    content: ""; position: absolute; right: -20px; bottom: -24px;
    width: 90px; height: 90px; border-radius: 50%;
    background: currentColor; opacity: .06;
}

.btn { border-radius: 12px; font-weight: 600; }
.btn-teal { background: var(--teal); color: #fff; border: 0; }
.btn-teal:hover, .btn-teal:focus { background: var(--teal-dark); color: #fff; }
.btn-saffron { background: var(--saffron); color: #fff; border: 0; }
.btn-saffron:hover { color: #fff; filter: brightness(.95); }
.btn-navy { background: var(--navy); color: #fff; border: 0; }
.btn-navy:hover { color: #fff; }
.btn-ghost { background: var(--paper); border: 1px solid var(--line); color: var(--ink); }
.btn-ghost:hover { background: #f4efe8; color: var(--ink); }
.form-control, .form-select {
    border-radius: 12px; border-color: var(--line); min-height: 44px;
}
.form-control:focus, .form-select:focus {
    border-color: var(--teal); box-shadow: 0 0 0 .2rem rgba(15,122,116,.15);
}
.table-wrap, .dataTables_wrapper { overflow-x: auto; }
.table thead th {
    font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
    color: var(--muted); font-weight: 700; background: #f4efe8;
    white-space: nowrap;
}
.table td { vertical-align: middle; }
.badge-status {
    display: inline-flex; align-items: center; gap: 6px;
    border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 600;
    text-transform: capitalize; white-space: nowrap;
}
.badge-status i { font-size: 7px; }
.st-active, .st-paid, .st-approved, .st-printed { background: #e4f5ea; color: var(--ok); }
.st-inactive, .st-cancelled, .st-unpaid { background: #fde8e6; color: var(--danger); }
.st-partial, .st-pending_approval, .st-draft, .st-in_progress { background: #fff3dd; color: #b45309; }
.st-registered, .st-sample_collected { background: #e7f3f2; color: var(--teal); }

.flag {
    display: inline-block; min-width: 18px; text-align: center;
    font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 6px; margin-left: 4px;
}
.flag-N { color: #1f7a4d; background: #e5f6ec; }
.flag-H { color: #b42318; background: #fde8e6; }
.flag-L { color: #b45309; background: #fff4e0; }
.report-values td { background: #f8fbfa; border-top: 0 !important; }

.filter-bar {
    padding: 12px 14px 10px;
    margin: -4px -4px 16px;
    background: #f7f3ee;
    border: 1px solid var(--line);
    border-radius: 16px;
}
.filter-bar .form-label { color: var(--muted); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.filter-bar .form-control-sm,
.filter-bar .form-select-sm { min-height: 40px; border-radius: 10px; }

.wizard-steps { display: flex; gap: 8px; margin-bottom: 18px; }
.wizard-step {
    flex: 1; padding: 12px 14px; border-radius: 14px; border: 1px dashed var(--line);
    background: #fff; font-weight: 600; font-size: 13px; color: var(--muted);
    text-align: center;
}
.wizard-step.active { border-style: solid; border-color: var(--teal); color: var(--teal); background: #eef8f7; }
.wizard-pane { display: none; }
.wizard-pane.active { display: block; }

.auth-wrap {
    min-height: 100vh; display: grid; grid-template-columns: 1.1fr .9fr;
    background: var(--cream);
}
.auth-art {
    position: relative; overflow: hidden; color: #fff;
    background:
        linear-gradient(160deg, rgba(11,79,76,.92), rgba(18,48,71,.86)),
        url("data:image/svg+xml,%3Csvg width='80' height='80' viewBox='0 0 80 80' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='.07'%3E%3Cpath d='M50 50c0-5.5-4.5-10-10-10s-10 4.5-10 10 4.5 10 10 10 10-4.5 10-10zm-10-24c2.2 0 4-1.8 4-4s-1.8-4-4-4-4 1.8-4 4 1.8 4 4 4z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    padding: 56px;
    display: flex; flex-direction: column; justify-content: space-between;
}
.auth-mobile-brand { display: none; }
.auth-form { display: grid; place-items: center; padding: 40px 20px; }
.auth-card { width: 100%; max-width: 420px; }
.chart-box { position: relative; width: 100%; height: 240px; }
@media (max-width: 576px) {
    .chart-box { height: 200px; }
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter { float: none !important; text-align: left; width: 100%; margin-bottom: 10px; }
    .dataTables_wrapper .dataTables_filter input { width: 100% !important; }
}
.lis-preview { overflow: visible; padding-bottom: 8px; }
.lis-preview .a4-page {
    width: 210mm;
    min-height: 297mm;
    height: 297mm !important;
    margin: 0 auto 28px;
    background: #fff;
    box-shadow: 0 18px 40px rgba(18, 48, 71, .12);
    position: relative;
    display: block;
}
.lis-preview .page-body { padding-bottom: 62mm; }
.lis-preview .page-bottom {
    position: absolute;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
}

.app-loader {
    position: fixed; inset: 0; z-index: 2000;
    display: flex; align-items: center; justify-content: center;
    background: rgba(246, 241, 234, .82);
    backdrop-filter: blur(8px);
    opacity: 0; visibility: hidden; pointer-events: none;
    transition: opacity .2s ease, visibility .2s ease;
}
.app-loader.show { opacity: 1; visibility: visible; pointer-events: auto; }
.loader-card {
    display: flex; flex-direction: column; align-items: center; gap: 14px;
    background: var(--paper); border: 1px solid var(--line);
    border-radius: 22px; padding: 28px 32px; box-shadow: var(--shadow);
    min-width: 180px;
}
.loader-mark {
    width: 58px; height: 58px; border-radius: 18px;
    background: linear-gradient(135deg, #1aa39a, #d97706);
    color: #fff; display: grid; place-items: center;
    font-family: Fraunces, serif; font-size: 26px; font-weight: 700;
    animation: pulse 1.2s ease-in-out infinite;
}
.loader-spin {
    width: 28px; height: 28px; border-radius: 50%;
    border: 3px solid #e4d9cc; border-top-color: var(--teal);
    animation: spin .7s linear infinite;
}
.loader-text { font-size: 13px; color: var(--muted); font-weight: 600; }
.btn.loading { position: relative; pointer-events: none; color: transparent !important; }
.btn.loading::after {
    content: ""; position: absolute; inset: 0; margin: auto;
    width: 18px; height: 18px; border-radius: 50%;
    border: 2px solid rgba(255,255,255,.35); border-top-color: #fff;
    animation: spin .7s linear infinite;
}
.btn-ghost.loading::after { border-color: rgba(15,122,116,.2); border-top-color: var(--teal); }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse {
    0%, 100% { transform: scale(1); box-shadow: 0 8px 18px rgba(15,122,116,.25); }
    50% { transform: scale(1.06); box-shadow: 0 12px 24px rgba(217,119,6,.28); }
}

.select2-container .select2-selection--single,
.select2-container .select2-selection--multiple {
    min-height: 44px; border-radius: 12px !important; border-color: var(--line) !important;
}
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
    border-radius: 10px; border: 1px solid var(--line); min-height: 38px; padding: 4px 10px;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background: var(--teal) !important; color: #fff !important; border: 0 !important; border-radius: 8px;
}

@media print {
    .sidebar, .topbar, .no-print, .alert, .app-loader, .sidebar-backdrop, .menu-toggle { display: none !important; }
    .app-shell, .content-wrap, .page { display: block; background: #fff; padding: 0; margin: 0; }
    .lis-preview { overflow: visible; }
    .lis-preview .a4-page {
        width: auto;
        min-height: 277mm;
        height: 277mm;
        margin: 0;
        box-shadow: none;
        page-break-after: always;
        position: relative;
        display: block;
    }
    .lis-preview .a4-page.last { page-break-after: auto; }
}

@media (max-width: 1199px) {
    .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 991px) {
    .sidebar {
        position: fixed; left: 0; top: 0;
        transform: translateX(-105%);
        box-shadow: 24px 0 40px rgba(0,0,0,.18);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-close { display: grid; place-items: center; }
    .menu-toggle { display: grid; place-items: center; }
    .topbar { padding: 12px 14px; }
    .page { padding: 10px 14px 88px; }
    .page-title h2 { font-size: 20px; }
    .page-title p { display: none; }
    .user-chip .user-meta { display: none; }
    .top-actions .btn { font-size: 13px; padding: .4rem .7rem; }
    .wizard-steps { flex-direction: column; }
    .auth-wrap { grid-template-columns: 1fr; }
    .auth-art { display: none; }
    .auth-mobile-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
}

@media (max-width: 576px) {
    .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat-card { padding: 14px; }
    .stat-card h3 { font-size: 18px; }
    .stat-card .icon { width: 34px; height: 34px; margin-bottom: 10px; }
    .card-soft.p-4 { padding: 16px !important; }
    .btn-group { flex-wrap: wrap; }
}
