/* ==========================================================================
   DESIGN SYSTEM & THEME TOKENS (UI EDITOR)
   ========================================================================== */
:root {
    --bg-app: #0f172a;
    --bg-sidebar: #1e293b;
    --bg-card: #334155;
    --border-color: #475569;
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-glow: rgba(99, 102, 241, 0.2);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-red-ink: #dc2626; /* Authentic pre-printed red ink */
    --text-blue-ink: #1e3a8a; /* Pre-printed blue lines and labels */
    --handwriting-ink: #1d4ed8; /* Blue carbon-copy/typed ink for values */
    --paper-white: #ffffff;
    --font-ui: 'Outfit', 'Inter', sans-serif;
    --font-invoice: 'Inter', -apple-system, sans-serif;
    --font-courier: 'Courier Prime', 'Courier New', monospace;
}

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

body {
    background-color: var(--bg-app);
    color: var(--text-main);
    font-family: var(--font-ui);
    height: 100vh;
    overflow: hidden;
}

/* App Layout Grid */
.app-container {
    display: grid;
    grid-template-columns: 365px 1fr;
    height: 100vh;
    width: 100vw;
}

/* ==========================================================================
   SIDEBAR & FORM CONTROLS (LEFT PANEL)
   ========================================================================== */
.sidebar {
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.25);
    z-index: 10;
}

.sidebar-header {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-icon {
    font-size: 1.8rem;
    color: var(--accent);
    filter: drop-shadow(0 0 10px var(--accent-glow));
}

.sidebar-header h1 {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--text-main);
}

.sidebar-header p {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Custom Scrollbar for Sidebar */
.sidebar-content::-webkit-scrollbar {
    width: 6px;
}
.sidebar-content::-webkit-scrollbar-track {
    background: var(--bg-sidebar);
}
.sidebar-content::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

/* Quick Action Buttons */
.quick-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    outline: none;
    font-family: var(--font-ui);
}

.btn-primary {
    background-color: var(--accent);
    color: white;
}
.btn-primary:hover {
    background-color: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--accent-glow);
}

.btn-success {
    background-color: #25D366;
    color: white;
}
.btn-success:hover {
    background-color: #1ebe5a;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.3);
}

.btn-secondary {
    background-color: var(--bg-card);
    color: var(--text-main);
    border: 1px solid var(--border-color);
}
.btn-secondary:hover {
    background-color: var(--border-color);
    color: white;
}

.btn-outline {
    background-color: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
}
.btn-outline:hover {
    color: var(--text-main);
    border-color: var(--text-muted);
    background-color: rgba(255, 255, 255, 0.05);
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.78rem;
    border-radius: 5px;
}

.block-btn {
    width: 100%;
}

/* Form Styling */
#invoice-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-section {
    background-color: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.form-section:nth-of-type(odd) { border-left: 3px solid var(--accent); }
.form-section:nth-of-type(even) { border-left: 3px solid var(--text-muted); }

.form-section[open] {
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
}

.form-section summary {
    padding: 8px 12px;
    font-weight: 600;
    font-size: 0.8rem;
    cursor: pointer;
    user-select: none;
    background-color: rgba(255, 255, 255, 0.04);
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background-color 0.2s;
}

.form-section summary::-webkit-details-marker {
    display: none;
}

.form-section summary::after {
    content: '\f107';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    margin-left: auto;
    transition: transform 0.25s;
}

.form-section[open] summary::after {
    transform: rotate(180deg);
}

.form-section summary:hover {
    background-color: rgba(255, 255, 255, 0.08);
}

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

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

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

.address-three-cols {
    display: grid;
    grid-template-columns: 1.2fr 1.2fr 1fr;
    gap: 8px;
}

.form-three-cols {
    display: grid;
    grid-template-columns: 1fr 0.85fr 1.15fr;
    gap: 8px;
}

.form-group label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.3px;
}

.label-with-badge {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.char-badge {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-weight: normal;
    background-color: rgba(255, 255, 255, 0.05);
    padding: 1px 4px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    transition: all 0.2s;
    line-height: 1;
}

.char-badge.complete {
    color: #22c55e;
    background-color: rgba(34, 197, 94, 0.1);
    border-color: rgba(34, 197, 94, 0.25);
    font-weight: bold;
}

body.light-theme .char-badge.complete {
    color: #15803d;
    background-color: rgba(21, 128, 61, 0.08);
    border-color: rgba(21, 128, 61, 0.2);
}

.form-group input, .form-group select {
    background-color: var(--bg-app);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px 8px;
    color: var(--text-main);
    font-family: var(--font-ui);
    font-size: 0.78rem;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    width: 100%;
}

.form-group input:focus, .form-group select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.help-text {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 1px;
}

/* Dynamic Items List Form Grid */
.items-list-container {
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.items-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.item-form-card {
    background-color: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--accent);
    border-radius: 6px;
    padding: 8px 10px;
    position: relative;
    transition: all 0.2s ease;
}

.item-form-card:hover {
    background-color: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.2);
}

.item-form-card .btn-remove-item {
    position: absolute;
    top: 6px;
    right: 28px;
    background: transparent;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 0.8rem;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
}

.item-form-card .btn-remove-item:hover {
    background-color: rgba(239, 68, 68, 0.1);
    transform: scale(1.1);
}

.item-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-top: 6px;
}

/* Multi-meters group styling */
.multi-meters-group {
    margin-top: 6px;
}

.field-hint {
    font-size: 0.68rem;
    font-weight: 400;
    color: var(--accent);
    opacity: 0.8;
    margin-left: 4px;
}

.field-hint.auto-hint {
    color: #22d3ee;
}

/* Auto-filled Meters field (computed from multi-meters) */
.input-auto-filled {
    background-color: rgba(34, 211, 238, 0.06) !important;
    border-color: #22d3ee !important;
    color: #22d3ee !important;
    cursor: not-allowed;
    opacity: 0.85;
}

/* Multi-meters tag input container */
.multi-meters-tag-container {
    background-color: var(--bg-app);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 4px 8px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    min-height: 38px;
    cursor: text;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    margin-top: 4px;
}

.multi-meters-tag-container:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.multi-meters-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

/* Individual tag pills */
.meter-tag {
    background: linear-gradient(135deg, var(--accent) 0%, #4f46e5 100%);
    color: white;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 4px 8px 4px 10px;
    border-radius: 20px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 2px 4px rgba(99, 102, 241, 0.2);
    animation: tagScaleIn 0.15s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes tagScaleIn {
    from {
        opacity: 0;
        transform: scale(0.85);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.meter-tag .tag-remove {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border-radius: 50%;
    width: 14px;
    height: 14px;
    transition: all 0.15s;
    line-height: 1;
}

.meter-tag .tag-remove:hover {
    background-color: rgba(255, 255, 255, 0.25);
    color: white;
}

/* Invisible text input inside the container */
.input-item-multi-meters-tag {
    background: transparent !important;
    border: none !important;
    padding: 4px 0 !important;
    color: var(--text-main) !important;
    font-family: var(--font-ui) !important;
    font-size: 0.88rem !important;
    flex-grow: 1;
    min-width: 80px;
    outline: none !important;
    box-shadow: none !important;
}

/* ==========================================================================
   PREVIEW AREA (RIGHT CONTAINER CANVAS)
   ========================================================================== */
.preview-area {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    background: radial-gradient(circle at 50% 35%, #1e293b 0%, #0b0f19 100%);
}

.preview-toolbar {
    padding: 10px 20px;
    background-color: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    z-index: 5;
}

.preview-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
}

.preview-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

/* Copies control: label + number input in the toolbar */
.copies-control {
    display: flex;
    align-items: center;
    gap: 6px;
    background-color: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 4px 10px;
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 600;
}

.copies-control label {
    cursor: default;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
}

.copies-control input[type="number"] {
    width: 52px;
    background-color: var(--bg-app);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-main);
    font-size: 0.88rem;
    font-weight: 700;
    text-align: center;
    padding: 4px 6px;
    font-family: var(--font-ui);
    transition: border-color 0.2s;
}

.copies-control input[type="number"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Invoice Sheet Scaling and Page Mimicry */
.invoice-sheet-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.invoice-sheet-container::-webkit-scrollbar {
    width: 8px;
}
.invoice-sheet-container::-webkit-scrollbar-track {
    background: #0b0f19;
}
.invoice-sheet-container::-webkit-scrollbar-thumb {
    background: var(--bg-card);
    border-radius: 4px;
}

/* Size designed to mimic precise printed bill page ratios (A4 / Letter scale) */
.invoice-sheet {
    background-color: var(--paper-white);
    color: #000000;
    width: 794px; /* A4 standard width at 96 DPI */
    min-height: 1122px; /* A4 standard height at 96 DPI */
    padding: 41px 35px 36px 35px;
    position: relative;
    box-shadow: 0 25px 65px rgba(0, 0, 0, 0.45), 0 0 1px rgba(255, 255, 255, 0.1);
    font-family: var(--font-invoice);
    overflow: hidden;
    border-radius: 4px;
}

@media screen {
    .invoice-sheet {
        zoom: 0.82;
    }
    .invoice-sheet::after {
        content: '';
        position: absolute;
        top: 0; left: 0; right: 0; bottom: 0;
        box-shadow: inset 0 0 24px rgba(0,0,0,0.02);
        pointer-events: none;
    }
}

/* Font helper styles for handwritten carbon look */
.font-courier {
    font-family: var(--font-courier);
}
.font-sans {
    font-family: var(--font-invoice);
}
.font-bold {
    font-weight: 700;
}
.font-xxs { font-size: 9px; line-height: 1.2; }
.font-xs { font-size: 11px; line-height: 1.3; }
.font-sm { font-size: 13px; line-height: 1.3; }
.font-md { font-size: 15px; line-height: 1.4; }
.font-lg { font-size: 18px; line-height: 1.5; }

/* Red & Blue Ink Branding Styles */
.text-red {
    color: var(--text-red-ink);
}
.red-ink {
    color: var(--text-red-ink);
}
.blue-ink {
    color: var(--text-blue-ink);
}
.black-ink {
    color: #000000;
}

/* The dynamic values filled in by user will use this look (typed blue ink) */
.invoice-sheet [id^="view-"], .invoice-sheet [id^="tot-"] {
    color: var(--handwriting-ink);
}

.invoice-sheet a {
    color: inherit;
    text-decoration: none;
}
.invoice-sheet a:hover {
    text-decoration: underline;
}

/* Repeated Branding Margins in Red (Printed Board) */
.margin-text {
    position: absolute;
    color: var(--text-red-ink);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 1px;
    opacity: 0.95;
    user-select: none;
}

.margin-text.top-left { top: 18px; left: 35px; }
.margin-text.top-center { top: 18px; left: 50%; transform: translateX(-50%); }
.margin-text.top-right { top: 18px; right: 35px; }

.margin-text-vertical {
    position: absolute;
    color: var(--text-red-ink);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 2px;
    opacity: 0.95;
    user-select: none;
    writing-mode: vertical-lr; /* Standard top-to-bottom vertical text */
    right: 15px; /* Added gap from the 35px right border */
}

/* Absolute positions along the right border margin */
.margin-text-vertical.right-1 { top: 100px; }
.margin-text-vertical.right-2 { top: 300px; }
.margin-text-vertical.right-3 { top: 500px; }
.margin-text-vertical.right-4 { top: 700px; }
.margin-text-vertical.right-5 { top: 900px; }

.margin-text.bottom-left { bottom: 13px; left: 35px; }
.margin-text.bottom-center { bottom: 13px; left: 50%; transform: translateX(-50%); }
.margin-text.bottom-right { bottom: 13px; right: 35px; }

/* Inner Content Box (Double lined borders as in real bills) */
.invoice-inner-box {
    border: 2px solid var(--text-blue-ink);
    outline: 1px solid var(--text-blue-ink);
    outline-offset: -5px;
    height: 100%;
    min-height: 1045px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
}

/* ==========================================================================
   INVOICE BRANDING HEADER SECTION
   ========================================================================== */
.invoice-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: flex-start;
    padding-bottom: 5px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 6px;
    text-align: left;
    white-space: nowrap;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 6px;
    text-align: right;
    justify-content: flex-end;
    white-space: nowrap;
}

.header-center {
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.header-prayer {
    color: #000000;
    white-space: nowrap;
}

.header-jurisdiction {
    color: #4b5563;
    font-style: italic;
}



/* Mill Title Row with red Ganesha Logos */
.title-block {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    margin-bottom: 8px;
}

.emblem-wrapper {
    width: 60px;
    height: 60px;
    flex-shrink: 0;
    border: 2.5px solid #dc2626;
    border-radius: 6px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.emblem-svg {
    width: 50px;
    height: 50px;
    display: block;
}

.title-text-container {
    text-align: center;
    flex: 1;
}

.mill-title {
    font-family: var(--font-invoice);
    font-size: 28px;
    font-weight: 900;
    color: var(--text-red-ink);
    letter-spacing: 2px;
    line-height: 1.1;
    margin-bottom: 2px;
    text-shadow: 1px 1px 0px rgba(0,0,0,0.1);
}

.mill-subtitle {
    font-size: 9px;
    letter-spacing: 0.2px;
}

.mill-gstin-header {
    font-size: 11px;
    letter-spacing: 0.5px;
    margin-top: 4px;
}

/* Addresses block with divider */
.address-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border-top: 1px solid var(--text-blue-ink);
    border-bottom: 1px solid var(--text-blue-ink);
    padding: 4px 0;
    margin-bottom: 0;
}

.address-col {
    padding: 2px 10px;
    line-height: 1.3;
}

.address-col.border-right {
    border-right: 1px solid var(--text-blue-ink);
}

/* Shop Phone, Bill, Date Info Row */
.shop-bill-row {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    align-items: center;
    padding: 7px 10px;
    background-color: rgba(30, 58, 138, 0.03);
}

.shop-bill-row .bill-no-col {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: bold;
    color: var(--text-blue-ink);
}

.shop-bill-row #view-bill-no {
    border-bottom: 1px dashed rgba(30, 58, 138, 0.35);
    min-width: 130px;
    display: inline-block;
    padding-left: 5px;
    letter-spacing: 0.5px;
}



.shop-bill-row .date-col {
    text-align: right;
    font-weight: bold;
    color: var(--text-blue-ink);
}

.shop-bill-row #view-date {
    border-bottom: 1px dashed rgba(30, 58, 138, 0.35);
    min-width: 80px;
    display: inline-block;
    text-align: center;
}

/* ==========================================================================
   METADATA GRID (PARTY & SHIPPING)
   ========================================================================== */
.metadata-grid {
    display: grid;
    grid-template-columns: 1.15fr 1fr;
    border-bottom: 1px solid var(--text-blue-ink);
}

.party-details-block {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.party-details-block .meta-row {
    display: flex;
    padding: 8px 10px;
    flex-grow: 1;
}

.party-details-block .label {
    width: 110px;
    font-weight: bold;
    color: var(--text-blue-ink);
}

.val-lines {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 60px;
}

.line-val {
    border-bottom: 1px dashed rgba(30, 58, 138, 0.3);
    min-height: 20px;
    height: auto;
    line-height: 1.2;
    word-break: break-word;
    padding-left: 6px;
}

.party-details-block .gstin-row,
.party-details-block .mobile-row {
    padding: 8px 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    background-color: rgba(30, 58, 138, 0.02);
}

.party-details-block .gstin-row .label,
.party-details-block .mobile-row .label {
    width: auto;
}

/* Shipping Details Grid rows */
.shipping-details-block {
    display: flex;
    flex-direction: column;
}

.shipping-row {
    display: flex;
    align-items: center;
    padding: 6px 10px;
    min-height: 28px;
}

.shipping-row.split-2 {
    display: grid;
    padding: 0;
}

.shipping-row.split-2.rr-date-row {
    grid-template-columns: 1.25fr 0.75fr;
}

.shipping-row.split-2.bale-order-row {
    grid-template-columns: 1fr 1fr;
}

.shipping-row.split-2 .sub-col {
    display: flex;
    align-items: center;
    padding: 6px 10px;
    height: 100%;
}

.shipping-row .label, .shipping-row.split-2 .label {
    font-weight: bold;
    color: var(--text-blue-ink);
    margin-right: 8px;
    font-size: 11px;
}

.shipping-row .val, .shipping-row.split-2 .val {
    flex-grow: 1;
    border-bottom: 1px dashed rgba(30, 58, 138, 0.3);
    min-height: 18px;
    padding-left: 5px;
    line-height: 1.1;
}

/* ==========================================================================
   ITEMS DATA TABLE SECTION (GRID LAYOUT)
   ========================================================================== */
.items-table-container {
    position: relative;
    flex-grow: 1;
    min-height: 380px;
    background-color: transparent;
}

/* Watermark rotated behind the cells */
.watermark-bg {
    position: absolute;
    top: 52%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-12deg);
    color: var(--text-red-ink);
    font-size: 38px;
    font-weight: 900;
    opacity: 0.04;
    white-space: nowrap;
    pointer-events: none;
    letter-spacing: 3px;
    z-index: 1;
}

.items-table {
    width: 100%;
    border-collapse: collapse;
    position: relative;
    z-index: 2;
    height: 100%;
}

.items-table th {
    color: var(--text-blue-ink);
    font-weight: 700;
    font-size: 11px;
    text-align: center;
    padding: 4px;
    vertical-align: middle;
}

.items-table th div {
    padding: 2px;
}

.items-table th.col-sr { width: 4.5%; }
.items-table th.col-desc { width: 44%; }
.items-table th.col-hsn { width: 7%; }
.items-table th.col-pcs { width: 5%; }
.items-table th.col-meters { width: 11%; }
.items-table th.col-rate { width: 14%; padding: 0; }
.items-table th.col-amount { width: 14%; padding: 0; }

.sub-header-split {
    display: grid;
    grid-template-columns: 3fr 1fr;
    font-size: 9px;
}

.sub-header-split span {
    padding: 2px 0;
}

/* Row elements in items body */
.items-table tbody tr {
    height: 26px;
    border-bottom: 1px solid rgba(30, 58, 138, 0.15);
}

.items-table tbody td {
    padding: 4px 6px;
    vertical-align: middle;
    font-size: 12px;
}

/* Alignment rules matching printed table layout */
.items-table tbody td.cell-sr { text-align: center; }
.items-table tbody td.cell-desc {
    text-align: left;
    word-break: break-word;
    max-height: 52px;
    overflow: hidden;
}
.items-table tbody td.cell-hsn { text-align: center; }
.items-table tbody td.cell-pcs { text-align: right; }
.items-table tbody td.cell-meters { text-align: right; }

/* PDF/Print: hard-clamp desc cell so table never overflows page */
@media print {
    .items-table tbody td.cell-desc {
        max-height: 26px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
    }
    .items-table tbody tr {
        height: 26px !important;
        max-height: 26px !important;
    }
}

/* Multi-meters breakdown label shown inside the description cell */
.bill-multi-meters {
    display: block;
    font-size: 9.5px;
    color: var(--text-blue-ink);
    font-family: var(--font-courier);
    font-weight: 600;
    opacity: 0.85;
    letter-spacing: 0.2px;
    margin-top: 1px;
}

/* Dual fields for split Rs and P */
.items-table tbody td.cell-rs { text-align: right; width: 10.5%; padding-right: 4px; }
.items-table tbody td.cell-p { text-align: center; width: 3.5%; padding-left: 2px; }

/* Grid divider lines */
.border-right { border-right: 1px solid var(--text-blue-ink); }
.border-left { border-left: 1px solid var(--text-blue-ink); }
.border-top { border-top: 1px solid var(--text-blue-ink); }
.border-bottom { border-bottom: 1px solid var(--text-blue-ink); }

/* ==========================================================================
   TOTALS & CALCULATION SUMMARY FOOTER
   ========================================================================== */
.totals-section {
    display: grid;
    grid-template-columns: 71.5% 28.5%;
}

.totals-left {
    display: flex;
    flex-direction: column;
}

.bank-details-box {
    padding: 8px 10px;
    line-height: 1.4;
    background-color: rgba(220, 38, 38, 0.02);
}

.gstin-nett-box {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.mill-gstin-row {
    padding: 8px 10px;
    display: flex;
    align-items: center;
    color: var(--text-blue-ink);
}

.nett-rate-terms-row {
    padding: 8px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: rgba(220, 38, 38, 0.02);
    flex-grow: 1;
}

/* Totals right table with values */
.totals-right {
    display: flex;
}

.totals-table {
    width: 100%;
    border-collapse: collapse;
}

.totals-table td {
    padding: 5px 8px;
    vertical-align: middle;
}

.totals-table td.total-label {
    width: 50%;
    color: #000000;
    font-weight: bold;
    text-align: left;
}

.totals-table td.total-rs {
    width: 37.5%;
    text-align: right;
    font-size: 13px;
}

.totals-table td.total-p {
    width: 12.5%;
    text-align: center;
    font-size: 13px;
}

.gtotal-row {
    background: linear-gradient(135deg, rgba(30, 58, 138, 0.14) 0%, rgba(30, 58, 138, 0.08) 100%);
    border-top: 2px solid var(--text-blue-ink);
}

.gtotal-row td {
    padding: 8px;
}

.gtotal-row .total-label {
    font-size: 13px !important;
    font-weight: 800 !important;
    color: var(--text-blue-ink) !important;
    letter-spacing: 0.5px;
}

/* Payee Reminder Sub Box */
.reminder-sub-box {
    padding: 6px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: rgba(220, 38, 38, 0.02);
}

.e-oe-label {
    color: #000000;
}

.draft-reminder-text {
    flex-grow: 1;
    text-align: center;
    letter-spacing: 0.2px;
}

.footer-terms-row {
    display: grid;
    grid-template-columns: 1.3fr 1fr;
    padding-top: 2px;
}

.terms-col {
    padding: 6px 10px;
    line-height: 1.4;
}

.terms-list {
    margin-left: 14px;
    margin-top: 4px;
    color: #374151;
}

.terms-list li {
    margin-bottom: 2px;
}

.signature-col {
    padding: 6px 10px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    text-align: right;
}

.sig-space {
    height: 45px;
}

.sig-footer {
    border-top: 1px dashed rgba(220, 38, 38, 0.3);
    padding-top: 4px;
    display: inline-block;
    width: 150px;
    margin-left: auto;
}

/* ==========================================================================
   PRINT MEDIA RULES (FOR WEB BROWSER PRINT AND PDF SAVE)
   ========================================================================== */
@media print {
    /* Hide all web components */
    .no-print, .sidebar, .preview-toolbar {
        display: none !important;
    }

    body {
        background-color: #ffffff !important;
        color: #000000 !important;
        height: auto;
        overflow: visible;
    }

    .app-container {
        display: block !important;
        height: auto;
        width: 100%;
    }

    .preview-area {
        background-color: #ffffff !important;
        background: #ffffff !important;
        height: auto;
        overflow: visible;
        display: block;
    }

    .invoice-sheet-container {
        padding: 0 !important;
        margin: 0 !important;
        overflow: visible;
        display: block;
        background: #ffffff !important;
        background-color: #ffffff !important;
        /* Kill the dark radial-gradient that leaks through as a bottom bar */
        background-image: none !important;
    }

    /* Multi-copy wrapper: must be white so dark UI doesn't bleed */
    #temp-print-copies {
        background: #ffffff !important;
        background-color: #ffffff !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* Black & White copies (2nd copy onwards) */
    .invoice-sheet.bw-copy {
        filter: grayscale(100%) !important;
        -webkit-filter: grayscale(100%) !important;
    }
    .invoice-sheet.bw-copy * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }
    .invoice-sheet.bw-copy .text-red,
    .invoice-sheet.bw-copy .red-ink,
    .invoice-sheet.bw-copy .blue-ink,
    .invoice-sheet.bw-copy [id^="view-"],
    .invoice-sheet.bw-copy [id^="tot-"] {
        color: #000000 !important;
    }

    @page {
        margin: 0;
    }

    .invoice-sheet {
        box-shadow: none !important;
        border: 1px solid #d1d5db !important;
        padding: 41px 35px 36px 35px !important;
        margin: 0 auto !important;
        width: 794px !important;
        min-height: 1122px !important;
        height: auto !important;
        overflow: visible !important;
        /* page-break-after set per-clone in JS; avoid double-break on single copy */
        page-break-inside: avoid;
    }

    .invoice-sheet .items-table-container {
        height: auto !important;
        min-height: 380px !important;
    }

    .invoice-sheet .items-table {
        height: auto !important;
    }

    /* Enforce exact background colors and colors to print */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}

/* Print Page Configuration */
@page {
    size: A4;
    margin: 8mm 10mm 8mm 10mm;
}

/* Custom section styles & color codes */
.dates-sec { border-left: 4px solid #38bdf8 !important; }
.dates-sec[open] { border-color: #38bdf8 !important; background-color: rgba(56, 189, 248, 0.02) !important; }
.dates-sec summary { background-color: rgba(56, 189, 248, 0.08) !important; color: #38bdf8 !important; }
.dates-sec summary:hover { background-color: rgba(56, 189, 248, 0.15) !important; }
.dates-sec summary i { color: #38bdf8; }

.party-sec { border-left: 4px solid #fb923c !important; }
.party-sec[open] { border-color: #fb923c !important; background-color: rgba(251, 146, 60, 0.02) !important; }
.party-sec summary { background-color: rgba(251, 146, 60, 0.08) !important; color: #fb923c !important; }
.party-sec summary:hover { background-color: rgba(251, 146, 60, 0.15) !important; }
.party-sec summary i { color: #fb923c; }

.wa-sec { border-left: 4px solid #25D366 !important; }
.wa-sec[open] { border-color: #25D366 !important; background-color: rgba(37, 211, 102, 0.02) !important; }
.wa-sec summary { background-color: rgba(37, 211, 102, 0.08) !important; color: #25D366 !important; }
.wa-sec summary:hover { background-color: rgba(37, 211, 102, 0.15) !important; }
.wa-sec summary i { color: #25D366; }

body.light-theme .wa-sec { border-left-color: #1da851 !important; }
body.light-theme .wa-sec[open] { background-color: rgba(29, 168, 81, 0.02) !important; }
body.light-theme .wa-sec summary { background-color: rgba(29, 168, 81, 0.06) !important; color: #1da851 !important; }
body.light-theme .wa-sec summary i { color: #1da851; }

.shipping-sec { border-left: 4px solid #34d399 !important; }
.shipping-sec[open] { border-color: #34d399 !important; background-color: rgba(52, 211, 153, 0.02) !important; }
.shipping-sec summary { background-color: rgba(52, 211, 153, 0.08) !important; color: #34d399 !important; }
.shipping-sec summary:hover { background-color: rgba(52, 211, 153, 0.15) !important; }
.shipping-sec summary i { color: #34d399; }

.items-sec { border-left: 4px solid #a78bfa !important; }
.items-sec[open] { border-color: #a78bfa !important; background-color: rgba(167, 139, 250, 0.02) !important; }
.items-sec summary { background-color: rgba(167, 139, 250, 0.08) !important; color: #a78bfa !important; }
.items-sec summary:hover { background-color: rgba(167, 139, 250, 0.15) !important; }
.items-sec summary i { color: #a78bfa; }

.discount-sec { border-left: 4px solid #f43f5e !important; }
.discount-sec[open] { border-color: #f43f5e !important; background-color: rgba(244, 63, 94, 0.02) !important; }
.discount-sec summary { background-color: rgba(244, 63, 94, 0.08) !important; color: #f43f5e !important; }
.discount-sec summary:hover { background-color: rgba(244, 63, 94, 0.15) !important; }
.discount-sec summary i { color: #f43f5e; }

.mill-sec { border-left: 4px solid #2dd4bf !important; }
.mill-sec[open] { border-color: #2dd4bf !important; background-color: rgba(45, 212, 191, 0.02) !important; }
.mill-sec summary { background-color: rgba(45, 212, 191, 0.08) !important; color: #2dd4bf !important; }
.mill-sec summary:hover { background-color: rgba(45, 212, 191, 0.15) !important; }
.mill-sec summary i { color: #2dd4bf; }

/* Item Card Serial Number Badge */
.item-sr-badge {
    position: absolute;
    top: 6px;
    right: 72px;
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--text-muted);
    background-color: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-color);
    padding: 1px 4px;
    border-radius: 4px;
    line-height: 1.2;
}

.item-form-card .btn-copy-item {
    position: absolute;
    top: 6px;
    right: 50px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.8rem;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
}

.item-form-card .btn-copy-item:hover {
    background-color: rgba(255, 255, 255, 0.08);
    color: var(--text-main);
    transform: scale(1.1);
}

body.light-theme .item-form-card .btn-copy-item:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

/* Header icon group (gear + moon) */
.header-icon-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Theme Toggle Button Styles */
.theme-toggle-btn {
    background: transparent;
    border: none;
    color: var(--text-main);
    cursor: pointer;
    font-size: 1rem;
    padding: 6px;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    outline: none;
}

.theme-toggle-btn:hover {
    background-color: rgba(255, 255, 255, 0.08);
    transform: scale(1.05);
}

#btn-api-settings .fa-gear {
    transition: transform 0.5s ease;
}
#btn-api-settings:hover .fa-gear {
    transform: rotate(60deg);
}

/* ==========================================================================
   API SETTINGS MODAL
   ========================================================================== */
.settings-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.22s ease;
}
.settings-modal-overlay.active {
    opacity: 1;
}

.settings-modal-box {
    background: var(--bg-sidebar);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    width: 420px;
    max-width: 94vw;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
    transform: translateY(18px) scale(0.97);
    transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow: hidden;
}
.settings-modal-overlay.active .settings-modal-box {
    transform: translateY(0) scale(1);
}

.settings-modal-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 20px 14px;
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(135deg, rgba(99,102,241,0.08) 0%, transparent 100%);
}
.settings-modal-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent) 0%, #4f46e5 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1rem;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(99,102,241,0.35);
}
.settings-modal-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: 0.2px;
}
.settings-modal-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.settings-modal-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.settings-field-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.3px;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.settings-field-label i {
    color: var(--accent);
}

.settings-input {
    width: 100%;
    background-color: var(--bg-app);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 9px 12px;
    color: var(--text-main);
    font-family: var(--font-ui);
    font-size: 0.82rem;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
}
.settings-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
.settings-input::placeholder {
    color: var(--text-muted);
    opacity: 0.6;
}

.settings-hint {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 4px;
    line-height: 1.4;
}

.settings-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 20px 18px;
    border-top: 1px solid var(--border-color);
}

.settings-btn-cancel {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    padding: 8px 18px;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font-ui);
    transition: all 0.2s;
}
.settings-btn-cancel:hover {
    border-color: var(--text-muted);
    color: var(--text-main);
    background-color: rgba(255,255,255,0.04);
}

.settings-btn-save {
    background: linear-gradient(135deg, var(--accent) 0%, #4f46e5 100%);
    border: none;
    color: white;
    padding: 8px 20px;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    font-family: var(--font-ui);
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(99,102,241,0.25);
    display: flex;
    align-items: center;
    gap: 7px;
}
.settings-btn-save:hover {
    opacity: 0.9;
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(99,102,241,0.4);
}

/* Light theme overrides for settings modal */
body.light-theme .settings-modal-box {
    background: #ffffff;
    box-shadow: 0 16px 48px rgba(0,0,0,0.15);
}
body.light-theme .settings-input {
    background-color: #f8fafc;
}


/* Light Theme Styling Overrides */
body.light-theme {
    --bg-app: #ffffff;
    --bg-sidebar: #ffffff;
    --bg-card: #f8fafc;
    --border-color: #cbd5e1;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --accent: #4f46e5;
    --accent-hover: #4338ca;
}

body.light-theme .sidebar-header {
    background: linear-gradient(135deg, #ffffff 0%, #f1f5f9 100%);
}

body.light-theme .preview-area {
    background: #ffffff !important;
}

body.light-theme .preview-toolbar {
    background-color: rgba(255, 255, 255, 0.95);
    border-bottom: 1px solid var(--border-color);
}

body.light-theme .invoice-sheet-container::-webkit-scrollbar-track {
    background: #f1f5f9;
}

body.light-theme .invoice-sheet {
    box-shadow: 0 2px 16px rgba(0,0,0,0.10), 0 0 0 1px rgba(0,0,0,0.04);
    border: 1px solid #e2e8f0;
}

body.light-theme .theme-toggle-btn:hover {
    background-color: rgba(15, 23, 42, 0.06);
}

body.light-theme .form-section {
    background-color: rgba(0, 0, 0, 0.01);
}

body.light-theme .form-section summary {
    background-color: rgba(0, 0, 0, 0.02);
}

body.light-theme .item-form-card {
    background-color: rgba(0, 0, 0, 0.01);
}

body.light-theme .item-form-card:hover {
    background-color: rgba(0, 0, 0, 0.02);
    border-color: rgba(0, 0, 0, 0.1);
}

body.light-theme input, body.light-theme select {
    background-color: #ffffff;
}

body.light-theme input::placeholder, body.light-theme select::placeholder {
    color: #94a3b8;
}

body.light-theme .multi-meters-tag-container {
    background-color: #ffffff;
}

body.light-theme .input-item-multi-meters-tag {
    color: #0f172a !important;
}

body.light-theme .item-sr-badge {
    background-color: rgba(0, 0, 0, 0.03);
}

/* Colored sections overrides for Light Theme to maintain high contrast */
body.light-theme .dates-sec { border-left-color: #0284c7 !important; }
body.light-theme .dates-sec[open] { border-color: #0284c7 !important; background-color: rgba(2, 132, 199, 0.02) !important; }
body.light-theme .dates-sec summary { background-color: rgba(2, 132, 199, 0.06) !important; color: #0284c7 !important; }
body.light-theme .dates-sec summary:hover { background-color: rgba(2, 132, 199, 0.12) !important; }
body.light-theme .dates-sec summary i { color: #0284c7; }

body.light-theme .party-sec { border-left-color: #ea580c !important; }
body.light-theme .party-sec[open] { border-color: #ea580c !important; background-color: rgba(234, 88, 12, 0.02) !important; }
body.light-theme .party-sec summary { background-color: rgba(234, 88, 12, 0.06) !important; color: #ea580c !important; }
body.light-theme .party-sec summary:hover { background-color: rgba(234, 88, 12, 0.12) !important; }
body.light-theme .party-sec summary i { color: #ea580c; }

body.light-theme .shipping-sec { border-left-color: #16a34a !important; }
body.light-theme .shipping-sec[open] { border-color: #16a34a !important; background-color: rgba(22, 163, 74, 0.02) !important; }
body.light-theme .shipping-sec summary { background-color: rgba(22, 163, 74, 0.06) !important; color: #16a34a !important; }
body.light-theme .shipping-sec summary:hover { background-color: rgba(22, 163, 74, 0.12) !important; }
body.light-theme .shipping-sec summary i { color: #16a34a; }

body.light-theme .items-sec { border-left-color: #7c3aed !important; }
body.light-theme .items-sec[open] { border-color: #7c3aed !important; background-color: rgba(124, 58, 237, 0.02) !important; }
body.light-theme .items-sec summary { background-color: rgba(124, 58, 237, 0.06) !important; color: #7c3aed !important; }
body.light-theme .items-sec summary:hover { background-color: rgba(124, 58, 237, 0.12) !important; }
body.light-theme .items-sec summary i { color: #7c3aed; }

body.light-theme .discount-sec { border-left-color: #e11d48 !important; }
body.light-theme .discount-sec[open] { border-color: #e11d48 !important; background-color: rgba(225, 29, 72, 0.02) !important; }
body.light-theme .discount-sec summary { background-color: rgba(225, 29, 72, 0.06) !important; color: #e11d48 !important; }
body.light-theme .discount-sec summary:hover { background-color: rgba(225, 29, 72, 0.12) !important; }
body.light-theme .discount-sec summary i { color: #e11d48; }

body.light-theme .mill-sec { border-left-color: #0d9488 !important; }
body.light-theme .mill-sec[open] { border-color: #0d9488 !important; background-color: rgba(13, 148, 136, 0.02) !important; }
body.light-theme .mill-sec summary { background-color: rgba(13, 148, 136, 0.06) !important; color: #0d9488 !important; }
body.light-theme .mill-sec summary:hover { background-color: rgba(13, 148, 136, 0.12) !important; }
body.light-theme .mill-sec summary i { color: #0d9488; }

/* PDF rendering overrides to fix text overlapping caused by browser zoom and page overflow */
.invoice-sheet.rendering-pdf {
    zoom: 1 !important;
    transform: none !important;
    height: 1122px !important;
    min-height: 1122px !important;
    padding: 31px 35px 26px 35px !important;
    box-shadow: none !important;
    border: 1px solid #d1d5db !important;
    border-radius: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
}

.invoice-sheet.rendering-pdf .items-table-container {
    height: auto !important;
    min-height: 160px !important;
}

.invoice-sheet.rendering-pdf .bank-details-box {
    padding: 4px 8px !important;
}

.invoice-sheet.rendering-pdf .mill-gstin-row {
    padding: 4px 8px !important;
}

.invoice-sheet.rendering-pdf .nett-rate-terms-row {
    padding: 4px 8px !important;
}

.invoice-sheet.rendering-pdf .reminder-sub-box {
    padding: 3px 8px !important;
}

.invoice-sheet.rendering-pdf .amount-words-strip {
    padding: 3px 8px !important;
    min-height: 18px !important;
}

.invoice-sheet.rendering-pdf .terms-col {
    padding: 3px 8px !important;
}

.invoice-sheet.rendering-pdf .signature-col {
    padding: 3px 8px !important;
}

.invoice-sheet.rendering-pdf .sig-space {
    height: 20px !important;
}

.invoice-sheet.rendering-pdf .totals-table td {
    padding: 3px 8px !important;
}

.invoice-sheet.rendering-pdf .gtotal-row td {
    padding: 5px 8px !important;
}

.invoice-sheet.rendering-pdf .terms-list {
    margin-top: 2px !important;
}

.invoice-sheet.rendering-pdf .terms-list li {
    margin-bottom: 1px !important;
}

.invoice-sheet.rendering-pdf .items-table {
    height: auto !important;
}

/* ── PDF rendering overrides for Challan sheet ── */
.challan-sheet.rendering-pdf {
    zoom: 1 !important;
    transform: none !important;
    width: 651px !important;
    min-width: 651px !important;
    height: 700px !important;
    min-height: 700px !important;
    padding: 12px 14px !important;
    box-shadow: none !important;
    border: 1px solid #d1d5db !important;
    border-radius: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
}

.challan-sheet.rendering-pdf .challan-inner-box {
    height: 100% !important;
    min-height: 670px !important;
    padding: 4px 6px !important;
    border-width: 1px !important;
    box-sizing: border-box !important;
}

.challan-sheet.rendering-pdf .challan-top-header {
    padding-bottom: 2px !important;
    border-bottom-width: 1px !important;
}

.challan-sheet.rendering-pdf .challan-proforma-title {
    font-size: 11px !important;
}

.challan-sheet.rendering-pdf .challan-jurisdiction-line {
    font-size: 9px !important;
}

.challan-sheet.rendering-pdf .challan-date-right,
.challan-sheet.rendering-pdf .challan-date-line {
    font-size: 11px !important;
}

.challan-sheet.rendering-pdf .challan-date-underline {
    font-size: 11px !important;
    min-width: 50px !important;
}

.challan-sheet.rendering-pdf .challan-info-row {
    border-bottom-width: 1px !important;
}

.challan-sheet.rendering-pdf .challan-company-block {
    padding: 3px 6px 3px 2px !important;
    gap: 1px !important;
}

.challan-sheet.rendering-pdf .challan-company-name {
    font-size: 12px !important;
}

.challan-sheet.rendering-pdf .challan-company-desc {
    font-size: 9px !important;
}

.challan-sheet.rendering-pdf .challan-company-addr {
    font-size: 9px !important;
    line-height: 1.2 !important;
    margin-top: 1px !important;
}

.challan-sheet.rendering-pdf .challan-company-gstin-row {
    margin-top: 2px !important;
    padding: 0 4px !important;
}

.challan-sheet.rendering-pdf .challan-company-gstin-label,
.challan-sheet.rendering-pdf .challan-company-gstin-val {
    font-size: 9px !important;
}

.challan-sheet.rendering-pdf .challan-company-mobile-row {
    font-size: 9px !important;
    margin-top: 1px !important;
}

.challan-sheet.rendering-pdf .challan-customer-block {
    padding: 3px 2px 3px 8px !important;
    gap: 2px !important;
}

.challan-sheet.rendering-pdf .challan-ms-label {
    font-size: 9px !important;
}

.challan-sheet.rendering-pdf .challan-customer-name-val {
    font-size: 12px !important;
    border-bottom-width: 0 !important;
    min-height: 14px !important;
}

.challan-sheet.rendering-pdf .challan-customer-gstin-row {
    margin-top: 1px !important;
    margin-left: 0 !important;
}

.challan-sheet.rendering-pdf .challan-cust-gstin-label,
.challan-sheet.rendering-pdf .challan-cust-gstin-val {
    font-size: 9px !important;
}

.challan-sheet.rendering-pdf .challan-table-container {
    flex: 1 1 auto !important;
    min-height: 280px !important;
    border-bottom-width: 1px !important;
}

.challan-sheet.rendering-pdf .challan-table th {
    padding: 2px 2px !important;
    font-size: 11px !important;
    border-top-width: 1px !important;
    border-bottom-width: 1px !important;
}

.challan-sheet.rendering-pdf .challan-table td {
    padding: 1px 2px !important;
    font-size: 12px !important;
}

.challan-sheet.rendering-pdf .challan-table tbody tr {
    height: 22px !important;
}

.challan-sheet.rendering-pdf .challan-totals-section {
    padding: 1px 0 !important;
    border-bottom-width: 1px !important;
}

.challan-sheet.rendering-pdf .challan-total-label {
    font-size: 9px !important;
    padding: 1px 6px !important;
}

.challan-sheet.rendering-pdf .challan-total-amount {
    font-size: 12px !important;
    padding: 1px 6px !important;
    min-width: 50px !important;
}

.challan-sheet.rendering-pdf .challan-total-paise {
    font-size: 9px !important;
    padding: 1px 4px !important;
    min-width: 20px !important;
}

.challan-sheet.rendering-pdf .challan-yours-faithfully {
    font-size: 9px !important;
    padding: 1px 4px 1px 10px !important;
}

.challan-sheet.rendering-pdf .challan-amount-words {
    padding: 1px 4px !important;
    font-size: 9px !important;
    min-height: 14px !important;
    border-top-width: 1px !important;
    border-bottom-width: 1px !important;
}

.challan-sheet.rendering-pdf .challan-footer-row {
    min-height: 40px !important;
    grid-template-columns: 1.8fr 0.6fr 1fr 1fr !important;
}

.challan-sheet.rendering-pdf .challan-dispatch-col {
    padding: 3px 4px 3px 2px !important;
    gap: 2px !important;
}

.challan-sheet.rendering-pdf .challan-dispatch-label {
    font-size: 9px !important;
}

.challan-sheet.rendering-pdf .challan-dispatch-val {
    font-size: 11px !important;
    min-height: 12px !important;
}

.challan-sheet.rendering-pdf .challan-mumbai-col {
    padding: 3px 2px !important;
}

.challan-sheet.rendering-pdf .challan-mumbai-label {
    font-size: 9px !important;
}

.challan-sheet.rendering-pdf .challan-to-col {
    padding: 3px 4px !important;
    gap: 1px !important;
}

.challan-sheet.rendering-pdf .challan-to-label {
    font-size: 9px !important;
}

.challan-sheet.rendering-pdf .challan-to-val {
    font-size: 11px !important;
    min-height: 12px !important;
}

.challan-sheet.rendering-pdf .challan-sig-col {
    padding: 3px 4px 3px 8px !important;
}

.challan-sheet.rendering-pdf .challan-sig-header {
    font-size: 9px !important;
}

.challan-sheet.rendering-pdf .challan-sig-space {
    min-height: 16px !important;
}

.challan-sheet.rendering-pdf .challan-sig-footer {
    font-size: 9px !important;
    border-top-width: 0.5px !important;
    padding-top: 1px !important;
}

/* Collapse item card styling */
.item-form-card.collapsed .multi-meters-group,
.item-form-card.collapsed .item-form-grid {
    display: none;
}

.item-form-card .btn-collapse-item {
    position: absolute;
    top: 6px;
    right: 6px;
    background: transparent;
    border: none;
    color: #ef4444; /* User requested red */
    cursor: pointer;
    font-size: 0.8rem;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
}

.item-form-card .btn-collapse-item:hover {
    background-color: rgba(239, 68, 68, 0.1);
    transform: scale(1.1);
}

.item-form-card .btn-collapse-item i {
    transition: transform 0.2s ease;
}

/* Custom Confirmation Modal */
.confirm-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.confirm-modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.confirm-modal-box {
    background-color: var(--bg-sidebar);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 24px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.4), 0 10px 10px -5px rgba(0, 0, 0, 0.4);
    transform: scale(0.95);
    opacity: 0;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.confirm-modal-overlay.active .confirm-modal-box {
    transform: scale(1);
    opacity: 1;
}

.confirm-modal-header {
    display: flex;
    align-items: center;
    gap: 12px;
}

.confirm-modal-icon {
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
}

.confirm-modal-icon.danger {
    color: #ef4444;
    background-color: rgba(239, 68, 68, 0.1);
}

.confirm-modal-icon.primary {
    color: var(--accent);
    background-color: var(--accent-glow);
}

.confirm-modal-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-main);
}

.confirm-modal-body {
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.confirm-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 8px;
}

.confirm-modal-btn {
    padding: 8px 16px;
    font-size: 0.88rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font-ui);
}

.btn-confirm-cancel {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-main);
}

.btn-confirm-cancel:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.btn-confirm-danger {
    background-color: #ef4444;
    border: none;
    color: #ffffff;
}

.btn-confirm-danger:hover {
    background-color: #dc2626;
}

.btn-confirm-primary {
    background-color: var(--accent);
    border: none;
    color: #ffffff;
}

.btn-confirm-primary:hover {
    background-color: var(--accent-hover);
}

/* Light theme support for custom modal */
body.light-theme .confirm-modal-box {
    background-color: #ffffff;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

body.light-theme .btn-confirm-cancel:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

/* ==========================================================================
   FEATURE 4: SIDEBAR ITEMS COUNT BADGE
   ========================================================================== */
.sidebar-count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 18px;
    padding: 0 5px;
    border-radius: 10px;
    font-size: 0.68rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), #4f46e5);
    color: white;
    margin-left: 6px;
    line-height: 1;
    box-shadow: 0 2px 6px rgba(99, 102, 241, 0.3);
    transition: all 0.2s;
    /* Ensure the badge doesn't rotate with the chevron */
    position: relative;
    z-index: 1;
}

body.light-theme .sidebar-count-badge {
    background: linear-gradient(135deg, #4f46e5, #6366f1);
}

/* ==========================================================================
   FEATURE 5: PREVIEW ZOOM SLIDER
   ========================================================================== */
.zoom-control {
    display: flex;
    align-items: center;
    gap: 8px;
    background-color: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 5px 12px;
}

.zoom-control input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 80px;
    height: 4px;
    background: var(--border-color);
    border-radius: 4px;
    outline: none;
    cursor: pointer;
    transition: background 0.2s;
}

.zoom-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
    transition: transform 0.15s;
}

.zoom-control input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 0 0 5px rgba(99, 102, 241, 0.25);
}

.zoom-label {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-main);
    min-width: 34px;
    text-align: center;
}

body.light-theme .zoom-control {
    background-color: rgba(0, 0, 0, 0.03);
}

/* Zoom +/- Buttons */
.zoom-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-main);
    cursor: pointer;
    font-size: 0.75rem;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    padding: 0;
}
.zoom-btn:hover {
    background-color: var(--accent);
    border-color: var(--accent);
    color: white;
    transform: scale(1.1);
}
body.light-theme .zoom-btn {
    color: #0f172a;
}
body.light-theme .zoom-btn:hover {
    color: white;
}

/* ==========================================================================
   FEATURE 6: AMOUNT IN WORDS — FULL-WIDTH STRIP
   ========================================================================== */
.amount-words-strip {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 6px;
    padding: 5px 10px;
    background-color: rgba(30, 58, 138, 0.025);
    min-height: 22px;
    text-align: center;
}

.amount-words-prefix {
    font-size: 9.5px;
    font-weight: 700;
    color: var(--text-blue-ink);
    white-space: nowrap;
    flex-shrink: 0;
}

.amount-words-text {
    font-size: 9.5px;
    font-style: italic;
    font-weight: 600;
    color: var(--text-blue-ink);
    font-family: var(--font-invoice);
    letter-spacing: 0.15px;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


/* ==========================================================================
   FEATURE 10: SAVE DRAFTS PANEL
   ========================================================================== */
.drafts-sec { border-left: 4px solid #f59e0b !important; }
.drafts-sec[open] { border-color: #f59e0b !important; background-color: rgba(245, 158, 11, 0.02) !important; }
.drafts-sec summary { background-color: rgba(245, 158, 11, 0.08) !important; color: #f59e0b !important; }
.drafts-sec summary:hover { background-color: rgba(245, 158, 11, 0.15) !important; }
.drafts-sec summary i { color: #f59e0b; }

body.light-theme .drafts-sec { border-left-color: #d97706 !important; }
body.light-theme .drafts-sec[open] { background-color: rgba(217, 119, 6, 0.02) !important; }
body.light-theme .drafts-sec summary { background-color: rgba(217, 119, 6, 0.06) !important; color: #d97706 !important; }
body.light-theme .drafts-sec summary i { color: #d97706; }

.drafts-panel-body {
    padding: 10px;
}

.drafts-empty {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    padding: 12px 8px;
    border: 1px dashed var(--border-color);
    border-radius: 6px;
    line-height: 1.4;
}

.drafts-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 230px;
    overflow-y: auto;
}

.drafts-list::-webkit-scrollbar { width: 4px; }
.drafts-list::-webkit-scrollbar-track { background: transparent; }
.drafts-list::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }

.draft-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    background-color: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 7px 10px;
    transition: all 0.2s;
    animation: draftSlideIn 0.2s ease forwards;
}

@keyframes draftSlideIn {
    from { opacity: 0; transform: translateX(-6px); }
    to   { opacity: 1; transform: translateX(0); }
}

.draft-item:hover {
    background-color: rgba(255, 255, 255, 0.07);
    border-color: rgba(245, 158, 11, 0.4);
}

body.light-theme .draft-item {
    background-color: rgba(0,0,0,0.02);
}
body.light-theme .draft-item:hover {
    background-color: rgba(0,0,0,0.04);
    border-color: rgba(217, 119, 6, 0.35);
}

.draft-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
}

.draft-bill-no {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.draft-customer {
    font-size: 0.7rem;
    color: #f59e0b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 600;
}

.draft-date {
    font-size: 0.65rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.draft-type-badge {
    font-size: 0.6rem;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    align-self: flex-start;
}
.draft-type-invoice {
    background: #dbeafe;
    color: #1e40af;
}
.draft-type-challan {
    background: #fef3c7;
    color: #92400e;
}
body.light-theme .draft-type-invoice {
    background: #dbeafe;
    color: #1e40af;
}
body.light-theme .draft-type-challan {
    background: #fef3c7;
    color: #92400e;
}

.draft-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.draft-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.72rem;
    padding: 4px 7px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.draft-load-btn:hover {
    background-color: rgba(99, 102, 241, 0.15);
    border-color: var(--accent);
    color: var(--accent);
    transform: scale(1.05);
}

.draft-del-btn:hover {
    background-color: rgba(239, 68, 68, 0.12);
    border-color: #ef4444;
    color: #ef4444;
    transform: scale(1.05);
}

/* ==========================================================================
   TOAST NOTIFICATIONS
   ========================================================================== */
.toast-notification {
    position: fixed;
    bottom: 28px;
    right: 28px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: var(--font-ui);
    z-index: 99999;
    box-shadow: 0 8px 24px rgba(0,0,0,0.35);
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.34,1.56,0.64,1);
    pointer-events: none;
    color: white;
    backdrop-filter: blur(8px);
}

.toast-notification.visible {
    opacity: 1;
    transform: translateY(0);
}

.toast-success {
    background: linear-gradient(135deg, #16a34a, #15803d);
    border: 1px solid rgba(255,255,255,0.15);
}

.toast-info {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    border: 1px solid rgba(255,255,255,0.15);
}

.toast-warning {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    border: 1px solid rgba(255,255,255,0.15);
}

/* ==========================================================================
   FORM VALIDATION
   ========================================================================== */
.is-invalid {
    border-color: #ef4444 !important;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2) !important;
    animation: shake 0.4s ease;
}

.field-error {
    color: #ef4444;
    font-size: 0.75rem;
    font-weight: 600;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.field-error::before {
    content: '\f071';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    font-size: 0.7rem;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-4px); }
    40% { transform: translateX(4px); }
    60% { transform: translateX(-3px); }
    80% { transform: translateX(3px); }
}

.prompt-modal-box {
    max-width: 360px !important;
}

.prompt-input-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
}

.prompt-input {
    width: 100px;
    padding: 10px 16px;
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    background-color: var(--bg-card);
    color: var(--text-main);
    font-family: var(--font-ui);
    outline: none;
    transition: border-color 0.2s;
    -moz-appearance: textfield;
}

.prompt-input::-webkit-inner-spin-button,
.prompt-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

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

.prompt-input.is-invalid {
    border-color: #ef4444 !important;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2) !important;
    animation: shake 0.4s ease;
}

body.light-theme .prompt-input {
    background-color: #f8fafc;
    color: #0f172a;
}

body.light-theme .field-error {
    color: #dc2626;
}

body.light-theme .is-invalid {
    border-color: #dc2626 !important;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.15) !important;
}

/* ==========================================================================
   PREVIEW TAB SWITCHER & PRINTING STACK STYLES
   ========================================================================== */
/* Sidebar Unified Tab Switcher (controls both form fields and preview) */
.sidebar-tabs {
    display: flex;
    gap: 4px;
    background-color: rgba(255, 255, 255, 0.04);
    border-radius: 8px;
    padding: 3px;
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-tab-btn {
    flex: 1;
    background-color: transparent;
    border: none;
    outline: none;
    color: var(--text-muted);
    font-family: var(--font-ui);
    font-size: 0.78rem;
    font-weight: 600;
    padding: 7px 10px;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-tab-btn:hover {
    color: var(--text-main);
    background-color: rgba(255, 255, 255, 0.05);
}

.sidebar-tab-btn.active {
    color: white;
    background-color: var(--accent);
    box-shadow: 0 2px 8px var(--accent-glow);
}

body.light-theme .sidebar-tabs {
    background-color: rgba(0, 0, 0, 0.04);
    border-color: #cbd5e1;
}

body.light-theme .sidebar-tab-btn {
    color: #475569;
}

body.light-theme .sidebar-tab-btn:hover {
    color: #0f172a;
    background-color: rgba(0, 0, 0, 0.04);
}

body.light-theme .sidebar-tab-btn.active {
    color: white;
    background-color: var(--accent);
}

/* Form tab content visibility */
.form-tab-content {
    display: none;
}

.form-tab-content.active {
    display: block;
}

/* Preserve gap between form sections inside tab wrappers */
.invoice-form-fields.active,
.challan-form-fields.active {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Screen tab display control */
@media screen {
    .invoice-sheet.hidden-tab, .challan-sheet.hidden-tab {
        display: none !important;
    }
}

/* ==========================================================================
   DELIVERY CHALLAN PORTRAIT SHEET STYLES
   Size: 651 x 557 px
   ========================================================================== */
.challan-sheet {
    background-color: var(--paper-white);
    color: #000000;
    width: 651px;
    min-height: 585px;
    height: 585px;
    padding: 14px 16px;
    position: relative;
    box-shadow: 0 25px 65px rgba(0, 0, 0, 0.45), 0 0 1px rgba(255, 255, 255, 0.1);
    font-family: var(--font-invoice);
    overflow: hidden;
    border-radius: 4px;
}

@media screen {
    .challan-sheet::after {
        content: '';
        position: absolute;
        top: 0; left: 0; right: 0; bottom: 0;
        box-shadow: inset 0 0 24px rgba(0,0,0,0.02);
        pointer-events: none;
    }
}

/* ── Outer border box ── */
.challan-inner-box {
    border: 1.5px solid var(--text-blue-ink);
    height: 100%;
    min-height: 525px;
    padding: 6px 8px;
    display: flex;
    flex-direction: column;
    gap: 0;
    box-sizing: border-box;
}

/* ── TOP HEADER ROW: "PROFORMA INVOICE" left | jurisdiction center | Date right ── */
.challan-top-header {
    display: grid;
    grid-template-columns: 1fr 1.6fr 1fr;
    align-items: flex-start;
    padding-bottom: 3px;
    border-bottom: 1px solid var(--text-blue-ink);
    margin-bottom: 0;
}

.challan-proforma-title {
    font-size: 11px;
    font-weight: 800;
    color: var(--text-blue-ink);
    text-decoration: underline;
    letter-spacing: 0.2px;
}

.challan-jurisdiction-center {
    text-align: center;
}

.challan-jurisdiction-line {
    font-size: 9px;
    font-weight: 700;
    color: var(--text-blue-ink);
    display: block;
    text-align: center;
    line-height: 1.3;
}

.challan-date-right {
    text-align: right;
    font-size: 11px;
    color: var(--text-blue-ink);
    font-weight: 600;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 1px;
}

.challan-date-line {
    display: flex;
    align-items: baseline;
    gap: 2px;
    font-size: 11px;
}

.challan-date-label {
    font-weight: 700;
    color: var(--text-red-ink);
}

.challan-date-underline {
    border-bottom: 1px solid var(--text-blue-ink);
    min-width: 55px;
    font-family: var(--font-courier);
    font-weight: 700;
    font-size: 11px;
    color: var(--text-blue-ink);
}

.challan-year-suffix {
    font-weight: 700;
    color: var(--text-blue-ink);
}

/* ── COMPANY + CUSTOMER INFO ROW ── */
.challan-info-row {
    display: grid;
    grid-template-columns: 1fr 1px 1fr;
    border-bottom: 1px solid var(--text-blue-ink);
}

.challan-company-block {
    padding: 4px 6px 4px 2px;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.challan-company-name {
    font-size: 14px;
    font-weight: 900;
    color: var(--text-blue-ink);
    letter-spacing: 0.5px;
    line-height: 1.1;
    margin-bottom: 1px;
}

.challan-company-desc {
    font-size: 9px;
    font-style: italic;
    color: var(--text-blue-ink);
    font-weight: 600;
}

.challan-company-addr {
    font-size: 9px;
    color: var(--text-blue-ink);
    line-height: 1.3;
    margin-top: 1px;
}

.challan-company-gstin-row {
    display: inline-block;
    /* margin-top: 2px; */
    border: 1px solid var(--text-blue-ink);
    padding: 0 4px;
}

.challan-company-gstin-label {
    font-size: 11px;
    font-weight: 800;
    color: var(--text-blue-ink);
}

.challan-company-gstin-val {
    font-size: 11px;
    font-weight: 700;
    font-family: var(--font-courier);
    color: var(--text-blue-ink);
}

.challan-company-mobile-row {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-blue-ink);
    margin-top: 9px;
}

/* Vertical divider */
.challan-info-divider {
    background-color: var(--text-blue-ink);
    width: 1px;
}

.challan-customer-block {
    padding: 4px 2px 4px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.challan-customer-ms-row {
    display: flex;
    align-items: flex-start;
    gap: 4px;
}

.challan-ms-label {
    font-size: 9px;
    font-weight: 700;
    color: var(--text-blue-ink);
    white-space: nowrap;
    padding-top: 1px;
}

.challan-customer-line-val {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-blue-ink);
    font-family: var(--font-courier);
    border-bottom: 1px solid var(--text-blue-ink);
    min-height: 14px;
    width: 100%;
    line-height: 1.2;
}

.challan-customer-name-val {
    flex: 1;
    font-size: 12px;
    font-weight: 800;
}

.challan-customer-gstin-row {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 5px;
    margin-left: 0;
}

.challan-cust-gstin-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-blue-ink);
}

.challan-cust-gstin-val {
    font-size: 11px;
    font-family: var(--font-courier);
    font-weight: 700;
    color: var(--text-blue-ink);
    border-bottom: 1px solid var(--text-blue-ink);
    min-width: 80px;
}

/* ── ITEMS TABLE ── */
.challan-table-container {
    flex: 1 1 auto;
    position: relative;
    min-height: 220px;
    border-bottom: 1px solid var(--text-blue-ink);
    display: flex;
    flex-direction: column;
}

.challan-table {
    width: 100%;
    border-collapse: collapse;
    flex: 1;
    height: 100%;
}

.challan-table tbody tr {
    height: 22px;
}

.challan-table th {
    background-color: transparent;
    color: var(--text-blue-ink);
    font-weight: 700;
    font-size: 11px;
    text-align: center;
    border-bottom: 1px solid var(--text-blue-ink);
    border-top: 1px solid var(--text-blue-ink);
    padding: 2px 2px;
    white-space: nowrap;
}

.challan-table td {
    padding: 2px 3px;
    font-size: 12px;
    text-align: center;
    vertical-align: top;
    border-bottom: 1px solid rgba(30, 58, 138, 0.15);
}

.challan-table .col-desc,
.challan-table .cell-desc {
    text-align: left !important;
}

/* Sub headers for Rate/Amount split columns */
.challan-table .sub-header-split {
    display: flex;
    justify-content: space-between;
    font-size: 9px;
    padding-top: 2px;
}

.challan-table .sub-header-split span {
    flex: 1;
    text-align: center;
}

/* Table cell borders */
.challan-table td.border-right,
.challan-table th.border-right {
    border-right: 1.5px solid var(--text-blue-ink);
}

/* ── TOTALS SECTION: TOTAL + Your's faithfully bottom-right ── */
.challan-totals-section {
    border-bottom: 1px solid var(--text-blue-ink);
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 1px 0;
}

.challan-total-row {
    display: flex;
    align-items: center;
}

.challan-total-label {
    font-size: 9px;
    font-weight: 800;
    color: var(--text-blue-ink);
    padding: 1px 6px;
    border-right: 1px solid var(--text-blue-ink);
    text-align: right;
}

.challan-total-amount {
    font-size: 12px;
    font-weight: 900;
    color: var(--text-blue-ink);
    font-family: var(--font-courier);
    padding: 1px 8px;
    min-width: 55px;
    text-align: right;
    border-right: 1px solid var(--text-blue-ink);
}

.challan-total-paise {
    font-size: 9px;
    font-weight: 700;
    color: var(--text-blue-ink);
    font-family: var(--font-courier);
    padding: 1px 6px;
    min-width: 25px;
    text-align: center;
}

.challan-yours-faithfully {
    font-size: 9px;
    font-style: italic;
    color: var(--text-blue-ink);
    font-weight: 600;
    text-align: right;
    padding: 1px 4px 1px 15px;
}

.challan-top-header,
.challan-info-row {
    flex-shrink: 0;
}

/* ── FOOTER ROW: Despatched Through | MUMBAI | TO | Signature ── */
.challan-footer-row {
    display: grid;
    grid-template-columns: 1.8fr 0.6fr 1fr 1fr;
    border-top: 0;
    min-height: 50px;
    align-items: start;
    flex-shrink: 0;
}

.challan-totals-section,
.challan-amount-words {
    flex-shrink: 0;
}

.challan-dispatch-col {
    padding: 4px 6px 4px 2px;
    border-right: 1px solid var(--text-blue-ink);
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 2px;
}

.challan-dispatch-label {
    font-size: 9px;
    font-weight: 700;
    color: var(--text-red-ink);
}

.challan-dispatch-val {
    font-size: 11px;
    font-weight: 800;
    font-family: var(--font-courier);
    color: var(--text-blue-ink);
    border-bottom: 1px solid var(--text-blue-ink);
    min-height: 14px;
}

.challan-mumbai-col {
    padding: 4px 4px;
    border-right: 1px solid var(--text-blue-ink);
    display: flex;
    align-items: center;
    justify-content: center;
}

.challan-mumbai-label {
    font-size: 9px;
    font-weight: 800;
    color: var(--text-blue-ink);
    text-align: center;
    writing-mode: horizontal-tb;
}

.challan-to-col {
    padding: 4px 6px;
    border-right: 1px solid var(--text-blue-ink);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.challan-to-label {
    font-size: 9px;
    font-weight: 700;
    color: var(--text-red-ink);
}

.challan-to-val {
    font-size: 11px;
    font-weight: 800;
    font-family: var(--font-courier);
    color: var(--text-blue-ink);
    border-bottom: 1px solid var(--text-blue-ink);
    min-height: 14px;
}

.challan-sig-col {
    padding: 4px 4px 4px 8px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.challan-sig-header {
    font-size: 9px;
    font-weight: 700;
    color: var(--text-red-ink);
    text-align: center;
}

.challan-sig-space {
    flex: 1;
    min-height: 20px;
}

.challan-sig-footer {
    font-size: 9px;
    color: var(--text-blue-ink);
    font-weight: 600;
    text-align: center;
    border-top: 0.5px solid var(--text-blue-ink);
    padding-top: 1px;
    margin-top: auto;
}

/* ── Amount in Words strip ── */
.challan-amount-words {
    padding: 2px 6px;
    font-size: 9px;
    font-weight: 700;
    color: var(--text-blue-ink);
    border-top: 1px solid var(--text-blue-ink);
    border-bottom: 1px solid var(--text-blue-ink);
    background-color: rgba(30, 58, 138, 0.025);
    display: flex;
    gap: 4px;
    align-items: baseline;
}

/* ── Screen tab display control ── */
@media screen {
    .invoice-sheet.hidden-tab, .challan-sheet.hidden-tab {
        display: none !important;
    }
}

/* ── Print media: portrait for challan ── */
@media print {
    .invoice-sheet, .challan-sheet {
        box-shadow: none !important;
        border: none !important;
        margin: 0 !important;
        padding: 8mm 10mm !important;
    }
    
    .invoice-sheet {
        width: 210mm !important;
        min-height: 297mm !important;
    }
    
    .challan-sheet {
        width: 240mm !important;
        min-height: 200mm !important;
        height: auto !important;
        padding: 8mm 10mm !important;
        box-sizing: border-box !important;
    }
    
    .invoice-sheet.hidden-tab, .challan-sheet.hidden-tab {
        display: none !important;
    }
}
