:root {
    --navy: #0d1b3d;
    --navy-2: #13254f;
    --bg: #f3f5f9;
    --card: #ffffff;
    --accent: #198754;
    --text: #1d2433;
}
* { box-sizing: border-box; }
body { font-family: 'Plus Jakarta Sans', sans-serif; color: var(--text); background: var(--bg); }

.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: 260px; background: linear-gradient(180deg, var(--navy), var(--navy-2)); color: #fff; position: fixed; top: 0; left: 0; bottom: 0; z-index: 1000; overflow-y: auto; transition: transform .25s ease; }
.brand h5 { font-weight: 800; }
.brand small { opacity: 0.8; }
.menu-link { display: block; color: rgba(255,255,255,.9); text-decoration: none; padding: .65rem .85rem; border-radius: .7rem; margin: .2rem .35rem; font-weight: 600; }
.menu-link:hover, .menu-link.active { background: rgba(255,255,255,.14); color: #fff; }
.menu-section { color: rgba(255,255,255,.7); font-size: .75rem; text-transform: uppercase; margin: 1rem .7rem .3rem; letter-spacing: .08em; }

.main-wrap { margin-left: 260px; width: calc(100% - 260px); }
.topbar { background: var(--navy); display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; z-index: 900; box-shadow: 0 6px 18px rgba(0,0,0,.1); }
.content-area { min-height: calc(100vh - 58px); }
.stat-card { background: #fff; border-radius: 1rem; box-shadow: 0 6px 18px rgba(20,34,67,.08); padding: 1rem; height: 100%; }
.stat-card span { color: #6b7280; font-size: .87rem; }
.stat-card h4 { margin-top: .45rem; font-weight: 800; color: var(--navy); }

.login-bg { min-height: 100vh; background: radial-gradient(circle at top right, #e4ecff 0, #f4f7ff 45%, #f7f8fc 100%); }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { max-width: 520px; width: 100%; }

.table td, .table th { vertical-align: middle; }
.card { border-radius: 1rem !important; }

.pagination-wrap .pagination { margin: .75rem 0 0; }

.invoice-sheet, .challan-sheet {
    background: #fff;
    border: 1px solid #111;
    width: 210mm;
    min-height: 297mm;
    margin: 0 auto;
    padding: 8mm;
    color: #000;
    font-family: Arial, Helvetica, sans-serif;
}
.inv-grid-2, .ch-grid-top { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.inv-box, .ch-box, .sign-box { border: 1px solid #111; padding: 6px; }
.inv-box h1 { font-size: 44px; margin: 0 0 3px; font-weight: 800; letter-spacing: .2px; }
.inv-box h2 { font-size: 28px; margin: 0 0 6px; font-weight: 800; }
.inv-box p { margin: 1px 0; font-size: 19px; }
.section-head { border-bottom: 1px solid #111; margin: -6px -6px 6px; padding: 3px 6px; font-weight: 700; font-size: 13px; }
.detail-row { display: flex; gap: 8px; font-size: 19px; margin: 2px 0; }
.detail-row span { width: 130px; font-weight: 700; }

.inv-items { width: 100%; border-collapse: collapse; font-size: 18px; border: 1px solid #111; }
.inv-items th, .inv-items td { border: 1px solid #111; padding: 5px; vertical-align: top; }
.inv-items th { font-size: 12px; text-transform: uppercase; font-weight: 800; }
.tall-row td { height: 230px; }
.paybox p, .notesbox p, .signbox p { font-size: 15px; }
.duebox { text-align: center; display: grid; }
.duebox h3 { align-self: center; font-size: 36px; margin: 0; font-weight: 800; }
.signature-row { display: flex; align-items: center; gap: 18px; margin-top: 8px; }
.scribble { font-family: 'Caveat', cursive; font-size: 88px; line-height: 1; }
.stamp { border: 2px solid #d36f80; border-radius: 50%; color: #d36f80; font-weight: 800; padding: 14px 18px; font-size: 22px; }

.ch-box h2 { font-size: 48px; margin: 0 0 3px; font-weight: 800; }
.ch-box p { font-size: 19px; margin: 2px 0; }
.ch-box .line { display: flex; font-size: 20px; gap: 8px; margin: 2px 0; }
.ch-box .line span { width: 130px; font-weight: 700; }
.ch-sub-title { border-top: 1px solid #111; margin: 6px -6px 0; padding: 6px; font-weight: 700; font-size: 19px; min-height: 38px; }
.ch-item-head { border: 1px solid #111; margin-top: 8px; padding: 6px; font-weight: 700; font-size: 18px; }
.ch-item-grid { display: grid; grid-template-columns: 1fr 1.1fr 1fr; border: 1px solid #111; border-top: 0; min-height: 350px; }
.ch-item-grid .cell { border-right: 1px solid #111; padding: 12px; font-size: 34px; display: flex; justify-content: center; align-items: center; text-align: center; }
.ch-item-grid .cell:last-child { border-right: 0; }
.ch-item-grid .dates { flex-direction: column; font-size: 25px; gap: 6px; }
.ch-item-grid .qty { display: block; text-align: left; font-size: 21px; }
.ch-item-grid .qty p { font-size: 26px; }
.handwriting { font-family: 'Caveat', cursive; font-size: 62px; margin-top: 22px; }
.ch-sign-grid { display: grid; grid-template-columns: 1.2fr 1fr; border: 1px solid #111; border-top: 0; }
.sign-box { border: 0; border-right: 1px solid #111; min-height: 110px; }
.sign-box:last-child { border-right: 0; }
.sign-box .title { font-weight: 700; border-bottom: 1px solid #111; margin: -6px -6px 8px; padding: 4px 6px; }
.receiver-sign { font-family: 'Caveat', cursive; font-size: 56px; }
.stamp-area { border: 1px dashed #4f7fd9; color: #4f7fd9; padding: 8px; text-align: center; font-weight: 700; margin-top: 6px; }

@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-wrap { margin-left: 0; width: 100%; }
    .inv-grid-2, .ch-grid-top, .ch-sign-grid { grid-template-columns: 1fr; }
    .ch-item-grid { grid-template-columns: 1fr; }
}

@media print {
    @page {
        size: A4 portrait;
        margin: 4mm;
    }

    html, body {
        background: #fff !important;
        width: 210mm !important;
        height: 297mm !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: hidden !important;
    }

    .no-print, .topbar, .sidebar, .alert, .btn { display: none !important; }
    .app-shell, .main-wrap, .content-area {
        display: block !important;
        margin: 0 !important;
        width: 100% !important;
        min-height: auto !important;
        padding: 0 !important;
        overflow: visible !important;
    }

    .invoice-sheet, .challan-sheet {
        width: 202mm !important;
        height: 288mm !important;
        min-height: 288mm !important;
        max-height: 288mm !important;
        box-shadow: none;
        margin: 0 auto !important;
        padding: 3mm !important;
        border: 1px solid #111;
        page-break-inside: avoid;
        page-break-after: avoid;
        overflow: hidden !important;
    }

    .invoice-sheet,
    .challan-sheet,
    .invoice-sheet *:not(.handwriting):not(.scribble):not(.receiver-sign),
    .challan-sheet *:not(.handwriting):not(.scribble):not(.receiver-sign) {
        font-family: Arial, Helvetica, sans-serif !important;
    }

    .inv-grid-2, .ch-grid-top, .ch-sign-grid {
        gap: 4px !important;
        page-break-inside: avoid;
    }

    .inv-box, .ch-box, .sign-box {
        padding: 3px !important;
        page-break-inside: avoid;
    }

    .inv-box h1 { font-size: 18px !important; margin-bottom: 1px !important; }
    .inv-box h2 { font-size: 14px !important; margin-bottom: 1px !important; }
    .inv-box p { font-size: 10px !important; margin: 0 !important; }
    .detail-row { font-size: 10px !important; margin: 0 !important; }
    .detail-row span { width: 62px !important; }
    .section-head { font-size: 10px !important; padding: 2px 4px !important; margin: -4px -4px 4px !important; }

    .inv-items { font-size: 9px !important; margin-top: 4px !important; }
    .inv-items th, .inv-items td { padding: 2px !important; line-height: 1.15 !important; }
    .inv-items th { font-size: 8px !important; }
    .tall-row td { height: 22px !important; }
    .paybox p, .notesbox p, .signbox p { font-size: 9px !important; margin: 0 !important; line-height: 1.2 !important; }
    .duebox h3 { font-size: 18px !important; }
    .scribble { font-size: 36px !important; }
    .stamp { font-size: 12px !important; padding: 8px 10px !important; border-width: 1px !important; }

    .ch-box h2 { font-size: 20px !important; margin-bottom: 1px !important; }
    .ch-box p { font-size: 10px !important; margin: 0 !important; line-height: 1.2 !important; }
    .ch-box .line { font-size: 10px !important; margin: 0 !important; gap: 5px !important; line-height: 1.2 !important; }
    .ch-box .line span { width: 62px !important; }
    .ch-sub-title { font-size: 9px !important; min-height: 16px !important; padding: 3px !important; margin: 3px -3px 0 !important; }
    .ch-item-head { font-size: 9px !important; margin-top: 3px !important; padding: 3px !important; }
    .ch-item-grid { min-height: 98px !important; max-height: 118px !important; }
    .ch-item-grid .cell { padding: 4px !important; font-size: 10px !important; line-height: 1.15 !important; }
    .ch-item-grid .dates { font-size: 9px !important; gap: 1px !important; }
    .ch-item-grid .qty { font-size: 9px !important; }
    .ch-item-grid .qty p { font-size: 9px !important; margin: 0 0 1px !important; line-height: 1.15 !important; }
    .handwriting { font-size: 24px !important; margin-top: 4px !important; line-height: 1 !important; }
    .receiver-sign { font-size: 28px !important; }
    .stamp-area { font-size: 8px !important; padding: 3px !important; margin-top: 2px !important; }
    .signature-row { margin-top: 2px !important; gap: 6px !important; }
    .sign-box .title { margin: -3px -3px 3px !important; padding: 2px 3px !important; font-size: 9px !important; }
    .sign-box { min-height: 56px !important; }

    .invoice-sheet, .challan-sheet, .inv-grid-2, .ch-grid-top, .ch-item-grid, .ch-sign-grid, .inv-items {
        break-inside: avoid-page;
    }
}
