/* ===========================================================
   Modern Invoice Editor — clean, PayPal-inspired
   =========================================================== */

:root {
    --inv-bg: #f7f8fa;
    --inv-surface: #ffffff;
    --inv-border: #e5e7eb;
    --inv-border-strong: #d1d5db;
    --inv-text: #111827;
    --inv-muted: #6b7280;
    --inv-primary: #2563eb;
    --inv-primary-hover: #1d4ed8;
    --inv-success: #10b981;
    --inv-danger: #ef4444;
    --inv-warning: #f59e0b;
    --inv-radius: 10px;
    --inv-shadow: 0 1px 2px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.04);
}

body.invoice-editor-body {
    background: var(--inv-bg);
    color: var(--inv-text);
    font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    margin: 0;
    min-height: 100vh;
}

/* Top app bar */
.inv-appbar {
    background: var(--inv-surface);
    border-bottom: 1px solid var(--inv-border);
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 50;
}
.inv-appbar .inv-brand {
    font-weight: 700;
    font-size: 18px;
    text-decoration: none;
    color: var(--inv-text);
    display: flex;
    align-items: center;
    gap: 8px;
}
.inv-appbar .inv-brand svg { width: 22px; height: 22px; }
.inv-appbar .inv-actions { display: flex; gap: 8px; align-items: center; }
.inv-appbar .inv-status {
    font-size: 12px;
    color: var(--inv-muted);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.inv-appbar .inv-status .dot {
    width: 8px; height: 8px; border-radius: 50%; background: var(--inv-muted);
}
.inv-appbar .inv-status[data-state="saving"] .dot { background: var(--inv-warning); animation: pulse 1s infinite; }
.inv-appbar .inv-status[data-state="saved"] .dot { background: var(--inv-success); }
.inv-appbar .inv-status[data-state="error"] .dot { background: var(--inv-danger); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
.inv-guest-hint { font-size: 12px; color: var(--inv-muted); white-space: nowrap; }
.inv-guest-hint a { color: var(--inv-accent); text-decoration: none; }
.inv-guest-hint a:hover { text-decoration: underline; }

/* Layout: split editor */
.inv-shell {
    display: grid;
    grid-template-columns: minmax(360px, 480px) 1fr;
    gap: 0;
    max-width: 1600px;
    margin: 0 auto;
    min-height: calc(100vh - 60px);
}
@media (max-width: 992px) {
    .inv-shell { grid-template-columns: 1fr; }
    .inv-preview-wrap { display: none; }
    .inv-preview-wrap.is-open { display: block; position: fixed; inset: 0; z-index: 100; background: var(--inv-bg); overflow: auto; }
}

/* Form pane */
.inv-form {
    padding: 24px;
    background: var(--inv-surface);
    border-right: 1px solid var(--inv-border);
    overflow-y: auto;
    max-height: calc(100vh - 60px);
}
.inv-section {
    background: var(--inv-surface);
    border: 1px solid var(--inv-border);
    border-radius: var(--inv-radius);
    padding: 18px 18px 12px;
    margin-bottom: 16px;
}
.inv-section h3 {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--inv-muted);
    margin: 0 0 14px;
}
.inv-section .form-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--inv-muted);
    margin-bottom: 4px;
}
.inv-section .form-control,
.inv-section .form-select {
    border-radius: 8px;
    border: 1px solid var(--inv-border-strong);
    font-size: 14px;
    transition: border-color 0.12s, box-shadow 0.12s;
}
.inv-section .form-control:focus,
.inv-section .form-select:focus {
    border-color: var(--inv-primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

/* Preview pane */
.inv-preview-wrap {
    padding: 32px;
    overflow-y: auto;
    max-height: calc(100vh - 60px);
    background: var(--inv-bg);
}
.inv-preview {
    background: white;
    box-shadow: var(--inv-shadow);
    border-radius: 8px;
    max-width: 800px;
    margin: 0 auto;
    padding: 48px;
    min-height: 1000px;
    font-size: 14px;
    color: #1f2937;
}
.inv-preview .pv-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 32px;
    padding-bottom: 24px;
    border-bottom: 3px solid var(--pv-primary, var(--inv-primary));
}
.inv-preview .pv-header .pv-title {
    font-size: 32px;
    font-weight: 700;
    color: var(--pv-primary, var(--inv-primary));
    text-transform: uppercase;
    letter-spacing: 2px;
    margin: 0;
}
.inv-preview .pv-header .pv-number {
    font-size: 13px;
    color: var(--inv-muted);
    margin-top: 4px;
}
.inv-preview .pv-header .pv-logo img {
    max-height: 70px;
    max-width: 200px;
    object-fit: contain;
}
.inv-preview .pv-parties {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
    margin-bottom: 32px;
}
.inv-preview .pv-parties .label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--inv-muted);
    margin-bottom: 6px;
}
.inv-preview .pv-parties .name { font-size: 16px; font-weight: 600; margin-bottom: 2px; }
.inv-preview .pv-parties .lines { font-size: 13px; color: #4b5563; line-height: 1.5; white-space: pre-wrap; }
.inv-preview .pv-meta {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    background: #f9fafb;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 24px;
}
.inv-preview .pv-meta .label { font-size: 11px; text-transform: uppercase; color: var(--inv-muted); font-weight: 600; letter-spacing: 0.5px; }
.inv-preview .pv-meta .value { font-size: 14px; font-weight: 600; margin-top: 2px; }
.inv-preview .pv-items {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 24px;
}
.inv-preview .pv-items thead th {
    background: var(--pv-primary, var(--inv-primary));
    color: white;
    text-align: left;
    padding: 12px 14px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}
.inv-preview .pv-items thead th:last-child,
.inv-preview .pv-items tbody td:last-child { text-align: right; }
.inv-preview .pv-items tbody td {
    padding: 14px;
    border-bottom: 1px solid #e5e7eb;
    vertical-align: top;
}
.inv-preview .pv-items tbody tr:hover { background: #f9fafb; }
.inv-preview .pv-totals {
    margin-left: auto;
    width: 280px;
}
.inv-preview .pv-totals .row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 14px;
}
.inv-preview .pv-totals .row.total {
    border-top: 2px solid #111827;
    padding-top: 12px;
    margin-top: 8px;
    font-size: 18px;
    font-weight: 700;
}
.inv-preview .pv-notes {
    margin-top: 32px;
    padding-top: 20px;
    border-top: 1px solid #e5e7eb;
}
.inv-preview .pv-notes h4 {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--inv-muted);
    margin: 0 0 6px;
    letter-spacing: 0.5px;
}
.inv-preview .pv-notes p { font-size: 13px; color: #4b5563; margin: 0 0 12px; white-space: pre-wrap; line-height: 1.5; }
.inv-preview .pv-empty { color: #9ca3af; font-style: italic; }

/* Items editor */
.inv-items-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.inv-items-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.inv-items-table th {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--inv-muted);
    font-weight: 600;
    padding: 6px 4px;
    text-align: left;
    letter-spacing: 0.5px;
}
.inv-items-table td { padding: 4px; vertical-align: middle; }
.inv-items-table input { border: 1px solid var(--inv-border-strong); border-radius: 6px; padding: 8px 10px; width: 100%; font-size: 14px; }
.inv-items-table input:focus { outline: none; border-color: var(--inv-primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }
.inv-items-table { min-width: 720px; }
.inv-items-table .col-desc { width: 45%; }
.inv-items-table .col-qty { width: 14%; min-width: 96px; }
.inv-items-table .col-price { width: 18%; min-width: 140px; }
.inv-items-table .col-total { width: 18%; min-width: 130px; text-align: right; padding-right: 8px; font-weight: 600; }
.inv-items-table .col-action { width: 5%; text-align: center; }
.inv-items-table .btn-remove {
    background: transparent;
    border: none;
    color: var(--inv-muted);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.12s;
}
.inv-items-table .btn-remove:hover { background: #fee2e2; color: var(--inv-danger); }
.inv-add-item {
    margin-top: 8px;
    background: transparent;
    border: 1px dashed var(--inv-border-strong);
    border-radius: 8px;
    padding: 10px;
    width: 100%;
    color: var(--inv-muted);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.12s;
}
.inv-add-item:hover { border-color: var(--inv-primary); color: var(--inv-primary); background: #eff6ff; }

/* Buttons */
.btn-inv {
    border-radius: 8px;
    font-weight: 500;
    font-size: 14px;
    padding: 8px 16px;
    border: 1px solid transparent;
    transition: all 0.12s;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
}
.btn-inv-primary { background: var(--inv-primary); color: white; }
.btn-inv-primary:hover { background: var(--inv-primary-hover); color: white; }
.btn-inv-ghost { background: transparent; color: var(--inv-text); border-color: var(--inv-border-strong); }
.btn-inv-ghost:hover { background: var(--inv-bg); }
.btn-inv-danger { background: white; color: var(--inv-danger); border-color: var(--inv-border-strong); }
.btn-inv-danger:hover { background: #fef2f2; border-color: var(--inv-danger); }

/* Status badge */
.inv-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.inv-badge.draft { background: #e5e7eb; color: #374151; }
.inv-badge.sent { background: #dbeafe; color: #1e40af; }
.inv-badge.paid { background: #d1fae5; color: #065f46; }
.inv-badge.overdue { background: #fee2e2; color: #991b1b; }

/* Inline editable hint */
.editable-field {
    cursor: text;
    padding: 2px 4px;
    margin: -2px -4px;
    border-radius: 4px;
    transition: background 0.12s;
}
.editable-field:hover { background: rgba(37,99,235,0.06); }

/* Invoice list */
.inv-list { max-width: 1200px; margin: 32px auto; padding: 0 24px; }
.inv-list h1 { font-size: 24px; font-weight: 700; margin-bottom: 24px; display: flex; justify-content: space-between; align-items: center; }
.inv-list table { width: 100%; background: var(--inv-surface); border-radius: var(--inv-radius); overflow: hidden; box-shadow: var(--inv-shadow); }
.inv-list table th { background: #f9fafb; padding: 12px 16px; text-align: left; font-size: 12px; text-transform: uppercase; color: var(--inv-muted); font-weight: 600; letter-spacing: 0.5px; }
.inv-list table td { padding: 14px 16px; border-top: 1px solid var(--inv-border); }
.inv-list table tr:hover td { background: #f9fafb; }
.inv-list .empty { background: var(--inv-surface); border-radius: var(--inv-radius); padding: 48px; text-align: center; color: var(--inv-muted); box-shadow: var(--inv-shadow); }

/* Mobile toggle */
.inv-mobile-toggle { display: none; }
@media (max-width: 992px) {
    .inv-mobile-toggle { display: inline-flex; }
}

.toast-stack {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.inv-toast {
    background: var(--inv-text);
    color: white;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 13px;
    box-shadow: var(--inv-shadow);
    animation: slideIn 0.2s ease;
}
@keyframes slideIn { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
