* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: #eef2f6;
    font-family: Arial, Helvetica, sans-serif;
    color: #111;
}

.topbar {
    background: #111827;
    color: white;
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.topbar h1 {
    margin: 0;
    font-size: 22px;
}

.container {
    max-width: 1200px;
    margin: 24px auto;
    padding: 0 16px;
}

.card {
    background: white;
    border-radius: 16px;
    box-shadow: 0 8px 22px rgba(15,23,42,.08);
    padding: 20px;
    margin-bottom: 18px;
}

.btn {
    display: inline-block;
    border: 0;
    border-radius: 9px;
    padding: 10px 15px;
    text-decoration: none;
    font-weight: 700;
    cursor: pointer;
    background: #e5e7eb;
    color: #111;
    margin: 3px;
}

.btn-primary {
    background: #0f172a;
    color: white;
}

.btn-green {
    background: #15803d;
    color: white;
}

.btn-red {
    background: #b91c1c;
    color: white;
}

.btn-blue {
    background: #1d4ed8;
    color: white;
}

.grid {
    display: grid;
    grid-template-columns: repeat(2,minmax(0,1fr));
    gap: 14px;
}

.field label {
    display: block;
    font-weight: 700;
    margin-bottom: 6px;
    color: #374151;
}

.field input,
.field textarea {
    width: 100%;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    padding: 10px;
    font-size: 15px;
}

.field textarea {
    min-height: 78px;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    border-bottom: 1px solid #e5e7eb;
    padding: 10px;
    text-align: left;
}

.table th {
    background: #f9fafb;
}

.item-row {
    display: grid;
    grid-template-columns: 60px 120px 1.2fr 1.5fr 110px 90px 90px;
    gap: 8px;
    align-items: end;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 10px;
    margin-bottom: 10px;
    background: #fafafa;
}

.item-row input,
.item-row textarea {
    width: 100%;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 8px;
}

.item-row textarea {
    min-height: 40px;
}

.small-label {
    font-size: 12px;
    font-weight: 700;
    color: #555;
    margin-bottom: 3px;
}

.actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.totalbox {
    text-align: right;
    font-size: 18px;
    font-weight: 800;
}

.alert {
    padding: 12px;
    border-radius: 10px;
    background: #dcfce7;
    color: #14532d;
    margin-bottom: 15px;
}

.muted {
    color: #6b7280;
}

.nowrap {
    white-space: nowrap;
}

/* =========================
   BIG LOGO / INVOICE HEADER
========================= */

.top-hero {
    height: 220px !important;
}

.logo-box {
    position: absolute !important;
    left: 30px !important;
    top: 18px !important;
    width: 170px !important;
    height: 170px !important;
    background: white !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    overflow: hidden !important;
}

.logo-box img {
    width: 160px !important;
    height: 160px !important;
    max-width: none !important;
    max-height: none !important;
    object-fit: contain !important;
    transform: scale(1.45) !important;
}

.logo-fallback {
    font-size: 68px !important;
    font-weight: 900 !important;
    color: #0aa5de !important;
    font-style: italic !important;
}

/* =========================
   INVOICE A4 DESIGN
========================= */

.invoice-page {
    width: 210mm;
    min-height: 297mm;
    margin: 20px auto;
    padding: 10mm;
    background: #fff;
    box-shadow: 0 0 12px rgba(0,0,0,.15);
    overflow: visible;
}

.invoice-header,
.invoice-info,
.invoice-footer,
.summary-box,
.totalbox {
    page-break-inside: avoid;
    break-inside: avoid;
}

.items-table,
.invoice-table,
.table {
    width: 100%;
    border-collapse: collapse;
    page-break-inside: auto;
}

.items-table thead,
.invoice-table thead,
.table thead {
    display: table-header-group;
}

.items-table tfoot,
.invoice-table tfoot,
.table tfoot {
    display: table-footer-group;
}

.items-table tr,
.invoice-table tr,
.table tr {
    page-break-inside: avoid;
    break-inside: avoid;
}

.items-table th,
.items-table td,
.invoice-table th,
.invoice-table td {
    border: 1px solid #d1d5db;
    padding: 5px;
    font-size: 11px;
    vertical-align: middle;
}

.items-table th,
.invoice-table th {
    background: #f3f4f6;
    font-weight: 700;
}

.product-img,
.prod-img {
    width: 55px;
    height: 55px;
    max-width: 55px;
    max-height: 55px;
    object-fit: contain;
    display: block;
    margin: auto;
}

/* =========================
   RESPONSIVE
========================= */

@media(max-width:900px) {
    .grid {
        grid-template-columns: 1fr;
    }

    .item-row {
        grid-template-columns: 1fr;
    }

    .table {
        font-size: 13px;
    }

    .invoice-page {
        width: 100%;
        min-height: auto;
        margin: 10px auto;
        padding: 12px;
    }
}

/* =========================
   PRINT A4 SPLIT
========================= */

@page {
    size: A4;
    margin: 10mm;
}

@media print {
    html,
    body {
        width: 210mm;
        margin: 0;
        padding: 0;
        background: #fff !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .topbar,
    .actions,
    .btn,
    button,
    .no-print {
        display: none !important;
    }

    .container {
        width: 100%;
        max-width: none;
        margin: 0;
        padding: 0;
    }

    .card {
        box-shadow: none !important;
        border-radius: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
        background: transparent !important;
    }

    .invoice-page {
        width: 190mm;
        min-height: auto;
        margin: 0 auto;
        padding: 0;
        box-shadow: none !important;
        background: #fff !important;
        overflow: visible !important;
        page-break-after: auto;
    }

    table {
        width: 100%;
        border-collapse: collapse;
        page-break-inside: auto;
    }

    thead {
        display: table-header-group;
    }

    tfoot {
        display: table-footer-group;
    }

    tr {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    td,
    th {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    .invoice-header,
    .invoice-info,
    .summary-box,
    .invoice-footer,
    .totalbox {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    .items-table th,
    .items-table td,
    .invoice-table th,
    .invoice-table td,
    .table th,
    .table td {
        font-size: 10.5px;
        padding: 4px;
    }

    .product-img,
    .prod-img {
        width: 45px;
        height: 45px;
        max-width: 45px;
        max-height: 45px;
        object-fit: contain;
    }

    .top-hero {
        height: 220px !important;
    }

    .logo-box {
        left: 30px !important;
        top: 18px !important;
        width: 170px !important;
        height: 170px !important;
    }

    .logo-box img {
        width: 160px !important;
        height: 160px !important;
        max-width: none !important;
        max-height: none !important;
        transform: scale(1.45) !important;
        object-fit: contain !important;
    }

    .logo-fallback {
        font-size: 68px !important;
    }

    a {
        color: #000;
        text-decoration: none;
    }
}