/* ==========================================================
   INNOVICE — DESIGN SYSTEM & GLOBAL STYLES
   ========================================================== */
:root {
    /* Backgrounds */
    --bg-body: #07071a;
    --bg-nav: rgba(7, 7, 26, 0.85);
    --bg-panel: #0d0d24;
    --bg-card: rgba(255, 255, 255, 0.035);
    --bg-card-hover: rgba(255, 255, 255, 0.06);
    --bg-input: rgba(255, 255, 255, 0.055);
    --bg-input-focus: rgba(255, 255, 255, 0.09);
    --bg-preview: #111130;

    /* Text */
    --text-1: #eef0f6;
    --text-2: #a0a8c0;
    --text-3: #636b83;

    /* Accents */
    --accent: #7c5cfc;
    --accent-light: #a78bfa;
    --accent-glow: rgba(124, 92, 252, 0.25);
    --gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a855f7 100%);

    /* Semantic */
    --success: #22c55e;
    --success-bg: rgba(34, 197, 94, 0.12);
    --warning: #f59e0b;
    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.12);

    /* Borders */
    --border: rgba(255, 255, 255, 0.07);
    --border-focus: rgba(124, 92, 252, 0.5);

    /* Radii */
    --r-sm: 6px;
    --r-md: 10px;
    --r-lg: 16px;
    --r-xl: 24px;

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.45);
    --shadow-glow: 0 0 30px var(--accent-glow);

    /* Sizing */
    --nav-h: 64px;
    --form-w: 440px;
}

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

html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

input,
button,
select,
textarea {
    font-family: inherit;
    font-size: inherit;
}

button {
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
}

a {
    text-decoration: none;
    color: inherit;
}

.hidden {
    display: none !important;
}

/* ====== SCROLLBAR ====== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ==========================================================
   NAVBAR
   ========================================================== */
.navbar {
    height: var(--nav-h);
    background: var(--bg-nav);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.nav-logo {
    width: 40px;
    height: 40px;
    background: var(--gradient);
    border-radius: var(--r-md);
    display: grid;
    place-items: center;
    font-size: 20px;
    color: #fff;
    box-shadow: var(--shadow-glow);
    animation: logoPulse 3s ease-in-out infinite;
}

@keyframes logoPulse {

    0%,
    100% {
        box-shadow: 0 0 20px var(--accent-glow);
    }

    50% {
        box-shadow: 0 0 35px var(--accent-glow);
    }
}

.nav-title {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.nav-subtitle {
    font-size: 11px;
    color: var(--text-3);
    font-weight: 400;
    margin-top: 1px;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.bill-counter {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    padding: 6px 16px;
}

.counter-num {
    font-size: 16px;
    font-weight: 700;
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.counter-label {
    font-size: 12px;
    color: var(--text-3);
}

/* ==========================================================
   BUTTONS
   ========================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--r-md);
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn-download {
    background: var(--gradient);
    color: #fff;
    box-shadow: var(--shadow-sm);
}

.btn-download:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: var(--shadow-glow), var(--shadow-md);
}

.btn-download:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-download svg {
    flex-shrink: 0;
}

.btn-add {
    width: 100%;
    padding: 10px;
    background: var(--bg-input);
    border: 1px dashed rgba(255, 255, 255, 0.15);
    border-radius: var(--r-sm);
    color: var(--accent-light);
    font-size: 13px;
    font-weight: 500;
    margin-top: 8px;
    transition: all 0.2s ease;
}

.btn-add:hover {
    background: var(--accent-glow);
    border-color: var(--accent);
}

.btn-save {
    flex: 1;
    padding: 12px 20px;
    background: var(--gradient);
    color: #fff;
    border-radius: var(--r-md);
    font-weight: 600;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s ease;
}

.btn-save:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-glow), var(--shadow-md);
}

.btn-save-new {
    flex: 1;
    padding: 12px 20px;
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid rgba(34, 197, 94, 0.2);
    border-radius: var(--r-md);
    font-weight: 600;
    transition: all 0.2s ease;
}

.btn-save-new:hover {
    background: rgba(34, 197, 94, 0.2);
    border-color: rgba(34, 197, 94, 0.4);
}

.btn-cancel {
    width: 100%;
    padding: 10px;
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: var(--r-md);
    font-weight: 500;
    font-size: 13px;
    transition: all 0.2s ease;
}

.btn-cancel:hover {
    background: rgba(239, 68, 68, 0.2);
}

/* ==========================================================
   MAIN LAYOUT
   ========================================================== */
.main-layout {
    display: flex;
    height: calc(100vh - var(--nav-h));
    overflow: hidden;
}

/* ==========================================================
   FORM PANEL (LEFT)
   ========================================================== */
.form-panel {
    flex: 0 0 50%;
    max-width: 50%;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.form-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 20px 20px 30px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Form Card */
.form-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 18px;
    transition: border-color 0.2s ease;
}

.form-card:hover {
    border-color: rgba(255, 255, 255, 0.12);
}

.card-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 14px;
    color: var(--text-1);
}

.card-icon {
    font-size: 16px;
}

/* Form Grid */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.form-grid .span-2 {
    grid-column: span 2;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-group label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-group input {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    padding: 9px 12px;
    color: var(--text-1);
    font-size: 13px;
    transition: all 0.2s ease;
    outline: none;
}

.form-group input:focus {
    background: var(--bg-input-focus);
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-group input::placeholder {
    color: var(--text-3);
    font-weight: 300;
}

/* Items Table Header */
.items-table-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.ith-sr {
    width: 28px;
    text-align: center;
}

.ith-desc {
    flex: 1;
}

.ith-hsn {
    width: 60px;
}

.ith-qty {
    width: 50px;
}

.ith-rate {
    width: 60px;
}

.ith-amt {
    width: 65px;
    text-align: right;
}

.ith-del {
    width: 28px;
}

/* Item Row */
.item-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px;
    border-radius: var(--r-sm);
    margin-bottom: 4px;
    transition: background 0.15s ease;
}

.item-row:hover {
    background: rgba(255, 255, 255, 0.02);
}

.item-sr {
    width: 28px;
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-3);
}

.item-row input {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 7px 8px;
    color: var(--text-1);
    font-size: 12px;
    outline: none;
    transition: all 0.2s ease;
}

.item-row input:focus {
    border-color: var(--border-focus);
    background: var(--bg-input-focus);
}

.item-input-desc {
    flex: 1;
    min-width: 0;
}

.item-input-hsn {
    width: 60px;
}

.item-input-qty {
    width: 50px;
}

.item-input-rate {
    width: 60px;
}

.item-amt {
    width: 65px;
    text-align: right;
    font-size: 12px;
    font-weight: 500;
    color: var(--accent-light);
}

.item-del-btn {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: 4px;
    color: var(--text-3);
    font-size: 16px;
    transition: all 0.15s ease;
}

.item-del-btn:hover {
    background: var(--danger-bg);
    color: var(--danger);
}

.items-hint {
    font-size: 11px;
    color: var(--warning);
    margin-top: 6px;
    min-height: 16px;
}

/* Toggle Switch */
.toggle-switch {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    margin-bottom: 12px;
    user-select: none;
}

.toggle-switch input {
    display: none;
}

.toggle-track {
    width: 40px;
    height: 22px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 11px;
    position: relative;
    transition: background 0.25s ease;
    flex-shrink: 0;
}

.toggle-thumb {
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    position: absolute;
    top: 3px;
    left: 3px;
    transition: transform 0.25s ease;
}

.toggle-switch input:checked~.toggle-track {
    background: var(--accent);
}

.toggle-switch input:checked~.toggle-track .toggle-thumb {
    transform: translateX(18px);
}

.toggle-text {
    font-size: 13px;
    color: var(--text-2);
}

/* Summary Card */
.card-summary {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.08), rgba(139, 92, 246, 0.06));
    border-color: rgba(99, 102, 241, 0.15);
}

.summary-rows {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sum-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    font-size: 13px;
}

.sum-row span:first-child {
    color: var(--text-2);
}

.sum-row span:last-child {
    font-weight: 600;
}

.sum-grand {
    border-top: 1px solid var(--border);
    padding-top: 10px;
    margin-top: 4px;
    font-size: 15px;
}

.sum-grand span:last-child {
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-size: 17px;
    font-weight: 800;
}

.sum-round span:last-child {
    color: var(--success);
    font-weight: 700;
}

/* Form Actions */
.form-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    padding-top: 4px;
}

/* ==========================================================
   PREVIEW PANEL (RIGHT)
   ========================================================== */
.preview-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-preview);
}

.preview-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.preview-title {
    font-size: 15px;
    font-weight: 600;
}

.edit-badge {
    background: var(--warning);
    color: #000;
    font-size: 11px;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: var(--r-xl);
    animation: badgePulse 2s ease-in-out infinite;
}

@keyframes badgePulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.7;
    }
}

.preview-area {
    flex: 1;
    overflow: auto;
    display: flex;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(circle at 30% 50%, rgba(99, 102, 241, 0.04) 0%, transparent 50%),
        radial-gradient(circle at 70% 80%, rgba(139, 92, 246, 0.03) 0%, transparent 50%);
}

.preview-scaler {
    transform-origin: top center;
    flex-shrink: 0;
}

/* Saved Bills Section */
.saved-section {
    border-top: 1px solid var(--border);
    padding: 16px 24px 20px;
    flex-shrink: 0;
    max-height: 220px;
    overflow-y: auto;
}

.saved-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-2);
}

.bills-grid {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.bill-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 12px 16px;
    min-width: 180px;
    flex: 1;
    max-width: 250px;
    transition: all 0.2s ease;
    cursor: pointer;
    position: relative;
}

.bill-card:hover {
    border-color: var(--accent);
    background: var(--bg-card-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.bill-card-num {
    font-size: 11px;
    font-weight: 700;
    color: var(--accent-light);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.bill-card-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-1);
    margin: 4px 0 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bill-card-info {
    font-size: 11px;
    color: var(--text-3);
}

.bill-card-total {
    font-size: 14px;
    font-weight: 700;
    color: var(--success);
    margin-top: 6px;
}

.bill-card-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.bill-card:hover .bill-card-actions {
    opacity: 1;
}

.bill-card-del {
    width: 24px;
    height: 24px;
    display: grid;
    place-items: center;
    border-radius: 4px;
    font-size: 13px;
    color: var(--text-3);
    transition: all 0.15s ease;
}

.bill-card-del:hover {
    background: var(--danger-bg);
    color: var(--danger);
}

/* ==========================================================
   BILL PAGE (A4 LAYOUT — used for preview & PDF)
   ========================================================== */
.bill-page {
    width: 210mm;
    height: 297mm;
    padding: 30mm 10mm 8mm 10mm;
    box-sizing: border-box;
    background: #fff;
    color: #000;
    font-family: 'Noto Sans Devanagari', 'Times New Roman', serif;
    position: relative;
    box-shadow: var(--shadow-lg);
}

.bill-page * {
    color: #000;
}

.bill-table {
    width: 100%;
    border-collapse: collapse;
    border: 2px solid #000;
    table-layout: fixed;
}

.bill-table td,
.bill-table th {
    border: 1px solid #000;
    padding: 2px 5px;
    vertical-align: middle;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Bill Column Widths */
.bill-table .col-sr {
    width: 7%;
}

.bill-table .col-desc {
    width: 34%;
}

.bill-table .col-hsn {
    width: 13%;
}

.bill-table .col-qty {
    width: 11%;
}

.bill-table .col-rate {
    width: 15%;
}

.bill-table .col-amt {
    width: 20%;
}

/* Bill Header */
.b-hdr-left {
    font-size: 11pt;
    text-align: left;
    padding: 4px 6px;
    border-right: hidden !important;
}

.b-hdr-center {
    font-size: 11pt;
    text-align: center;
    font-weight: bold;
    padding: 4px 6px;
    border-left: hidden !important;
    border-right: hidden !important;
}

.b-hdr-right {
    font-size: 11pt;
    text-align: right;
    padding: 4px 6px;
    border-left: hidden !important;
}

/* Company */
.b-company-name {
    text-align: center;
    font-size: 28pt;
    font-weight: bold;
    padding: 4px 6px 2px;
    line-height: 1.15;
    border-bottom: hidden !important;
}

.b-company-sub {
    text-align: center;
    font-size: 18pt;
    font-weight: bold;
    padding: 2px 6px;
    border-top: hidden !important;
    border-bottom: hidden !important;
}

.b-company-addr {
    text-align: center;
    font-size: 14pt;
    font-weight: bold;
    padding: 2px 6px 4px;
    border-top: hidden !important;
}

/* Detail Rows */
.b-detail {
    font-size: 13pt;
    padding: 3px 6px;
}

.b-detail-r1 {
    border-bottom: hidden !important;
}

.b-detail-r2 {
    border-top: hidden !important;
}

.b-border-right-hidden {
    border-right: hidden !important;
}

.b-border-left-hidden {
    border-left: hidden !important;
}

.b-border-top-hidden {
    border-top: hidden !important;
}

.b-border-bottom-hidden {
    border-bottom: hidden !important;
}

/* Items Header */
.b-item-hdr {
    font-size: 12pt;
    font-weight: bold;
    text-align: center;
    padding: 4px 5px;
    background: #f8f8f8;
}

/* Item Rows */
.b-item-cell {
    font-size: 11pt;
    padding: 2px 5px;
    height: 7mm;
}

.b-item-cell.c {
    text-align: center;
}

.b-item-cell.r {
    text-align: right;
}

/* Footer */
.b-footer-left {
    vertical-align: top;
    padding: 6px 8px;
    font-size: 11pt;
}

.b-footer-words-title {
    font-size: 11pt;
}

.b-footer-words-val {
    font-size: 11pt;
    font-weight: bold;
    font-style: italic;
    margin-top: 2px;
}

.b-footer-bank-group {
    margin-top: 14px;
}

.b-footer-bank-val {
    font-size: 10pt;
    margin-top: 2px;
}

.b-footer-label {
    font-size: 11pt;
    padding: 3px 6px;
    text-align: left;
}

.b-footer-value {
    font-size: 11pt;
    padding: 3px 6px;
    text-align: right;
}

.b-bold {
    font-weight: bold !important;
}

.b-sig-block {
    margin-top: 10mm;
    /* 2 cm below the Round-of row */
    margin-right: 12mm;
    /* align to right edge of page */
    text-align: center;
    display: inline-block;
    /* shrink-wrap to text width */
    float: right;
    /* pin to right side */
}

.b-sig-line {
    font-size: 11pt;
    margin-bottom: 12mm;
}

.b-sig-name {
    font-size: 11pt;
    font-weight: bold;
}

.b-sig-prop {
    font-size: 10pt;
}

/* ==========================================================
   PDF CONTAINER (hidden off-screen)
   ========================================================== */
#pdfContainer {
    position: absolute;
    left: -99999px;
    top: 0;
    z-index: -1;
    background: #fff;
}

#pdfContainer .bill-page {
    box-shadow: none;
    margin: 0;
}

/* ==========================================================
   LOADING OVERLAY
   ========================================================== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(7, 7, 26, 0.85);
    backdrop-filter: blur(8px);
    display: grid;
    place-items: center;
    z-index: 9999;
}

.loading-box {
    text-align: center;
}

.loading-box p {
    margin-top: 16px;
    font-size: 14px;
    color: var(--text-2);
}

.spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    margin: 0 auto;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ==========================================================
   TOAST NOTIFICATIONS
   ========================================================== */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 10000;
    pointer-events: none;
}

.toast {
    background: rgba(20, 20, 40, 0.92);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 12px 20px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-1);
    box-shadow: var(--shadow-md);
    pointer-events: auto;
    animation: toastIn 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
}

.toast.success {
    border-left: 3px solid var(--success);
}

.toast.error {
    border-left: 3px solid var(--danger);
}

.toast.info {
    border-left: 3px solid var(--accent);
}

.toast-exit {
    animation: toastOut 0.25s ease forwards;
}

@keyframes toastIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes toastOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }

    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* ==========================================================
   RESPONSIVE — MOBILE (≤ 768px)
   ========================================================== */
@media (max-width: 768px) {

    /* ── Navbar ── */
    .navbar {
        padding: 0 12px;
        gap: 6px;
    }

    .nav-logo {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }

    .nav-title {
        font-size: 14px;
    }

    .nav-subtitle {
        display: none;
    }

    .nav-actions {
        gap: 8px;
    }

    .bill-counter {
        padding: 4px 8px;
        gap: 4px;
    }

    .counter-num {
        font-size: 14px;
    }

    .counter-label {
        font-size: 10px;
    }

    /* Icon-only download button on mobile */
    .btn-download-text {
        display: none;
    }

    .btn-download {
        padding: 8px 10px;
        font-size: 12px;
        gap: 0;
        min-width: 36px;
        justify-content: center;
    }


    /* ── Main layout: stack vertically ── */
    .main-layout {
        flex-direction: column;
        height: auto;
        min-height: calc(100vh - var(--nav-h));
        overflow: visible;
    }

    /* ── Form Panel ── */
    .form-panel {
        flex: none;
        width: 100%;
        max-width: 100%;
        border-right: none;
        border-bottom: 2px solid var(--border);
        overflow: visible;
    }

    .form-scroll {
        flex: none;
        overflow: visible;
        padding: 14px 14px 20px;
        gap: 14px;
    }

    .form-card {
        padding: 14px;
    }

    .card-title {
        font-size: 13px;
        margin-bottom: 12px;
    }

    /* ── Form Grid: 2-col (stays readable) ── */
    .form-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .form-group label {
        font-size: 10px;
    }

    .form-group input {
        padding: 10px;
        font-size: 14px;
    }

    /* ── Items: hide desktop header, card-style rows ── */
    .items-table-header {
        display: none;
    }

    /*
     * Item row: 4-row CSS grid layout (mobile)
     * Row 1: [#] [----description----] [×]
     * Row 2: [HSN ────────] [QTY ────]
     * Row 3: [Rate ───────────────────]
     * Row 4: [Amount (right-aligned)──]
     *
     * Grid columns: 26px | 1fr | 1fr | 30px
     * HTML order: item-sr, item-input-desc, item-input-hsn,
     *   item-input-qty, item-input-rate, item-amt, item-del-btn
     */
    .item-row {
        display: grid;
        grid-template-columns: 26px 1fr 1fr 30px;
        grid-template-rows: auto auto auto auto;
        gap: 6px;
        padding: 10px;
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: var(--r-md);
        margin-bottom: 8px;
        align-items: center;
    }

    .item-row:hover {
        background: var(--bg-card-hover);
    }

    /* Row 1 — serial number */
    .item-sr {
        grid-column: 1;
        grid-row: 1;
        width: auto;
        text-align: center;
        font-size: 12px;
        font-weight: 700;
        color: var(--accent-light);
    }

    /* Row 1 — description spans cols 2–3 */
    .item-input-desc {
        grid-column: 2 / 4;
        grid-row: 1;
        width: 100% !important;
        min-width: 0;
        font-size: 14px;
        padding: 9px 10px;
    }

    /* Row 1 — delete button col 4 (explicit placement overrides HTML order) */
    .item-del-btn {
        grid-column: 4;
        grid-row: 1;
        width: 30px;
        height: 30px;
    }

    /* Row 2 — HSN (cols 1–2) + QTY (cols 3–4) */
    .item-input-hsn {
        grid-column: 1 / 3;
        grid-row: 2;
        width: 100% !important;
        min-width: 0;
        font-size: 13px;
        padding: 8px 9px;
    }

    .item-input-qty {
        grid-column: 3 / 5;
        grid-row: 2;
        width: 100% !important;
        min-width: 0;
        font-size: 13px;
        padding: 8px 9px;
    }

    /* Row 3 — Rate full width */
    .item-input-rate {
        grid-column: 1 / 5;
        grid-row: 3;
        width: 100% !important;
        min-width: 0;
        font-size: 13px;
        padding: 8px 9px;
    }

    /* Row 4 — Amount full width, right-aligned */
    .item-amt {
        grid-column: 1 / 5;
        grid-row: 4;
        width: 100% !important;
        font-size: 13px;
        font-weight: 700;
        color: var(--accent-light);
        text-align: right;
        padding: 2px 4px 4px;
    }

    /* ── Totals ── */
    .totals-grid {
        gap: 6px;
    }

    .totals-row {
        font-size: 12px;
    }

    .totals-row.grand {
        font-size: 14px;
    }

    /* ── Action buttons ── */
    .form-actions {
        flex-direction: column;
        gap: 8px;
        padding: 12px 14px;
    }

    .btn-save,
    .btn-save-new {
        flex: none;
        width: 100%;
        padding: 14px 16px;
        font-size: 15px;
    }

    .btn-cancel {
        margin-top: 2px;
    }

    /* ── Preview Panel ── */
    .preview-panel {
        flex: none;
        width: 100%;
        min-height: unset;
        height: auto;
        overflow: visible;
        /* allow content to flow naturally */
    }

    /* Preview area: switch to block so scaler anchors to left edge */
    .preview-area {
        display: block;        /* not flex — prevents centering offset */
        flex: none;
        height: auto;
        overflow: visible;
        padding: 0;
    }

    /* Scaler starts from top-left of block container */
    .preview-scaler {
        display: block;
        transform-origin: top left;
        margin: 0;
    }




    /* ── Bills History ── */
    .bills-header {
        padding: 12px 14px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .bills-list {
        padding: 0 10px 10px;
    }

    .bill-card {
        padding: 12px;
    }

    /* ── Toast ── */
    .toast-container {
        bottom: 12px;
        right: 12px;
        left: 12px;
    }

    .toast {
        font-size: 12px;
    }
}

/* ── Extra small phones ≤ 480px ── */
@media (max-width: 480px) {
    .navbar {
        padding: 0 10px;
    }

    .nav-logo {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }

    .nav-title {
        font-size: 13px;
    }

    .form-scroll {
        padding: 10px 10px 14px;
        gap: 10px;
    }

    .form-card {
        padding: 11px;
    }

    .form-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .form-grid .span-2 {
        grid-column: span 1;
    }

    .form-group input {
        font-size: 15px;
        padding: 11px 10px;
    }

    .item-row {
        padding: 9px 8px 7px;
        gap: 5px 5px;
    }

    .item-input-desc {
        font-size: 15px;
        padding: 10px 9px;
    }

    .item-input-hsn,
    .item-input-qty,
    .item-input-rate {
        font-size: 13px;
        padding: 8px 7px;
    }
}