/* app.css */

/* ==========================================================================
   1. DESIGN SYSTEM & ROOT TOKENS
   ========================================================================== */
:root {
    /* Brand Gradients & Accents */
    --brand-primary: #f97316;
    --brand-primary-rgb: 249, 115, 22;
    --brand-secondary: #ea580c;
    --brand-gradient: linear-gradient(135deg, var(--brand-primary) 0%, var(--brand-secondary) 100%);
    
    /* Global Radius & Animations */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 12px 24px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 25px rgba(249, 115, 22, 0.18);

    /* HSL Theme Colors (Base Setup) */
    --font-heading: 'Outfit', 'Inter', system-ui, sans-serif;
    --font-body: 'Inter', system-ui, sans-serif;

    /* baseline Titanium Light Mode Tokens (Baseline Default) */
    --bg-main: #f3f4f6;
    --bg-card: #ffffff;
    --bg-card-hover: #f9fafb;
    --bg-sidebar: #ffffff;
    --bg-input: #f8fafc;
    --border-color: #cbd5e1;
    --border-hover: #94a3b8;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-inverse: #ffffff;
    --glass-opacity: 0.04;
    --glass-border: rgba(0, 0, 0, 0.06);
    --glass-bg: rgba(255, 255, 255, 0.85);
    --metric-border: #e2e8f0;
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;
    --info: #2563eb;
}

/* --- Premium Titanium Light Theme (Unified Theme System) --- */
[data-theme="dark"],
[data-theme="light"] {
    --bg-main: #f3f4f6;
    --bg-card: #ffffff;
    --bg-card-hover: #f9fafb;
    --bg-sidebar: #ffffff;
    --bg-input: #f8fafc;
    --border-color: #cbd5e1;
    --border-hover: #94a3b8;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-inverse: #ffffff;
    --glass-opacity: 0.04;
    --glass-border: rgba(0, 0, 0, 0.06);
    --glass-bg: rgba(255, 255, 255, 0.85);
    --metric-border: #e2e8f0;
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;
    --info: #2563eb;
}

/* ==========================================================================
   2. GLOBAL STYLES & RESET
   ========================================================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1.5;
    transition: background-color var(--transition-smooth), color var(--transition-smooth);
    overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    font-weight: 600;
    color: var(--text-main);
}

a {
    color: inherit;
    text-decoration: none;
}

button, input, select, textarea {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    background: none;
    border: none;
    outline: none;
}

button {
    cursor: pointer;
}

.hidden {
    display: none !important;
}

/* Scrollbar customization */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: var(--bg-main);
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
    background: var(--border-hover);
}

/* ==========================================================================
   3. APP SHELL & CORE LAYOUT
   ========================================================================== */
#root {
    display: flex;
    min-height: 100vh;
    width: 100vw;
    overflow: hidden;
}

#app-container {
    display: flex;
    width: 100%;
    height: 100vh;
    overflow: hidden;
}

/* --- SIDEBAR PANEL --- */
#sidebar {
    width: 260px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100%;
    z-index: 100;
    transition: width var(--transition-smooth), background-color var(--transition-smooth), border-color var(--transition-smooth);
    flex-shrink: 0;
}

.sidebar-brand {
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.brand-logo {
    max-width: 100%;
    max-height: 60px;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
}

.sidebar-menu {
    flex: 1;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    font-weight: 500;
    transition: var(--transition-fast);
}

.nav-item i {
    font-size: 18px;
    width: 24px;
    text-align: center;
    transition: var(--transition-fast);
}

.nav-item:hover {
    color: var(--text-main);
    background-color: var(--bg-card-hover);
}

.nav-item.active {
    color: var(--text-inverse);
    background: var(--brand-gradient);
    box-shadow: var(--shadow-glow);
}

.nav-item.active i {
    color: var(--text-inverse);
}

.sidebar-user {
    padding: 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    font-size: 32px;
    color: var(--brand-primary);
}

.user-info h4 {
    font-size: 14px;
    font-weight: 600;
}

.user-info span {
    font-size: 12px;
    color: var(--text-muted);
}

/* --- MAIN CANVAS PANEL --- */
#main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* --- TOP HEADER --- */
#top-header {
    height: 70px;
    background-color: var(--glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 90;
    transition: background-color var(--transition-smooth), border-color var(--transition-smooth);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

#sidebar-toggle {
    font-size: 20px;
    color: var(--text-main);
    transition: var(--transition-fast);
}

#sidebar-toggle:hover {
    color: var(--brand-primary);
    transform: scale(1.05);
}

#page-title {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-main);
    font-size: 18px;
    transition: var(--transition-fast);
}

.header-btn:hover {
    background-color: var(--bg-card-hover);
    border-color: var(--border-hover);
}

.icon-sun, .icon-moon {
    display: none;
}

[data-theme="dark"] .icon-sun {
    display: inline-block;
}

[data-theme="light"] .icon-moon {
    display: inline-block;
}

.divider {
    width: 1px;
    height: 24px;
    background-color: var(--border-color);
}

.logout-btn {
    padding: 10px 16px;
    border-radius: var(--radius-md);
    background-color: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition-fast);
}

.logout-btn:hover {
    background-color: var(--danger);
    color: #ffffff;
    box-shadow: 0 4px 10px rgba(239, 68, 68, 0.2);
}

#page-canvas {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
    padding: 24px;
    position: relative;
}

/* ==========================================================================
   4. COMPONENT & CORE UI STYLES
   ========================================================================== */
.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    transition: background-color var(--transition-smooth), border-color var(--transition-smooth);
}

/* --- BUTTONS --- */
.btn-primary {
    background: var(--brand-gradient);
    color: #ffffff !important;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition-fast);
    box-shadow: var(--shadow-glow);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(249, 115, 22, 0.35);
}

.btn-secondary {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition-fast);
}

.btn-secondary:hover {
    background-color: var(--bg-card-hover);
    border-color: var(--border-hover);
}

.btn-danger {
    background-color: var(--danger);
    color: #ffffff;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition-fast);
}

.btn-danger:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: var(--radius-sm);
}

/* --- INPUT FORMS --- */
.form-group {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.form-group input, .form-group select, .form-group textarea {
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    color: var(--text-main);
    transition: var(--transition-fast);
    width: 100%;
}

.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.15);
}

/* --- TABLES --- */
.table-container {
    overflow-x: auto;
    width: 100%;
}

.custom-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.custom-table th {
    background-color: var(--bg-card-hover);
    color: var(--text-muted);
    font-weight: 600;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.custom-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    transition: var(--transition-fast);
    font-size: 14px;
}

.custom-table tr:last-child td {
    border-bottom: none;
}

.custom-table tr:hover td {
    background-color: var(--bg-card-hover);
}

/* --- CHIPS & CHIPS --- */
.status-chip {
    padding: 4px 8px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.status-chip.success { background-color: rgba(16, 185, 129, 0.1); color: var(--success); }
.status-chip.warning { background-color: rgba(245, 158, 11, 0.1); color: var(--warning); }
.status-chip.danger { background-color: rgba(239, 68, 68, 0.1); color: var(--danger); }
.status-chip.info { background-color: rgba(59, 130, 246, 0.1); color: var(--info); }

/* ==========================================================================
   5. SPECIFIC CORE PAGE LAYOUTS
   ========================================================================== */

/* --- AUTH PAGE STYLES --- */
#auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100vh;
    background: radial-gradient(circle at 10% 20%, rgba(249, 115, 22, 0.15) 0%, transparent 40%),
                radial-gradient(circle at 90% 80%, rgba(234, 88, 12, 0.15) 0%, transparent 40%),
                var(--bg-main);
}

.glass-auth-card {
    background-color: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 40px;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.auth-brand {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

/* Auth Card Logo */
.auth-logo-wrap {
    width: 120px;
    height: 120px;
    border-radius: var(--radius-lg);
    background: #ffffff;
    border: 2px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
    box-shadow: var(--shadow-md), var(--shadow-glow);
    overflow: hidden;
    padding: 8px;
}

.auth-logo-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.auth-brand h2 {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.auth-brand p {
    color: var(--text-muted);
    font-size: 14px;
}

.auth-btn {
    justify-content: center;
    margin-top: 10px;
}

.auth-footer {
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
}

/* --- TOAST SYSTEM --- */
#toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    padding: 16px 24px;
    border-radius: var(--radius-md);
    color: #ffffff;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    min-width: 300px;
}

.toast.success { background: linear-gradient(135deg, #10b981 0%, #059669 100%); }
.toast.error { background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%); }
.toast.info { background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%); }

@keyframes slideIn {
    from { transform: translateX(120%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* --- DASHBOARD STYLES --- */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.metric-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border: 1px solid var(--metric-border);
}

.metric-left h5 {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.metric-left h3 {
    font-size: 26px;
    font-weight: 800;
    margin-top: 4px;
}

.metric-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    background-color: var(--bg-card-hover);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--brand-primary);
    border: 1px solid var(--border-color);
}

.dashboard-charts-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
    margin-bottom: 24px;
}

@media (max-width: 1024px) {
    .dashboard-charts-grid {
        grid-template-columns: 1fr;
    }
}

.chart-card h3 {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 20px;
}

.chart-wrapper {
    position: relative;
    height: 320px;
    width: 100%;
}

/* --- PRODUCT VIEWS --- */
.page-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
    flex-wrap: wrap;
}

.search-filters-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    max-width: 600px;
}

.search-input-wrapper {
    position: relative;
    flex: 1;
}

.search-input-wrapper i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.search-input-wrapper input {
    padding-left: 38px !important;
}

/* CSV Drag Drop zone */
.csv-dropzone {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    padding: 30px;
    text-align: center;
    cursor: pointer;
    background-color: var(--bg-input);
    transition: var(--transition-fast);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.csv-dropzone:hover {
    border-color: var(--brand-primary);
    background-color: var(--bg-card-hover);
}

.csv-dropzone i {
    font-size: 40px;
    color: var(--brand-primary);
}

.csv-dropzone h4 {
    font-size: 16px;
    font-weight: 700;
}

.csv-dropzone p {
    color: var(--text-muted);
    font-size: 12px;
}

/* --- DOCUMENT FORM BUILDER (DYNAMIC QUOTATIONS/INVOICES) --- */
.document-builder-grid {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 24px;
}

.document-builder-grid > div {
    min-width: 0;
}

@media (max-width: 1024px) {
    .document-builder-grid {
        grid-template-columns: 1fr;
    }
}

.builder-section-title {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
    color: var(--brand-primary);
}

.builder-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.dynamic-items-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-bottom: 20px;
}

.dynamic-items-table th {
    padding: 12px 10px;
    background-color: var(--bg-card-hover);
    color: var(--text-muted);
    border-bottom: 2px solid var(--border-color);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.dynamic-items-table td {
    padding: 10px 8px;
    border-bottom: 1px dashed var(--border-color);
    vertical-align: middle;
}

.dynamic-items-table td input, 
.dynamic-items-table td select {
    padding: 8px 10px !important;
    font-size: 13px !important;
    border: 1px solid var(--border-color) !important;
    border-radius: var(--radius-sm) !important;
    background-color: var(--bg-input) !important;
    color: var(--text-main) !important;
    height: 38px !important;
    box-sizing: border-box !important;
    width: 100% !important;
    transition: var(--transition-fast) !important;
}

.dynamic-items-table td input:focus, 
.dynamic-items-table td select:focus {
    border-color: var(--brand-primary) !important;
    box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.15) !important;
}

.dynamic-items-table td input:disabled {
    background-color: #cbd5e1 !important;
    color: #64748b !important;
    border-color: #cbd5e1 !important;
    cursor: not-allowed !important;
}

.btn-remove-row {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background-color: rgba(239, 68, 68, 0.08) !important;
    color: var(--danger) !important;
    border: 1px solid rgba(239, 68, 68, 0.15) !important;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
}

.btn-remove-row:hover {
    background-color: var(--danger) !important;
    color: #ffffff !important;
    border-color: var(--danger) !important;
    box-shadow: 0 2px 6px rgba(220, 38, 38, 0.2) !important;
}

/* Total calculations block */
.bill-math-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 20px;
    background-color: var(--bg-card-hover);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
}

.math-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
}

.math-row.grand-total {
    border-top: 1px dashed var(--border-color);
    padding-top: 12px;
    margin-top: 4px;
    font-size: 18px;
    font-weight: 800;
    color: var(--brand-primary);
}

/* --- MODAL DIALOGS --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: zoomIn 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: justify;
    justify-content: space-between;
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 700;
}

.modal-close {
    font-size: 20px;
    color: var(--text-muted);
}

.modal-close:hover {
    color: var(--text-main);
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
}

@keyframes zoomIn {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* ==========================================================================
   6. PREMIUM A4 PRINTABLE SHEET DESIGN
   ========================================================================== */
.a4-sheet-container {
    padding: 10px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Designed to mimic a physical A4 paper page on screen - adapts to Obsidian Theme */
.printable-a4-sheet {
    width: 800px; /* Precise aspect ratio on screen */
    min-height: 1040px;
    background-color: var(--bg-card);
    color: var(--text-main);
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    border-radius: var(--radius-lg);
    padding: 40px;
    font-family: var(--font-body);
    font-size: 13px;
    line-height: 1.45;
    position: relative;
    border: 1px solid var(--border-color);
    margin-bottom: 30px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: background-color var(--transition-smooth), border-color var(--transition-smooth);
}

.printable-a4-sheet h1, 
.printable-a4-sheet h2, 
.printable-a4-sheet h3, 
.printable-a4-sheet h4, 
.printable-a4-sheet h5, 
.printable-a4-sheet h6 {
    color: var(--text-main);
}

.printable-a4-sheet p,
.printable-a4-sheet span,
.printable-a4-sheet td,
.printable-a4-sheet th,
.printable-a4-sheet code {
    color: var(--text-muted);
}

.printable-a4-sheet strong {
    color: var(--text-main);
}

/* Sheet Top Row (Header branding) */
.sheet-brand-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 2px solid var(--brand-primary);
    padding-bottom: 20px;
    margin-bottom: 20px;
}

.logo-container {
    background-color: #ffffff;
    padding: 6px 10px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #e2e8f0;
    width: 140px;
    height: 60px;
    box-sizing: border-box;
}

.sheet-logo {
    max-width: 120px;
    max-height: 48px;
    width: auto;
    height: auto;
    display: block;
}

.sheet-brand-icon {
    font-size: 40px;
    color: var(--brand-primary);
}

.sheet-brand-name {
    font-size: 22px;
    font-weight: 800;
    font-family: var(--font-heading);
    color: var(--text-main);
}

.sheet-header-title {
    text-align: right;
}

.sheet-header-title h1 {
    font-family: var(--font-heading);
    font-size: 30px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--brand-primary);
    margin-bottom: 4px;
}

.sheet-header-title span {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-muted);
}

/* Metadata cards (Company details vs Client details) */
.sheet-meta-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 20px;
    margin-bottom: 25px;
}

.meta-col h3 {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--brand-primary);
    margin-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 4px;
}

.meta-info-card {
    line-height: 1.6;
}

.meta-info-card p {
    margin-bottom: 2px;
}

/* Themed adaptive boxes on screen */
.sheet-info-card-box {
    background-color: var(--bg-card-hover);
    border: 1px solid var(--border-color);
    padding: 14px;
    border-radius: var(--radius-sm);
    display: flex;
    justify-content: space-between;
    margin-bottom: 25px;
    font-size: 12px;
    flex-wrap: wrap;
    gap: 10px;
}

.sheet-status-box {
    background-color: var(--bg-card-hover);
    border: 1px solid var(--border-color);
    padding: 12px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    margin-bottom: 10px;
}

.sheet-bank-box {
    background-color: var(--bg-card-hover);
    border: 1px solid var(--border-color);
    padding: 12px;
    border-radius: var(--radius-sm);
    font-size: 11px;
}

/* Table styling for the sheet */
.sheet-product-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 25px;
}

.sheet-product-table th {
    background-color: var(--bg-card-hover);
    color: var(--text-main);
    font-weight: 700;
    font-size: 11px;
    text-transform: uppercase;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    text-align: left;
}

.sheet-product-table td {
    padding: 10px;
    border: 1px solid var(--border-color);
    font-size: 12px;
    color: var(--text-muted);
}

.sheet-product-table tr:nth-child(even) td {
    background-color: rgba(255, 255, 255, 0.02);
}

.text-right {
    text-align: right !important;
}

.text-center {
    text-align: center !important;
}

/* Dynamic Mathematical Totals & Payment (Bank + QR Code) */
.sheet-bottom-section {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 30px;
    margin-bottom: 20px;
}

.payment-qr-col {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.qr-box-wrapper {
    display: flex;
    align-items: center;
    gap: 16px;
    background-color: var(--bg-card-hover);
    border: 1px solid var(--border-color);
    padding: 12px;
    border-radius: var(--radius-sm);
}

.qr-canvas-mount {
    width: 95px;
    background-color: #ffffff; /* Scanner contrast */
    padding: 5px;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
}

.qr-details-box p {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.4;
}

.sheet-math-box {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sheet-math-row {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-muted);
}

.sheet-math-row.grand-total {
    border-top: 2px solid var(--brand-primary);
    padding-top: 8px;
    margin-top: 4px;
    font-size: 16px;
    font-weight: 800;
    color: var(--brand-primary);
}

.sheet-terms-box {
    border-top: 1px solid var(--border-color);
    padding-top: 15px;
    margin-top: 15px;
}

.sheet-terms-box h4 {
    font-size: 12px;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--brand-primary);
}

.sheet-terms-box p {
    font-size: 10px;
    color: var(--text-muted);
    white-space: pre-line;
    line-height: 1.5;
}

.terms-list {
    margin: 4px 0 0 0;
    padding-left: 18px;
    font-size: 10px;
    color: var(--text-muted);
    line-height: 1.8;
}

.terms-list li {
    margin-bottom: 2px;
}

/* Footer elements: Signatures */
.sheet-signatures-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px dashed var(--border-color);
}

.sig-box {
    text-align: center;
    width: 200px;
}

.sig-box p {
    font-size: 11px;
    color: var(--text-muted);
}

.sig-line {
    border-top: 1px solid var(--border-color);
    margin-bottom: 6px;
}

.seal-placeholder {
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: var(--text-muted);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
}

.fully-paid-stamp {
    position: absolute;
    top: 120px;
    right: 50px;
    border: 4px solid var(--success);
    color: var(--success);
    font-size: 20px;
    font-weight: 900;
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    text-transform: uppercase;
    transform: rotate(-10deg);
    font-family: var(--font-heading);
    opacity: 0.85;
    z-index: 10;
    letter-spacing: 1px;
    box-shadow: 0 0 12px rgba(16, 185, 129, 0.25);
    background-color: rgba(16, 185, 129, 0.1);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}



/* ==========================================================================
   7. SPINNING LOADER CORE
   ========================================================================== */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(11, 15, 25, 0.85);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    color: #ffffff;
}

.spinner-box {
    width: 60px;
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: transparent;
}

.circle-core {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(249, 115, 22, 0.15);
    border-left-color: var(--brand-primary);
    border-right-color: var(--brand-secondary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ==========================================================================
   8. MEDIA QUERIES & RESPONSIVENESS
   ========================================================================== */
@media (max-width: 768px) {
    #app-container {
        flex-direction: column;
    }
    
    #sidebar {
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        position: relative;
    }
    
    .sidebar-menu {
        flex-direction: row;
        overflow-x: auto;
        padding: 8px;
    }
    
    .nav-item {
        white-space: nowrap;
        padding: 8px 12px;
    }
    
    .sidebar-user {
        display: none;
    }
    
    .sidebar-brand {
        padding: 12px 16px;
    }
    
    .brand-logo {
        max-height: 40px;
    }
    
    .metrics-grid {
        grid-template-columns: 1fr;
    }
    
    .printable-a4-sheet {
        width: 100%;
        min-height: auto;
        padding: 16px;
        transform: scale(1);
    }
    
    .sheet-bottom-section {
        grid-template-columns: 1fr;
    }
}

/* ==========================================================================
   9. STRICT A4 PRINTING ENGINE SPECIFICS
   ========================================================================== */
@page {
    size: A4 portrait;
    margin: 10mm;
}

.printable-a4-sheet.generating-pdf,
@media print {
    /* Reset everything to a clean slate */
    *, *::before, *::after {
        box-shadow: none !important;
        text-shadow: none !important;
    }

    /* Ensure colors print correctly */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Set deep obsidian dark theme baseline */
    body, html {
        background-color: #070b13 !important;
        color: #f3f4f6 !important;
        width: 100% !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
    }
    
    #toast-container,
    #loading-overlay,
    #sidebar,
    #top-header,
    .page-header-row,
    .btn-secondary,
    .btn-primary,
    .btn-danger,
    .document-actions-panel,
    .a4-sheet-container button,
    #main-content > header,
    .no-print {
        display: none !important;
    }
    
    /* Neutralize all layout containers to plain dark block flow */
    #app-container, #root, #main-content, #page-canvas, .a4-sheet-container {
        display: block !important;
        width: 100% !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
        background-color: #070b13 !important;
    }
    
    /* Elegant Dark Document Wrapper */
    .printable-a4-sheet {
        width: 100% !important;
        max-width: 100% !important;
        min-height: auto !important;
        background-color: #0f1524 !important;
        color: #f3f4f6 !important;
        border: 1px solid #1b253b !important;
        box-shadow: none !important;
        border-radius: 12px !important;
        padding: 8mm !important;
        margin: 0 !important;
        page-break-inside: avoid;
        display: flex !important;
        flex-direction: column !important;
        justify-content: space-between !important;
        box-sizing: border-box !important;
        font-family: 'Inter', system-ui, sans-serif !important;
    }

    .printable-a4-sheet h1, 
    .printable-a4-sheet h2, 
    .printable-a4-sheet h3, 
    .printable-a4-sheet h4, 
    .printable-a4-sheet h5, 
    .printable-a4-sheet h6 {
        color: #ffffff !important;
    }

    .printable-a4-sheet p,
    .printable-a4-sheet span,
    .printable-a4-sheet td,
    .printable-a4-sheet th,
    .printable-a4-sheet code {
        color: #94a3b8 !important;
    }

    .printable-a4-sheet strong {
        color: #ffffff !important;
    }

    .sheet-brand-row {
        border-bottom: 2px solid #f97316 !important;
    }

    .sheet-brand-name {
        color: #ffffff !important;
    }

    /* Product dynamic table */
    .sheet-product-table {
        width: 100% !important;
        table-layout: fixed !important;
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
        border-collapse: collapse !important;
    }

    .sheet-product-table th {
        background-color: #151d30 !important;
        color: #ffffff !important;
        border: 1px solid #1b253b !important;
        padding: 6px 8px !important;
        font-size: 11px !important;
    }

    .sheet-product-table td {
        border: 1px solid #1b253b !important;
        color: #94a3b8 !important;
        background-color: transparent !important;
        padding: 8px 10px !important;
        font-size: 11px !important;
    }

    .sheet-product-table tr:nth-child(even) td {
        background-color: rgba(255, 255, 255, 0.02) !important;
    }

    .sheet-info-card-box {
        background-color: #151d30 !important;
        border: 1px solid #1b253b !important;
    }

    .sheet-status-box {
        background-color: #151d30 !important;
        border: 1px solid #1b253b !important;
    }

    .sheet-bank-box {
        background-color: #151d30 !important;
        border: 1px solid #1b253b !important;
    }

    .qr-box-wrapper {
        background-color: #151d30 !important;
        border: 1px solid #1b253b !important;
        gap: 12px !important;
    }

    .qr-canvas-mount {
        background-color: #ffffff !important; /* Scanner contrast */
        border: 1px solid #1b253b !important;
    }

    .sheet-signatures-row {
        border-top: 1px dashed #1b253b !important;
        page-break-inside: avoid;
    }

    .sig-line {
        border-top: 1px solid #1b253b !important;
    }

    .sig-box p {
        color: #94a3b8 !important;
    }

    .fully-paid-stamp {
        border: 4px solid #10b981 !important;
        color: #10b981 !important;
        background-color: rgba(16, 185, 129, 0.1) !important;
        box-shadow: 0 0 10px rgba(16, 185, 129, 0.2) !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }

    .sheet-meta-grid {
        gap: 15px !important;
    }

    .sheet-bottom-section {
        gap: 15px !important;
    }
}

/* Custom class to dynamically hide the GST column in form builders */
.hide-gst-column th:nth-child(5),
.hide-gst-column td:nth-child(5) {
    display: none !important;
}

/* --- PREMIUM DISCOUNT UI STYLES --- */
.discount-section-wrapper {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 6px 0;
}

.discount-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.discount-label-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 700;
    color: var(--brand-primary);
}

.discount-type-toggle {
    display: flex;
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 2px;
}

.discount-toggle-btn {
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 600;
    border-radius: calc(var(--radius-sm) - 2px);
    color: var(--text-muted);
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    gap: 4px;
}

.discount-toggle-btn:hover {
    color: var(--text-main);
    background-color: rgba(255, 255, 255, 0.05);
}

.discount-toggle-btn.active {
    background: var(--brand-gradient);
    color: #ffffff !important;
    box-shadow: var(--shadow-sm);
}

.discount-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

.discount-input-prefix {
    position: absolute;
    left: 12px;
    font-size: 14px;
    font-weight: 700;
    color: var(--text-muted);
    pointer-events: none;
}

.discount-value-input {
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 10px 32px 10px 30px !important;
    font-size: 14px;
    color: var(--text-main);
    width: 100%;
    text-align: right;
    transition: var(--transition-fast);
}

.discount-value-input:focus {
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.15);
}

.discount-input-clear {
    position: absolute;
    right: 12px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.discount-input-clear:hover {
    color: var(--danger);
    transform: scale(1.1);
}

.discount-savings-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background-color: rgba(16, 185, 129, 0.1);
    color: var(--success);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    margin-top: 4px;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- High-end Light Theme Overrides for Invoice and Quotation Creation Forms --- */
#new-invoice-form,
#new-quote-form {
    --form-bg-card: #ffffff;
    --form-border: #e2e8f0;
    --form-text-main: #0f172a;
    --form-text-muted: #64748b;
    --form-bg-input: #f8fafc;
    --form-border-input: #cbd5e1;
}

#new-invoice-form .card,
#new-quote-form .card {
    background-color: var(--form-bg-card) !important;
    border: 1px solid var(--form-border) !important;
    color: var(--form-text-main) !important;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.04), 0 2px 4px -1px rgba(0, 0, 0, 0.02) !important;
}

#new-invoice-form .builder-section-title,
#new-quote-form .builder-section-title {
    color: var(--brand-primary) !important;
    border-bottom: 1px solid var(--form-border) !important;
}

#new-invoice-form label,
#new-quote-form label {
    color: var(--form-text-muted) !important;
}

#new-invoice-form input,
#new-invoice-form select,
#new-invoice-form textarea,
#new-quote-form input,
#new-quote-form select,
#new-quote-form textarea {
    background-color: var(--form-bg-input) !important;
    border: 1px solid var(--form-border-input) !important;
    color: var(--form-text-main) !important;
}

#new-invoice-form input:focus,
#new-invoice-form select:focus,
#new-invoice-form textarea:focus,
#new-quote-form input:focus,
#new-quote-form select:focus,
#new-quote-form textarea:focus {
    border-color: var(--brand-primary) !important;
    box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.15) !important;
}

#new-invoice-form input:disabled,
#new-quote-form input:disabled {
    background-color: #e2e8f0 !important;
    color: #64748b !important;
}

/* Style the dynamic line items table inside the forms */
#new-invoice-form .dynamic-items-table th,
#new-quote-form .dynamic-items-table th {
    background-color: #f1f5f9 !important;
    color: #475569 !important;
    border-bottom: 1px solid var(--form-border) !important;
}

#new-invoice-form .dynamic-items-table td,
#new-quote-form .dynamic-items-table td {
    border-bottom: 1px dashed var(--form-border) !important;
}

#new-invoice-form .row-amount,
#new-quote-form .row-amount {
    color: var(--form-text-main) !important;
}

/* Style the math calculation panel */
#new-invoice-form .bill-math-panel,
#new-quote-form .bill-math-panel {
    background-color: #f8fafc !important;
    border: 1px solid var(--form-border) !important;
}

#new-invoice-form .bill-math-panel .math-row,
#new-quote-form .bill-math-panel .math-row {
    color: var(--form-text-main) !important;
}

#new-invoice-form .bill-math-panel .divider,
#new-quote-form .bill-math-panel .divider {
    background-color: var(--form-border) !important;
}

#new-invoice-form .bill-math-panel .discount-toggle-btn,
#new-quote-form .bill-math-panel .discount-toggle-btn {
    background-color: #e2e8f0 !important;
    color: #475569 !important;
}

#new-invoice-form .bill-math-panel .discount-toggle-btn.active,
#new-quote-form .bill-math-panel .discount-toggle-btn.active {
    background: var(--brand-gradient) !important;
    color: #ffffff !important;
}

/* Adjust page header text inside these forms */
#main-content:has(#new-invoice-form) h3,
#main-content:has(#new-quote-form) h3 {
    color: var(--text-main) !important;
}

/* Custom premium styles for Lead and GST features */
.lead-requirement-badge {
    margin-top: 16px;
    background: linear-gradient(135deg, rgba(249, 115, 22, 0.05) 0%, rgba(234, 88, 12, 0.05) 100%);
    border: 1px solid rgba(249, 115, 22, 0.2);
    border-left: 4px solid var(--brand-primary);
    border-radius: var(--radius-md);
    padding: 16px;
    animation: fadeIn 0.3s ease-out;
}

.lead-requirement-badge .badge-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--brand-primary);
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.lead-requirement-badge .badge-content {
    font-size: 13px;
    color: var(--text-main);
    line-height: 1.5;
    white-space: pre-wrap;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.watermark-paid {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-30deg);
    font-size: 100px;
    font-weight: 900;
    color: rgba(16, 185, 129, 0.15); /* Green with 15% opacity */
    pointer-events: none;
    text-transform: uppercase;
    white-space: nowrap;
    z-index: 0;
    border: 8px solid rgba(16, 185, 129, 0.15);
    padding: 10px 40px;
    border-radius: 20px;
}

/* Custom premium month picker button */
.premium-month-picker {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: border-color var(--transition-fast), background-color var(--transition-fast), box-shadow var(--transition-fast);
    min-width: 150px;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
}

.premium-month-picker:hover {
    border-color: var(--border-hover);
    background-color: var(--bg-card-hover);
}

.premium-month-picker i {
    font-size: 14px;
    color: var(--text-muted);
}

.premium-month-picker input[type="month"] {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 10;
}

/* Smaller variant for KPI cards */
.premium-month-picker-sm {
    padding: 6px 10px;
    font-size: 11px;
    min-width: 125px;
    background-color: var(--bg-main);
}

.premium-month-picker-sm:hover {
    background-color: rgba(0, 0, 0, 0.02);
}
[data-theme="dark"] .premium-month-picker-sm:hover {
    background-color: rgba(255, 255, 255, 0.02);
}


