/* ============================================================
   InvoiceCraft — Unified Modern Premium Dark Theme
   ============================================================ */
:root {
    --bg: #0c0e14;
    --bg-panel: #12151f;
    --bg-card: #181c28;
    --bg-hover: #1e2334;
    --bg-input: #10131d;
    --border: rgba(255, 255, 255, 0.08);
    --border-focus: #6366f1;
    
    --text: #e8eaf0;
    --text-muted: #8b8fa8;
    --text-dim: #5c6080;
    
    --accent: #6366f1;
    --accent-light: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.15);
    
    --purple: #a855f7;
    --purple-glow: rgba(168, 85, 247, 0.15);
    
    --green: #22c55e;
    --green-bg: rgba(34, 197, 94, 0.1);
    
    --red: #ef4444;
    --red-bg: rgba(239, 68, 68, 0.1);
    
    --orange: #f59e0b;
    --orange-bg: rgba(245, 158, 11, 0.1);
    
    --radius: 12px;
    --radius-sm: 8px;
    --font: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    --transition: .2s cubic-bezier(0.4, 0, 0.2, 1);
    --shadow: 0 4px 20px rgba(0,0,0,0.3);
}

/* ---- Reset & Base ---- */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    background-color: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ---- Typography ---- */
h1, h2, h3, h4, h5, h6 { color: #fff; font-weight: 600; line-height: 1.25; }

/* ---- Scrollbars ---- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ---- Form Controls ---- */
label { display: block; font-size: .8rem; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .05em; }
input[type="text"], input[type="email"], input[type="tel"], input[type="number"], input[type="date"], input[type="password"], select, textarea {
    width: 100%;
    background-color: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font);
    font-size: .9rem;
    padding: 10px 12px;
    transition: all var(--transition);
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
input::placeholder, textarea::placeholder { color: var(--text-dim); }
input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 18px; font-family: var(--font); font-size: .88rem; font-weight: 600;
    border-radius: var(--radius-sm); border: 1px solid transparent; cursor: pointer;
    transition: all var(--transition); text-decoration: none; white-space: nowrap;
}
.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--purple));
    color: #fff;
    box-shadow: 0 4px 14px var(--accent-glow);
}
.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px var(--accent-glow);
    filter: brightness(1.1);
}
.btn-ghost {
    background: transparent;
    border-color: var(--border);
    color: var(--text-muted);
}
.btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text);
    border-color: var(--text-dim);
}
.btn-sm { padding: 6px 12px; font-size: .8rem; border-radius: 6px; }

/* ---- Toast Notifications ---- */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 10000; display: flex; flex-direction: column; gap: 8px; }
.toast {
    background: var(--bg-card); border: 1px solid var(--border); color: var(--text);
    padding: 12px 20px; border-radius: var(--radius-sm); font-size: .88rem; font-weight: 600;
    box-shadow: var(--shadow); display: flex; align-items: center; gap: 10px;
    animation: slideIn .3s ease forwards;
}
.toast.success { border-left: 4px solid var(--green); }
.toast.success span { color: var(--green); }
.toast.error { border-left: 4px solid var(--red); }
.toast.error span { color: var(--red); }

/* ---- App Layout ---- */
.app-header {
    height: 64px; border-bottom: 1px solid var(--border);
    background-color: rgba(12, 14, 20, 0.85); backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px); z-index: 50; flex-shrink: 0;
}
.header-inner { max-width: 1600px; margin: 0 auto; height: 100%; display: flex; align-items: center; justify-content: space-between; padding: 0 24px; }
.header-actions { display: flex; align-items: center; gap: 8px; }

.app-main { display: flex; flex: 1; overflow: hidden; position: relative; }

/* ---- Editor Panel ---- */
.editor-panel {
    width: 480px; flex-shrink: 0; border-right: 1px solid var(--border);
    background-color: var(--bg-panel); display: flex; flex-direction: column; overflow: hidden;
}
.editor-scroll { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.editor-section {
    background-color: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden; flex-shrink: 0;
}
.section-header {
    display: flex; align-items: center; gap: 12px; padding: 14px 18px;
    border-bottom: 1px solid var(--border); background-color: rgba(255,255,255,0.01);
}
.section-icon { font-size: 1.25rem; }
.section-title { font-size: .95rem; font-weight: 700; color: #fff; }
.section-body { padding: 18px; display: flex; flex-direction: column; gap: 14px; }

.form-group { display: flex; flex-direction: column; }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
.required { color: var(--red); }

/* Logo Upload Area */
.logo-upload { cursor: pointer; border: 2px dashed var(--border); border-radius: var(--radius-sm); transition: all var(--transition); }
.logo-upload:hover { border-color: var(--accent); background: var(--bg-hover); }
.logo-preview { height: 120px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: var(--text-muted); font-size: .8rem; }

/* Items grid builder */
.item-row { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 12px; animation: fadeSlideIn .25s ease; }
.flex-2 { flex: 2; }
.btn-delete-item {
    background: transparent; border: 1px solid var(--border); color: var(--text-dim);
    padding: 10px; border-radius: var(--radius-sm); cursor: pointer; display: flex;
    align-items: center; justify-content: center; transition: all var(--transition);
}
.btn-delete-item:hover { background: var(--red-bg); color: var(--red); border-color: var(--red); }
.btn-add-item {
    width: 100%; border: 1px dashed var(--border); background: transparent;
    color: var(--text-muted); padding: 12px; border-radius: var(--radius-sm);
    cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
    gap: 8px; font-weight: 600; font-family: var(--font); transition: all var(--transition);
}
.btn-add-item:hover { border-color: var(--accent); color: var(--accent-light); background: var(--bg-hover); }

/* Signature Pad Wrapper */
.signature-pad-wrapper { background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px; display: flex; flex-direction: column; gap: 8px; }
#signature-pad { background: #131722; border-radius: 4px; width: 100%; height: 120px; cursor: crosshair; }

/* ---- Preview Panel ---- */
.preview-panel { flex: 1; background-color: var(--bg); display: flex; flex-direction: column; overflow: hidden; }
.preview-toolbar {
    height: 48px; border-bottom: 1px solid var(--border);
    background-color: var(--bg-panel); display: flex; align-items: center;
    justify-content: space-between; padding: 0 24px; flex-shrink: 0;
}
.preview-label { font-size: .78rem; font-weight: 700; text-transform: uppercase; color: var(--text-muted); letter-spacing: .06em; }
.preview-actions { display: flex; gap: 8px; }
.preview-scroll { flex: 1; overflow-y: auto; padding: 40px 24px; display: flex; justify-content: center; align-items: flex-start; }

/* ---- Invoice Paper Sheet (A4 Styled) ---- */
.invoice-paper {
    width: 210mm; min-height: 297mm; background-color: #fff;
    color: #1e293b; padding: 20mm 15mm; border-radius: 4px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5); font-size: 13px;
    position: relative; overflow: hidden; display: flex; flex-direction: column;
    box-sizing: border-box;
}

.inv-header { display: flex; justify-content: space-between; margin-bottom: 10mm; }
.inv-brand { display: flex; gap: 15px; max-width: 60%; }
.inv-logo { width: 64px; height: 64px; overflow: hidden; border-radius: 6px; }
.inv-logo img { width: 100%; height: 100%; object-fit: contain; }
.inv-business-info { display: flex; flex-direction: column; }
.inv-business-name { font-size: 18px; font-weight: 800; color: #0f172a; margin-bottom: 4px; }
.inv-business-contact { font-size: 12px; color: #64748b; }
.inv-business-address { font-size: 12px; color: #475569; margin-top: 4px; white-space: pre-line; }

.inv-title-block { text-align: right; }
.inv-title { font-size: 28px; font-weight: 900; color: #0f172a; letter-spacing: -.02em; margin-bottom: 4px; }
.inv-meta { display: flex; flex-direction: column; gap: 2px; }
.inv-meta-row { display: flex; justify-content: flex-end; gap: 10px; font-size: 12px; }
.inv-meta-label { color: #64748b; font-weight: 500; }
.inv-meta-value { color: #0f172a; font-weight: 700; }

.inv-status-badge {
    position: absolute; top: 12mm; left: 50%; transform: translateX(-50%) rotate(-5deg);
    border: 3px double; padding: 4px 16px; border-radius: 6px; font-weight: 800; font-size: 14px;
    letter-spacing: .08em; opacity: 0.85; z-index: 10;
}
.inv-status-badge.status-paid { color: #16a34a; border-color: #16a34a; background: rgba(22, 163, 74, 0.05); }
.inv-status-badge.status-unpaid { color: #dc2626; border-color: #dc2626; background: rgba(220, 38, 38, 0.05); }
.inv-status-badge.status-partial { color: #ea580c; border-color: #ea580c; background: rgba(234, 88, 12, 0.05); }
.inv-status-badge.status-overdue { color: #b91c1c; border-color: #b91c1c; background: rgba(185, 28, 28, 0.05); }

.inv-addresses { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-bottom: 10mm; }
.inv-address-block { display: flex; flex-direction: column; }
.inv-address-label { font-size: 11px; font-weight: 700; text-transform: uppercase; color: #64748b; margin-bottom: 6px; letter-spacing: .05em; }
.inv-customer-name { font-size: 14px; font-weight: 700; color: #0f172a; margin-bottom: 4px; }
.inv-customer-detail { font-size: 12px; color: #64748b; }
.inv-customer-address { font-size: 12px; color: #475569; margin-top: 4px; white-space: pre-line; }

.inv-table-wrapper { margin-bottom: 8mm; }
.inv-table { width: 100%; border-collapse: collapse; text-align: left; }
.inv-table th { padding: 10px 8px; font-size: 11px; font-weight: 700; text-transform: uppercase; color: #64748b; border-bottom: 2px solid #cbd5e1; }
.inv-table td { padding: 12px 8px; border-bottom: 1px solid #e2e8f0; color: #334155; }
.inv-th-num { width: 8%; }
.inv-th-desc { width: 52%; }
.inv-th-qty { width: 10%; text-align: right; }
.inv-th-price { width: 15%; text-align: right; }
.inv-th-total { width: 15%; text-align: right; }
.inv-table td:nth-child(3), .inv-table td:nth-child(4), .inv-table td:nth-child(5) { text-align: right; }

.inv-totals { display: flex; justify-content: flex-end; margin-bottom: 10mm; }
.inv-totals-table { width: 45%; display: flex; flex-direction: column; gap: 8px; }
.inv-total-row { display: flex; justify-content: space-between; font-size: 13px; color: #475569; }
.inv-total-row.inv-grand-total { font-size: 18px; font-weight: 800; color: #0f172a; border-top: 2px solid #0f172a; padding-top: 8px; margin-top: 4px; }

.inv-footer-sections { display: grid; grid-template-columns: 1fr; gap: 15px; margin-bottom: 8mm; }
.inv-notes-block h4, .inv-terms-block h4 { font-size: 11px; font-weight: 700; text-transform: uppercase; color: #64748b; margin-bottom: 4px; }
.inv-notes-block p, .inv-terms-block p { font-size: 11px; color: #475569; white-space: pre-line; line-height: 1.4; }

.inv-signature-block { display: flex; justify-content: flex-end; margin-top: auto; }
.inv-signature-line { display: flex; flex-direction: column; align-items: center; width: 180px; text-align: center; }
.inv-signature-line img { max-height: 60px; max-width: 150px; margin-bottom: 4px; filter: multiply(1); mix-blend-mode: multiply; }
.inv-signature-line span { font-size: 11px; color: #64748b; border-top: 1px solid #cbd5e1; width: 100%; padding-top: 4px; }

.inv-watermark {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%) rotate(-45deg);
    font-size: 130px; font-weight: 900; color: rgba(241, 245, 249, 0.4);
    pointer-events: none; z-index: 1; user-select: none;
}

/* Logo icon SVG gradient branding */
.logo-icon { display: flex; align-items: center; }
.logo-text { font-size: 1.3rem; font-weight: 800; color: #fff; display: inline-flex; align-items: center; letter-spacing: -0.02em; }
.logo-accent { color: var(--accent-light); }

/* ---- Animations ---- */
@keyframes slideIn { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes fadeSlideIn { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---- Responsive Print Hacks ---- */
@media print {
    body * { visibility: hidden; }
    .invoice-paper, .invoice-paper * { visibility: visible; }
    .invoice-paper { position: absolute; left: 0; top: 0; width: 100%; box-shadow: none; padding: 0; }
}

@media (max-width: 1024px) {
    .app-main { flex-direction: column; }
    .editor-panel { width: 100%; height: 50vh; border-right: none; border-bottom: 1px solid var(--border); }
    .preview-panel { height: 50vh; }
    .preview-scroll { padding: 20px 10px; }
    .invoice-paper { width: 100%; min-height: auto; font-size: 11px; }
}

@media (max-width: 768px) {
    .header-inner { padding: 0 12px; }
    .logo-text { font-size: 1rem; }
    .logo-icon svg { width: 22px; height: 22px; }
    .header-actions span { display: none; }
    .header-actions .btn { padding: 8px 10px; }
}
