/* ==========================================
   STELLAR INVOICE - DESIGN SYSTEM & STYLES
   ========================================== */

/* Design Tokens & Theme Variables */
:root {
    --bg-app: #090d16;
    --bg-editor: #0f172a;
    --bg-card: #1e293b;
    --bg-input: #151f32;
    --border-color: #334155;
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --color-brand: #6366f1;
    --color-brand-hover: #4f46e5;
    --color-brand-glow: rgba(99, 102, 241, 0.15);
    
    --color-success: #10b981;
    --color-success-hover: #059669;
    --color-success-glow: rgba(16, 185, 129, 0.15);
    
    --color-danger: #f43f5e;
    --color-danger-hover: #e11d48;
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.15), 0 8px 10px -6px rgb(0 0 0 / 0.15);
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    
    /* Live Preview Paper Tokens (Standard Light Page Theme) */
    --paper-bg: #ffffff;
    --paper-text-primary: #1e293b;
    --paper-text-secondary: #475569;
    --paper-text-muted: #64748b;
    --paper-border: #e2e8f0;
    --paper-accent: #312e81; /* Deep indigo */
}

/* Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
}

body {
    background-color: var(--bg-app);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
}

/* App Container Split Screen */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar Editor Panel */
.editor-panel {
    width: 42%;
    min-width: 480px;
    max-width: 600px;
    height: 100%;
    background-color: var(--bg-editor);
    border-right: 1px solid var(--border-color);
    padding: 2.2rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

.editor-panel::-webkit-scrollbar {
    width: 6px;
}
.editor-panel::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: var(--radius-sm);
}

/* App Header & Branding */
.app-header {
    margin-bottom: 2rem;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.3rem;
}

.app-logo {
    width: 28px;
    height: 28px;
    color: var(--color-brand);
}

.logo-area h1 {
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: -0.025em;
    color: var(--text-primary);
}

.logo-area h1 span {
    color: var(--color-brand);
}

.subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Editor Action Bar Buttons */
.action-buttons-group {
    display: grid;
    grid-template-columns: 1.5fr 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 2.2rem;
    background-color: rgba(21, 31, 50, 0.4);
    padding: 0.75rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: center;
    width: 100%;
}

.btn-primary {
    background-color: var(--color-brand);
    color: #ffffff;
    box-shadow: 0 0 12px var(--color-brand-glow);
}

.btn-primary:hover {
    background-color: var(--color-brand-hover);
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.3);
}

.btn-secondary {
    background-color: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

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

.btn-danger-link {
    background-color: transparent;
    color: var(--text-secondary);
    border: 1px dashed var(--border-color);
}

.btn-danger-link:hover {
    background-color: rgba(244, 63, 94, 0.08);
    color: var(--color-danger);
    border-color: var(--color-danger);
}

.btn-add {
    background-color: var(--color-success-glow);
    color: var(--color-success);
    border: 1px solid rgba(16, 185, 129, 0.3);
    padding: 0.5rem 0.9rem;
    border-radius: var(--radius-sm);
    width: auto;
    font-size: 0.8rem;
}

.btn-add:hover {
    background-color: var(--color-success);
    color: #ffffff;
    box-shadow: 0 0 12px var(--color-success-glow);
}

.btn-delete-row {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    padding: 0.5rem;
    margin-top: 1.5rem;
}

.btn-delete-row:hover {
    color: var(--color-danger);
    background-color: rgba(244, 63, 94, 0.1);
}

.icon {
    width: 16px;
    height: 16px;
    stroke-width: 2.2px;
}

.icon-sm {
    width: 14px;
    height: 14px;
    stroke-width: 2.5px;
}

/* Form Sections */
.form-section {
    background-color: rgba(30, 41, 59, 0.3);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    transition: border-color var(--transition-normal);
}

.form-section:focus-within {
    border-color: var(--color-brand);
}

.section-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
    position: relative;
}

.section-badge {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--color-brand);
    font-size: 0.75rem;
    font-weight: 700;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.section-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.badge-saved {
    position: absolute;
    right: 0;
    font-size: 0.65rem;
    color: var(--color-success);
    background-color: rgba(16, 185, 129, 0.1);
    padding: 0.2rem 0.5rem;
    border-radius: 20px;
    border: 1px solid rgba(16, 185, 129, 0.2);
}

/* Grids and Forms */
.grid-2-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-bottom: 1rem;
}

label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

input[type="text"],
input[type="email"],
input[type="number"],
input[type="date"],
select,
textarea {
    background-color: var(--bg-input);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    padding: 0.7rem 0.8rem;
    font-size: 0.85rem;
    outline: none;
    transition: all var(--transition-fast);
    width: 100%;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--color-brand);
    box-shadow: 0 0 0 3px var(--color-brand-glow);
    background-color: var(--bg-editor);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-muted);
}

textarea {
    resize: vertical;
}

/* Bank Details Dropdown Collapsible */
.collapsible-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--color-brand);
    cursor: pointer;
    font-weight: 600;
    padding: 0.5rem 0;
    margin-top: 0.5rem;
    border-top: 1px dashed var(--border-color);
}

.collapsible-trigger:hover {
    color: var(--text-primary);
}

.arrow-icon {
    width: 16px;
    height: 16px;
    transition: transform var(--transition-normal);
}

.collapsible-content {
    max-height: 500px;
    opacity: 1;
    overflow: hidden;
    transition: all var(--transition-normal) cubic-bezier(0.4, 0, 0.2, 1);
}

.collapsible-content.collapsed {
    max-height: 0;
    opacity: 0;
    padding: 0;
}

.pt-10 {
    padding-top: 10px;
}

/* Line Items Input Rows */
.line-items-header {
    justify-content: space-between;
}

.items-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.item-row {
    display: grid;
    grid-template-columns: 2fr 75px 115px 42px;
    gap: 0.6rem;
    align-items: center;
    background-color: rgba(21, 31, 50, 0.2);
    padding: 0.75rem;
    border-radius: var(--radius-md);
    border: 1px solid rgba(51, 65, 85, 0.5);
    animation: fadeIn 0.25s var(--transition-fast);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Preview Panel Wrapper (Right Column) */
.preview-panel {
    flex: 1;
    height: 100%;
    background-color: var(--bg-app);
    overflow-y: auto;
    padding: 2.2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.preview-header {
    width: 100%;
    max-width: 800px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 1.5rem;
}

.preview-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.preview-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Invoice Paper Sheet Styling (Simulated Document) */
.invoice-paper-wrapper {
    background-color: var(--paper-bg);
    width: 100%;
    max-width: 800px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    margin-bottom: 3rem;
}

.invoice-paper {
    padding: 3rem;
    color: var(--paper-text-primary);
    font-size: 0.85rem;
    line-height: 1.5;
    position: relative;
    min-height: 1040px; /* Standard ratio approximation */
    display: flex;
    flex-direction: column;
    background: white;
}

/* Paper Details Structure */
.paper-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 2rem;
}

.biz-info-block {
    display: flex;
    align-items: flex-start;
    gap: 1.25rem;
    max-width: 55%;
}

.preview-logo-placeholder {
    width: 50px;
    height: 50px;
    border-radius: var(--radius-sm);
    background-color: var(--paper-accent);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.preview-logo-placeholder svg {
    width: 24px;
    height: 24px;
}

.biz-info-block h3 {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--paper-accent);
    margin-bottom: 0.35rem;
    letter-spacing: -0.015em;
    word-break: break-word;
}

.biz-info-block p {
    color: var(--paper-text-secondary);
    font-size: 0.8rem;
    margin-bottom: 0.15rem;
}

.invoice-title-block {
    text-align: right;
}

.invoice-title-block h1 {
    font-size: 2.2rem;
    font-weight: 900;
    color: var(--paper-accent);
    letter-spacing: -0.03em;
    margin-bottom: 0.75rem;
    line-height: 1;
}

.meta-preview-grid {
    display: grid;
    grid-template-columns: auto auto;
    gap: 0.25rem 1rem;
    text-align: right;
    font-size: 0.8rem;
}

.meta-preview-grid div:nth-child(odd) {
    color: var(--paper-text-muted);
}

.meta-preview-grid div:nth-child(even) {
    color: var(--paper-text-primary);
    font-weight: 600;
}

.paper-divider {
    height: 1px;
    background-color: var(--paper-border);
    margin: 2rem 0;
}

.paper-billing-details {
    margin-bottom: 2rem;
}

.bill-to-section {
    max-width: 60%;
}

.sub-label {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--paper-text-muted);
    display: block;
    margin-bottom: 0.5rem;
}

.bill-to-section h4 {
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: 0.3rem;
}

.bill-to-section p {
    color: var(--paper-text-secondary);
    font-size: 0.8rem;
    margin-bottom: 0.15rem;
}

/* Paper Tables */
.paper-items-table-wrapper {
    flex: 1; /* Pushes calculations/totals to page bottom if items list is small */
    margin-bottom: 2.5rem;
}

.paper-items-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.paper-items-table th {
    border-bottom: 2px solid var(--paper-accent);
    color: var(--paper-text-muted);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.75rem 0.5rem;
}

.paper-items-table td {
    padding: 0.9rem 0.5rem;
    border-bottom: 1px solid var(--paper-border);
    color: var(--paper-text-primary);
    font-size: 0.85rem;
    vertical-align: top;
    word-break: break-word;
}

.paper-items-table tbody tr:last-child td {
    border-bottom-color: var(--paper-accent);
}

.width-qty { width: 60px; }
.width-rate { width: 110px; }
.width-total { width: 120px; }

.text-right { text-align: right; }
.text-center { text-align: center; }

.empty-table-msg {
    color: var(--paper-text-muted);
    padding: 2.5rem 0 !important;
    font-style: italic;
}

/* Bottom Grid (Notes & Totals) */
.paper-bottom-grid {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 2.5rem;
    align-items: start;
    margin-top: auto;
}

.bottom-block {
    margin-bottom: 1.5rem;
}

.bottom-block h5 {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--paper-text-muted);
    margin-bottom: 0.4rem;
    border-bottom: 1px solid var(--paper-border);
    padding-bottom: 0.25rem;
}

.bottom-block p {
    font-size: 0.8rem;
    color: var(--paper-text-secondary);
}

.bank-grid {
    display: grid;
    grid-template-columns: 75px auto;
    gap: 0.15rem 0.5rem;
    font-size: 0.78rem;
}

.bank-grid div:nth-child(odd) {
    color: var(--paper-text-muted);
}

.totals-calculation-section {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.totals-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--paper-text-secondary);
}

.totals-row span:last-child {
    font-weight: 600;
    color: var(--paper-text-primary);
}

.totals-divider {
    height: 1px;
    background-color: var(--paper-border);
    margin: 0.25rem 0;
}

.total-due-row {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--paper-accent);
}

.total-due-row span:first-child {
    font-weight: 800;
    color: var(--paper-text-primary);
}

.total-due-row span:last-child {
    font-weight: 900;
    color: var(--paper-accent);
    font-size: 1.25rem;
}

/* Paper Footer */
.paper-footer {
    border-top: 1px solid var(--paper-border);
    padding-top: 1.5rem;
    margin-top: 2.5rem;
    text-align: center;
    color: var(--paper-text-muted);
    font-size: 0.75rem;
}

.branding-watermark {
    font-size: 0.65rem;
    margin-top: 0.25rem;
    opacity: 0.6;
}

/* Helpers & Placeholders styling */
.multi-line {
    white-space: pre-wrap;
}

.empty-field {
    opacity: 0.45;
    font-style: italic;
}

.hidden {
    display: none !important;
}

/* ==========================================
   RESPONSIVE DESIGN (EDITOR STACK)
   ========================================== */
@media (max-width: 1024px) {
    .app-container {
        flex-direction: column;
        height: auto;
        overflow-y: auto;
    }
    
    .editor-panel {
        width: 100%;
        max-width: 100%;
        min-width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding: 1.5rem;
    }
    
    .preview-panel {
        width: 100%;
        padding: 1.5rem;
        height: auto;
    }
    
    .invoice-paper-wrapper {
        box-shadow: none;
        border: 1px solid var(--border-color);
    }
}

@media (max-width: 600px) {
    .grid-2-col {
        grid-template-columns: 1fr;
        gap: 0;
    }
    
    .item-row {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
    
    .btn-delete-row {
        margin-top: 0;
        width: 100%;
        justify-content: center;
        background-color: rgba(244, 63, 94, 0.1);
        color: var(--color-danger);
    }
    
    .invoice-paper {
        padding: 1.5rem;
    }
    
    .paper-header {
        flex-direction: column;
        gap: 1.5rem;
    }
    
    .invoice-title-block {
        text-align: left;
    }
    
    .meta-preview-grid {
        text-align: left;
        justify-content: flex-start;
    }
    
    .paper-bottom-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
}

/* ==========================================
   PRINT MEDIA RULES (WINDOW.PRINT)
   ========================================== */
@media print {
    body {
        background-color: #ffffff !important;
        color: #000000 !important;
        overflow: visible !important;
        height: auto !important;
    }
    
    .app-container {
        display: block !important;
        height: auto !important;
    }
    
    .editor-panel,
    .preview-header {
        display: none !important;
    }
    
    .preview-panel {
        padding: 0 !important;
        background: transparent !important;
        height: auto !important;
        display: block !important;
    }
    
    .invoice-paper-wrapper {
        box-shadow: none !important;
        border: none !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        border-radius: 0 !important;
    }
    
    .invoice-paper {
        padding: 0 !important;
        min-height: 0 !important;
    }
    
    /* Ensure page break calculations look perfect in browser print dialog */
    thead {
        display: table-header-group;
    }
    
    tr {
        page-break-inside: avoid;
    }
}

/* ==========================================
   THEME TOGGLE STYLES
   ========================================== */
.btn-theme-toggle {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    padding: 0.4rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    margin-left: auto;
}

.btn-theme-toggle:hover {
    color: var(--text-primary);
    background-color: var(--bg-card);
}

.btn-theme-toggle svg {
    width: 18px;
    height: 18px;
}

.btn-theme-toggle svg.hidden {
    display: none !important;
}

/* ==========================================
   LIGHT THEME OVERRIDES
   ========================================== */
body.light-theme {
    --bg-app: #f1f5f9;
    --bg-editor: #ffffff;
    --bg-card: #f8fafc;
    --bg-input: #ffffff;
    --border-color: #cbd5e1;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --bg-editor-glow: rgba(15, 23, 42, 0.03);
}

/* Light mode modifications for scrollbars and shadows */
body.light-theme ::-webkit-scrollbar-track {
    background: #f1f5f9;
}

body.light-theme ::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border: 3px solid #f1f5f9;
}

body.light-theme ::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

body.light-theme .editor-panel {
    box-shadow: 10px 0 35px rgba(0, 0, 0, 0.03);
}

body.light-theme .invoice-sheet {
    box-shadow: 0 10px 40px rgba(15, 23, 42, 0.06);
}

body.light-theme .form-section {
    border-bottom: 1px solid #f1f5f9;
}

/* ==========================================
   DONATION & SUPPORT CALLOUT
   ========================================== */
.donate-section {
    border-top: 1px dashed var(--border-color);
    padding-top: 1.5rem;
    margin-top: 1.5rem;
}

.donate-card {
    background: rgba(255, 221, 0, 0.04);
    border: 1px solid rgba(255, 221, 0, 0.15);
    border-radius: var(--radius-md);
    padding: 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    transition: all var(--transition-normal);
}

.donate-card:hover {
    border-color: rgba(255, 221, 0, 0.3);
    background: rgba(255, 221, 0, 0.06);
}

.donate-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.donate-icon-badge {
    width: 28px;
    height: 28px;
    background-color: rgba(239, 68, 68, 0.1);
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #ef4444;
}

.heart-icon {
    width: 14px;
    height: 14px;
    fill: currentColor;
}

.donate-card h3 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
}

.donate-lead {
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.45;
}

.btn-bmc {
    background-color: #ffdd00;
    color: #000000;
    font-weight: 700;
    font-size: 0.82rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border-radius: var(--radius-sm);
    padding: 0.65rem;
    text-decoration: none;
    transition: background-color var(--transition-fast), transform var(--transition-fast);
    border: 1px solid #e6c300;
}

.btn-bmc:hover {
    background-color: #ffea33;
    transform: translateY(-1px);
}

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

.icon-bmc {
    width: 16px;
    height: 16px;
}

