.swal2-container { z-index: 9999 !important; }

/* ── Invoice Preview Overlay ── */
.invoice-overlay {
    position: fixed;
    inset: 0;
    z-index: 9000;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
}

.invoice-overlay[hidden] { display: none; }

.invoice-overlay__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.7rem 1.25rem;
    background: #111827;
    gap: 1rem;
    flex-shrink: 0;
}

.overlay-btn {
    border: none;
    border-radius: 0.55rem;
    padding: 0.55rem 1.1rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.overlay-btn:hover { opacity: 0.82; }
.overlay-btn--back     { background: #4b5563; color: #fff; }
.overlay-btn--download { background: #284b63; color: #fff; }

.invoice-overlay__frame {
    flex: 1;
    border: none;
    width: 100%;
    background: #f3f4f6;
}

/* ── Shipping Area Search ── */
#modal-invoice-preview {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    margin: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    overflow-y: auto !important;
    z-index: 10500 !important;
}

#modal-invoice-preview.fade:not(.show) {
    display: none !important;
}

#modal-invoice-preview .modal-dialog {
    position: relative !important;
    margin: auto !important;
    transform: none !important;
    width: calc(85vh * 0.707);
    max-width: 92vw;
    max-height: 85vh;
}

#modal-invoice-preview .modal-content {
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#modal-invoice-preview .modal-header {
    padding: 1.25rem 1.5rem;
}

#modal-invoice-preview .modal-footer {
    padding: 1rem 1.5rem;
}

#modal-invoice-preview .modal-body {
    padding: 1rem;
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
    background: #f1f5f9;
}

#modal-invoice-preview .modal-body iframe {
    width: 100%;
    height: 0;
    border: none;
    display: block;
    background: #fff;
    border-radius: .5rem;
    box-shadow: 0 2px 16px rgba(0, 0, 0, .10);
}

.inv-area-search-wrap {
    position: relative;
}

.inv-area-search-wrap input {
    width: 100%;
    border: 1px solid #c8d2dc;
    border-radius: 0.75rem;
    padding: 0.85rem 0.95rem;
    font-size: 0.96rem;
    color: #1f2f3d;
    background: #fff;
    outline: none;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.inv-area-search-wrap input:focus {
    border-color: #284b63;
    box-shadow: 0 0 0 3px rgba(40, 75, 99, 0.12);
}

.inv-area-results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 200;
    max-height: 260px;
    overflow-y: auto;
    padding: 6px;
    border: 1px solid #d8e0e8;
    border-radius: 0.85rem;
    background: #fff;
    box-shadow: 0 12px 32px rgba(14, 34, 56, 0.14);
}

.inv-area-results[hidden] { display: none !important; }

.inv-area-result {
    width: 100%;
    padding: 10px 12px;
    border: 0;
    border-radius: 0.6rem;
    background: transparent;
    color: #1f2f3d;
    text-align: left;
    cursor: pointer;
    transition: background 0.12s;
}

.inv-area-result:hover { background: rgba(40, 75, 99, 0.07); }

.inv-area-result strong {
    display: block;
    font-size: 0.9rem;
    line-height: 1.4;
}

.inv-area-result span {
    display: block;
    margin-top: 2px;
    font-size: 0.8rem;
    color: #607485;
    line-height: 1.4;
}

.inv-area-status {
    display: block;
    min-height: 16px;
    margin-top: 0.55rem;
    font-size: 0.8rem;
    color: #607485;
    line-height: 1.5;
}

/* ── Shipping Couriers ── */
#invoice-shipping-methods {
    display: grid;
    gap: 1rem;
    margin-top: 0.35rem;
}
#invoice-shipping-methods[hidden] { display: none !important; }

.inv-shipping-couriers {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.inv-courier-btn {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 110px;
    aspect-ratio: 4 / 3;
    padding: 8px;
    border: 1.5px solid #d8e0e8;
    border-radius: 0.75rem;
    background: #fff;
    cursor: pointer;
    overflow: hidden;
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.inv-courier-btn img {
    width: 85%;
    height: 85%;
    object-fit: contain;
    filter: grayscale(1) opacity(0.65);
    transition: filter 0.18s, transform 0.18s;
}

.inv-courier-btn span {
    display: none;
    font-size: 0.84rem;
    font-weight: 700;
    color: #284b63;
    text-align: center;
    line-height: 1.3;
}

.inv-courier-btn img[hidden] + span {
    display: block;
}

.inv-courier-btn.is-active {
    border-color: #284b63;
    background: rgba(40, 75, 99, 0.06);
}

.inv-courier-btn.is-active img {
    filter: none;
    transform: scale(1.04);
}

.inv-courier-btn.is-disabled {
    cursor: not-allowed;
    background: #f5f7fa;
    border-color: #e1e6eb;
    opacity: 0.72;
}

.inv-courier-btn.is-disabled img {
    filter: grayscale(1) opacity(0.4);
    transform: none;
}

/* ── Shipping Options ── */
.inv-shipping-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.inv-shipping-option {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 12px;
    border: 1.5px solid #d8e0e8;
    border-radius: 0.75rem;
    background: #fff;
    cursor: pointer;
    text-align: left;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.inv-shipping-option:hover { border-color: #9ab4c8; }

.inv-shipping-option.is-active {
    border-color: #284b63;
    background: rgba(40, 75, 99, 0.05);
}

.inv-shipping-option input[type="radio"] {
    margin: 2px 0 0;
    flex-shrink: 0;
    accent-color: #284b63;
}

.inv-shipping-option-body { flex: 1; min-width: 0; }

.inv-shipping-option-label {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #1f2f3d;
    line-height: 1.35;
}

.inv-shipping-option-label strong {
    white-space: nowrap;
    color: #284b63;
    font-size: 0.88rem;
}

.inv-shipping-option-eta {
    display: block;
    margin-top: 3px;
    font-size: 0.77rem;
    color: #607485;
}

.inv-shipping-status {
    font-size: 0.82rem;
    color: #607485;
    min-height: 16px;
}

@media (max-width: 640px) {
    .inv-shipping-options { grid-template-columns: 1fr; }
    .inv-courier-btn { width: 90px; }
}

[hidden] {
    display: none !important;
}

.invoice-generator-shell {
    max-width: 1180px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.9) !important;
    overflow: visible !important;
}

.invoice-filter {
    align-items: flex-start;
    height: auto;
    max-height: none;
    padding: 1.25rem 1.5rem;
}

.invoice-filter h1 {
    font-size: 1.5rem;
    color: #16324f;
    margin-bottom: 0.35rem;
}

.invoice-filter p {
    color: #4f6575;
    max-width: 760px;
    line-height: 1.55;
}

.invoice-generator-body {
    padding: 1.5rem;
    background: linear-gradient(180deg, rgba(245, 247, 250, 0.92), rgba(233, 238, 242, 0.96));
    overflow: visible;
    display: grid;
    gap: 1.5rem;
}

.invoice-generator-body > * {
    margin: 0;
}

.invoice-generator-body > * + * {
    margin-top: 0.25rem;
}

.invoice-form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.invoice-field {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.invoice-inline-fields {
    display: grid;
    gap: 0.9rem;
}

.invoice-inline-fields--additional-fee {
    grid-template-columns: minmax(0, 1fr) minmax(240px, 0.9fr);
    align-items: start;
}

.invoice-inline-fields--shipping-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
}

.invoice-panel {
    background: #ffffff;
    border: 1px solid #d8e0e8;
    border-radius: 1rem;
    padding: 1.15rem;
    box-shadow: 0 10px 30px rgba(14, 34, 56, 0.06);
    margin-bottom: 0.25rem;
}

.invoice-lockable-panel {
    position: relative;
    overflow: hidden;
}

.invoice-panel-lock {
    position: absolute;
    inset: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    border-radius: inherit;
    background: rgba(7, 12, 18, 0.85);
    color: #fff;
    text-align: center;
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    backdrop-filter: blur(1px);
}

.invoice-panel-lock[hidden] {
    display: none !important;
}

.invoice-panel__header {
    margin-bottom: 1rem;
}

.invoice-panel__header h2 {
    color: #16324f;
    font-size: 1.15rem;
    margin-bottom: 0.2rem;
}

.invoice-panel__header p {
    color: #607485;
    line-height: 1.5;
}

.invoice-panel__body {
    display: grid;
    gap: 1rem;
}

#shipping-fees-panel .invoice-panel__body {
    gap: 1.25rem;
}

.invoice-field--single-row {
    width: 100%;
}

.invoice-field--compact {
    margin-top: 0.8rem;
}

.invoice-meta-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 1rem;
}

.invoice-meta-grid--2col {
    grid-template-columns: 1fr 1fr;
}

.invoice-field input[readonly]:not(.flatpickr-input) {
    background: #f3f6f9;
    color: #607485;
    cursor: default;
}

.flatpickr-input[readonly] {
    cursor: pointer;
    background: #fff;
    color: #1f2f3d;
}

/* ── Due date input wrapper ── */
.date-input-wrap {
    position: relative;
}

.date-input-wrap input {
    padding-right: 2.5rem !important;
    cursor: pointer;
}

.date-input-icon {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: #7a90a4;
    pointer-events: none;
    display: flex;
    align-items: center;
}


.invoice-field label {
    color: #1b3b54;
    font-weight: 700;
    font-size: 0.95rem;
}

.invoice-field textarea,
.invoice-field input,
.shipping-field textarea,
.shipping-field input,
.invoice-items-table input {
    width: 100%;
    border: 1px solid #c8d2dc;
    border-radius: 0.75rem;
    padding: 0.85rem 0.95rem;
    font-size: 0.96rem;
    color: #1f2f3d;
    background: #fff;
    outline: none;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.invoice-field input,
.shipping-field input,
.invoice-items-table input {
    min-height: 51px;
}

.invoice-field textarea,
.shipping-field textarea {
    resize: vertical;
    min-height: 90px;
}

.invoice-field textarea:focus,
.invoice-field input:focus,
.shipping-field textarea:focus,
.shipping-field input:focus,
.invoice-items-table input:focus {
    border-color: #284b63;
    box-shadow: 0 0 0 3px rgba(40, 75, 99, 0.12);
}

.shipping-combobox-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.9rem;
}

.shipping-field {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    min-width: 0;
}

.shipping-field label {
    color: #1b3b54;
    font-weight: 700;
    font-size: 0.95rem;
}

.shipping-combobox-grid--address {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.95rem 1rem;
}

#shipping-manual-fields,
#shipping-auto-fields {
    display: grid;
    gap: 1.1rem;
}

#shipping-area-based-fields,
#shipping-point-based-fields {
    display: grid;
    gap: 1rem;
}

#shipping-auto-fields .invoice-field:first-child textarea {
    min-height: 104px;
}

#shipping-auto-fields .invoice-field > label,
#shipping-manual-fields .invoice-field > label {
    margin-bottom: 0.1rem;
}

#shipping-fees-panel .invoice-field--compact {
    margin-top: 0.15rem;
}

#shipping-fees-panel #shipping-cost-input[readonly] {
    background: #f3f6f9;
}

#additional-fee-label-input {
    min-width: 0;
}

.shipping-point-grid {
    display: grid;
    grid-template-columns: minmax(320px, 1.2fr) minmax(260px, 0.8fr);
    gap: 1rem;
    align-items: stretch;
}

.shipping-point-map-wrap {
    min-width: 0;
}

.shipping-point-map {
    min-height: 320px;
    border: 1px solid #d8e0e8;
    border-radius: 1rem;
    overflow: hidden;
    background: linear-gradient(180deg, #eef4f8, #dfe8ef);
}

.shipping-point-fields {
    display: grid;
    gap: 1rem;
    align-content: start;
}

.shipping-point-map .leaflet-control-attribution {
    font-size: 10px;
}

.shipping-field--wide {
    min-width: 0;
    width: 100%;
}

.shipping-field--wide textarea {
    min-height: 96px;
}

#bill-to-preview {
    min-height: 68px;
    padding: 0.85rem 0.95rem;
    border: 1px solid #d8e0e8;
    border-radius: 0.75rem;
    background: #fff;
    color: #334c61;
    white-space: pre-line;
}

.shipping-combobox {
    position: relative;
}

.shipping-combobox.is-open {
    z-index: 60;
}

.shipping-combobox-trigger {
    width: 100%;
    border: 1px solid #c8d2dc;
    border-radius: 0.75rem;
    background: #fff;
    color: #1f2f3d;
    padding: 0.85rem 2.5rem 0.85rem 0.95rem;
    min-height: 51px;
    text-align: left;
    cursor: pointer;
    position: relative;
    font-size: 0.96rem;
}

.shipping-combobox-trigger[disabled] {
    background: #f3f6f9;
    color: #95a3af;
    cursor: not-allowed;
}

.shipping-combobox-caret {
    position: absolute;
    right: 0.95rem;
    top: 50%;
    width: 10px;
    height: 10px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: translateY(-65%) rotate(45deg);
    pointer-events: none;
}

.shipping-combobox-menu {
    position: absolute;
    top: calc(100% + 0.4rem);
    left: 0;
    right: 0;
    z-index: 20;
    background: #fff;
    border: 1px solid #d5dee6;
    border-radius: 0.9rem;
    box-shadow: 0 18px 36px rgba(14, 34, 56, 0.12);
    padding: 0.75rem;
    max-height: min(420px, 70vh);
    overflow: hidden;
}

.item-combobox {
    width: 100%;
}

.invoice-field--shipping-service .shipping-combobox-menu {
    top: auto;
    bottom: calc(100% + 0.4rem);
}

.shipping-combobox-search {
    width: 100%;
    border: 1px solid #d5dee6;
    border-radius: 0.7rem;
    padding: 0.75rem 0.85rem;
    margin-bottom: 0.65rem;
    outline: none;
}

.shipping-combobox-options {
    max-height: min(300px, 52vh);
    overflow-y: auto;
    display: grid;
    gap: 0.35rem;
}

.shipping-combobox-option,
.shipping-combobox-empty {
    width: 100%;
    border: none;
    border-radius: 0.7rem;
    background: #f4f7fa;
    color: #20384d;
    text-align: left;
    padding: 0.7rem 0.8rem;
}

.item-combobox .shipping-combobox-option,
.item-combobox .shipping-combobox-empty {
    white-space: normal;
    line-height: 1.4;
}

.shipping-combobox-option {
    cursor: pointer;
}

.shipping-combobox-option:hover,
.shipping-combobox-option.is-active {
    background: #dfe9f1;
}

.shipping-combobox-option.is-disabled {
    background: #f7f9fb;
    color: #8ca0b2;
    cursor: not-allowed;
}

.invoice-items-panel {
    background: #ffffff;
    border: 1px solid #d8e0e8;
    border-radius: 1rem;
    padding: 1rem;
    box-shadow: 0 10px 30px rgba(14, 34, 56, 0.06);
    margin-bottom: 0.25rem;
}

.invoice-items-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.invoice-items-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.invoice-items-head h2 {
    color: #16324f;
    font-size: 1.15rem;
    margin-bottom: 0.2rem;
}

.invoice-items-head p {
    color: #607485;
    line-height: 1.5;
}

.action-button {
    border: none;
    border-radius: 0.8rem;
    padding: 0.85rem 1.25rem;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.16s ease, box-shadow 0.16s ease, background-color 0.16s ease;
}

.action-button:hover {
    transform: translateY(-1px);
}

.action-button--primary,
.action-button--submit {
    background: #284b63;
    color: #fff;
    box-shadow: 0 10px 18px rgba(40, 75, 99, 0.18);
}

.action-button--secondary {
    background: #eef4f8;
    color: #284b63;
    border: 1px solid #c8d6e1;
    box-shadow: none;
}

.action-button--secondary:hover {
    background: #e4edf4;
}

.action-button--submit {
    min-width: 220px;
}

.invoice-items-table-wrap {
    overflow-x: auto;
    overflow-y: visible;
}

.invoice-items-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 980px;
    table-layout: fixed;
    overflow: visible;
    position: relative;
}

.invoice-items-table th {
    background: #34495e;
    color: #fff;
    text-align: left;
    padding: 0.9rem 1rem;
    font-weight: 700;
}

.invoice-items-table th:first-child,
.invoice-items-table td:first-child {
    width: calc(100% - 636px);
}

.invoice-items-table th:nth-child(2),
.invoice-items-table td:nth-child(2) {
    width: 100px;
}

.invoice-items-table th:nth-child(3),
.invoice-items-table td:nth-child(3),
.invoice-items-table th:nth-child(4),
.invoice-items-table td:nth-child(4) {
    width: 220px;
}

.invoice-items-table th:nth-child(5),
.invoice-items-table td:nth-child(5) {
    width: 96px;
}

.invoice-items-table th:first-child {
    border-radius: 0.75rem 0 0 0.75rem;
}

.invoice-items-table th:last-child {
    border-radius: 0 0.75rem 0.75rem 0;
}

.invoice-items-table td {
    padding: 0.85rem 0.65rem;
    vertical-align: middle;
    overflow: visible;
    position: relative;
}

.invoice-items-table td:has(.item-combobox.is-open) {
    z-index: 140;
}

.invoice-items-table td:first-child {
    padding-left: 1rem;
}

.invoice-items-table td:last-child {
    padding-right: 1rem;
}

.invoice-items-table .amount-output {
    background: #f4f7fa;
    color: #1e3243;
    font-weight: 700;
}

.invoice-row-action-cell {
    width: 96px;
    text-align: center;
    padding: 0;
    box-sizing: border-box;
    position: sticky;
    right: 0;
    z-index: 3;
    background: var(--tblr-bg-surface, #fff);
    box-shadow: -10px 0 14px -14px rgba(11, 25, 39, 0.28);
}

.invoice-row-action-head,
.invoice-row-action-cell {
    text-align: center;
}

.invoice-row-action-head {
    position: sticky;
    right: 0;
    z-index: 4;
    background: #34495e;
    box-shadow: -10px 0 14px -14px rgba(11, 25, 39, 0.6);
}

.invoice-row-action-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 100%;
}

.invoice-items-table .remove-row-button {
    width: 100%;
    max-width: 48px;
    height: 51px;
    min-width: 48px;
    padding: 0;
    border-radius: 0.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.invoice-live-summary {
    background: #fff;
    border: 1px solid #d8e0e8;
    border-radius: 1rem;
    padding: 1.15rem;
    box-shadow: 0 10px 30px rgba(14, 34, 56, 0.06);
    overflow: visible;
    margin-bottom: 0.25rem;
}

.invoice-live-summary__grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    align-items: start;
}

.footer-editor__grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.footer-editor-preview {
    display: grid;
    gap: 0.9rem;
    margin-bottom: 1.15rem;
}

.footer-editor-preview__head h3 {
    margin: 0 0 0.2rem;
    color: #16324f;
    font-size: 1rem;
}

.footer-editor-preview__head p {
    margin: 0;
    color: #607485;
    font-size: 0.88rem;
    line-height: 1.5;
}

.footer-editor-preview__frame {
    padding: 1rem;
    border: 1px solid #d8e0e8;
    border-radius: 1rem;
    background: linear-gradient(180deg, #f8fbfe, #f2f7fb);
    overflow: hidden;
    width: 100%;
    box-sizing: border-box;
}

.footer-editor-preview__scale-wrap {
    width: 100%;
    transform-origin: top left;
    overflow: hidden;
}

.footer-editor-preview__canvas {
    width: 182mm;
    font-family: Arial, Helvetica, sans-serif;
    color: #1a2e3f;
}

.footer-editor-preview__rule {
    width: 100%;
    height: 1.5px;
    background: #b2cbdf;
}

.footer-editor-preview__footer {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12mm;
    padding: 5mm 0 4mm;
}

.footer-editor-preview__notes {
    flex: 1;
    min-width: 0;
}

.footer-editor-preview__notes strong {
    display: block;
    font-size: 9.9pt;
    font-weight: 700;
    color: #1a3f63;
    margin-bottom: 2mm;
}

.footer-editor-preview__notes p {
    margin: 0 0 1.5mm;
    font-size: 9pt;
    color: #4a6278;
    line-height: 1.45;
}

.footer-editor-preview__closing {
    text-align: right;
    flex-shrink: 0;
    max-width: 60mm;
}

.footer-editor-preview__closing p {
    margin: 0 0 1.5mm;
    font-size: 9pt;
    color: #4a6278;
    line-height: 1.55;
}

.footer-editor-preview__closing p.is-lead {
    font-weight: 700;
    color: #1a3f63;
    font-size: 9.9pt;
    margin-bottom: 2mm;
}

.footer-editor__field-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.footer-editor textarea {
    min-height: 172px;
    line-height: 1.55;
}

textarea.footer-line-input {
    resize: none;
    overflow: hidden;
    line-height: 1.55;
    min-height: 0;
}

.footer-editor textarea.is-draft {
    border-color: #d97706;
    box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.12);
    background: #fffdf7;
}

.footer-editor__meta {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
    margin-top: 0.4rem;
}

.footer-editor__meta-left {
    display: grid;
    gap: 0.35rem;
    min-width: 0;
}

.footer-editor__status {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 700;
    line-height: 1.2;
    color: #486071;
    background: #edf2f7;
}

.footer-editor__status.is-draft {
    color: #9a3412;
    background: #ffedd5;
}

.footer-editor__counter {
    color: #607485;
    font-size: 0.78rem;
    line-height: 1.4;
    font-variant-numeric: tabular-nums;
    margin-left: auto;
    white-space: nowrap;
}

.footer-editor__counter.is-warning {
    color: #b45309;
}

.footer-editor__counter.is-limit {
    color: #b91c1c;
}

.footer-editor__hint {
    display: block;
    flex: 1 1 260px;
    color: #607485;
    font-size: 0.8rem;
    line-height: 1.45;
}

.footer-editor__reset-btn {
    border: 1px solid #d8e0e8;
    background: #fff;
    color: #355066;
    border-radius: 999px;
    padding: 0.45rem 0.8rem;
    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1.2;
    cursor: pointer;
    transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease;
    white-space: nowrap;
}

.footer-editor__reset-btn:hover {
    border-color: #b8c7d4;
    background: #f6f9fb;
}

.items-subtotal-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 56px 0 0.25rem;
    margin-top: 1rem;
    border-top: 2px solid #d8e0e8;
    font-size: 0.96rem;
    color: #486071;
    font-weight: 600;
}

.items-subtotal-bar strong {
    color: #1b3044;
    font-size: 1rem;
}

/* ── Flatpickr theme overrides ── */
.flatpickr-calendar {
    border-radius: 0.75rem;
    box-shadow: 0 8px 28px rgba(14, 34, 56, 0.16);
    font-family: inherit;
}
.flatpickr-months .flatpickr-month {
    background: #284b63;
    border-radius: 0.75rem 0.75rem 0 0;
    color: #fff;
}
.flatpickr-months .flatpickr-prev-month,
.flatpickr-months .flatpickr-next-month {
    fill: #fff;
    color: #fff;
}
.flatpickr-months .flatpickr-prev-month:hover svg,
.flatpickr-months .flatpickr-next-month:hover svg {
    fill: #cfe0ee;
}
.flatpickr-current-month span.cur-month,
.flatpickr-current-month .numInputWrapper input {
    color: #fff;
    font-weight: 700;
}
.flatpickr-weekday {
    color: #607485;
    font-weight: 700;
}
.flatpickr-day.selected,
.flatpickr-day.selected:hover,
.flatpickr-day.selected:focus {
    background: #284b63;
    border-color: #284b63;
    color: #fff;
}
.flatpickr-day:hover,
.flatpickr-day:focus {
    background: #e3eef6;
    border-color: #e3eef6;
}
.flatpickr-day.today {
    border-color: #284b63;
    color: #284b63;
}
.flatpickr-day.today:hover {
    background: #284b63;
    color: #fff;
}
.flatpickr-day.flatpickr-disabled,
.flatpickr-day.flatpickr-disabled:hover {
    color: #c8d2dc;
}

.summary-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 0;
    color: #486071;
}

.summary-line strong {
    color: #1b3044;
}

.summary-group-break {
    height: 1px;
    background: #d8e0e8;
    margin: 0.15rem 0;
}

.summary-line--grand {
    margin-top: 0.2rem;
    padding-top: 0.85rem;
    font-size: 1.05rem;
}

.invoice-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 0.5rem;
}

/* ── Discount type tabs ──────────────────────────────────────────────────── */
.discount-input-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.discount-input-row .discount-type-tabs {
    flex-shrink: 0;
    margin-bottom: 0;
}

.discount-input-row #discount-flat-wrap,
.discount-input-row #discount-percent-wrap {
    flex: 1;
    min-width: 0;
}

.discount-type-tabs {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 0.55rem;
}

.discount-tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #c8d2dc;
    border-radius: 0.75rem;
    background: #f4f7fa;
    color: #486071;
    width: 51px;
    min-width: 51px;
    min-height: 51px;
    height: 51px;
    padding: 0;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    flex: 0 0 51px;
}

.discount-tab.is-active {
    background: #284b63;
    color: #fff;
    border-color: #284b63;
}

.discount-percent-inputs {
    display: grid;
    grid-template-columns: 88px 1fr;
    gap: 0.5rem;
}

.discount-pct-input {
    width: 100%;
    border: 1px solid #c8d2dc;
    border-radius: 0.75rem;
    padding: 0.85rem 0.75rem;
    font-size: 0.96rem;
    color: #1f2f3d;
    background: #fff;
    outline: none;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.discount-pct-input:focus {
    border-color: #284b63;
    box-shadow: 0 0 0 3px rgba(40, 75, 99, 0.12);
}

.discount-percent-preview {
    display: block;
    font-size: 0.82rem;
    color: #607485;
    margin-top: 0.4rem;
    min-height: 1.1em;
}

.hint-lite-warning {
    color: #d97706;
    font-size: 0.76rem;
    font-weight: 500;
    margin-top: 0.5rem;
}

.hint-lite-warning::before {
    content: "* ";
}

@media (max-width: 860px) {
    .shipping-combobox-grid,
    .shipping-combobox-grid--address {
        grid-template-columns: 1fr;
    }

    .shipping-point-grid {
        grid-template-columns: 1fr;
    }

    .shipping-point-map {
        min-height: 260px;
    }

    .invoice-items-head {
        flex-direction: column;
        align-items: stretch;
    }

    .invoice-actions {
        justify-content: stretch;
    }

    .action-button--submit {
        width: 100%;
    }
}

/* ── Mobile ≤ 640px ─────────────────────────── */
@media (max-width: 1100px) {

    .invoice-inline-fields--additional-fee {
        grid-template-columns: 1fr;
    }

    .invoice-inline-fields--shipping-summary {
        grid-template-columns: 1fr;
    }

    /* Prevent any overflow from escaping the shell */
    .invoice-generator-shell {
        overflow-x: hidden !important;
        width: 100% !important;
    }

    /* All direct grid children must not force the grid wider */
    .invoice-generator-body > * {
        min-width: 0;
        max-width: 100%;
    }

    .invoice-generator-body {
        padding: 0.85rem 0.75rem;
        gap: 0.85rem;
    }

    .invoice-filter {
        padding: 0.85rem 0.75rem;
    }

    .invoice-filter h1 {
        font-size: 1.15rem;
    }

    .invoice-filter p {
        font-size: 0.875rem;
    }

    .invoice-meta-grid,
    .invoice-meta-grid--2col {
        grid-template-columns: 1fr;
    }

    .invoice-panel,
    .invoice-items-panel,
    .invoice-live-summary {
        padding: 0.875rem 0.85rem;
        border-radius: 0.75rem;
        min-width: 0;
        width: 100%;
        box-sizing: border-box;
    }

    .invoice-panel__header {
        margin-bottom: 0.75rem;
    }

    .invoice-panel__header h2,
    .invoice-items-head h2 {
        font-size: 1rem;
    }

    .footer-editor__grid {
        grid-template-columns: 1fr;
    }

    .footer-editor-preview__frame {
        padding: 0.6rem;
    }

    .footer-editor-preview__canvas {
        width: 160mm;
    }

    .footer-editor-preview__footer {
        gap: 6mm;
    }

    .footer-editor-preview__closing {
        max-width: 45mm;
    }

    .invoice-items-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .invoice-items-actions {
        width: 100%;
    }

    /* Constrain combobox triggers so they don't push layout */
    .shipping-combobox,
    .shipping-combobox-trigger {
        min-width: 0;
        max-width: 100%;
        box-sizing: border-box;
    }

    /* ── Items table → card layout ── */
    .invoice-items-table-wrap {
        overflow-x: auto;
        overflow-y: visible;
        -webkit-overflow-scrolling: touch;
    }

    .invoice-items-table {
        display: table;
        width: 980px;
        min-width: 980px;
        table-layout: fixed;
        box-sizing: border-box;
    }

    .invoice-items-table thead {
        display: table-header-group;
    }

    .invoice-items-table tbody {
        display: table-row-group;
        width: auto;
    }

    .invoice-item-row {
        display: table-row;
        background: transparent;
        border: 0;
        border-radius: 0;
        padding: 0;
        margin-bottom: 0;
        width: auto;
        box-sizing: border-box;
    }

    /*
     * td = flex column container so children auto-stretch horizontally.
     * align-items:stretch (flex default) makes inputs fill the cell width
     * without relying on width:100% percentage chains inside grid items.
     */
    .invoice-item-row > td {
        display: table-cell;
        min-width: 0;
        width: auto !important;
        padding: 0.85rem 0.65rem;
        box-sizing: border-box;
        vertical-align: middle;
    }

    /* Item — full width */
    .invoice-item-row > td:nth-child(1) {
        grid-column: auto;
        grid-row: auto;
    }

    /* Qty — left col */
    .invoice-item-row > td:nth-child(2) {
        grid-column: auto;
        grid-row: auto;
    }

    /* Rate — right col */
    .invoice-item-row > td:nth-child(3) {
        grid-column: auto;
        grid-row: auto;
    }

    /* Amount — full width */
    .invoice-item-row > td:nth-child(4) {
        grid-column: auto;
        grid-row: auto;
    }

    /* Remove button — final row */
    .invoice-item-row > td:nth-child(5) {
        grid-column: auto;
        grid-row: auto;
        align-items: center;
        justify-content: center;
        padding-top: 0.85rem;
        border-top: 0;
    }

    .invoice-items-table .remove-row-button {
        width: 100%;
        max-width: 48px;
        height: 50px;
        min-width: 48px;
        padding: 0;
        border-radius: 0.75rem;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
    }

    /* Keep item input aligned with the rest of the card on mobile */
    .invoice-item-row > td:nth-child(1) .invoice-item-manual-input {
        margin-left: 0;
        width: 100%;
    }

    /*
     * Inputs stretch from flex parent (td). No width:100% needed here.
     * min-height: 48px = minimum touch target.
     * font-size: 1rem prevents iOS Safari auto-zoom (triggers when < 16px).
     */
    .invoice-items-table input,
    .invoice-items-table .shipping-combobox-trigger {
        min-height: 48px;
        padding: 0.75rem 0.85rem;
        font-size: 1rem;
        box-sizing: border-box;
        min-width: 0;
        width: 100%;
    }

    .invoice-items-table .shipping-combobox {
        min-width: 0;
        display: flex;
        flex-direction: column;
    }

    /* Also fix Bill To / Invoice Type combobox triggers on mobile */
    .invoice-panel .shipping-combobox-trigger,
    .invoice-field--single-row .shipping-combobox-trigger {
        min-height: 48px;
        font-size: 1rem;
        padding: 0.75rem 2.5rem 0.75rem 0.95rem;
    }

    /* Fix Ship To, Bill To text inputs */
    .invoice-field input,
    .invoice-field textarea,
    .shipping-field input,
    .shipping-field textarea {
        font-size: 1rem;
        min-height: 48px;
    }

    .invoice-field textarea,
    .shipping-field textarea {
        min-height: 90px;
    }

    /* Field labels */
    .invoice-item-row > td::before {
        display: none;
        content: none;
    }

    .invoice-row-action-cell {
        width: 96px;
        text-align: center;
        position: sticky;
        right: 0;
        z-index: 3;
        background: var(--tblr-bg-surface, #fff);
        box-shadow: -10px 0 14px -14px rgba(11, 25, 39, 0.28);
    }

    .invoice-row-action-wrap {
        justify-content: center;
    }

    .invoice-row-action-head {
        position: sticky;
        right: 0;
        z-index: 4;
        background: #34495e;
        box-shadow: -10px 0 14px -14px rgba(11, 25, 39, 0.6);
    }

    /* Generate Invoice button */
    .invoice-actions {
        justify-content: stretch;
        margin-top: 0.25rem;
    }

    .action-button--submit {
        width: 100%;
        min-width: 0;
    }
}
