:root {
    --ink: #111;
    --muted: #666;
    --line: #e6e6e6;
    --panel: #f6f6f6;
    --header: #3c3c3c;
    --paper: #fff;
    --accent: #00bcd4;
    --accent-deep: #0f6b78;
    --accent-soft: #eef9fb;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: #f0f0f0;
    font-family: "Segoe UI", Arial, sans-serif;
    color: var(--ink);
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
}

.page {
    width: 820px;
    margin: 24px auto;
    background: var(--paper);
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.12);
    padding: 42px 46px;
    position: relative;
    min-height: auto;
}

.top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 24px;
}

.signature {
    font-family: "Segoe Script", cursive;
    font-size: 34px;
    font-weight: 900;
    color: #1a1a1a;
}

.tagline {
    font-size: 10px;
    color: #bbb;
    border-top: 1px solid var(--line);
    margin-top: 8px;
    padding-top: 6px;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.invoice-title {
    font-size: 32px;
    font-weight: 800;
    text-transform: uppercase;
}

.vendor {
    margin-top: 10px;
    font-size: 12px;
    color: var(--muted);
    text-align: right;
    line-height: 1.4;
}

.vendor-name {
    font-weight: 700;
    color: #000;
}

.mid {
    margin-top: 30px;
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 24px;
}

.section-label {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    color: var(--ink);
    margin-bottom: 8px;
}

.card {
    background: #fafafa !important;
    border: 1px solid var(--line);
    padding: 12px 14px;
}

.line-input {
    width: 100%;
    border: 0;
    background: transparent;
    padding: 4px 0;
    font-size: 12px;
    outline: none;
}

.line-input.strong {
    font-weight: 800;
    color: #000;
}

.meta-row {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    padding: 4px 0;
}

.meta-input {
    border: 0;
    background: transparent;
    text-align: right;
    width: 140px;
    font-size: 12px;
    outline: none;
}

.meta-highlight {
    background: var(--panel) !important;
    padding: 12px;
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
    font-weight: 800;
    border: 1px solid var(--line);
}

.items {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin-top: 20px;
}

th {
    background: var(--header) !important;
    color: #fff !important;
    padding: 10px;
    text-align: left;
}

td {
    border-bottom: 1px solid var(--line);
    padding: 12px 10px;
    vertical-align: top;
}

.r { text-align: right; }

.item-title-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
}

.item-title {
    font-weight: 800;
    margin-bottom: 4px;
}

.item-desc {
    color: var(--muted);
    font-size: 11px;
    line-height: 1.4;
}

.item-actions {
    display: flex;
    gap: 8px;
}

.bottom {
    margin-top: 40px;
    display: flex;
    justify-content: flex-end;
}

.totals-box {
    width: 340px;
    border: 1px solid var(--line);
    background: #fafafa !important;
    padding: 14px;
}

.tot-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 13px;
    align-items: center;
}

.tot-label-group {
    display: flex;
    gap: 6px;
    font-weight: 700;
    color: var(--ink);
}

.tot-strong {
    border-top: 2px solid var(--line);
    margin-top: 10px;
    padding-top: 10px;
    font-weight: 800;
    font-size: 16px;
}

.no-print { display: block; }

.mode-switcher {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 15px;
}

.btn-mode {
    background: var(--accent);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    font-weight: 800;
    cursor: pointer;
}

#BtnToggleProfile {
    background: #1f8f5f;
}

.controls {
    margin-top: 20px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

button {
    padding: 8px 16px;
    font-weight: 700;
    cursor: pointer;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 10px;
    transition: transform 0.12s ease, box-shadow 0.12s ease, background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

button:hover,
button:focus-visible,
button:active {
    transform: scale(1.05);
    box-shadow: 0 10px 18px rgba(0, 0, 0, 0.12);
}

button:not(.btn-mode):not(#BtnFinishDesc):hover,
button:not(.btn-mode):not(#BtnFinishDesc):focus-visible,
button:not(.btn-mode):not(#BtnFinishDesc):active {
    background: #fff;
    border-color: var(--line);
    color: inherit;
}

.btn-mode:hover,
.btn-mode:focus-visible,
.btn-mode:active {
    background: var(--accent);
    color: #fff;
    border: none;
}

#BtnToggleProfile:hover,
#BtnToggleProfile:focus-visible,
#BtnToggleProfile:active {
    background: #1f8f5f;
}

.editor {
    margin-top: 20px;
    background: linear-gradient(180deg, #ffffff 0%, #fbfefe 100%);
    border: 1px solid rgba(15, 107, 120, 0.18);
    border-radius: 18px;
    padding: 22px;
    box-shadow: 0 16px 32px rgba(15, 107, 120, 0.08);
}

.editor h3 {
    margin: 0 0 18px;
    font-size: 18px;
    letter-spacing: 0.02em;
}

.editor-grid {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(180px, 0.9fr);
    gap: 16px 18px;
    align-items: start;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.field-main { min-width: 0; }

.field-side {
    background: var(--accent-soft);
    border: 1px solid rgba(15, 107, 120, 0.14);
    border-radius: 14px;
    padding: 12px;
}

.field-label {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent-deep);
}

.input,
.textarea {
    width: 100%;
    border: 1px solid #d7e6e8;
    background: #fff;
    border-radius: 12px;
    padding: 12px 14px;
    font: inherit;
    color: var(--ink);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
    outline: none;
}

.input { min-height: 46px; }

.input-compact {
    text-align: right;
    font-weight: 700;
}

.textarea {
    min-height: 118px;
    resize: vertical;
    line-height: 1.45;
}

.input:focus,
.textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(0, 188, 212, 0.12);
}

.editor-actions {
    margin-top: 18px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

#BtnFinishDesc {
    background: var(--accent-deep);
    border-color: var(--accent-deep);
    color: #fff;
}

#BtnFinishDesc:hover {
    background: var(--accent-deep);
    border-color: var(--accent-deep);
}

#BtnFinishDesc:focus-visible,
#BtnFinishDesc:active {
    background: var(--accent-deep);
    border-color: var(--accent-deep);
}

@media print {
    @page {
        size: letter portrait;
        margin: 0.35in;
    }

    body { background: white !important; }

    .page {
        margin: 0;
        box-shadow: none;
        width: 100%;
        max-width: none;
        padding: 0;
        min-height: auto !important;
        height: auto !important;
    }

    .top {
        display: flex !important;
        justify-content: space-between;
        align-items: flex-start;
        gap: 24px;
    }

    .mid {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) 340px !important;
        gap: 24px;
        align-items: start;
    }

    .bottom {
        display: flex !important;
        justify-content: flex-end;
    }

    .table-wrap,
    .billto,
    .meta,
    .totals-box,
    tr,
    td {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    thead {
        display: table-header-group;
    }

    tfoot {
        display: table-footer-group;
    }

    .no-print,
    .mode-switcher,
    .controls,
    .editor,
    .item-actions {
        display: none !important;
    }

    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .card,
    .meta-highlight,
    .totals-box {
        background-color: #fafafa !important;
    }

    th {
        background-color: #3c3c3c !important;
        color: #fff !important;
    }

    .card,
    .meta-highlight,
    .totals-box,
    th,
    .btn-mode {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}

@media screen and (max-width: 860px) {
    .page {
        width: auto;
        margin: 0;
        padding: 24px 18px 32px;
    }

    .top {
        display: grid;
        gap: 18px;
    }

    .mid,
    .editor-grid {
        grid-template-columns: 1fr;
    }

    .vendor {
        text-align: left;
    }

    .field-side {
        padding: 0;
        background: transparent;
        border: 0;
        border-radius: 0;
    }

    .controls,
    .editor-actions {
        justify-content: stretch;
        flex-direction: column;
    }

    button {
        width: 100%;
    }
}
