@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

:root {
    --primary: #4361ee;
    --accent: #f72585;
    --accent2: #3f37c9;
    --gold: #f8961e;
    --bg: #f4f7fe;
    --surface: #ffffff;
    --surface2: #f8f9fa;
    --border: #e2e8f0;
    --text: #2b3674;
    --muted: #a3aed1;
    --white: #ffffff;
    --radius: 16px;
    --shadow: 0 18px 40px rgba(112, 144, 176, 0.12);
    --shadow-sm: 0 4px 12px rgba(112, 144, 176, 0.08);
    --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

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

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ── APP LAYOUT ── */
.app {
    display: grid;
    grid-template-columns: 460px 1fr;
    min-height: 100vh;
    position: relative;
}

/* ── WEB PANEL ── */
.web-panel {
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 32px 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    box-shadow: 4px 0 24px rgba(112, 144, 176, 0.08);
    z-index: 10;
}

.web-panel::-webkit-scrollbar { width: 6px; }
.web-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

.panel-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    padding-bottom: 24px;
    border-bottom: 1px dashed var(--border);
}

.panel-brand .logo-icon {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--primary), var(--accent2));
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    box-shadow: var(--shadow-sm);
}

.panel-brand h1 { font-size: 18px; font-weight: 800; color: var(--text); letter-spacing: -0.5px; }
.panel-brand p { font-size: 12px; color: var(--muted); font-weight: 500; }

/* ── ACCORDION ── */
.accordion-item {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}
.accordion-item:hover { box-shadow: var(--shadow); border-color: #cbd5e1; }
.accordion-header {
    width: 100%; padding: 18px 20px; display: flex; align-items: center;
    justify-content: space-between; background: transparent; border: none;
    cursor: pointer; font-family: inherit; font-size: 14px; font-weight: 700;
    color: var(--text); transition: var(--transition);
}
.accordion-header .title-wrap { display: flex; align-items: center; gap: 10px; }
.accordion-header .icon-wrap {
    width: 32px; height: 32px; background: var(--surface2); border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: var(--primary); font-size: 16px;
}
.accordion-header .chevron { font-size: 12px; color: var(--muted); transition: transform 0.3s ease; }
.accordion-content {
    max-height: 0; overflow: hidden; transition: max-height 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    padding: 0 20px; background: var(--surface);
}
.accordion-item.active .accordion-header { border-bottom: 1px solid var(--border); background: #f8faff; color: var(--primary); }
.accordion-item.active .accordion-header .icon-wrap { background: var(--primary); color: white; box-shadow: 0 4px 12px rgba(67, 97, 238, 0.3); }
.accordion-item.active .accordion-header .chevron { transform: rotate(180deg); }
.accordion-item.active .accordion-content { padding: 20px; }

/* ── FORMS & BUTTONS (SOFT UI FIX) ── */
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 12px; color: var(--text); font-weight: 600; margin-bottom: 6px; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; background: var(--surface2); border: 2px solid transparent;
    border-radius: 10px; font-size: 13px; padding: 10px 14px;
    color: var(--text); font-family: inherit; font-weight: 500;
    transition: var(--transition); outline: none; resize: vertical;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    background: var(--white); border-color: var(--primary); box-shadow: 0 0 0 4px rgba(67, 97, 238, 0.1);
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Items */
.items-header {
    display: grid; grid-template-columns: 2fr 1fr 1fr 36px; gap: 6px;
    font-size: 10px; font-weight: 700; text-transform: uppercase;
    letter-spacing: 1px; color: var(--muted); padding: 0 4px 6px;
}
.item-row { display: grid; grid-template-columns: 2fr 1fr 1fr 36px; gap: 6px; margin-bottom: 8px; }
.item-row input {
    background: var(--surface2); border: 2px solid transparent; border-radius: 8px;
    padding: 8px 10px; font-size: 12px; color: var(--text); font-family: inherit;
    transition: var(--transition); width: 100%; outline: none;
}
.item-row input:focus { border-color: var(--primary); background: var(--white); }

.btn-icon {
    width: 36px; height: 36px; border: none; border-radius: 8px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; transition: var(--transition);
}
.btn-remove { background: rgba(247, 37, 133, 0.1); color: var(--accent); }
.btn-remove:hover { background: var(--accent); color: white; transform: scale(1.05); }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 18px; border-radius: 12px; border: none; cursor: pointer;
    font-family: inherit; font-size: 13px; font-weight: 600;
    transition: var(--transition); text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(67, 97, 238, 0.2); }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(67, 97, 238, 0.3); }
.btn-secondary { background: var(--surface2); color: var(--text); }
.btn-secondary:hover { background: #e2e8f0; }
.btn-gold { background: var(--gold); color: #fff; box-shadow: 0 4px 12px rgba(248, 150, 30, 0.2); }
.btn-gold:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(248, 150, 30, 0.3); }
.btn-sm { padding: 8px 14px; font-size: 12px; border-radius: 8px; }
.w-full { width: 100%; }

.logo-upload-area {
    border: 2px dashed var(--border); border-radius: 12px; padding: 20px;
    text-align: center; cursor: pointer; position: relative; transition: var(--transition);
}
.logo-upload-area:hover { border-color: var(--primary); background: rgba(67, 97, 238, 0.02); }
.logo-upload-area input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.logo-upload-area img { max-height: 60px; max-width: 100%; object-fit: contain; border-radius: 6px; }
.upload-icon { font-size: 24px; margin-bottom: 4px; }

.color-row { display: flex; align-items: center; gap: 12px; }
.color-row input[type=color] {
    width: 36px; height: 36px; border: none; border-radius: 8px;
    cursor: pointer; padding: 0; background: none; overflow: hidden;
}
.color-row input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
.color-row input[type=color]::-webkit-color-swatch { border: none; border-radius: 8px; box-shadow: var(--shadow-sm); }

.sig-canvas-wrap { background: var(--surface2); border-radius: 10px; overflow: hidden; border: 2px solid transparent; transition: var(--transition); }
.sig-canvas-wrap:hover { border-color: var(--border); }
.sig-canvas-wrap canvas { display: block; width: 100%; cursor: crosshair; }
.sig-actions { display: flex; gap: 8px; margin-top: 8px; }

.action-bar { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 16px; border-top: 1px dashed var(--border); }

/* Mobile Toggle */
.mobile-toggle-btn {
    display: none; position: fixed; bottom: 24px; right: 24px;
    background: var(--primary); color: white; border: none;
    border-radius: 50px; padding: 14px 24px; font-family: inherit;
    font-weight: 700; font-size: 14px; box-shadow: 0 10px 24px rgba(67, 97, 238, 0.4);
    cursor: pointer; z-index: 1000; align-items: center; gap: 8px;
    transition: var(--transition);
}
.mobile-toggle-btn:active { transform: scale(0.95); }

/* ── PREVIEW PANEL ── */
.preview-panel {
    background: var(--bg);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 32px 24px;
}

.preview-toolbar {
    display: flex; gap: 10px; margin-bottom: 24px; flex-wrap: wrap;
    width: 100%; max-width: 794px;
}

/* ── RESTORED INVOICE DOCUMENT ── */
#invoice-doc {
    width: 794px;
    min-height: 1122px;
    background: #fff;
    color: #1a1a2e;
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
    position: relative;
    flex-shrink: 0;
}

.inv-header { padding: 40px 48px 24px; display: flex; justify-content: space-between; align-items: flex-start; }
.inv-logo-area img { max-height: 64px; max-width: 200px; object-fit: contain; }
.inv-logo-placeholder { font-size: 22px; font-weight: 800; color: #1a1a2e; letter-spacing: -0.5px; max-width: 240px; line-height: 1.2; }
.inv-title-area { text-align: right; }
.inv-title { font-size: 32px; font-weight: 800; letter-spacing: -1px; }
.inv-number { font-size: 13px; color: #666; margin-top: 4px; }
.inv-accent-bar { height: 4px; }
.inv-meta { padding: 24px 48px; display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.inv-company-info .company-name { font-size: 14px; font-weight: 700; color: #1a1a2e; margin-bottom: 4px; }
.inv-company-info p { font-size: 12px; color: #555; line-height: 1.6; }
.inv-dates-box { background: #f8f9ff; border-radius: 10px; padding: 16px; font-size: 12px; }
.inv-dates-box .row { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid #eee; }
.inv-dates-box .row:last-child { border-bottom: none; }
.inv-dates-box .label { color: #888; font-weight: 500; }
.inv-dates-box .value { font-weight: 600; color: #1a1a2e; }
.inv-bill-to { padding: 0 48px 24px; }
.inv-bill-to .bill-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 1.5px; color: #888; margin-bottom: 8px; }
.inv-bill-to .client-name { font-size: 16px; font-weight: 700; color: #1a1a2e; }
.inv-bill-to p { font-size: 12px; color: #555; line-height: 1.6; }

/* Items table */
.inv-items { padding: 0 48px 24px; }
.inv-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.inv-table thead tr { border-radius: 8px; overflow: hidden; }
.inv-table thead th { padding: 12px 16px; text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: #fff; }
.inv-table thead th:first-child { border-radius: 8px 0 0 8px; }
.inv-table thead th:last-child { border-radius: 0 8px 8px 0; text-align: right; }
.inv-table tbody td { padding: 12px 16px; border-bottom: 1px solid #f0f0f0; color: #333; vertical-align: top; }
.inv-table tbody td:last-child { text-align: right; font-weight: 600; }
.inv-table tbody tr:last-child td { border-bottom: none; }

/* Totals */
.inv-totals { padding: 0 48px; display: flex; justify-content: flex-end; }
.totals-box { width: 280px; }
.totals-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13px; border-bottom: 1px solid #f0f0f0; }
.totals-row:last-child { border-bottom: none; }
.totals-row .t-label { color: #666; }
.totals-row .t-value { font-weight: 600; color: #1a1a2e; }
.totals-grand { background: linear-gradient(135deg, #1a1a2e, #0f3460); border-radius: 10px; padding: 14px 18px; margin-top: 12px; display: flex; justify-content: space-between; align-items: center; }
.totals-grand .g-label { color: rgba(255, 255, 255, .8); font-size: 13px; font-weight: 600; }
.totals-grand .g-value { color: #fff; font-size: 20px; font-weight: 800; }

.inv-footer-section { padding: 24px 48px 32px; display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.inv-notes .notes-label, .inv-sig .sig-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 1.5px; color: #888; margin-bottom: 8px; }
.inv-notes p { font-size: 12px; color: #555; line-height: 1.6; }
.inv-sig .sig-line { border-bottom: 1.5px solid #ccc; margin-top: 48px; margin-bottom: 6px; }
.inv-sig p { font-size: 12px; color: #555; }
.inv-sig img { max-height: 60px; object-fit: contain; }
.inv-footer-bar { padding: 14px 48px; font-size: 11px; color: rgba(255, 255, 255, .7); display: flex; justify-content: space-between; }

/* Status badge */
.inv-status-badge { display: inline-flex; align-items: center; gap: 6px; padding: 6px 16px; border-radius: 20px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; margin-top: 10px; }
.status-paid { background: #e8f5e9; color: #2e7d32; border: 1.5px solid #a5d6a7; }
.status-unpaid { background: #fff3e0; color: #e65100; border: 1.5px solid #ffcc80; }
.status-pending { background: #e3f2fd; color: #1565c0; border: 1.5px solid #90caf9; }
.inv-watermark { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%) rotate(-35deg); font-size: 80px; font-weight: 900; opacity: .04; pointer-events: none; text-transform: uppercase; white-space: nowrap; color: #1a1a2e; }

/* Media Queries */
@media print {
    body { background: #fff !important; }
    @page { size: A4 portrait; margin: 0; }
    .app { display: block; }
    .web-panel, .preview-toolbar, .mobile-toggle-btn { display: none !important; }
    .preview-panel { padding: 0; display: block; }
    #invoice-doc { width: 210mm; min-height: 297mm; max-height: 297mm; overflow: hidden; box-shadow: none; border-radius: 0; page-break-inside: avoid; margin: 0; }
}

@media (max-width: 1100px) {
    .app { display: block; }
    .web-panel {
        position: fixed; inset: 0; width: 100%; z-index: 100;
        transform: translateX(0); transition: transform 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    }
    .web-panel.hidden { transform: translateX(-100%); }
    .preview-panel { padding-top: 20px; padding-bottom: 100px; display: flex; align-items: flex-start; }
    .mobile-toggle-btn { display: flex; }
    
    /* Biarkan invoice-doc tetap 794px agar format A4 tidak hancur.
       Dengan align-items: flex-start di atas, user bisa scroll horizontal tanpa terpotong. */
    #invoice-doc { margin: 0 auto; }
}
