/* ==========================================================================
   MabrookTech Daylight Editorial / Apple Liquid Glass Invoice Generator
   ========================================================================== */

:root {
    --mt-bg: #F5F5F7;
    --mt-glass: rgba(255, 255, 255, 0.86);
    --mt-glass-strong: rgba(255, 255, 255, 0.94);
    --mt-ink: #1D1D1F;
    --mt-ink-secondary: #515154;
    --mt-border: rgba(29, 29, 31, 0.10);
    --mt-border-strong: rgba(29, 29, 31, 0.16);
    --mt-cobalt: #0F4C81;
    --mt-cobalt-hover: #0B3A63;
    --mt-teal: #0F766E;
    --mt-teal-soft: rgba(15, 118, 110, 0.10);
    --mt-danger: #DC2626;
    --mt-shadow-glass:
        inset 0 1px 0 rgba(255, 255, 255, 0.96),
        0 18px 40px -22px rgba(15, 23, 42, 0.14),
        0 2px 8px rgba(15, 23, 42, 0.04);

    /* Invoice Paper Defaults */
    --paper-bg: #ffffff;
    --paper-text: #334155;
    --paper-accent: #0F4C81;
    --paper-border: #e2e8f0;
    --brand-primary: #0F4C81;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

body {
    font-family: 'Inter Tight', -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--mt-ink);
    background:
        radial-gradient(64% 58% at 10% 12%, rgba(15, 76, 129, 0.10), transparent 62%),
        radial-gradient(56% 52% at 90% 18%, rgba(15, 118, 110, 0.09), transparent 58%),
        radial-gradient(52% 48% at 58% 88%, rgba(125, 211, 252, 0.16), transparent 60%),
        var(--mt-bg);
    background-attachment: fixed;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
    font-family: 'Outfit', sans-serif;
    letter-spacing: -0.02em;
}

/* --- Synchronized MabrookTech Ecosystem Topbar --- */
.ecosystem-topbar {
    position: sticky;
    top: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    padding: 0.65rem 1.25rem;
    background: var(--mt-glass);
    -webkit-backdrop-filter: blur(22px) saturate(180%);
    backdrop-filter: blur(22px) saturate(180%);
    border-bottom: 1px solid var(--mt-border);
    box-shadow: 0 4px 20px -12px rgba(15, 23, 42, 0.12);
}

.ecosystem-topbar-left {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-shrink: 0;
}

.ecosystem-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    text-decoration: none;
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 0.98rem;
    color: var(--mt-ink);
}

.brand-dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--mt-cobalt), var(--mt-teal));
    display: inline-block;
}

.ecosystem-badge {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--mt-cobalt);
    background: rgba(15, 76, 129, 0.08);
    border: 1px solid rgba(15, 76, 129, 0.14);
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
}

.ecosystem-pills {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.eco-pill {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--mt-ink-secondary);
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid var(--mt-border);
    padding: 0.34rem 0.68rem;
    border-radius: 999px;
    transition: all 0.18s ease;
    white-space: nowrap;
}

.eco-pill:hover {
    color: var(--mt-cobalt);
    background: #ffffff;
    border-color: rgba(15, 76, 129, 0.24);
}

.eco-pill-current {
    background: var(--mt-cobalt);
    color: #ffffff !important;
    border-color: var(--mt-cobalt);
    font-weight: 600;
}

.eco-pill-cta {
    background: linear-gradient(135deg, var(--mt-cobalt), var(--mt-teal));
    color: #ffffff !important;
    border-color: transparent;
    font-weight: 600;
}

.eco-pill-cta:hover {
    opacity: 0.94;
    transform: translateY(-1px);
}

/* --- Main App Layout --- */
.app-container {
    display: flex;
    gap: 1.25rem;
    padding: 1.25rem;
    flex: 1;
    align-items: flex-start;
    max-width: 1640px;
    width: 100%;
    margin: 0 auto;
}

/* --- Editor Panel (Frosted Apple Liquid Glass) --- */
.editor-panel {
    width: 440px;
    flex-shrink: 0;
    background: var(--mt-glass);
    -webkit-backdrop-filter: blur(22px) saturate(180%);
    backdrop-filter: blur(22px) saturate(180%);
    border: 1px solid var(--mt-border);
    border-radius: 22px;
    box-shadow: var(--mt-shadow-glass);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.editor-header {
    padding: 1.15rem 1.35rem;
    border-bottom: 1px solid var(--mt-border);
    background: rgba(255, 255, 255, 0.72);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
}

.editor-title-block h1 {
    font-size: 1.22rem;
    font-weight: 700;
    color: var(--mt-ink);
    margin: 0;
}

.editor-title-block p {
    font-size: 0.76rem;
    color: var(--mt-ink-secondary);
    margin-top: 0.15rem;
}

.language-switcher select {
    width: auto;
    min-width: 108px;
    background: #ffffff;
    border: 1px solid var(--mt-border-strong);
    color: var(--mt-ink);
    padding: 0.35rem 0.6rem;
    border-radius: 10px;
    font-size: 0.78rem;
    font-weight: 600;
}

#invoiceForm {
    padding: 1.25rem 1.35rem;
    display: flex;
    flex-direction: column;
    gap: 1.15rem;
}

.form-section {
    background: rgba(255, 255, 255, 0.62);
    border: 1px solid var(--mt-border);
    border-radius: 16px;
    padding: 1rem;
}

.form-section h2 {
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--mt-cobalt);
    margin-bottom: 0.85rem;
    font-weight: 700;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.form-group {
    margin-bottom: 0.75rem;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-size: 0.76rem;
    font-weight: 600;
    margin-bottom: 0.32rem;
    color: var(--mt-ink-secondary);
}

input,
select,
textarea {
    width: 100%;
    background-color: rgba(255, 255, 255, 0.94);
    border: 1px solid var(--mt-border-strong);
    color: var(--mt-ink);
    padding: 0.55rem 0.7rem;
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.84rem;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--mt-cobalt);
    box-shadow: 0 0 0 3px rgba(15, 76, 129, 0.14);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
    outline: 2px solid var(--mt-cobalt);
    outline-offset: 2px;
}

.logo-upload-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.file-input-compact {
    padding: 0.35rem 0.5rem;
    font-size: 0.76rem;
}

.btn-chip {
    background: rgba(220, 38, 38, 0.08);
    color: var(--mt-danger);
    border: 1px solid rgba(220, 38, 38, 0.22);
    border-radius: 8px;
    padding: 0.38rem 0.55rem;
    font-size: 0.74rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.section-header h2 {
    margin-bottom: 0;
}

/* VAT Presets Bar */
.vat-presets-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 0.85rem;
    padding: 0.55rem 0.65rem;
    background: rgba(15, 118, 110, 0.06);
    border: 1px solid rgba(15, 118, 110, 0.16);
    border-radius: 12px;
}

.vat-presets-label {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--mt-teal);
    margin-right: 0.2rem;
}

.vat-preset-btn {
    border: 1px solid rgba(15, 118, 110, 0.25);
    background: #ffffff;
    color: var(--mt-ink);
    font-size: 0.74rem;
    font-weight: 600;
    padding: 0.28rem 0.62rem;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.16s ease;
}

.vat-preset-btn:hover {
    border-color: var(--mt-teal);
    color: var(--mt-teal);
}

.vat-preset-btn.is-active {
    background: var(--mt-teal);
    color: #ffffff;
    border-color: var(--mt-teal);
}

/* Line Items & Installments */
.item-row {
    background: #ffffff;
    border: 1px solid var(--mt-border);
    padding: 0.8rem;
    border-radius: 12px;
    margin-bottom: 0.7rem;
}

.item-row:last-child {
    margin-bottom: 0;
}

.item-row-header,
.installment-row-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.text-muted {
    font-size: 0.74rem;
    font-weight: 700;
    color: var(--mt-ink-secondary);
}

.installment-row {
    background: #ffffff;
    border: 1px dashed var(--mt-border-strong);
    padding: 0.75rem;
    border-radius: 12px;
    margin-bottom: 0.65rem;
}

.installment-row:last-child {
    margin-bottom: 0;
}

.installment-row-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0.5rem;
}

.btn-remove {
    background: none;
    border: none;
    color: var(--mt-danger);
    cursor: pointer;
    font-size: 0.76rem;
    font-weight: 600;
    padding: 0.18rem 0.4rem;
    border-radius: 6px;
}

.btn-remove:hover {
    background: rgba(220, 38, 38, 0.08);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid var(--mt-border-strong);
    color: var(--mt-cobalt);
    padding: 0.5rem 0.85rem;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    transition: all 0.18s ease;
}

.btn-secondary:hover {
    background: #ffffff;
    border-color: var(--mt-cobalt);
    box-shadow: 0 4px 12px rgba(15, 76, 129, 0.10);
}

.btn-danger-ghost {
    background: rgba(220, 38, 38, 0.06);
    border: 1px solid rgba(220, 38, 38, 0.18);
    color: var(--mt-danger);
    padding: 0.5rem 0.85rem;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    transition: all 0.18s ease;
}

.btn-danger-ghost:hover {
    background: rgba(220, 38, 38, 0.12);
}

.btn-primary {
    width: 100%;
    background: linear-gradient(135deg, var(--mt-cobalt), var(--mt-teal));
    color: #ffffff;
    border: none;
    padding: 0.78rem 1rem;
    border-radius: 12px;
    font-weight: 700;
    font-size: 0.88rem;
    cursor: pointer;
    box-shadow: 0 10px 22px -12px rgba(15, 76, 129, 0.55);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 14px 26px -12px rgba(15, 76, 129, 0.65);
}

.editor-footer {
    padding: 1.05rem 1.35rem 1.25rem;
    border-top: 1px solid var(--mt-border);
    background: rgba(255, 255, 255, 0.85);
}

.footer-buttons-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

/* --- Preview Panel --- */
.preview-panel {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
}

.preview-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    padding: 0.65rem 1rem;
    border-radius: 16px;
    background: var(--mt-glass);
    -webkit-backdrop-filter: blur(22px) saturate(180%);
    backdrop-filter: blur(22px) saturate(180%);
    border: 1px solid var(--mt-border);
    box-shadow: var(--mt-shadow-glass);
}

.preview-toolbar-info {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--mt-ink);
}

.preview-dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--mt-teal);
}

.preview-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-toolbar {
    background: #ffffff;
    border: 1px solid var(--mt-border-strong);
    color: var(--mt-ink);
    font-size: 0.78rem;
    font-weight: 600;
    padding: 0.42rem 0.82rem;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.16s ease;
}

.btn-toolbar:hover {
    border-color: var(--mt-cobalt);
    color: var(--mt-cobalt);
}

.btn-toolbar-primary {
    background: var(--mt-cobalt);
    border-color: var(--mt-cobalt);
    color: #ffffff;
}

.btn-toolbar-primary:hover {
    background: var(--mt-cobalt-hover);
    color: #ffffff;
}

.preview-wrapper {
    width: min(210mm, 100%);
    max-width: 210mm;
    min-height: 297mm;
    background: #ffffff;
    border-radius: 14px;
    border: 1px solid rgba(29, 29, 31, 0.08);
    box-shadow: 0 24px 55px -24px rgba(15, 23, 42, 0.22);
    margin: 0 auto 2rem auto;
    overflow: hidden;
}

/* --- Invoice Paper Base --- */
.invoice-paper {
    padding: 15mm;
    color: #334155;
    font-size: 10pt;
    line-height: 1.4;
    position: relative;
    min-height: 297mm;
    height: auto;
    display: flex;
    flex-direction: column;
    font-family: 'Inter Tight', sans-serif;
    background: #ffffff;
}

.payment-status-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 0.5rem;
    padding: 0.16rem 0.48rem;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    border: 1px solid transparent;
}

.payment-status-unpaid {
    background: rgba(220, 38, 38, 0.10);
    color: #b91c1c;
    border-color: rgba(220, 38, 38, 0.25);
}

.payment-status-partial {
    background: rgba(217, 119, 6, 0.12);
    color: #b45309;
    border-color: rgba(217, 119, 6, 0.30);
}

.payment-status-paid {
    background: rgba(15, 118, 110, 0.12);
    color: #0F766E;
    border-color: rgba(15, 118, 110, 0.30);
}

.installments-preview {
    margin-top: 14px;
    border-top: 1px dashed #cbd5e1;
    padding-top: 10px;
}

.installments-title {
    font-size: 8pt;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #475569;
    margin-bottom: 8px;
}

.installment-line {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    font-size: 9pt;
    color: #334155;
    margin-bottom: 5px;
}

.installment-line strong {
    font-weight: 700;
    color: #0f172a;
}

.installment-warning {
    margin-top: 6px;
    font-size: 8pt;
    color: #b45309;
}

/* --- Compact Mode For PDF Export --- */
.pdf-export-mode .invoice-paper {
    padding: 10mm 11mm 9mm !important;
    font-size: 9.2pt;
    line-height: 1.28;
}

/* --- Print Optimization (Hide ALL Chrome / Navbars / Controls) --- */
@media print {
    @page {
        size: A4;
        margin: 0;
    }

    body {
        background: #ffffff !important;
        height: auto !important;
        min-height: 0 !important;
        overflow: visible !important;
        display: block !important;
    }

    .ecosystem-topbar,
    .editor-panel,
    .preview-toolbar,
    .notification {
        display: none !important;
    }

    .app-container {
        display: block !important;
        padding: 0 !important;
        margin: 0 !important;
        max-width: none !important;
    }

    .preview-panel {
        padding: 0 !important;
        display: block !important;
    }

    .preview-wrapper {
        width: 100% !important;
        max-width: none !important;
        box-shadow: none !important;
        border: none !important;
        border-radius: 0 !important;
        margin: 0 !important;
    }

    .invoice-paper {
        padding: 10mm 11mm 9mm !important;
        min-height: 297mm !important;
    }

    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}

/* --- Notification Toast --- */
.notification {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    background: var(--mt-glass-strong);
    -webkit-backdrop-filter: blur(18px) saturate(180%);
    backdrop-filter: blur(18px) saturate(180%);
    color: var(--mt-ink);
    padding: 0.85rem 1.2rem;
    border-radius: 14px;
    box-shadow: 0 18px 40px -16px rgba(15, 23, 42, 0.25);
    z-index: 1000;
    opacity: 0;
    transform: translateY(18px);
    transition: opacity 0.25s ease, transform 0.25s ease;
    pointer-events: none;
    border: 1px solid var(--mt-border-strong);
    max-width: 340px;
    font-size: 0.84rem;
    font-weight: 600;
}

.notification.show {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.notification-success {
    border-left: 4px solid var(--mt-teal);
}

.notification-error {
    border-left: 4px solid var(--mt-danger);
}

.notification-info {
    border-left: 4px solid var(--mt-cobalt);
}

/* --- Responsive Layout --- */
@media (max-width: 1120px) {
    .app-container {
        flex-direction: column;
        padding: 0.9rem;
    }

    .editor-panel {
        width: 100%;
    }

    .preview-panel {
        width: 100%;
    }

    .preview-wrapper {
        min-height: 0;
    }

    .invoice-paper {
        min-height: 0;
        padding: 18px;
    }
}

@media (max-width: 640px) {
    .form-grid,
    .installment-row-grid {
        grid-template-columns: 1fr;
    }

    .ecosystem-topbar {
        padding: 0.6rem 0.85rem;
    }

    .notification {
        left: 1rem;
        right: 1rem;
        max-width: none;
    }
}
