:root {
    --brand: #28a745;
    --brand-dark: #218838;
    --brand-darker: #1c7430;
    --ink: #2b2f33;
    --muted: #6b7280;
    --bg: #f4f6f8;
    --sidebar-bg: #14241b;
    --sidebar-ink: #cbd5cc;
    --card-shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.04);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 14.5px;
}

a { color: var(--brand-dark); text-decoration: none; }
a:hover { color: var(--brand-darker); }

/* ---------- Scrollbars ---------- */
* { scrollbar-width: thin; scrollbar-color: #c7ccd1 transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c7ccd1; border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #a9afb6; background-clip: padding-box; }
::-webkit-scrollbar-corner { background: transparent; }

.sidebar-nav { scrollbar-color: rgba(255,255,255,.25) transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.22); background-clip: padding-box; }
.sidebar-nav::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.38); background-clip: padding-box; }

.app-shell { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
    width: 250px;
    background: var(--sidebar-bg);
    color: var(--sidebar-ink);
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1040;
    transition: transform .25s ease;
}
.sidebar-brand {
    display: flex; align-items: center; gap: .75rem;
    padding: 1.15rem 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,.07);
}
.brand-mark {
    width: 40px; height: 40px; border-radius: 11px;
    background: linear-gradient(135deg, var(--brand), var(--brand-dark));
    display: grid; place-items: center; color: #fff; font-size: 1.25rem;
    box-shadow: 0 4px 12px rgba(40,167,69,.35);
}
.brand-logo {
    width: 40px; height: 40px; border-radius: 11px; flex-shrink: 0;
    background: #fff; display: grid; place-items: center; padding: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,.18);
}
.brand-logo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.brand-logo-lg { width: 52px; height: 52px; border-radius: 14px; padding: 8px; }
.brand-name { font-weight: 700; color: #fff; letter-spacing: .2px; }
.brand-sub { font-size: .72rem; text-transform: uppercase; letter-spacing: 1.5px; color: #7fb98c; }

.sidebar-nav { padding: .75rem .65rem; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; }
.nav-section-label {
    font-size: .68rem; text-transform: uppercase; letter-spacing: 1.3px;
    color: #6f8a78; font-weight: 700; padding: .9rem .8rem .35rem;
}
.sidebar-nav .nav-link {
    display: flex; align-items: center; gap: .8rem;
    padding: .62rem .8rem; border-radius: 9px;
    color: var(--sidebar-ink); font-weight: 500; font-size: .92rem;
}
.sidebar-nav .nav-link i { font-size: 1.05rem; width: 20px; text-align: center; opacity: .85; }
.sidebar-nav .nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-nav .nav-link.active {
    background: linear-gradient(135deg, var(--brand), var(--brand-dark));
    color: #fff; box-shadow: 0 4px 12px rgba(40,167,69,.3);
}

/* ---------- Main ---------- */
.main { flex: 1; margin-left: 250px; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    height: 62px; background: #fff; border-bottom: 1px solid #e8ebee;
    display: flex; align-items: center; gap: 1rem; padding: 0 1.5rem;
    position: sticky; top: 0; z-index: 1030;
}
.topbar-title {
    font-size: 1.12rem; font-weight: 700; margin: 0; flex: 1; min-width: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar-right { flex-shrink: 0; }
.user-chip {
    display: inline-flex; align-items: center; gap: .55rem;
    background: var(--bg); border: 1px solid #e3e7ea; border-radius: 999px;
    padding: .3rem .8rem .3rem .35rem; font-weight: 600; color: var(--ink); font-size: .88rem;
}
.avatar {
    width: 30px; height: 30px; border-radius: 50%;
    background: linear-gradient(135deg, var(--brand), var(--brand-dark));
    color: #fff; display: grid; place-items: center; font-size: .85rem; font-weight: 700;
}
.content { padding: 1.5rem; flex: 1; }

/* ---------- User dropdown ---------- */
.user-dropdown-menu {
    min-width: 250px; padding: .5rem; margin-top: .5rem !important;
    border: 1px solid #e8ebee; border-radius: 14px;
    box-shadow: 0 16px 32px rgba(16,24,40,.14), 0 2px 6px rgba(16,24,40,.06);
}
.user-dropdown-header { display: flex; align-items: center; gap: .7rem; padding: .4rem .6rem .65rem; }
.avatar-lg { width: 42px; height: 42px; font-size: 1.05rem; flex-shrink: 0; }
.user-dropdown-info { min-width: 0; }
.user-dropdown-name { font-weight: 700; font-size: .93rem; color: var(--ink); line-height: 1.25; }
.user-dropdown-email {
    font-size: .78rem; color: var(--muted); overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap;
}
.user-dropdown-menu .dropdown-divider { margin: .35rem 0; }
.user-dropdown-menu .dropdown-item {
    border-radius: 8px; padding: .55rem .65rem; font-size: .88rem;
    font-weight: 500; display: flex; align-items: center;
}
.user-dropdown-menu .dropdown-item:hover,
.user-dropdown-menu .dropdown-item:focus { background: var(--bg); }
.user-dropdown-menu .dropdown-item.text-danger:hover,
.user-dropdown-menu .dropdown-item.text-danger:focus { background: rgba(220,53,69,.08); color: #dc3545; }

/* ---------- Cards & stats ---------- */
.card { border: 1px solid #e8ebee; border-radius: 14px; box-shadow: var(--card-shadow); overflow: hidden; }
.card-header { background: #fff; border-bottom: 1px solid #eef1f3; font-weight: 600; border-radius: 14px 14px 0 0 !important; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1rem; }
.stat-card {
    background: #fff; border: 1px solid #e8ebee; border-radius: 14px;
    padding: 1.15rem 1.25rem; box-shadow: var(--card-shadow);
    display: flex; align-items: center; gap: 1rem;
}
.stat-icon { width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center; font-size: 1.4rem; flex-shrink: 0; }
.stat-icon.green { background: rgba(40,167,69,.12); color: var(--brand-dark); }
.stat-icon.blue  { background: rgba(13,110,253,.12); color: #0d6efd; }
.stat-icon.amber { background: rgba(255,193,7,.16); color: #b8860b; }
.stat-icon.red   { background: rgba(220,53,69,.12); color: #dc3545; }
.stat-icon.violet{ background: rgba(111,66,193,.12); color: #6f42c1; }
.stat-icon.slate { background: rgba(108,117,125,.14); color: #495057; }
.stat-icon.sm { width: 34px; height: 34px; border-radius: 9px; font-size: 1rem; }
.stat-value { font-size: 1.55rem; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .5px; }

/* ---------- Dashboard KPI cards ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.kpi-card { background: #fff; border: 1px solid #e8ebee; border-radius: 14px; padding: 1.15rem 1.25rem; box-shadow: var(--card-shadow); }
.kpi-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: .6rem; }
.kpi-label { color: var(--muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
.kpi-value { font-size: 1.55rem; font-weight: 700; line-height: 1.1; }
.kpi-foot { font-size: .82rem; margin-top: .4rem; }

/* ---------- Invoice status breakdown ---------- */
.donut-total { font-size: 1.35rem; font-weight: 700; line-height: 1.1; color: var(--ink); }
.donut-label { font-size: .65rem; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.status-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .55rem; }
.status-legend li { display: flex; align-items: center; font-size: .88rem; }
.status-legend .dot { width: 9px; height: 9px; border-radius: 50%; margin-right: .55rem; flex-shrink: 0; }

/* ---------- Dashboard action-needed cards ---------- */
.action-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .75rem; }
.action-card { display: flex; align-items: center; gap: .8rem; background: #fff; border: 1px solid #e8ebee; border-radius: 12px; padding: .85rem 1rem; color: var(--ink); font-size: .9rem; }
.action-card:hover { border-color: var(--brand); background: #f7faf8; color: var(--ink); }

/* ---------- Tables ---------- */
.table { vertical-align: middle; margin: 0; }
.table > :not(caption) > * > * { padding: .7rem .9rem; }
.table thead th { font-size: .74rem; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); background: #fafbfc; border-bottom: 1px solid #eef1f3; font-weight: 700; }
.table-hover tbody tr:hover { background: #f7faf8; }
.table td a.fw-semibold { color: var(--ink); }

.badge { font-weight: 600; letter-spacing: .3px; padding: .38em .6em; }

/* Sortable column headers */
.table thead th a.sort-link {
    color: var(--muted); text-decoration: none; display: inline-flex; align-items: center; gap: .3rem;
    font: inherit; text-transform: inherit; letter-spacing: inherit; white-space: nowrap;
}
.table thead th a.sort-link:hover { color: var(--brand-dark); }
.table thead th a.sort-link i { font-size: .7rem; }

/* Filter bar */
.filter-bar { border: 1px solid #e3e7ea; }
.filter-bar .form-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .4px; }

/* Pagination footer */
.card-footer.pager {
    background: #fff; border-top: 1px solid #eef1f3;
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
    gap: .75rem 1rem; padding: .7rem 1rem; border-radius: 0 0 14px 14px;
}
.pager-info { color: var(--muted); font-size: .82rem; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.pager-controls { display: flex; align-items: center; gap: .75rem 1.25rem; flex-wrap: wrap; margin-left: auto; }
.pager-info strong { color: var(--ink); font-weight: 600; }
.pager-perpage { display: inline-flex; align-items: center; gap: .4rem; }
.pager-perpage .form-select { width: auto; padding-top: .15rem; padding-bottom: .15rem; }
.pager-goto { display: flex; align-items: center; gap: .4rem; }
.pager-goto .form-control { width: 64px; }
.pager .pagination { flex-wrap: wrap; }
.pager .page-link { color: var(--brand-dark); border-color: #e3e7ea; min-width: 34px; text-align: center; }
.pager .page-link:hover { background: #f1f7f3; color: var(--brand-darker); }
.pager .page-item.active .page-link { background: var(--brand); border-color: var(--brand); color: #fff; }
.pager .page-item.disabled .page-link { color: #aeb6bc; }

/* ---------- Buttons / brand ---------- */
.btn-brand { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn-brand:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn-outline-brand { border-color: var(--brand); color: var(--brand-dark); font-weight: 600; }
.btn-outline-brand:hover { background: var(--brand); color: #fff; }
.text-brand { color: var(--brand-dark) !important; }
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* ---------- Confirm modal ---------- */
.confirm-icon {
    width: 44px; height: 44px; margin: 0 auto; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; font-size: 19px;
}
.confirm-icon-danger { background: rgba(220,53,69,.1); color: #dc3545; }
.confirm-icon-brand { background: rgba(40,167,69,.12); color: var(--brand-dark); }
.confirm-btn-half { flex: 1 1 0; }
#confirmModal .btn-light { background: #e2e6ea; border-color: #e2e6ea; }
#confirmModal .btn-light:hover { background: #d3d9df; border-color: #d3d9df; }

/* ---------- Schedule ---------- */
.sched-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }
#scheduleCalendar .fc-event { cursor: pointer; font-size: 12px; }
#scheduleCalendar .fc-toolbar-title { font-size: 1.1rem; }

.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 .2rem rgba(40,167,69,.18); }
.form-label { font-weight: 600; font-size: .85rem; margin-bottom: .3rem; }

.section-title { font-weight: 700; font-size: 1.05rem; margin: 0; }
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty-state i { font-size: 2.5rem; opacity: .35; }

.detail-list dt { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .4px; }
.detail-list dd { margin-bottom: .85rem; font-weight: 500; }

.detail-rows dt { color: var(--muted); font-weight: 500; padding: .25rem 0; }
.detail-rows dd { font-weight: 600; padding: .25rem 0; margin-bottom: 0; }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
    background: linear-gradient(135deg, #14241b 0%, #1c7430 100%); }
.auth-card { width: 100%; max-width: 400px; background: #fff; border-radius: 18px; padding: 2.2rem; box-shadow: 0 25px 60px rgba(0,0,0,.25); }
.auth-brand { display: flex; align-items: center; gap: .7rem; justify-content: center; margin-bottom: 1.5rem; }
.login-logo { width: 120px; height: auto; display: block; }

/* ---------- CAPTCHA widget ---------- */
.captcha-img-row { display: flex; justify-content: center; align-items: center; }
.captcha-img-wrap { flex-shrink: 0; border: 1px solid #e3e7ea; border-radius: 8px; overflow: hidden; cursor: pointer; transition: opacity .2s; }
.captcha-img-wrap:hover { opacity: .85; }
.captcha-img-wrap img { display: block; height: 65px; width: auto; transition: opacity .25s; }
.captcha-input { letter-spacing: .2em; text-transform: uppercase; }
.captcha-input::placeholder { letter-spacing: normal; text-transform: none; }

/* ---------- Print docs ---------- */
.doc { max-width: 820px; margin: 0 auto; background: #fff; }
@media print {
    .no-print { display: none !important; }
    body { background: #fff; }
    .doc { box-shadow: none; max-width: 100%; }
}

/* ---------- Responsive ---------- */
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; }

    /* Full-screen mobile menu, not a narrow drawer */
    .sidebar { width: 100vw; }
    .sidebar-brand { padding: 1.35rem 1.25rem; }
    .sidebar-close {
        margin-left: auto; width: 38px; height: 38px; border-radius: 10px;
        background: rgba(255,255,255,.06); border: none; color: #fff;
        display: flex; align-items: center; justify-content: center; font-size: 1.05rem;
        flex-shrink: 0;
    }
    .sidebar-close:hover { background: rgba(255,255,255,.12); }
    .sidebar-nav { padding: 1rem .85rem; gap: 4px; }
    .sidebar-nav .nav-link { padding: .85rem 1rem; font-size: 1rem; }
    .nav-section-label { padding: 1.15rem 1rem .4rem; }

    body.sidebar-locked { overflow: hidden; }
}
@media (max-width: 575.98px) {
    .topbar { padding: 0 1rem; gap: .65rem; }
    .content { padding: 1rem; }
    .user-chip { padding: .3rem .55rem .3rem .35rem; }
    .user-dropdown-menu { min-width: 0; width: calc(100vw - 2rem); max-width: 300px; }
}

.line-items-table input { border: 1px solid #dfe3e6; }
.line-items-table .form-control-sm { min-width: 70px; }
.drag-handle { cursor: grab; color: #b6bcc2; vertical-align: middle; }
.drag-handle:active { cursor: grabbing; }
.drag-handle:hover { color: var(--brand); }
tr.drag-ghost { opacity: .4; background: #eafaf0; }
tr.drag-chosen { background: #f7faf8; }

/* ---------- Error pages (404 / 403) ---------- */
.error-page { min-height: calc(100vh - 62px - 3rem); display: flex; align-items: center; justify-content: center; padding: 2rem 1rem; }
.error-card { background: #fff; border: 1px solid #e8ebee; border-radius: 18px; box-shadow: var(--card-shadow); max-width: 420px; width: 100%; text-align: center; padding: 3rem 2.5rem; }
.error-badge { width: 84px; height: 84px; border-radius: 50%; margin: 0 auto 1.5rem; background: rgba(108,117,125,.12); color: #495057; display: grid; place-items: center; font-size: 2.1rem; }
.error-card.is-danger .error-badge { background: rgba(220,53,69,.12); color: #dc3545; }
.error-card h2 { margin-bottom: .5rem; font-weight: 700; }
.error-card p { color: var(--muted); margin-bottom: 1.5rem; }

/* ---------- Rich text (sanitized HTML from Quill: payment instructions, terms) ---------- */
.rich-text p { margin: 0 0 6px; }
.rich-text p:last-child { margin-bottom: 0; }
.rich-text ul, .rich-text ol { margin: 0 0 6px; padding-left: 0; list-style: none; }
/* Quill 2 encodes both bullet and ordered items as <li data-list="bullet|ordered">
   inside a single <ol> — this page doesn't load Quill's own stylesheet, so the
   bullet/number marker and indent spacing have to be replicated here. */
.rich-text li[data-list] { position: relative; padding-left: 1.5em; margin: 0 0 2px; }
.rich-text li[data-list]::before { position: absolute; left: 0; }
.rich-text li[data-list="bullet"]::before { content: "\2022"; }
.rich-text li[data-list].ql-indent-1 { padding-left: 3em; }
.rich-text li[data-list].ql-indent-1::before { left: 1.5em; }
.rich-text li[data-list].ql-indent-2 { padding-left: 4.5em; }
.rich-text li[data-list].ql-indent-2::before { left: 3em; }
.rich-text li[data-list].ql-indent-3 { padding-left: 6em; }
.rich-text li[data-list].ql-indent-3::before { left: 4.5em; }
.rich-text li[data-list] { counter-reset: rt-item-1 rt-item-2 rt-item-3; }
.rich-text li[data-list].ql-indent-1 { counter-reset: rt-item-2 rt-item-3; }
.rich-text li[data-list].ql-indent-2 { counter-reset: rt-item-3; }
.rich-text li[data-list="ordered"] { counter-increment: rt-item-0; }
.rich-text li[data-list="ordered"].ql-indent-1 { counter-increment: rt-item-1; }
.rich-text li[data-list="ordered"].ql-indent-2 { counter-increment: rt-item-2; }
.rich-text li[data-list="ordered"].ql-indent-3 { counter-increment: rt-item-3; }
.rich-text li[data-list="ordered"]::before { content: counter(rt-item-0) ". "; }
.rich-text li[data-list="ordered"].ql-indent-1::before { content: counter(rt-item-1) ". "; }
.rich-text li[data-list="ordered"].ql-indent-2::before { content: counter(rt-item-2) ". "; }
.rich-text li[data-list="ordered"].ql-indent-3::before { content: counter(rt-item-3) ". "; }
.ql-toolbar.ql-snow { border-color: #dfe3e6; border-radius: 8px 8px 0 0; background: #fafbfc; }
.ql-container.ql-snow { border-color: #dfe3e6; border-radius: 0 0 8px 8px; font-size: .92rem; }
.ql-snow .ql-toolbar button:hover, .ql-snow .ql-toolbar button.ql-active { color: var(--brand-dark); }
.ql-snow .ql-toolbar button:hover .ql-stroke, .ql-snow .ql-toolbar button.ql-active .ql-stroke { stroke: var(--brand-dark); }
.ql-snow .ql-toolbar button.ql-active .ql-fill { fill: var(--brand-dark); }

/* ---------- Product thumbnails ---------- */
.product-thumb {
    display: inline-block; width: 44px; height: 44px; border-radius: 9px;
    overflow: hidden; border: 1px solid #e8ebee; background: #fafbfc; vertical-align: middle;
}
.product-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.product-thumb-fallback { width: 100%; height: 100%; display: grid; place-items: center; color: #b6bcc2; }
.product-thumb-lg { width: 88px; height: 88px; border-radius: 12px; }
.product-thumb-lg .product-thumb-fallback i { font-size: 1.6rem; }
