
* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: #f3f5f8;
    color: #172033;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    overflow-x: hidden;
}

nav {
    min-height: 64px;
    background: #10233f;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 0 4%;
    flex-wrap: wrap;
}

nav a {
    color: #fff;
    text-decoration: none;
    font-weight: 600;
}

nav a:first-child {
    font-size: 18px;
    font-weight: 700;
}

nav span {
    flex: 1;
}

main {
    width: 100%;
    max-width: 1240px;
    margin: 30px auto;
    padding: 0 20px;
}

h1, h2, h3 {
    overflow-wrap: anywhere;
}

.card {
    background: #fff;
    border: 1px solid #dfe5ee;
    border-radius: 12px;
    padding: 22px;
    margin-bottom: 22px;
    box-shadow: 0 5px 18px rgba(16, 35, 63, 0.06);
    overflow: hidden;
}

.narrow {
    max-width: 430px;
    margin: 70px auto;
}

.grid {
    display: grid;
    grid-template-columns: 420px minmax(0, 1fr);
    gap: 22px;
}

.two,
.three {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.three {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

label {
    display: block;
    margin-bottom: 14px;
    font-weight: 600;
}

input,
textarea,
select {
    width: 100%;
    max-width: 100%;
    padding: 11px 12px;
    border: 1px solid #cbd4df;
    border-radius: 7px;
    margin-top: 5px;
    font: inherit;
    background: #fff;
}

textarea {
    min-height: 75px;
    resize: vertical;
}

button,
.button {
    display: inline-block;
    background: #1554a3;
    color: #fff;
    border: 0;
    border-radius: 7px;
    padding: 10px 15px;
    text-decoration: none;
    cursor: pointer;
    font-weight: 700;
    text-align: center;
}

.secondary {
    background: #e9eef5;
    color: #172033;
}

.title-row,
.actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
}

.title-row form,
.actions form {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.table-scroll,
.card {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    text-align: left;
    padding: 11px;
    border-bottom: 1px solid #e7ebf1;
    vertical-align: top;
}

th {
    font-size: 12px;
    text-transform: uppercase;
    color: #667085;
}

.right,
.numeric {
    text-align: right;
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
}

.stats strong {
    display: block;
    font-size: 24px;
    margin-top: 8px;
    overflow-wrap: anywhere;
}

.error {
    color: #b42318;
}

.invoice-toolbar {
    max-width: 1000px;
    margin: 0 auto 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.status-form {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.status-form select {
    width: auto;
    min-width: 150px;
    margin: 0;
}

.invoice-document {
    width: 100%;
    max-width: 1000px;
    min-height: 1120px;
    margin: 0 auto 40px;
    padding: 52px 58px 38px;
    background: #fff;
    border: 1px solid #e0e5ec;
    box-shadow: 0 14px 35px rgba(15, 35, 65, 0.10);
}

.invoice-company-header {
    text-align: center;
    padding-bottom: 30px;
}

.invoice-company-header h1 {
    margin: 0;
    color: #10233f;
    font-size: 38px;
    letter-spacing: 0.4px;
}

.company-subtitle {
    margin-top: 8px;
    color: #1554a3;
    font-size: 14px;
    letter-spacing: 4px;
}

.company-details {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px 24px;
    margin-top: 25px;
    color: #475467;
    font-size: 13px;
}

.invoice-top-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 60px;
    margin-top: 22px;
    align-items: start;
}

.invoice-meta h2 {
    margin: 0 0 25px;
    font-size: 25px;
    color: #101828;
}

.invoice-meta dl {
    margin: 0;
}

.invoice-meta dl div {
    display: grid;
    grid-template-columns: 175px minmax(0, 1fr);
    gap: 12px;
    margin: 9px 0;
}

.invoice-meta dt,
.invoice-meta dd {
    margin: 0;
}

.invoice-status {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 6px;
    background: #eaf2ff;
    color: #1554a3;
    font-size: 13px;
    font-weight: 700;
}

.status-paid {
    background: #e9f8ef;
    color: #187a3d;
}

.status-overdue {
    background: #fff0ed;
    color: #b42318;
}

.status-cancelled {
    background: #f2f4f7;
    color: #667085;
}

.buyer-card {
    border: 1px solid #d7dee8;
    border-radius: 8px;
    padding: 22px 24px;
    min-height: 185px;
}

.buyer-label {
    color: #1554a3;
    font-size: 13px;
    font-weight: 700;
}

.buyer-card h3 {
    margin: 12px 0 6px;
    font-size: 20px;
}

.buyer-card p {
    margin: 5px 0;
    color: #344054;
}

.invoice-items-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 35px;
}

.invoice-items-table thead th {
    background: #f1f5fa;
    color: #164b91;
    padding: 16px 13px;
    border-top: 1px solid #b9cbe0;
    border-bottom: 1px solid #b9cbe0;
}

.invoice-items-table tbody td {
    padding: 18px 13px;
    color: #1d2939;
}

.number-col {
    width: 64px;
    text-align: center;
}

.invoice-summary {
    width: 46%;
    min-width: 390px;
    margin: 30px 0 0 auto;
}

.invoice-summary > div {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    padding: 10px 12px;
    border-bottom: 1px solid #dce3ec;
}

.invoice-summary .summary-total {
    margin-top: 8px;
    padding-top: 18px;
    padding-bottom: 18px;
    border-top: 2px solid #b8c8dc;
    color: #1554a3;
    font-size: 18px;
}

.invoice-notes {
    margin-top: 55px;
    color: #344054;
}

.invoice-footer {
    margin-top: 150px;
    padding-top: 18px;
    text-align: center;
    border-top: 2px solid #1554a3;
}

.invoice-footer strong {
    color: #1554a3;
}

.invoice-footer p {
    margin: 6px 0 0;
    font-size: 13px;
}

/* Tablet */
@media (max-width: 900px) {
    .grid {
        grid-template-columns: 1fr;
    }

    .stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .invoice-top-grid {
        gap: 30px;
    }

    .invoice-document {
        padding: 38px 30px;
    }
}

/* Phone */
@media (max-width: 640px) {
    body {
        font-size: 14px;
    }

    nav {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0;
        padding: 10px 14px;
    }

    nav span {
        display: none;
    }

    nav a {
        padding: 10px 8px;
        border-bottom: 1px solid rgba(255,255,255,0.12);
        font-size: 14px;
    }

    nav a:first-child {
        grid-column: 1 / -1;
        font-size: 17px;
    }

    main {
        margin: 16px auto;
        padding: 0 10px;
    }

    .card {
        padding: 16px;
        border-radius: 9px;
    }

    .narrow {
        margin: 25px auto;
    }

    .two,
    .three,
    .stats,
    .invoice-top-grid {
        grid-template-columns: 1fr;
    }

    .stats {
        gap: 10px;
    }

    .stats strong {
        font-size: 20px;
    }

    .title-row,
    .actions,
    .invoice-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .title-row form,
    .actions form,
    .status-form {
        width: 100%;
        align-items: stretch;
        flex-direction: column;
    }

    .status-form select,
    .status-form button,
    .invoice-toolbar .button,
    .title-row .button {
        width: 100%;
    }

    button,
    .button {
        min-height: 44px;
    }

    table {
        min-width: 680px;
    }

    .invoice-document {
        width: 100%;
        min-height: auto;
        padding: 24px 14px;
        margin-bottom: 20px;
        border-radius: 0;
        box-shadow: none;
    }

    .invoice-company-header {
        padding-bottom: 18px;
    }

    .invoice-company-header h1 {
        font-size: 25px;
        line-height: 1.15;
    }

    .company-subtitle {
        font-size: 11px;
        letter-spacing: 1.8px;
    }

    .company-details {
        display: block;
        margin-top: 18px;
        font-size: 12px;
    }

    .company-details span {
        display: block;
        margin: 5px 0;
    }

    .invoice-top-grid {
        gap: 20px;
    }

    .invoice-meta h2 {
        font-size: 22px;
        margin-bottom: 15px;
    }

    .invoice-meta dl div {
        grid-template-columns: 1fr;
        gap: 2px;
        margin: 12px 0;
    }

    .invoice-meta dt {
        color: #667085;
        font-size: 12px;
    }

    .buyer-card {
        min-height: 0;
        padding: 16px;
    }

    .invoice-items-table {
        min-width: 650px;
        margin-top: 24px;
    }

    .invoice-items-table th,
    .invoice-items-table td {
        padding: 12px 10px;
    }

    .invoice-summary {
        width: 100%;
        min-width: 0;
        margin-top: 22px;
    }

    .invoice-summary > div {
        padding: 10px 4px;
        gap: 12px;
    }

    .invoice-summary .summary-total {
        font-size: 16px;
    }

    .invoice-notes {
        margin-top: 30px;
    }

    .invoice-footer {
        margin-top: 60px;
    }
}

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

    body {
        background: #fff;
    }

    nav,
    .no-print {
        display: none !important;
    }

    main {
        max-width: none;
        margin: 0;
        padding: 0;
    }

    .invoice-document {
        width: 100%;
        max-width: none;
        min-height: 0;
        margin: 0;
        padding: 8mm;
        border: 0;
        box-shadow: none;
    }

    .invoice-footer {
        margin-top: 70px;
    }

    .invoice-items-table tr {
        page-break-inside: avoid;
    }
}
