/* Modern Professional Design System for Invoice Generator */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@400;500;600;700;800&display=swap');

:root {
    /* Color Palette */
    --bg-main: #0b0f19;
    --bg-sidebar: #131926;
    --border-color: #222d44;
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --accent: #d4af37; /* Warm Gold */
    --accent-hover: #f3cf65;
    --accent-glow: rgba(212, 175, 55, 0.15);
    
    --invoice-bg: #ffffff;
    --invoice-text: #1f2937;
    --invoice-text-muted: #4b5563;
    --invoice-border: #e5e7eb;
    
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;

    /* Styling Rules */
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.15), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --transition-all: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    overflow: hidden;
}

input, select, textarea, button {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: #2b354d;
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: #3e4c6e;
}

/* App Layout */
.app-container {
    display: flex;
    width: 100vw;
    height: 100vh;
    position: relative;
}

/* Sidebar Dashboard (Controls) */
.sidebar {
    width: 480px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: 100%;
    z-index: 10;
    transition: var(--transition-all);
}

.sidebar-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-icon {
    font-size: 24px;
    color: var(--accent);
}

.brand-title {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 20px;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, #ffffff 0%, #b2b9c9 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

/* Collapsible Section Layout */
.section-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px;
    transition: var(--transition-all);
}

.section-card:hover {
    border-color: rgba(212, 175, 55, 0.3);
}

.section-title {
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    font-size: 16px;
    color: var(--accent);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-left: 3px solid var(--accent);
    padding-left: 10px;
}

.form-group {
    margin-bottom: 16px;
}

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

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

input[type="text"],
input[type="date"],
input[type="number"],
textarea,
select {
    width: 100%;
    background-color: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: var(--transition-all);
}

input[type="text"]:focus,
input[type="date"]:focus,
input[type="number"]:focus,
textarea:focus,
select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

textarea {
    resize: vertical;
    min-height: 80px;
}

/* Preset Options List */
.preset-selector {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.preset-btn {
    flex: 1;
    background: transparent;
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 11px;
    font-weight: 500;
    transition: var(--transition-all);
}

.preset-btn:hover, .preset-btn.active {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-glow);
}

/* Line Items Editor List */
.editor-items-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 4px;
}

.editor-item-card {
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: relative;
    transition: var(--transition-all);
}

.editor-item-card.disabled {
    opacity: 0.5;
}

.editor-item-top {
    display: flex;
    align-items: center;
    gap: 10px;
}

.editor-item-drag {
    cursor: grab;
    color: var(--text-secondary);
}

.editor-item-checkbox {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    cursor: pointer;
}

.editor-item-desc {
    flex: 1;
    font-size: 13px;
    padding: 6px 8px;
}

.editor-item-bottom {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    align-items: center;
}

.editor-item-qty, .editor-item-price {
    width: 100px;
    padding: 6px 8px;
    font-size: 13px;
}

.editor-item-total {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
    width: 100px;
    text-align: right;
    padding-right: 4px;
}

.delete-item-btn {
    background: transparent;
    border: none;
    color: var(--danger);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: var(--transition-all);
}

.delete-item-btn:hover {
    background: rgba(239, 68, 68, 0.1);
}

.add-item-btn {
    width: 100%;
    background: transparent;
    border: 1px dashed var(--accent);
    color: var(--accent);
    padding: 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 16px;
    transition: var(--transition-all);
}

.add-item-btn:hover {
    background: var(--accent-glow);
}

/* Sidebar Footer (Action Buttons) */
.sidebar-footer {
    padding: 20px 24px;
    border-top: 1px solid var(--border-color);
    background-color: rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.primary-btn {
    width: 100%;
    background: linear-gradient(135deg, var(--accent) 0%, #b28e20 100%);
    color: #000000;
    border: none;
    padding: 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--transition-all);
    box-shadow: 0 4px 10px rgba(212, 175, 55, 0.2);
}

.primary-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(212, 175, 55, 0.35);
}

.primary-btn:active {
    transform: translateY(0);
}

.secondary-actions {
    display: flex;
    gap: 12px;
}

.secondary-btn {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: var(--transition-all);
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--text-secondary);
}

/* Preview Area Workspace */
.preview-container {
    flex: 1;
    background-color: var(--bg-main);
    background-image: radial-gradient(circle at 50% 50%, #151e33 0%, #0b0f19 100%);
    overflow-y: auto;
    padding: 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    position: relative;
}

.preview-controls {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 16px;
    background: rgba(11, 15, 25, 0.65);
    backdrop-filter: blur(12px);
    padding: 10px 24px;
    border-radius: 30px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
}

.tab-switcher {
    display: flex;
    background-color: rgba(0, 0, 0, 0.3);
    border-radius: 20px;
    padding: 3px;
    border: 1px solid var(--border-color);
}

.tab-switcher .tab-btn {
    background: transparent;
    border: none;
    padding: 6px 18px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-secondary);
    transition: var(--transition-all);
}

.tab-switcher .tab-btn:hover {
    color: var(--text-primary);
}

.tab-switcher .tab-btn.active {
    background-color: var(--accent);
    color: #000000;
}

.icon-badge-btn {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: var(--transition-all);
}

.icon-badge-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
}

/* Paper Sheet Layout */
.invoice-sheet {
    width: 800px;
    background-color: var(--invoice-bg);
    color: var(--invoice-text);
    padding: 50px 60px;
    box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 1030px; /* A4 aspect ratio scale */
    transition: var(--transition-all);
}

/* Dark version of paper sheet for UI viewing */
.invoice-sheet.dark-preview {
    --invoice-bg: #111827;
    --invoice-text: #f3f4f6;
    --invoice-text-muted: #9ca3af;
    --invoice-border: #374151;
}

/* Custom CSS Logo for Real Estate Connections */
.company-brand-section {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 40px;
}

.invoice-logo-container {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo-graphic {
    position: relative;
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--accent);
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.logo-graphic::before {
    content: '';
    position: absolute;
    width: 0;
    height: 0;
    border-left: 12px solid transparent;
    border-right: 12px solid transparent;
    border-bottom: 16px solid var(--accent);
    top: 8px;
}

.logo-graphic::after {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    background-color: var(--accent);
    bottom: 8px;
    border-radius: 2px;
}

/* Light Mode Specific Logo Graphic Adjustment */
body:not(.dark-preview) .logo-graphic {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}

.logo-text-title {
    font-family: 'Outfit', sans-serif;
    font-size: 22px;
    font-weight: 800;
    line-height: 1.1;
    color: var(--invoice-text);
    letter-spacing: -0.5px;
}

.logo-text-subtitle {
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 2px;
    color: var(--accent);
    text-transform: uppercase;
    margin-top: 2px;
}

.invoice-status-badge {
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.status-paid {
    background-color: rgba(16, 185, 129, 0.1);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.status-unpaid {
    background-color: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.status-estimate {
    background-color: rgba(245, 158, 11, 0.1);
    color: #f59e0b;
    border: 1px solid rgba(245, 158, 11, 0.2);
}

/* Invoice Info Rows */
.invoice-details-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 40px;
    margin-bottom: 40px;
    border-bottom: 1px solid var(--invoice-border);
    padding-bottom: 30px;
}

.billing-col {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.billing-address-box {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
    color: var(--invoice-text-muted);
    line-height: 1.5;
}

.address-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 4px;
}

.billing-address-box strong {
    color: var(--invoice-text);
    font-size: 15px;
}

.meta-col {
    display: flex;
    flex-direction: column;
    gap: 12px;
    background-color: rgba(0,0,0,0.02);
    border-radius: var(--radius-sm);
    padding: 16px;
    border: 1px solid var(--invoice-border);
    align-self: flex-start;
}

.invoice-sheet.dark-preview .meta-col {
    background-color: rgba(255, 255, 255, 0.02);
}

.meta-item {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
}

.meta-item span:first-child {
    color: var(--invoice-text-muted);
    font-weight: 500;
}

.meta-item span:last-child {
    font-weight: 600;
    color: var(--invoice-text);
}

/* Invoice Table Layout */
.invoice-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 30px;
}

.invoice-table th {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--invoice-text-muted);
    border-bottom: 2px solid var(--invoice-border);
    padding: 10px 12px;
    text-align: left;
    letter-spacing: 0.5px;
}

.invoice-table td {
    padding: 14px 12px;
    border-bottom: 1px solid var(--invoice-border);
    font-size: 13px;
    vertical-align: top;
    color: var(--invoice-text);
}

.invoice-table th.col-qty, .invoice-table td.col-qty {
    width: 60px;
    text-align: center;
}

.invoice-table th.col-price, .invoice-table td.col-price {
    width: 120px;
    text-align: right;
}

.invoice-table th.col-total, .invoice-table td.col-total {
    width: 120px;
    text-align: right;
}

.item-index {
    color: var(--invoice-text-muted);
    font-weight: 500;
    font-size: 12px;
}

.item-desc-wrapper {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.item-desc-title {
    font-weight: 600;
}

.item-desc-sub {
    font-size: 11px;
    color: var(--invoice-text-muted);
    line-height: 1.4;
}

.item-disabled-note {
    font-size: 10px;
    color: var(--danger);
    font-style: italic;
    margin-top: 4px;
}

.invoice-table tr.item-inactive td {
    text-decoration: line-through;
    color: var(--invoice-text-muted);
    opacity: 0.45;
}

/* Totals Summary Panel */
.totals-section {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 40px;
    page-break-inside: avoid;
}

.notes-terms-box {
    width: 55%;
    font-size: 12px;
    color: var(--invoice-text-muted);
    line-height: 1.6;
}

.notes-terms-title {
    font-weight: 700;
    color: var(--invoice-text);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.banking-instructions {
    margin-top: 16px;
    padding: 12px;
    background-color: rgba(0,0,0,0.015);
    border-radius: 4px;
    border: 1px dashed var(--invoice-border);
    font-size: 11px;
}

.invoice-sheet.dark-preview .banking-instructions {
    background-color: rgba(255, 255, 255, 0.01);
}

.banking-row {
    margin-bottom: 4px;
}

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

.banking-row strong {
    color: var(--invoice-text);
}

.totals-box {
    width: 35%;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.totals-row {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
}

.totals-row span:first-child {
    color: var(--invoice-text-muted);
}

.totals-row span:last-child {
    font-weight: 600;
}

.totals-row.grand-total {
    border-top: 2px solid var(--invoice-text);
    padding-top: 12px;
    margin-top: 4px;
    font-size: 18px;
    font-weight: 800;
    font-family: 'Outfit', sans-serif;
    color: var(--invoice-text);
}

.totals-row.grand-total span:first-child {
    color: var(--invoice-text);
}

.totals-row.balance-due {
    color: var(--danger);
    background-color: rgba(239, 68, 68, 0.05);
    padding: 8px;
    border-radius: 4px;
    font-weight: 700;
}

.totals-row.balance-due span:first-child {
    color: var(--danger);
}

/* Footer Section */
.invoice-footer {
    margin-top: auto;
    padding-top: 30px;
    border-top: 1px solid var(--invoice-border);
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--invoice-text-muted);
}

.footer-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: #1e293b;
    border-left: 4px solid var(--accent);
    color: var(--text-primary);
    padding: 12px 20px;
    border-radius: 4px;
    font-size: 13px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideIn 0.3s ease forwards;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Print Stylesheet overrides */
@media print {
    body {
        background: #ffffff !important;
        color: #000000 !important;
        overflow: visible !important;
        display: block !important;
    }
    
    .app-container {
        display: block !important;
        height: auto !important;
        overflow: visible !important;
    }
    
    .sidebar,
    .preview-controls,
    .toast-container,
    .no-print {
        display: none !important;
    }
    
    .preview-container {
        padding: 0 !important;
        margin: 0 !important;
        background: transparent !important;
        overflow: visible !important;
        display: block !important;
    }
    
    .invoice-sheet {
        box-shadow: none !important;
        border: none !important;
        padding: 0 !important;
        margin: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        min-height: 0 !important;
        background: #ffffff !important;
        color: #000000 !important;
        font-size: 11pt !important;
    }

    .invoice-sheet.dark-preview {
        --invoice-bg: #ffffff;
        --invoice-text: #1f2937;
        --invoice-text-muted: #4b5563;
        --invoice-border: #e5e7eb;
    }

    /* Print respects script-controlled inline style displays */
    .invoice-sheet[style*="display: none"] {
        display: none !important;
    }
    
    /* Ensure page breaks cleanly */
    .totals-section {
        page-break-inside: avoid;
    }
    
    .invoice-footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        page-break-after: avoid;
    }
}
