/* PDS Invoice - Isolated Styles (Astra & Elementor Safe) */
#pds-invoice-app.pds-inv-wrap {
    --pds-accent: #5B1FBA;
    --pds-accent-hover: #491699;
    --pds-accent-soft: #F5F0FF;
    --pds-border: #E2E8F0;
    --pds-text: #1E293B;
    --pds-muted: #64748B;
    --pds-bg: #F8FAFC;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
    color: var(--pds-text);
    background: var(--pds-bg);
    border: 1px solid var(--pds-border);
    border-radius: 14px;
    padding: 20px;
    max-width: 1180px;
    margin: 20px auto;
    box-sizing: border-box;
    line-height: 1.5;
}
#pds-invoice-app *, #pds-invoice-app *::before, #pds-invoice-app *::after {
    box-sizing: border-box;
}
#pds-invoice-app .pds-hidden { display: none !important; }

/* Topbar */
.pds-inv-topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    background: #FFFFFF;
    padding: 14px 18px;
    border-radius: 12px;
    border: 1px solid var(--pds-border);
    margin-bottom: 18px;
}
.pds-inv-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}
.pds-inv-logo-badge {
    background: var(--pds-accent);
    color: #fff;
    font-weight: 800;
    font-size: 14px;
    padding: 10px 12px;
    border-radius: 10px;
    letter-spacing: 0.5px;
}
.pds-inv-title {
    margin: 0 !important;
    font-size: 18px !important;
    font-weight: 700 !important;
    color: var(--pds-text) !important;
    line-height: 1.2 !important;
}
.pds-inv-subtitle {
    margin: 0 !important;
    font-size: 12px !important;
    color: var(--pds-muted) !important;
}

/* Domestic / Export Mode Toggle */
.pds-inv-mode-toggle {
    display: inline-flex;
    background: #F1F5F9;
    padding: 4px;
    border-radius: 10px;
    border: 1px solid var(--pds-border);
}
.pds-inv-mode-btn {
    border: none;
    background: transparent;
    color: var(--pds-muted);
    font-size: 13px;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    transition: all 0.2s ease;
}
.pds-inv-mode-btn .pds-inv-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #CBD5E1;
}
.pds-inv-mode-btn.is-active {
    background: var(--pds-accent);
    color: #FFFFFF;
    box-shadow: 0 2px 8px rgba(91, 31, 186, 0.25);
}
.pds-inv-mode-btn.is-active .pds-inv-dot {
    background: #FFFFFF;
}

/* Auth Bar & Buttons */
.pds-inv-auth-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.pds-inv-user-pill {
    background: var(--pds-accent-soft);
    color: var(--pds-accent);
    font-weight: 600;
    font-size: 13px;
    padding: 6px 12px;
    border-radius: 20px;
}
.pds-inv-btn-primary, .pds-inv-btn-outline, .pds-inv-btn-ghost, .pds-inv-btn-sm {
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    padding: 9px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    text-decoration: none;
}
.pds-inv-btn-primary {
    background: var(--pds-accent);
    color: #FFFFFF;
}
.pds-inv-btn-primary:hover { background: var(--pds-accent-hover); }
.pds-inv-btn-outline {
    background: #FFFFFF;
    color: var(--pds-accent);
    border-color: var(--pds-accent);
}
.pds-inv-btn-outline:hover { background: var(--pds-accent-soft); }
.pds-inv-btn-ghost {
    background: #F1F5F9;
    color: var(--pds-text);
}
.pds-inv-btn-ghost:hover { background: #E2E8F0; }
.pds-inv-btn-sm {
    padding: 5px 12px;
    font-size: 12px;
    background: var(--pds-accent);
    color: #fff;
}
.pds-inv-btn-lg { padding: 12px 24px; font-size: 14px; }
.pds-inv-btn-full { width: 100%; padding: 11px; font-size: 14px; }

/* Hard Wall */
.pds-inv-hard-wall {
    padding: 40px 16px;
    display: flex;
    justify-content: center;
}
.pds-inv-wall-card {
    background: #fff;
    border: 1px solid var(--pds-border);
    border-radius: 14px;
    padding: 36px 28px;
    max-width: 520px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
}
.pds-inv-wall-icon { font-size: 42px; margin-bottom: 10px; }
.pds-inv-wall-card h3 { margin: 0 0 10px !important; font-size: 20px !important; }
.pds-inv-wall-card p { color: var(--pds-muted); font-size: 14px; margin-bottom: 22px; }
.pds-inv-wall-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* Tabs */
.pds-inv-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    border-bottom: 2px solid var(--pds-border);
    padding-bottom: 0;
    overflow-x: auto;
}
.pds-inv-tab {
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 600;
    color: var(--pds-muted);
    cursor: pointer;
    margin-bottom: -2px;
    white-space: nowrap;
}
.pds-inv-tab.is-active {
    color: var(--pds-accent);
    border-bottom-color: var(--pds-accent);
}
.pds-inv-panel { display: none; }
.pds-inv-panel.is-active { display: block; }

/* Guest Banner */
.pds-inv-guest-banner {
    background: var(--pds-accent-soft);
    border: 1px solid #DDD6FE;
    color: #4C1D95;
    padding: 10px 16px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    font-size: 13px;
    flex-wrap: wrap;
}

/* Cards & Grids */
.pds-inv-card {
    background: #FFFFFF;
    border: 1px solid var(--pds-border);
    border-radius: 12px;
    padding: 18px;
    margin-bottom: 16px;
}
.pds-inv-export-card {
    border-color: #BAE6FD;
    background: #F0F9FF;
}
.pds-inv-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.pds-inv-card-header h3 {
    margin: 0 !important;
    font-size: 15px !important;
    font-weight: 700 !important;
    color: var(--pds-text) !important;
}
.pds-inv-badge-export {
    background: #0284C7;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 20px;
}
.pds-inv-badge-info {
    background: var(--pds-accent-soft);
    color: var(--pds-accent);
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
}
.pds-inv-inline-controls {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
}
.pds-inv-small-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--pds-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}
.pds-inv-small-label select {
    padding: 5px 8px;
    font-size: 12px;
    border-radius: 6px;
    border: 1px solid var(--pds-border);
}

.pds-inv-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.pds-inv-grid-2-tight { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pds-inv-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.pds-inv-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }

.pds-inv-field { margin-bottom: 10px; }
.pds-inv-field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #334155;
    margin-bottom: 4px;
}
.pds-inv-field input,
.pds-inv-field select,
.pds-inv-field textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #CBD5E1;
    border-radius: 7px;
    font-size: 13px;
    background: #FFFFFF;
    color: var(--pds-text);
    font-family: inherit;
}
.pds-inv-field input:focus,
.pds-inv-field select:focus,
.pds-inv-field textarea:focus {
    outline: none;
    border-color: var(--pds-accent);
    box-shadow: 0 0 0 3px rgba(91, 31, 186, 0.12);
}

/* Upload preview */
.pds-inv-upload-btn {
    background: var(--pds-accent-soft);
    color: var(--pds-accent);
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: inline-block;
}
.pds-inv-img-preview {
    position: relative;
    display: inline-block;
    margin-bottom: 10px;
    border: 1px dashed #CBD5E1;
    padding: 4px;
    border-radius: 6px;
    background: #fff;
}
.pds-inv-img-preview img { max-height: 92px; max-width: 260px; object-fit: contain; display: block; }
.pds-inv-remove-x {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #EF4444;
    color: #fff;
    border: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
}

/* Line Items Table */
.pds-inv-table-responsive { overflow-x: auto; }
.pds-inv-items-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 720px;
}
.pds-inv-items-table th {
    background: #F8FAFC;
    color: #475569;
    font-size: 12px;
    font-weight: 700;
    text-align: left;
    padding: 9px 8px;
    border-bottom: 1px solid var(--pds-border);
}
.pds-inv-items-table td {
    padding: 8px 6px;
    border-bottom: 1px solid #F1F5F9;
    vertical-align: middle;
}
.pds-inv-items-table input, .pds-inv-items-table select {
    width: 100%;
    padding: 7px 8px;
    border: 1px solid #CBD5E1;
    border-radius: 6px;
    font-size: 13px;
}
.pds-inv-row-total {
    font-weight: 700;
    text-align: right;
    font-size: 13px;
    white-space: nowrap;
}
.pds-inv-del-row {
    background: #FEE2E2;
    color: #DC2626;
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 700;
}

/* Summary */
.pds-inv-summary-grid {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 20px;
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--pds-border);
}
.pds-inv-totals-col {
    background: #F8FAFC;
    border: 1px solid var(--pds-border);
    border-radius: 10px;
    padding: 16px;
    align-self: start;
}
.pds-inv-total-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 14px;
}
.pds-inv-grand-row {
    border-top: 2px solid var(--pds-border);
    margin-top: 8px;
    padding-top: 10px;
    font-size: 17px;
    color: var(--pds-accent);
}
.pds-inv-words-box {
    margin-top: 10px;
    padding: 8px 10px;
    background: #FFFFFF;
    border: 1px dashed #CBD5E1;
    border-radius: 6px;
    font-size: 12px;
    color: #334155;
    font-style: italic;
}

/* Action Bar */
.pds-inv-action-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 10px;
}
.pds-inv-action-right { display: flex; gap: 10px; flex-wrap: wrap; }

/* Preview Stage */
.pds-inv-preview-toolbar {
    display: flex;
    justify-content: space-between;
    margin-bottom: 14px;
    gap: 10px;
    flex-wrap: wrap;
}
.pds-inv-a4-stage {
    overflow-x: auto;
    padding: 10px 0;
}
.pds-inv-a4-sheet {
    background: #FFFFFF;
    width: 794px;
    min-height: 980px;
    margin: 0 auto;
    padding: 36px 40px;
    border: 1px solid #CBD5E1;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    color: #0F172A;
    font-size: 12.5px;
    line-height: 1.45;
}

/* History Table */
.pds-inv-history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.pds-inv-history-table th, .pds-inv-history-table td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--pds-border);
    text-align: left;
}
.pds-inv-history-table th { background: #F8FAFC; font-weight: 700; }

/* Modal */
.pds-inv-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999999;
    padding: 16px;
}
.pds-inv-modal {
    background: #FFFFFF;
    width: 100%;
    max-width: 430px;
    border-radius: 14px;
    padding: 24px;
    position: relative;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
.pds-inv-modal-close {
    position: absolute;
    top: 12px;
    right: 14px;
    background: transparent;
    border: none;
    font-size: 24px;
    color: var(--pds-muted);
    cursor: pointer;
}
.pds-inv-modal-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--pds-border);
}
.pds-inv-mtab {
    flex: 1;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 10px;
    font-weight: 700;
    font-size: 14px;
    color: var(--pds-muted);
    cursor: pointer;
}
.pds-inv-mtab.is-active {
    color: var(--pds-accent);
    border-bottom-color: var(--pds-accent);
}
.pds-inv-modal-desc {
    font-size: 13px;
    color: var(--pds-muted);
    margin: 0 0 14px;
}
.pds-inv-alert {
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 12px;
}
.pds-inv-alert.is-error { background: #FEF2F2; color: #B91C1C; border: 1px solid #FECACA; }
.pds-inv-alert.is-success { background: #F0FDF4; color: #15803D; border: 1px solid #BBF7D0; }

/* Toast */
.pds-inv-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: #1E293B;
    color: #FFFFFF;
    padding: 12px 18px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    z-index: 1000000;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

/* Responsive */
@media (max-width: 820px) {
    .pds-inv-grid-2, .pds-inv-grid-3, .pds-inv-grid-4, .pds-inv-summary-grid {
        grid-template-columns: 1fr;
    }
    .pds-inv-topbar { flex-direction: column; align-items: stretch; }
    .pds-inv-mode-toggle { width: 100%; justify-content: center; }
    .pds-inv-mode-btn { flex: 1; justify-content: center; }
}
/* Forgot Password Link & Auto-save Badge */
.pds-inv-forgot-link {
    background: none;
    border: none;
    padding: 0;
    color: var(--pds-accent);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
    font-family: inherit;
}
.pds-inv-forgot-link:hover { color: var(--pds-accent-hover); }
.pds-inv-autosave-badge {
    font-size: 11px;
    font-weight: 600;
    color: #15803D;
    background: #DCFCE7;
    padding: 2px 8px;
    border-radius: 12px;
}
.pds-inv-btn-whatsapp {
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    padding: 9px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid #16A34A;
    background: #22C55E;
    color: #FFFFFF;
}
.pds-inv-btn-whatsapp:hover { background: #16A34A; }
/* Enhanced Mobile Responsiveness (v1.3.1) */
@media (max-width: 640px) {
    #pds-invoice-app.pds-inv-wrap {
        padding: 12px;
        margin: 8px auto;
        border-radius: 10px;
    }
    .pds-inv-topbar {
        padding: 12px;
        gap: 10px;
    }
    .pds-inv-auth-bar {
        width: 100%;
        justify-content: space-between;
    }
    .pds-inv-auth-bar button {
        flex: 1;
        text-align: center;
    }
    .pds-inv-grid-2-tight {
        grid-template-columns: 1fr;
    }
    .pds-inv-card {
        padding: 14px 12px;
    }
    .pds-inv-field input,
    .pds-inv-field select,
    .pds-inv-field textarea,
    .pds-inv-items-table input,
    .pds-inv-items-table select {
        font-size: 16px; /* Prevents iOS Safari auto-zoom on focus */
    }
    .pds-inv-action-bar {
        flex-direction: column;
        align-items: stretch;
    }
    .pds-inv-action-right {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        width: 100%;
    }
    .pds-inv-action-right #pds-download-pdf-btn {
        grid-column: 1 / -1;
    }
    .pds-inv-preview-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    .pds-inv-preview-toolbar > div {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 8px !important;
    }
    .pds-inv-a4-stage {
        -webkit-overflow-scrolling: touch;
        border: 1px dashed #CBD5E1;
        border-radius: 8px;
        padding: 8px;
        background: #F1F5F9;
    }
    .pds-inv-modal {
        padding: 18px 16px;
        max-height: 92vh;
        overflow-y: auto;
    }
    .pds-inv-toast {
        left: 12px;
        right: 12px;
        bottom: 14px;
        text-align: center;
    }
}
