/* =============================================
   RESET & BASE
   ============================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', sans-serif;
    background: #e8edf3;
    color: #1a1a2e;
    font-size: 14px;
    min-height: 100vh;
}

/* =============================================
   APP SHELL
   ============================================= */
.app {
    display: flex;
    min-height: 100vh;
}

/* =============================================
   SIDEBAR
   ============================================= */
.sidebar {
    width: 270px;
    flex-shrink: 0;
    background: #0f172a;
    color: #cbd5e1;
    padding: 0;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 20px 16px;
    font-size: 17px;
    font-weight: 700;
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,0.07);
}

.sidebar-logo .material-icons { color: #38bdf8; font-size: 22px; }

.sidebar-section {
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.section-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #475569;
    margin-bottom: 10px;
}

.sidebar-section label {
    display: block;
    font-size: 11px;
    color: #94a3b8;
    margin-bottom: 4px;
    margin-top: 8px;
}

.sidebar-section label:first-of-type { margin-top: 0; }

.sidebar-section input[type="text"],
.sidebar-section input[type="date"],
.sidebar-section input[type="number"],
.sidebar-section input#invNo,
.sidebar-section select {
    width: 100%;
    padding: 7px 10px;
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 6px;
    color: #e2e8f0;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s;
}

.sidebar-section input:focus,
.sidebar-section select:focus {
    border-color: #38bdf8;
}

/* file input */
.file-input-wrap {
    position: relative;
    overflow: hidden;
    background: #1e293b;
    border: 1px dashed #334155;
    border-radius: 6px;
    text-align: center;
    padding: 10px;
    cursor: pointer;
    transition: border-color 0.2s;
}

.file-input-wrap:hover { border-color: #38bdf8; }

.file-input-wrap input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
}

.file-hint {
    font-size: 12px;
    color: #64748b;
}

/* color row */
.color-row {
    display: flex;
    gap: 10px;
}

.color-row > div {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.color-row label {
    font-size: 10px;
    text-align: center;
    margin-bottom: 5px !important;
}

.color-row input[type="color"] {
    width: 100%;
    height: 34px;
    border-radius: 6px;
    border: 1px solid #334155;
    padding: 2px;
    background: #1e293b;
    cursor: pointer;
}

/* add item button */
.btn-add {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #0369a1;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 9px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    justify-content: center;
    transition: background 0.2s;
}

.btn-add:hover { background: #0284c7; }
.btn-add .material-icons { font-size: 18px; }

/* footer buttons */
.sidebar-footer {
    margin-top: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-top: 1px solid rgba(255,255,255,0.06);
}

.btn-save, .btn-pdf {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 10px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: opacity 0.2s;
}

.btn-save { background: #1e293b; color: #94a3b8; border: 1px solid #334155; }
.btn-save:hover { background: #273548; }
.btn-pdf { background: #dc2626; color: #fff; }
.btn-pdf:hover { opacity: 0.88; }
.btn-save .material-icons,
.btn-pdf .material-icons { font-size: 18px; }

/* =============================================
   CANVAS WRAP (scroll area)
   ============================================= */
.canvas-wrap {
    flex: 1;
    padding: 30px 24px;
    overflow-y: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

/* =============================================
   INVOICE CANVAS — Screen
   ============================================= */
.canvas {
    background: #ffffff;
    width: 794px;          /* exactly A4 @ 96dpi */
    min-height: 1122px;
    padding: 52px 56px;
    border-radius: 6px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.18);
    position: relative;
    font-size: 13px;
    line-height: 1.6;
    color: #1a1a2e;
}

/* =============================================
   INVOICE HEADER
   ============================================= */
.inv-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 28px;
}

.inv-brand {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

#logoPreview {
    max-width: 140px;
    max-height: 60px;
    object-fit: contain;
    display: block;
}

#logoPreview[src=""] { display: none; }

.inv-from {
    font-size: 12.5px;
    line-height: 1.7;
    color: #374151;
    outline: none;
}

.inv-from:focus {
    background: #f0f9ff;
    border-radius: 4px;
    padding: 4px 6px;
    margin: -4px -6px;
}

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

.inv-title {
    font-family: 'Playfair Display', serif;
    font-size: 42px;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: #1e5080;
    line-height: 1;
    margin-bottom: 16px;
}

.inv-meta {
    border-collapse: collapse;
    margin-left: auto;
}

.inv-meta td {
    padding: 4px 8px;
    font-size: 12.5px;
    border: none;
}

.inv-meta td:first-child {
    color: #6b7280;
    text-align: right;
    padding-right: 12px;
}

.inv-meta td:last-child {
    text-align: right;
    min-width: 110px;
    color: #111827;
}

/* =============================================
   DIVIDER
   ============================================= */
.inv-divider {
    height: 3px;
    background: #1e5080;
    border-radius: 2px;
    margin-bottom: 24px;
    position: relative;
}

.inv-divider::after {
    content: '';
    position: absolute;
    top: 5px;
    left: 0;
    right: 0;
    height: 1px;
    background: #e5e7eb;
}

/* =============================================
   BILLING
   ============================================= */
.billing {
    display: flex;
    gap: 30px;
    margin-bottom: 28px;
}

.billing-block {
    flex: 1;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 14px 16px;
}

.billing-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.12em;
    color: #1e5080;
    text-transform: uppercase;
    margin-bottom: 8px;
}

.billing-content {
    font-size: 12.5px;
    line-height: 1.75;
    color: #374151;
    outline: none;
}

.billing-content:focus {
    background: #eff6ff;
    border-radius: 4px;
    padding: 4px 6px;
    margin: -4px -6px;
}

/* =============================================
   ITEMS TABLE
   ============================================= */
.items-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 28px;
    table-layout: fixed;
}

.items-table thead tr {
    background: #1e5080;
    color: #ffffff;
}

.items-table th {
    padding: 10px 12px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    border: none;
    text-align: left;
}

.items-table th.col-qty,
.items-table th.col-price,
.items-table th.col-total { text-align: right; }

.col-desc  { width: 44%; }
.col-qty   { width: 10%; }
.col-price { width: 20%; }
.col-total { width: 20%; }
.col-action { width: 6%; }

.items-table tbody tr {
    border-bottom: 1px solid #e5e7eb;
    transition: background 0.15s;
}

.items-table tbody tr:last-child { border-bottom: 2px solid #1e5080; }

.items-table tbody tr:hover { background: #f0f7ff; }

.items-table tbody tr:nth-child(even) { background: #f9fafb; }
.items-table tbody tr:nth-child(even):hover { background: #f0f7ff; }

.items-table td {
    padding: 10px 12px;
    font-size: 13px;
    color: #374151;
    border: none;
    vertical-align: middle;
    outline: none;
}

.items-table td[contenteditable="true"]:focus {
    background: #eff6ff;
    border-radius: 3px;
}

.items-table td.qty,
.items-table td.price,
.items-table td.total { text-align: right; }

.items-table td.total {
    font-weight: 600;
    color: #1a1a2e;
}

/* delete button */
.delete-cell { text-align: center; vertical-align: middle; }

.delete-btn {
    cursor: pointer;
    color: #ef4444;
    font-size: 18px !important;
    transition: transform 0.2s, color 0.2s;
    user-select: none;
}

.delete-btn:hover { color: #b91c1c; transform: scale(1.15); }

/* =============================================
   FOOTER GRID (notes + totals)
   ============================================= */
.inv-footer-grid {
    display: flex;
    gap: 30px;
    align-items: flex-start;
    margin-bottom: 36px;
}

.inv-notes {
    flex: 1.3;
}

.notes-content {
    font-size: 12px;
    color: #6b7280;
    line-height: 1.7;
    outline: none;
    padding: 10px 12px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    min-height: 80px;
}

.notes-content:focus { background: #eff6ff; }

/* =============================================
   TOTALS BLOCK
   ============================================= */
.totals {
    flex: 1;
}

.totals-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px dashed #e5e7eb;
    font-size: 13px;
    color: #374151;
}

.totals-row span:first-child { color: #6b7280; }

.discount-row span:last-child { color: #dc2626; }

.totals-grand {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #1e5080;
    color: #ffffff;
    padding: 12px 14px;
    margin-top: 8px;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.words {
    font-size: 11.5px;
    font-style: italic;
    color: #6b7280;
    margin-top: 8px;
    text-align: right;
    line-height: 1.5;
}

/* =============================================
   FOOTER BAR
   ============================================= */
.inv-footer-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: #1e5080;
    color: rgba(255,255,255,0.75);
    padding: 10px 56px;
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    border-radius: 0 0 6px 6px;
    letter-spacing: 0.03em;
}

/* =============================================
   PDF MODE — This is what gets printed
   ============================================= */
.pdf-mode {
    /* Reset to plain A4 document — no screen decorations */
    box-shadow: none !important;
    border-radius: 0 !important;
    margin: 0 !important;
    width: 794px !important;
    min-height: 1122px !important;
    padding: 52px 56px 76px !important; /* extra bottom padding for footer bar */
    font-size: 13px !important;
}

/* Hide sidebar, canvas-wrap shell — only #invoice is cloned by html2pdf */
.pdf-mode .hide-in-pdf {
    display: none !important;
}

/* Ensure contenteditable borders don't render in PDF */
.pdf-mode [contenteditable] {
    outline: none !important;
    background: transparent !important;
    border: none !important;
}

/* Keep table borders crisp in PDF */
.pdf-mode .items-table tbody tr:nth-child(even) {
    background: #f9fafb !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

.pdf-mode .totals-grand,
.pdf-mode .inv-divider,
.pdf-mode .items-table thead tr {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

/* =============================================
   RESPONSIVE — sidebar collapses on small screens
   ============================================= */
@media (max-width: 900px) {
    .app { flex-direction: column; }

    .sidebar {
        width: 100%;
        height: auto;
        position: static;
        flex-direction: row;
        flex-wrap: wrap;
        padding: 12px 16px;
        gap: 12px;
    }

    .sidebar-section { border: none; padding: 0; flex: 1 1 160px; }
    .sidebar-footer { flex-direction: row; margin-top: 0; }
    .canvas-wrap { padding: 16px 8px; }
    .canvas { width: 100%; min-height: unset; padding: 28px 20px 60px; }
    .inv-title { font-size: 30px; }
}
