/* InvoiceApp v2 - Complete Production Styles */
:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --success: #10b981;
    --success-dark: #059669;
    --warning: #f59e0b;
    --danger: #ef4444;
    --danger-dark: #dc2626;
    --secondary: #64748b;
    --dark-bg: #0f172a;
    --light-bg: #f8fafc;
    --border: #e2e8f0;
    --text-dark: #0f172a;
    --text-muted: #475569;
    --text-light: #64748b;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body { 
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; 
    background: #f1f5f9; 
    padding: 1rem; 
}

.app-container { 
    max-width: 1400px; 
    margin: 0 auto; 
    background: white; 
    border-radius: 1.5rem; 
    box-shadow: 0 20px 35px -12px rgba(0,0,0,0.1); 
    overflow: hidden; 
}

.app-header { 
    background: #0f172a; 
    color: white; 
    padding: 1rem 1.5rem; 
    display: flex; 
    flex-wrap: wrap; 
    justify-content: space-between; 
    align-items: center; 
    gap: 0.75rem; 
}

.logo-area h1 { font-size: 1.5rem; font-weight: 600; }
.logo-area p { font-size: 0.75rem; opacity: 0.7; }

.nav-buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; }

/* Navigation button styles */
.nav-buttons button.primary {
    background: var(--primary);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.nav-buttons button.secondary {
    background: var(--secondary);
}

.nav-buttons button:hover {
    transform: translateY(-2px);
    opacity: 0.9;
    transition: all 0.2s ease;
}

.nav-buttons button:active {
    transform: translateY(0px);
}

/* General button styles */
button, .btn { 
    background: #334155; 
    border: none; 
    padding: 0.5rem 1rem; 
    border-radius: 40px; 
    font-weight: 500; 
    cursor: pointer; 
    color: white; 
    font-size: 0.85rem; 
    transition: all 0.2s; 
}

button.primary { background: var(--primary); }
button.primary:hover { background: var(--primary-dark); }
button.success { background: var(--success); }
button.success:hover { background: var(--success-dark); }
button.warning { background: var(--warning); }
button.danger { background: var(--danger); }
button.danger:hover { background: var(--danger-dark); }
button.secondary { background: var(--secondary); }
button.small { padding: 0.25rem 0.75rem; font-size: 0.75rem; }

.main-content { padding: 1.8rem; min-height: 550px; }

.stats-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); 
    gap: 1rem; 
    margin-bottom: 2rem; 
}

.stat-card { 
    background: #f8fafc; 
    border-radius: 1rem; 
    padding: 1rem; 
    border-left: 4px solid #3b82f6; 
}

.stat-card h3 { font-size: 0.8rem; text-transform: uppercase; color: #475569; }
.stat-value { font-size: 1.9rem; font-weight: 700; color: #0f172a; }

.aging-summary { 
    background: #fefce8; 
    border-radius: 1rem; 
    padding: 1rem; 
    margin-bottom: 2rem; 
    border: 1px solid #fde047; 
}

.aging-bar { 
    background: #e2e8f0; 
    border-radius: 20px; 
    height: 8px; 
    margin: 0.5rem 0; 
    overflow: hidden; 
    display: flex;
}

.aging-fill { background: #eab308; height: 100%; }

table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
th, td { text-align: left; padding: 0.75rem; border-bottom: 1px solid #e2e8f0; }
th { background: #f1f5f9; font-weight: 600; }

.badge { 
    display: inline-block; 
    padding: 0.2rem 0.6rem; 
    border-radius: 20px; 
    font-size: 0.7rem; 
    font-weight: 600; 
}

.badge-paid { background: #d1fae5; color: #065f46; }
.badge-sent { background: #dbeafe; color: #1e40af; }
.badge-draft { background: #e2e8f0; color: #334155; }
.badge-overdue { background: #fee2e2; color: #991b1b; }
.badge-partially_paid { background: #fef3c7; color: #92400e; }
.badge-overdue-partial { background: #fef3c7; color: #92400e; }

.invoice-container { 
    background: white; 
    padding: 2rem; 
    max-width: 800px; 
    margin: 0 auto; 
    position: relative; 
}

/* Toast Container */
#toastContainer {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Toast Notifications */
.toast-notification {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-width: 200px;
    max-width: 350px;
    padding: 12px 16px;
    border-radius: 8px;
    color: white;
    font-size: 14px;
    font-family: system-ui, sans-serif;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    cursor: default;
    animation: slideIn 0.3s ease;
}

.toast-notification span {
    margin-left: 12px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
}

.toast-notification span:hover { opacity: 0.8; }

@keyframes slideIn {
    from { opacity: 0; transform: translateX(100%); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes fadeOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(100%); }
}

.watermark-layer { 
    position: fixed; 
    bottom: 10px; 
    right: 10px; 
    font-size: 7px; 
    color: #ccc; 
    opacity: 0.4; 
    font-family: monospace; 
    pointer-events: none; 
    z-index: 1000; 
}

.empty-state { text-align: center; padding: 3rem; color: #64748b; }

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.25rem; font-weight: 500; }
.form-group input, .form-group textarea, .form-group select { 
    width: 100%; 
    padding: 0.5rem; 
    border: 1px solid #cbd5e1; 
    border-radius: 0.5rem; 
}

/* Template Styles */
.invoice-minimal { font-family: Arial, sans-serif; }
.invoice-professional { font-family: 'Times New Roman', serif; }
.invoice-modern { font-family: 'Helvetica Neue', sans-serif; }
.invoice-corporate { font-family: Georgia, serif; border: 2px solid #1a5276; border-radius: 8px; }

/* PDF Export Fixes */
#invoicePreviewContainer { height: auto !important; overflow: visible !important; display: block !important; }
.invoice-container { height: auto !important; overflow: visible !important; }

#notesPrintDisplay { display: none; }
#notesPrintContent { white-space: pre-wrap; }

@media (max-width: 700px) { 
    .main-content { padding: 1rem; } 
    th, td { font-size: 0.8rem; }
    .stats-grid { grid-template-columns: 1fr; }
    .toast-notification { min-width: 150px; max-width: 280px; font-size: 12px; padding: 10px 14px; }
}

@media print {
    body { margin: 0; padding: 0; background: white; }
    .app-header, .nav-buttons, .toast-notification, .toast, .watermark-layer, #toastContainer,
    button, .btn, button[onclick*="applyTemplate"], button.success, button.primary,
    div[style*="background: #fef3c7"], hr, .form-group:has(#invoiceNotes) {
        display: none !important;
    }
    #invoiceNotes {
        display: none !important;
    }
    #invoicePreviewContainer { margin: 0 !important; padding: 0 !important; }
    .invoice-container { background: white !important; box-shadow: none !important; padding: 20px !important; page-break-inside: avoid; }
    #notesPrintDisplay { display: block !important; }
    #notesPrintContent { white-space: pre-wrap !important; }
    .badge { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
    
    /* Table borders in print */
    table {
        width: 100% !important;
        border-collapse: collapse !important;
    }
    th, td {
        border: 1px solid #ddd !important;
        padding: 8px !important;
        text-align: left !important;
    }
}

/* Fix long text truncation (general) */
.invoice-table td, 
.invoice-table th,
table td, 
table th {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 700px) {
    .invoice-table td, 
    table td {
        white-space: normal;
        word-break: break-word;
    }
}

#custName, #custEmail {
    max-width: 100%;
    word-break: break-word;
}

/* ============================================ */
/* DASHBOARD TABLE – ACTION BUTTONS ALIGNMENT   */
/* ============================================ */
/* Force action buttons to stay in one line on desktop */
table td:last-child,
table th:last-child {
    white-space: nowrap;
    min-width: 320px;      /* enough space for Edit, Mark Paid, Undo Paid, Remind, Copy, Del */
}

/* Reduce the width of the Total column so Actions column can slide left */
td:nth-last-child(2),
th:nth-last-child(2) {
    white-space: nowrap;
    text-align: right;
    padding-right: 8px;
}

/* On smaller screens (tablets), buttons may wrap gracefully */
@media (max-width: 1000px) {
    table td:last-child {
        white-space: normal;
        min-width: 250px;
    }
}

/* ============================================ */
/* INVOICE EDITOR – ITEM ROW GRID LAYOUT        */
/* ============================================ */
/* Ensure the delete button stays aligned even with large numbers */
.item-row {
    display: grid;
    grid-template-columns: 2fr 80px 100px 80px 40px;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}

/* Fallback for older browsers (optional) */
.item-row input,
.item-row span,
.item-row button {
    width: 100%;
}

/* Validation error highlighting */
.validation-error {
    border: 2px solid #ef4444 !important;
    background-color: #fef2f2 !important;
}

.item-row {
    transition: all 0.2s ease;
}

.item-row.validation-error-row {
    border: 2px solid #ef4444;
    border-radius: 8px;
    padding: 4px;
    background-color: #fef2f2;
}

input.validation-error, 
textarea.validation-error, 
select.validation-error {
    border: 2px solid #ef4444 !important;
    background-color: #fef2f2 !important;
}

.btn-highlight {
    border: 2px solid #ef4444 !important;
    box-shadow: 0 0 0 2px #ef4444 !important;
    animation: pulse 1s ease-in-out 2;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

/* Make labels look like buttons (for Import Backup) */
label.secondary {
    display: inline-block;
    background: #64748b;
    padding: 0.5rem 1rem;
    border-radius: 40px;
    font-weight: 500;
    cursor: pointer;
    color: white;
    font-size: 0.85rem;
    transition: all 0.2s;
    margin-left: 8px;
}

label.secondary:hover {
    background: #475569;
    transform: translateY(-1px);
}