/* ============================================
   Invoice Generator - Clean Professional Theme
   ============================================ */
/* CSS Variables */
:root {
    /* Colors - Light Professional Theme */
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-input: #ffffff;
    /* Branding */
    --brand-primary: #2563eb;
    --brand-dark: #1e40af;
    --brand-light: #dbeafe;
    /* Text Colors */
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    /* Borders */
    --border-color: #e2e8f0;
    --border-focus: #2563eb;
    /* Status */
    --success: #10b981;
    --success-bg: #dcfce7;
    --warning: #f59e0b;
    --warning-bg: #fef3c7;
    --error: #ef4444;
    --error-bg: #fee2e2;
    /* Spacing & Radius */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    /* Font */
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

/* Form file fields css */
.hintTexts {
    display: none;
}

/* ---------------- Share fallback modal ---------------- */
.share-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.share-card {
    background: #fff;
    padding: 16px;
    border-radius: 12px;
    width: min(360px, 92vw);
    display: flex;
    flex-direction: column;
    gap: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}

.share-title {
    font-weight: 700;
    font-size: 16px;
    color: #0f172a;
}

.share-subtitle {
    font-size: 13px;
    color: #64748b;
    margin-bottom: 6px;
}

.share-btn,
.share-close {
    padding: 10px;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    background: #ffffff;
    cursor: pointer;
    font-weight: 600;
}

.share-btn:hover {
    background: #f8fafc;
}

.share-close {
    margin-top: 6px;
    background: #0f172a;
    color: #ffffff;
    border: 1px solid #0f172a;
}

/* Reset & Base */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Global overflow prevention */
html,
body {
    overflow-x: hidden;
    max-width: 100%;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

/* App Layout */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 240px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    position: fixed;
    height: 100vh;
    padding: 20px;
    z-index: 50;
    transition: transform 0.3s ease;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 40px;
    padding-left: 10px;
}

.brand-icon {
    font-size: 24px;
}

.brand-text {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

.nav-link:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.nav-link.active {
    background: var(--brand-light);
    color: var(--brand-primary);
}

/* Mobile Nav */
.mobile-nav {
    display: none;
    width: 100%;
    height: 60px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 0 20px;
    align-items: center;
    justify-content: space-between;
    position: fixed;
    top: 0;
    z-index: 100;
}

.nav-toggle span {
    display: block;
    width: 24px;
    height: 2px;
    background: var(--text-primary);
    margin: 6px 0;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 240px;
    padding: 32px;
    max-width: 1200px;
    overflow-x: hidden;
    /* Prevent horizontal scrolling */
}

.page-header {
    margin-bottom: 32px;
}

.page-title {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 4px;
}

.page-subtitle {
    color: var(--text-secondary);
    font-size: 14px;
}

/* Cards & Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 24px;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--brand-primary);
    color: white;
}

.btn-primary:hover {
    background: var(--brand-dark);
}

.btn-secondary {
    background: white;
    border-color: var(--border-color);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--bg-primary);
}

.btn-outline {
    background: transparent;
    border-color: var(--brand-primary);
    color: var(--brand-primary);
}

.btn-large {
    padding: 12px 24px;
    font-size: 16px;
}

.btn-full {
    width: 100%;
}

/* Forms */
.form-section {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 24px;
}

.section-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.form-group {
    margin-bottom: 16px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.form-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 14px;
    transition: border-color 0.2s;
    background: var(--bg-input);
}

.form-input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--brand-light);
}

.form-textarea {
    min-height: 80px;
    resize: vertical;
}

.form-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
    display: block;
}

/* File Upload */
.file-upload {
    position: relative;
}

.file-upload-area {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    text-align: center;
    position: relative;
    background: var(--bg-primary);
    min-height: 100px;
    cursor: pointer;
}

.file-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    z-index: 10;
}

.preview-image {
    max-height: 80px;
    object-fit: contain;
    display: block;
    margin: 0 auto;
}

/* Upload area hint text — always shown until a file is selected */
.upload-hint {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 8px 0 4px;
    pointer-events: none;
    display: block;
}

/* Ensure Remove button sits on top and is always visible */
.file-remove {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 30;
    padding: 6px 12px;
    font-size: 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.file-upload-area {
    position: relative;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    padding: 30px 20px;
    text-align: center;
    background: var(--bg-primary);
    min-height: 120px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.file-upload-area:hover {
    border-color: var(--brand-primary);
    background: var(--brand-light);
}

/* Stamp Preview scaling for 4K internal resolution */
.stamp-preview-wrapper {
    width: 180px;
    height: 180px;
    margin: 0 auto 15px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#stampCanvas {
    width: 180px !important;
    height: 180px !important;
    display: block;
}

/* Toggles and Radio */
.toggle-label {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
}

.toggle-slider {
    width: 44px;
    height: 24px;
    background: var(--border-color);
    border-radius: 20px;
    position: relative;
    transition: 0.3s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    background: white;
    border-radius: 50%;
    top: 3px;
    left: 3px;
    transition: 0.3s;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.toggle-input {
    display: none;
}

.toggle-input:checked+.toggle-slider {
    background: var(--brand-primary);
}

.toggle-input:checked+.toggle-slider::before {
    transform: translateX(20px);
}

.radio-group {
    display: flex;
    gap: 20px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.radio-custom {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    position: relative;
}

.radio-label input:checked+.radio-custom {
    border-color: var(--brand-primary);
}

.radio-label input:checked+.radio-custom::after {
    content: '';
    position: absolute;
    width: 10px;
    height: 10px;
    background: var(--brand-primary);
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.radio-label input {
    display: none;
}

/* Stamp Preview */
.stamp-preview {
    margin-top: 20px;
    text-align: center;
}

.stamp-canvas-container {
    background: white;
    padding: 20px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    display: inline-block;
}

/* Bill Items */
.items-table-header {
    display: grid;
    grid-template-columns: 3fr 1fr 1fr 1fr 40px;
    gap: 10px;
    padding: 10px;
    background: var(--bg-primary);
    font-weight: 500;
    font-size: 14px;
    margin-bottom: 10px;
    border-radius: var(--radius-md);
}

.item-row {
    display: grid;
    grid-template-columns: 3fr 1fr 1fr 1fr 40px;
    gap: 10px;
    margin-bottom: 10px;
    align-items: center;
}

.item-amount {
    font-weight: 600;
    text-align: right;
    padding-right: 10px;
}

.btn-remove {
    color: var(--error);
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
}

/* Totals */
.totals-section {
    /* margin-top: 24px; */
    border-top: 1px solid var(--border-color);
    padding-top: 24px;
}

.total-row {
    display: flex;
    justify-content: flex-end;
    gap: 40px;
    margin-bottom: 8px;
    font-size: 14px;
}

.grand-total {
    font-size: 18px;
    font-weight: 700;
    color: var(--brand-primary);
    margin-top: 12px;
}

/* Bill Preview Document - Multi-page with vertical scrolling */
/* Wrapper allows vertical scroll but prevents horizontal */
.bill-preview-wrapper {
    background: #525659;
    padding: 20px;
    border-radius: var(--radius-lg);
    margin-bottom: 24px;
    overflow-y: auto;
    /* Allow vertical scrolling */
    overflow-x: hidden;
    /* Prevent horizontal scrolling */
    position: relative;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    /* Align to top for vertical scroll */
    /* Height set by JavaScript based on available viewport */
    min-height: 400px;
}

/* Scale container - MUST be normal flow for multi-page preview */
/* Using !important to override any conflicting rules */
#scaleContainer,
.preview-scale-container {
    position: relative !important;
    /* Normal flow, NOT absolute */
    top: auto !important;
    left: auto !important;
    transform: none !important;
    /* No centering transform */
    width: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    /* Center pages horizontally */
    gap: 16px !important;
    /* Space between pages */
}

/* Page shell - wrapper that holds scaled dimensions */
.page-shell {
    position: relative;
    display: block !important;
    overflow: hidden;
    /* Width, height, and margin set by JavaScript based on scale */
}

/* Invoice page inside shell */
.page-shell .bill-preview,
.page-shell .invoice-page {
    transform-origin: top left;
    /* Transform scale set by JavaScript */
}

.bill-preview {
    background: white;
    /* Fixed A4 dimensions in pixels (794px × 1123px at 96 DPI) */
    width: 794px;
    height: 1153px;
    padding: 60px 50px;
    /* 15mm margins in pixels */
    margin: 0;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    position: relative;
    color: #000;
    box-sizing: border-box;
    overflow: hidden;
}

/* Add Responsive styles */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
        padding-top: 80px;
    }

    .mobile-nav {
        display: flex;
    }

    .form-row,
    .items-table-header,
    .item-row {
        grid-template-columns: 1fr;
    }

    /* Mobile preview - reduce padding for more space */
    .bill-preview-wrapper {
        padding: 12px;
        margin-bottom: 16px;
        border-radius: 8px;
    }

    /* Keep absolute positioning and fixed dimensions */
    .preview-scale-container {
        position: absolute;
        top: 50%;
        left: 50%;
        transform-origin: top left;
    }

    .bill-preview {
        width: 794px;
        height: 1153px;
        padding: 60px 50px;
    }
}

/* ========= Quotation auto-fit (subject 1–3 lines) ========= */
.doc-quotation .heading-highlight {
    color: #0f172a;
    font-weight: 800;
    letter-spacing: .3px;
}

/* Bold headings like "Owner:" (Subject / Quotation For) */
.doc-quotation .q-heading {
    color: #0f172a;
    font-weight: 800;
    letter-spacing: .3px;
}

.doc-quotation .bill-header.bill-header-section {
    margin-bottom: 18px !important;
    padding-bottom: 18px !important;
}

.doc-quotation .quotation-subject {
    margin: 6px 0 12px 0;
    max-width: 560px;
}

.doc-quotation .quotation-subject-line {
    margin: 0;
    font-size: calc(14px * var(--q-subject-scale));
    color: #0f172a;
    line-height: 1.35;
}

/* Cross-browser 3-line clamp (no -webkit-line-clamp; avoids random hiding on refresh) */
.doc-quotation .quotation-subject-text {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    display: inline-block;
    max-height: calc(1.35em * 3);
    overflow: hidden;
}

/* Reduce spacing a bit when subject exists (keeps stamp/signature fitting) */
.doc-quotation .totals-section,
.doc-quotation .payment-section {
    margin-top: 10px !important;
}

/* Signature / stamp area: allow wrapping & smaller captions in quotation */
.doc-quotation .signatures {
    gap: 14px !important;
    flex-wrap: wrap;
}

.doc-quotation .signature-box .label,
.doc-quotation .stamp-box .label {
    font-size: calc(11px * var(--q-scale));
}

.doc-quotation .signature-section {
    margin-top: calc(32px * var(--q-scale)) !important;
}

.doc-quotation .signature-section>div {
    width: calc(170px * var(--q-scale)) !important;
}

/* ========= Overflow fixes for Subject, Address, Item names ========= */
/* Subject text wrapping (screen preview - full wrap, no clamp) */
.quotation-subject {
    margin-bottom: 20px;
    padding: 12px 15px;
    background-color: #f8fafc;
    border-left: none !important;
    /* Removed left accent border */
    border-radius: 4px;
}

.quotation-subject-line {
    margin: 0;
    padding: 0;
    line-height: 1.6;
    font-size: 14px;
}

.quotation-subject-text {
    color: #334155;
    white-space: pre-line;
    overflow-wrap: anywhere;
    word-break: break-word;
    display: inline;
}

.q-heading {
    color: #1e3a8a;
    font-weight: 600;
    display: inline;
    margin-right: 5px;
}

/* Customer section spacing and overflow fixes */
.customer-label {
    margin-bottom: 8px;
}

.customer-name {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 8px;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.customer-mobile {
    color: #323C4A;
    font-size: 14px;
    margin-bottom: 4px;
}

.customer-address {
    color: #323C4A;
    font-size: 14px;
    max-width: 400px;
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: normal;
}

/* Item name cell wrapping in table */
.item-name-cell {
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: normal;
    max-width: 300px;
}

/* ========= Compact quotation layout ========= */
/* Quotation header - reduce height */
.quotation-header {
    display: flex;
    gap: 20px;
    margin-bottom: 15px !important;
    padding-bottom: 15px !important;
    border-bottom: 2px solid #eee;
}

.header-logo-box {
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.header-logo-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.header-business-info {
    flex: 1;
}

.header-business-name {
    font-size: 22px;
    font-weight: 700;
    color: #1e3a8a;
    margin-bottom: 6px;
}

.header-business-address {
    color: #475569;
    font-size: 13px;
    margin-bottom: 4px;
    max-width: 300px;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.header-business-details {
    font-size: 13px;
    margin-top: 6px;
}

.header-doc-info {
    text-align: right;
}

.header-doc-type {
    font-size: 18px;
    font-weight: 700;
    color: #94a3b8;
    letter-spacing: 2px;
}

.doc-number {
    font-size: 15px;
    font-weight: 600;
    margin-top: 8px;
}

.doc-date {
    color: #64748b;
    font-size: 13px;
    margin-top: 4px;
}

/* Quotation customer section - compact */
.quotation-customer {
    margin-bottom: 20px;
}

.quotation-customer .customer-label {
    margin-bottom: 6px;
}

.quotation-customer .q-heading {
    font-size: 13px;
}

.quotation-customer .customer-name {
    font-size: 15px;
    margin-bottom: 6px;
}

.quotation-customer .customer-mobile {
    font-size: 12px;
}

.quotation-customer .customer-address {
    font-size: 12px;
    max-width: 350px;
}

/* Quotation Subject - compact */
.doc-quotation .quotation-subject {
    margin-bottom: 18px;
    padding: 10px 12px;
}

/* Quotation table - smaller fonts */
.doc-quotation table thead th {
    font-size: 13.75px !important;
    padding: 10px !important;
}

.doc-quotation table tbody td {
    font-size: 13px !important;
    padding: 10px !important;
}

.doc-quotation .item-name-cell {
    font-weight: 500;
}

/* Quotation totals section - smaller fonts */
.doc-quotation .totals-section {
    margin-bottom: 20px;
    /* Reduced from 40px to 50% */
}

.doc-quotation .totals-section>div>div {
    font-size: 13px !important;
    padding: 6px 0 !important;
}

.doc-quotation .totals-section>div>div:last-child {
    font-size: 16px !important;
    padding: 10px 0 !important;
}

/* Totals and signature - compact spacing for quotation */
.quotation-totals-sig {
    margin-top: 15px;
    /* Reduced from 30px to 50% */
}

.quotation-signature {
    margin-top: 12.5px !important;
    /* Reduced from 25px to 50% */
}

/* Non-quotation default header styles */
.bill-header-section:not(.quotation-header) {
    display: flex;
    gap: 30px;
    margin-bottom: 30px;
    padding-bottom: 25px;
    border-bottom: 2px solid #eee;
}

.bill-header-section:not(.quotation-header) .header-logo-box {
    width: 100px;
    height: 100px;
}

.bill-header-section:not(.quotation-header) .header-business-name {
    font-size: 28px;
    margin-bottom: 8px;
}

.bill-header-section:not(.quotation-header) .header-business-address {
    font-size: 14px;
}

.bill-header-section:not(.quotation-header) .header-business-details {
    font-size: 14px;
    margin-top: 8px;
}

.bill-header-section:not(.quotation-header) .header-doc-type {
    font-size: 22px;
}

.bill-header-section:not(.quotation-header) .doc-number {
    font-size: 16px;
    margin-top: 10px;
}

.bill-header-section:not(.quotation-header) .doc-date {
    font-size: 14px;
}

.customer-section:not(.quotation-customer) {
    margin-bottom: 30px;
}

.customer-section:not(.quotation-customer) .customer-name {
    font-size: 17px;
}

/* ============================
   FIXES (Invoice vs Quotation)
   ============================ */
/* (2) QUOTATION: remove left blue line beside Subject (keep grey background) */
.doc-quotation .quotation-subject {
    border-left: none !important;
}

/* (3) INVOICE: match Quotation text sizing (headers + Bill To section + table + totals) */
.doc-invoice table thead th {
    font-size: 13.75px !important;
    padding: 10px !important;
}

.doc-invoice table tbody td {
    font-size: 13px !important;
    padding: 10px !important;
}

/* Bill To section sizing to match quotation */
.doc-invoice .q-heading {
    font-size: 13px;
    font-weight: 800;
    letter-spacing: .3px;
    color: #0f172a;
}

.doc-invoice .customer-name {
    font-size: 15px;
    margin-bottom: 6px;
}

.doc-invoice .customer-mobile {
    font-size: 12px;
}

.doc-invoice .customer-address {
    font-size: 12px;
    max-width: 350px;
}

/* Totals sizing to match quotation */
.doc-invoice .totals-section>div>div {
    font-size: 13px !important;
    padding: 6px 0 !important;
}

.doc-invoice .totals-section>div>div:last-child {
    font-size: 16px !important;
    padding: 10px 0 !important;
}

/* Small button (used for remove logo/signature) */
.btn-sm {
    padding: 6px 10px;
    font-size: 12px;
    border-radius: 8px;
}

.file-remove {
    margin-top: 8px;
}

/* ================= FINAL OVERRIDES ================= */
/* QUOTATION: remove blue left line beside Subject (ensure wins over base rule) */
.doc-quotation .quotation-subject {
    border-left: none !important;
}

/* QUOTATION: make Subject/Quotation For labels bold */
.doc-quotation .q-heading {
    font-weight: 800;
}

/* INVOICE: totals section text sizes match quotation (override inline sizes) */
.doc-invoice .totals-section>div>div {
    font-size: 13px !important;
    padding: 6px 0 !important;
}

.doc-invoice .totals-section div[style*="font-size"] {
    font-size: 16px !important;
    /* Total row */
}