        * { font-family: 'DM Sans', sans-serif; }

        /* ═══ Theme: Classic Green (default) ═══ */
        :root, [data-theme="classic"] {
            --primary: #1e6b45;
            --primary-light: #e8f5ee;
            --primary-hover: #175536;
            --accent: #d97706;
            --surface: #ffffff;
            --surface-alt: #f8faf9;
            --border: #e5e8e6;
            --text: #1a2e23;
            --text-secondary: #5f7268;
            --danger: #dc2626;
            --danger-light: #fef2f2;
            --warning: #f59e0b;
            --warning-light: #fffbeb;
            --success: #16a34a;
            --sidebar-bg: #ffffff;
            --sidebar-text: #5f7268;
            --sidebar-active-bg: #1e6b45;
            --sidebar-active-text: #ffffff;
            --header-bg: #ffffff;
        }

        /* ═══ Theme: Ocean Blue ═══ */
        [data-theme="ocean"] {
            --primary: #2563eb;
            --primary-light: #dbeafe;
            --primary-hover: #1d4ed8;
            --accent: #06b6d4;
            --surface: #ffffff;
            --surface-alt: #f0f7ff;
            --border: #dde5f0;
            --text: #0f172a;
            --text-secondary: #64748b;
            --danger: #ef4444;
            --danger-light: #fef2f2;
            --warning: #f59e0b;
            --warning-light: #fffbeb;
            --success: #22c55e;
            --sidebar-bg: #0f2a5c;
            --sidebar-text: #94a3c8;
            --sidebar-active-bg: #2563eb;
            --sidebar-active-text: #ffffff;
            --header-bg: #ffffff;
        }

        /* ═══ Theme: Slate Modern ═══ */
        [data-theme="slate"] {
            --primary: #6366f1;
            --primary-light: #e0e7ff;
            --primary-hover: #4f46e5;
            --accent: #a78bfa;
            --surface: #ffffff;
            --surface-alt: #f8fafc;
            --border: #e2e8f0;
            --text: #0f172a;
            --text-secondary: #64748b;
            --danger: #ef4444;
            --danger-light: #fef2f2;
            --warning: #f59e0b;
            --warning-light: #fffbeb;
            --success: #22c55e;
            --sidebar-bg: #1e1b4b;
            --sidebar-text: #a5b4fc;
            --sidebar-active-bg: #6366f1;
            --sidebar-active-text: #ffffff;
            --header-bg: #ffffff;
        }

        /* ═══ Theme: Sunset Warm ═══ */
        [data-theme="sunset"] {
            --primary: #ea580c;
            --primary-light: #fff7ed;
            --primary-hover: #c2410c;
            --accent: #f59e0b;
            --surface: #ffffff;
            --surface-alt: #fffbf5;
            --border: #f0e4d7;
            --text: #292524;
            --text-secondary: #78716c;
            --danger: #dc2626;
            --danger-light: #fef2f2;
            --warning: #f59e0b;
            --warning-light: #fffbeb;
            --success: #16a34a;
            --sidebar-bg: #431407;
            --sidebar-text: #d6a87c;
            --sidebar-active-bg: #ea580c;
            --sidebar-active-text: #ffffff;
            --header-bg: #ffffff;
        }

        /* ═══ Theme: Dark Mode ═══ */
        [data-theme="dark"] {
            --primary: #22c55e;
            --primary-light: #052e16;
            --primary-hover: #16a34a;
            --accent: #facc15;
            --surface: #1e1e2e;
            --surface-alt: #181825;
            --border: #313244;
            --text: #cdd6f4;
            --text-secondary: #a6adc8;
            --danger: #f38ba8;
            --danger-light: #302028;
            --warning: #f9e2af;
            --warning-light: #302a18;
            --success: #a6e3a1;
            --sidebar-bg: #11111b;
            --sidebar-text: #a6adc8;
            --sidebar-active-bg: #22c55e;
            --sidebar-active-text: #11111b;
            --header-bg: #1e1e2e;
        }

        /* ═══ Theme: Harvest ═══ */
        [data-theme="harvest"] {
            --primary: #15803d;
            --primary-light: #dcfce7;
            --primary-hover: #166534;
            --accent: #ca8a04;
            --surface: #ffffff;
            --surface-alt: #fafdf7;
            --border: #d9e7d5;
            --text: #14532d;
            --text-secondary: #4d7c5a;
            --danger: #dc2626;
            --danger-light: #fef2f2;
            --warning: #f59e0b;
            --warning-light: #fffbeb;
            --success: #16a34a;
            --sidebar-bg: #052e16;
            --sidebar-text: #86efac;
            --sidebar-active-bg: #22c55e;
            --sidebar-active-text: #052e16;
            --header-bg: #ffffff;
        }

        /* Apply sidebar theme variables */
        .sidebar { background: var(--sidebar-bg); }
        .nav-item { color: var(--sidebar-text); }
        .nav-item:hover { background: var(--primary-light); color: var(--primary); }
        .nav-item.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); }
        .nav-section-header { color: var(--sidebar-text); }
        body { background: var(--surface-alt); color: var(--text); }

        /* Sidebar */
        .sidebar { width: 240px; background: var(--sidebar-bg); border-right: 1px solid var(--border);
                   height: 100vh; position: fixed; left: 0; top: 0; z-index: 40;
                   transition: transform 0.25s ease; overflow-y: auto; overflow-x: hidden; }
        .sidebar::-webkit-scrollbar { width: 4px; }
        .sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
        .sidebar::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }
        .sidebar.collapsed { transform: translateX(-240px); }
        .main-content { margin-left: 240px; transition: margin-left 0.25s ease; }
        .main-content.expanded { margin-left: 0; }

        /* Nav items */
        .nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 16px;
                    border-radius: 8px; margin: 2px 8px; cursor: pointer; font-size: 14px;
                    font-weight: 500; color: var(--sidebar-text); transition: all 0.15s; }
        .nav-item:hover { background: var(--primary-light); color: var(--primary); }
        .nav-item.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); }
        .nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
        .nav-section-header { display:flex;align-items:center;padding:10px 16px;cursor:pointer;user-select:none;
            font-size:13px;font-weight:800;text-transform:uppercase;letter-spacing:0.06em;color:var(--sidebar-text);
            margin-top:6px;transition:color 0.15s; }
        .nav-section-header:hover { color:var(--text-primary); }
        .nav-section-header .nav-chevron { margin-left:auto;transition:transform 0.2s;font-size:14px;line-height:1; }
        .nav-section-header.collapsed .nav-chevron { transform:rotate(-90deg); }
        .nav-section-body { overflow:hidden;transition:max-height 0.25s ease; }
        .nav-section-body.collapsed { max-height:0 !important; }

        /* Mode switcher */
        .mode-btn { flex:1 1 45%;padding:7px 4px;border:1px solid var(--border);background:var(--surface);
            color:var(--text-secondary);font-size:12px;font-weight:600;cursor:pointer;border-radius:6px;
            transition:all 0.15s;text-align:center; }
        .mode-btn:hover { background:var(--primary-light);color:var(--primary); }
        .mode-btn.active { background:var(--primary);color:#fff;border-color:var(--primary); }

        /* Cards */
        .card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
        .metric-card { padding: 20px 24px; }
        .metric-card .metric-value { font-size: 28px; font-weight: 700; color: var(--text); letter-spacing: -0.5px; }
        .metric-card .metric-label { font-size: 13px; font-weight: 500; color: var(--text-secondary); margin-bottom: 4px; }
        .metric-card .metric-sub { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }

        /* Table */
        .data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
        .data-table thead th { padding: 10px 16px; text-align: left; font-weight: 700; font-size: 12px;
                               text-transform: uppercase; letter-spacing: 0.05em; color: #fff;
                               background: var(--primary); border-bottom: 2px solid var(--primary-dark, #155a36);
                               white-space: nowrap; cursor: pointer; user-select: none; }
        .data-table thead th:hover { color: #e0f0e8; }
        .data-table tbody td { padding: 10px 16px; border-bottom: 1px solid var(--border); white-space: nowrap;
                               overflow: hidden; text-overflow: ellipsis; max-width: 250px; }
        .data-table tbody tr { cursor: pointer; transition: background 0.1s; }
        .data-table tbody tr:nth-child(even) { background: #f8faf9; }
        .data-table tbody tr:hover { background: var(--primary-light); }

        /* Badges */
        .badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
        .badge-green { background: #dcfce7; color: #166534; }
        .badge-yellow { background: #fef9c3; color: #854d0e; }
        .badge-red { background: #fee2e2; color: #991b1b; }
        .badge-blue { background: #dbeafe; color: #1e40af; }
        .badge-gray { background: #f3f4f6; color: #374151; }

        /* Search overlay */
        .search-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 100; display: none;
                         align-items: flex-start; justify-content: center; padding-top: 100px; }
        .search-overlay.active { display: flex; }
        .search-box { background: #fff; border-radius: 16px; width: 560px; max-width: 95vw;
                     box-shadow: 0 25px 50px rgba(0,0,0,0.15); overflow: hidden; }
        .search-input { width: 100%; padding: 16px 20px; border: none; outline: none; font-size: 16px;
                       border-bottom: 1px solid var(--border); }
        .search-results { max-height: 400px; overflow-y: auto; }
        .search-result-item { padding: 12px 20px; cursor: pointer; display: flex; align-items: center; gap: 12px; }
        .search-result-item:hover { background: var(--primary-light); }

        /* Detail panel */
        .detail-panel { position: fixed; right: 0; top: 0; width: 680px; max-width: 100vw; height: 100vh;
                       background: var(--surface); z-index: 50; box-shadow: -4px 0 30px rgba(0,0,0,0.1);
                       transform: translateX(100%); transition: transform 0.25s ease; overflow-y: auto; }
        .detail-panel.open { transform: translateX(0); }
        .detail-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.3); z-index: 45; display: none; }
        .detail-overlay.open { display: block; }

        /* Loading */
        .spinner { width: 24px; height: 24px; border: 3px solid var(--border); border-top-color: var(--primary);
                  border-radius: 50%; animation: spin 0.6s linear infinite; }
        @keyframes spin { to { transform: rotate(360deg); } }

        /* Splash loading animation */
        .splash-icon-wrap { position: relative; display: inline-block; width: 96px; height: 96px; }
        .splash-icon { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
                       width: 56px; height: 56px; background: var(--primary); border-radius: 14px;
                       top: 50%; left: 50%; transform: translate(-50%, -50%); }
        .splash-ring { position: absolute; inset: 0; border-radius: 50%;
                       border: 3px solid transparent; border-top-color: var(--primary); border-right-color: var(--primary);
                       animation: spin 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite; }
        .splash-ring::before { content: ''; position: absolute; inset: 5px; border-radius: 50%;
                               border: 3px solid transparent; border-bottom-color: #81c784; border-left-color: #81c784;
                               animation: spin 0.8s cubic-bezier(0.5, 0, 0.5, 1) infinite reverse; }

        /* Detail tabs */
        .detail-tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); padding: 0 24px; background: #fff; }
        .detail-tab { padding: 10px 16px; font-size: 13px; font-weight: 600; color: var(--text-secondary);
                     cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all 0.15s;
                     white-space: nowrap; }
        .detail-tab:hover { color: var(--primary); }
        .detail-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

        /* Stat mini cards inside detail */
        .stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 20px; }
        .stat-mini { padding: 14px; border-radius: 10px; background: var(--surface-alt); border: 1px solid var(--border); }
        .stat-mini .stat-val { font-size: 22px; font-weight: 700; color: var(--text); line-height: 1.3; }
        .stat-mini .stat-label { font-size: 11px; font-weight: 700; color: var(--text-secondary); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.03em; }

        /* Inventory bar */
        .inv-bar-wrap { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
        .inv-bar-label { font-size: 12px; font-weight: 500; color: var(--text-secondary); width: 80px; text-align: right; }
        .inv-bar { flex: 1; height: 22px; background: #f0f0f0; border-radius: 6px; overflow: hidden; position: relative; }
        .inv-bar-fill { height: 100%; border-radius: 6px; display: flex; align-items: center; padding-left: 8px;
                       font-size: 11px; font-weight: 600; color: #fff; min-width: fit-content; }

        /* Mini table in detail */
        .mini-table { width: 100%; border-collapse: collapse; font-size: 13px; }
        .mini-table th { text-align: left; padding: 10px 12px; font-size: 11px; text-transform: uppercase;
                        letter-spacing: 0.04em; color: var(--text-secondary); background: var(--surface-alt);
                        border-bottom: 2px solid var(--border); font-weight: 700; }
        .mini-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
        .mini-table tr:hover { background: var(--primary-light); }
        .mini-table tr.clickable { cursor: pointer; }

        /* Quick buttons */
        .quick-btn { padding: 6px 16px; border-radius: 6px; font-size: 13px; font-weight: 600;
                    border: 1px solid var(--border); cursor: pointer; transition: all 0.15s; background: #fff; color: var(--text); }
        .quick-btn:hover { border-color: var(--primary); }
        .quick-btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
        .quick-btn-primary:hover { background: var(--primary-hover); }

        /* Aging bar */
        .aging-bar { display: flex; height: 32px; border-radius: 6px; overflow: hidden; gap: 2px; }
        .aging-segment { display: flex; align-items: center; justify-content: center; font-size: 11px;
                        font-weight: 600; color: #fff; transition: width 0.4s; }

        /* Responsive */

        /* Kanban drag styles */
        .kanban-card { touch-action: auto; -webkit-user-select: none; user-select: none; }
        .kanban-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
        .kanban-card[draggable="true"] { cursor: grab; }
        .kanban-card[draggable="true"]:active { cursor: grabbing; }

        @media (max-width: 768px) {
            .sidebar { transform: translateX(-240px); }
            .sidebar.mobile-open { transform: translateX(0); }
            .main-content { margin-left: 0 !important; padding: 0 !important; }
            .detail-panel { width: 100vw; }

            /* ─── Mobile top header ─── */
            header[style*="height: 56px"] {
                height: 48px !important;
                padding: 0 12px !important;
            }

            /* ─── Mobile page content padding ─── */
            #pageContent { padding: 12px !important; }

            /* ─── Force ALL inline grids to stack on mobile ─── */
            /* 2-col layouts → 1 col */
            [style*="grid-template-columns: 1fr 1fr"],
            [style*="grid-template-columns:1fr 1fr"],
            [style*="grid-template-columns: 2fr 1fr"],
            [style*="grid-template-columns:2fr 1fr"] {
                grid-template-columns: 1fr !important;
            }
            /* 3-col and 4-col form field grids → 2 col */
            [style*="grid-template-columns: 1fr 1fr 1fr"],
            [style*="grid-template-columns:1fr 1fr 1fr"],
            [style*="grid-template-columns:1fr 1fr 1fr 1fr"],
            [style*="grid-template-columns:repeat(4,1fr)"],
            [style*="grid-template-columns: repeat(4,1fr)"],
            [style*="grid-template-columns:repeat(4, 1fr)"],
            [style*="grid-template-columns: repeat(4, 1fr)"] {
                grid-template-columns: 1fr 1fr !important;
            }

            /* span overrides — let spans stretch full width in 2-col */
            [style*="grid-column: span"],
            [style*="grid-column:span 3"],
            [style*="grid-column:span 4"] {
                grid-column: 1 / -1 !important;
            }
            [style*="grid-column:span 2"] {
                grid-column: 1 / -1 !important;
            }

            /* ─── Line item rows → summary card + modal on mobile ─── */
            /* Hide column header rows on mobile */
            [id$="_lines_container"] > div:first-child:not([class*="line-row"]),
            [id$="LinesContainer"] > div:first-child:not([class*="line-row"]) {
                display: none !important;
            }

            /* PO line rows: hide grid fields, show summary card */
            .spo-line-row {
                display: block !important;
                padding: 0 !important;
                margin-bottom: 8px !important;
                border: 1px solid var(--border) !important;
                border-radius: 8px !important;
                background: var(--bg) !important;
                position: relative !important;
                cursor: pointer !important;
            }
            /* Hide all grid children (the actual inputs) */
            .spo-line-row > div,
            .spo-line-row > input,
            .spo-line-row > select,
            .spo-line-row > button {
                display: none !important;
            }
            /* Show the summary card overlay */
            .spo-line-row .spo-line-summary {
                display: block !important;
                padding: 12px !important;
            }

            /* SO line rows: hide grid fields, show summary card */
            .sso-line-row {
                display: block !important;
                padding: 0 !important;
                margin-bottom: 8px !important;
                border: 1px solid var(--border) !important;
                border-radius: 8px !important;
                background: var(--bg) !important;
                position: relative !important;
                cursor: pointer !important;
            }
            .sso-line-row > div,
            .sso-line-row > input,
            .sso-line-row > select,
            .sso-line-row > button {
                display: none !important;
            }
            .sso-line-row .sso-line-summary {
                display: block !important;
                padding: 12px !important;
            }

            /* Quick Sale line rows: hide grid fields, show summary card */
            .qs-line-row {
                display: block !important;
                padding: 0 !important;
                margin-bottom: 8px !important;
                border: 1px solid var(--border) !important;
                border-radius: 8px !important;
                background: var(--bg) !important;
                position: relative !important;
                cursor: pointer !important;
            }
            .qs-line-row > div,
            .qs-line-row > input,
            .qs-line-row > select,
            .qs-line-row > button {
                display: none !important;
            }
            .qs-line-row .qs-line-summary {
                display: block !important;
                padding: 12px !important;
            }

            /* Transfer line rows: hide grid fields, show summary card */
            .tr-line-row {
                display: block !important;
                padding: 0 !important;
                margin-bottom: 8px !important;
                border: 1px solid var(--border) !important;
                border-radius: 8px !important;
                background: var(--bg) !important;
                position: relative !important;
                cursor: pointer !important;
            }
            .tr-line-row > div,
            .tr-line-row > input,
            .tr-line-row > select,
            .tr-line-row > button {
                display: none !important;
            }
            .tr-line-row .tr-line-summary {
                display: block !important;
                padding: 12px !important;
            }

            /* Invoice line rows: hide grid fields, show summary card */
            .ssi-line-row {
                display: block !important;
                padding: 0 !important;
                margin-bottom: 8px !important;
                border: 1px solid var(--border) !important;
                border-radius: 8px !important;
                background: var(--bg) !important;
                position: relative !important;
                cursor: pointer !important;
            }
            .ssi-line-row > div,
            .ssi-line-row > input,
            .ssi-line-row > select,
            .ssi-line-row > button {
                display: none !important;
            }
            .ssi-line-row .ssi-line-summary {
                display: block !important;
                padding: 12px !important;
            }

            /* Sales Receipt line rows: hide grid fields, show summary card */
            .ssr-line-row {
                display: block !important;
                padding: 0 !important;
                margin-bottom: 8px !important;
                border: 1px solid var(--border) !important;
                border-radius: 8px !important;
                background: var(--bg) !important;
                position: relative !important;
                cursor: pointer !important;
            }
            .ssr-line-row > div,
            .ssr-line-row > input,
            .ssr-line-row > select,
            .ssr-line-row > button {
                display: none !important;
            }
            .ssr-line-row .ssr-line-summary {
                display: block !important;
                padding: 12px !important;
            }

            /* Shipment line rows: hide grid fields, show summary card */
            .ssh-line-row {
                display: block !important;
                padding: 0 !important;
                margin-bottom: 8px !important;
                border: 1px solid var(--border) !important;
                border-radius: 8px !important;
                background: var(--bg) !important;
                position: relative !important;
                cursor: pointer !important;
            }
            .ssh-line-row > div,
            .ssh-line-row > input,
            .ssh-line-row > select,
            .ssh-line-row > button {
                display: none !important;
            }
            .ssh-line-row .ssh-line-summary {
                display: block !important;
                padding: 12px !important;
            }

            /* Estimate line rows: hide grid fields, show summary card */
            .est-line-row {
                display: block !important;
                padding: 0 !important;
                margin-bottom: 8px !important;
                border: 1px solid var(--border) !important;
                border-radius: 8px !important;
                background: var(--bg) !important;
                position: relative !important;
                cursor: pointer !important;
            }
            .est-line-row > div,
            .est-line-row > input,
            .est-line-row > select,
            .est-line-row > button {
                display: none !important;
            }
            .est-line-row .est-line-summary {
                display: block !important;
                padding: 12px !important;
            }

            /* Return to Vendor line rows: hide grid fields, show summary card */
            .rtv-line-row {
                display: block !important;
                padding: 0 !important;
                margin-bottom: 8px !important;
                border: 1px solid var(--border) !important;
                border-radius: 8px !important;
                background: var(--bg) !important;
                position: relative !important;
                cursor: pointer !important;
            }
            .rtv-line-row > div,
            .rtv-line-row > input,
            .rtv-line-row > select,
            .rtv-line-row > button {
                display: none !important;
            }
            .rtv-line-row .rtv-line-summary {
                display: block !important;
                padding: 12px !important;
            }

            /* Pick Ticket line rows: hide grid fields, show summary card */
            .pt-line-row {
                display: block !important;
                padding: 0 !important;
                margin-bottom: 8px !important;
                border: 1px solid var(--border) !important;
                border-radius: 8px !important;
                background: var(--bg) !important;
                position: relative !important;
                cursor: pointer !important;
            }
            .pt-line-row > div,
            .pt-line-row > input,
            .pt-line-row > select,
            .pt-line-row > button {
                display: none !important;
            }
            .pt-line-row .pt-line-summary {
                display: block !important;
                padding: 12px !important;
            }

            /* Item Receipt line rows: hide grid fields, show summary card */
            .sir-line-row {
                display: block !important;
                padding: 0 !important;
                margin-bottom: 8px !important;
                border: 1px solid var(--border) !important;
                border-radius: 8px !important;
                background: var(--bg) !important;
                position: relative !important;
                cursor: pointer !important;
            }
            .sir-line-row > div,
            .sir-line-row > input,
            .sir-line-row > select,
            .sir-line-row > button {
                display: none !important;
            }
            .sir-line-row .sir-line-summary {
                display: block !important;
                padding: 12px !important;
            }

            /* Customer Return line rows: hide grid fields, show summary card */
            .cr-line-row {
                display: block !important;
                padding: 0 !important;
                margin-bottom: 8px !important;
                border: 1px solid var(--border) !important;
                border-radius: 8px !important;
                background: var(--bg) !important;
                position: relative !important;
                cursor: pointer !important;
            }
            .cr-line-row > div,
            .cr-line-row > input,
            .cr-line-row > select,
            .cr-line-row > button {
                display: none !important;
            }
            .cr-line-row .cr-line-summary {
                display: block !important;
                padding: 12px !important;
            }

            /* Adjustment line rows: hide grid fields, show summary card */
            .adj-line-row {
                display: block !important;
                padding: 0 !important;
                border: 1px solid var(--border) !important;
                border-radius: 8px !important;
                margin-bottom: 8px !important;
                background: var(--surface) !important;
                overflow: hidden !important;
                cursor: pointer !important;
            }
            .adj-line-row > div,
            .adj-line-row > input,
            .adj-line-row > select,
            .adj-line-row > button {
                display: none !important;
            }
            .adj-line-row .adj-line-summary {
                display: block !important;
                padding: 12px !important;
            }

            /* Other form line rows (not yet converted) — 2-col card fallback */
            .po-line-row {
                grid-template-columns: 1fr 1fr !important;
                gap: 6px !important;
                padding: 10px !important;
                margin-bottom: 10px !important;
                border: 1px solid var(--border) !important;
                border-radius: 8px !important;
                background: var(--bg) !important;
                position: relative !important;
            }
            .po-line-row > div,
            .po-line-row > input,
            .po-line-row > select {
                min-width: 0 !important;
            }
            /* First child (Item) spans full */
            .po-line-row > div:first-child {
                grid-column: 1 / -1 !important;
            }

            /* ─── Form header bar — wrap on mobile ─── */
            #pageContent > div:first-child[style*="justify-content:space-between"] {
                flex-wrap: wrap !important;
                gap: 8px !important;
            }
            #pageContent > div:first-child[style*="justify-content:space-between"] > div {
                flex-wrap: wrap !important;
                gap: 6px !important;
            }
            #pageContent > div:first-child h2 {
                font-size: 16px !important;
            }

            /* Charts taller on mobile for readability */
            [style*="height:220px"] { height: 260px !important; }
            [style*="height:260px"] { height: 300px !important; }

            /* ─── Stat row / KPI cards ─── */
            .stat-row { 
                grid-template-columns: 1fr 1fr !important;
                gap: 8px !important;
            }
            .metric-card { padding: 10px 12px !important; }
            .metric-value { font-size: 20px !important; }
            .metric-label { font-size: 10px !important; }
            .metric-sub { font-size: 10px !important; }

            /* ─── Tables — horizontal scroll + mobile sizing ─── */
            .data-table { font-size: 12px !important; }
            .data-table thead th { padding: 8px 8px !important; font-size: 11px !important; white-space: nowrap; }
            .data-table tbody td { padding: 8px 8px !important; }
            .card:has(.data-table) { overflow-x: auto; -webkit-overflow-scrolling: touch; }

            /* ─── Form rows stack on mobile ─── */
            .form-row, .form-row-3 { grid-template-columns: 1fr !important; }

            /* ─── Pipeline kanban — horizontal scroll ─── */
            [style*="display:flex;gap:12px;overflow-x:auto"] {
                -webkit-overflow-scrolling: touch;
            }
            /* Kanban columns minimum width on mobile */
            [style*="min-width:260px"] { min-width: 240px !important; }

            /* ─── CRM modals — full screen on mobile ─── */
            #crmModalOverlay > div, #crmModal > div {
                width: 100vw !important;
                max-width: 100vw !important;
                max-height: 95vh !important;
                border-radius: 12px 12px 0 0 !important;
                position: fixed !important;
                bottom: 0 !important;
                top: auto !important;
                left: 0 !important;
                transform: none !important;
            }
            #crmModal [style*="grid-template-columns"] {
                grid-template-columns: 1fr !important;
            }

            /* ─── Buttons — larger touch targets ─── */
            .btn {
                min-height: 40px !important;
                padding: 8px 14px !important;
                font-size: 13px !important;
            }
            .btn-primary {
                min-height: 40px !important;
            }

            /* Button groups wrap */
            [style*="display:flex;gap:8px"],
            [style*="display:flex;gap:6px"] {
                flex-wrap: wrap;
            }

            /* ─── Contact detail — mobile optimized ─── */
            /* Action buttons — scrollable row */
            [style*="padding:0 24px 16px;display:flex;gap:8px"] {
                padding: 8px 12px !important;
                overflow-x: auto;
                -webkit-overflow-scrolling: touch;
                flex-wrap: nowrap !important;
                gap: 6px !important;
            }
            [style*="padding:0 24px 16px;display:flex;gap:8px"] .btn {
                white-space: nowrap;
                flex-shrink: 0;
                min-height: 36px !important;
                padding: 6px 12px !important;
                font-size: 12px !important;
            }

            /* Contact header padding */
            [style*="padding:20px 24px;background:linear-gradient"] {
                padding: 14px 12px !important;
            }
            [style*="padding:20px 24px;background:linear-gradient"] [style*="font-size:22px"] {
                font-size: 18px !important;
            }

            /* ─── Header bar adjustments ─── */
            .header-bar h1 { font-size: 15px !important; }
            #pageTitle { font-size: 15px !important; }

            /* Header search bar — hide text, icon only */
            .header-search-btn { min-width: auto !important; padding: 6px 10px !important; }
            .header-search-btn .search-label { display: none; }
            .header-search-btn .search-shortcut { display: none; }

            /* ─── Search/filter bars — stack and full width ─── */
            [style*="display:flex;gap:8px;margin-bottom:16px"],
            [style*="display:flex;justify-content:space-between;align-items:center;margin-bottom:16px"] {
                flex-wrap: wrap;
            }
            [style*="display:flex;gap:8px;margin-bottom:16px"] input,
            [style*="display:flex;gap:8px;margin-bottom:16px"] select {
                min-width: 0;
                flex: 1 1 100%;
            }

            /* ─── Cards — tighter on mobile ─── */
            .card {
                border-radius: 10px !important;
            }
            .card [style*="padding:20px"] { padding: 12px !important; }
            .card [style*="padding:16px"] { padding: 12px !important; }
            .card [style*="padding:14px 20px"] { padding: 10px 12px !important; }

            /* ─── Timeline entries — tighter ─── */
            #crmTimeline > div[style*="padding:12px 20px"] {
                padding: 10px 12px !important;
            }

            /* ─── Quote detail — stack layout ─── */
            [style*="display:grid;grid-template-columns:1fr 1fr;gap:16px;margin-bottom:16px"] {
                grid-template-columns: 1fr !important;
                gap: 10px !important;
            }

            /* ─── Lead detail grid ─── */
            [style*="grid-template-columns:auto 1fr;gap:4px 12px"] {
                gap: 2px 8px !important;
            }

            /* ─── Mobile bottom nav bar ─── */
            #mobileBottomNav {
                display: flex !important;
            }
            /* Add bottom padding to content so it doesn't hide behind bottom nav */
            #pageContent { padding-bottom: 70px !important; }

            /* ─── Analytics period dropdown ─── */
            select[style*="font-size:12px"] {
                font-size: 13px !important;
                min-height: 36px !important;
            }

            /* ─── Tab buttons (analytics) ─── */
            [style*="display:flex;gap:4px"] {
                flex-wrap: wrap;
                gap: 4px;
            }

            /* ─── Email compose modal ─── */
            #em_body { min-height: 150px !important; }

            /* ─── Contact list — cards on mobile ─── */
            .contact-table-desktop { display: none !important; }
            .contact-cards-mobile { display: block !important; }

            /* ─── Task list — cards on mobile ─── */
            .task-table-desktop { display: none !important; }
            .task-cards-mobile { display: block !important; }

            /* ─── Mobile header action buttons ─── */
            .mobile-header-actions { display: flex !important; gap: 6px; position: relative; }

            /* ─── Sidebar close button visible on mobile ─── */

            /* ─── Contact detail — tap to call/email ─── */
            a[href^="tel:"], a[href^="mailto:"] {
                color: var(--primary);
                text-decoration: none;
            }

            /* ─── Pipeline cards — larger touch targets ─── */
            .pipeline-card { min-height: 60px; }

            /* ─── Pipeline overview — compact cards on mobile ─── */
            .pipeline-overview-row {
                gap: 8px !important;
            }
            .pipeline-overview-row > div {
                min-width: 80px !important;
                padding: 8px !important;
                flex-shrink: 0 !important;
                flex: 0 0 auto !important;
            }
            .pipeline-overview-row > div [style*="font-size:22px"] {
                font-size: 18px !important;
            }
            .pipeline-overview-row > div [style*="font-size:12px"] {
                font-size: 10px !important;
            }
            .pipeline-overview-row > div [style*="font-size:11px"] {
                font-size: 9px !important;
            }

            /* ─── Sidebar close button — show on mobile ─── */
            .sidebar-close-btn { display: flex !important; }

            /* ─── Search overlay mobile ─── */
            .search-box {
                width: 95vw !important;
                max-width: 95vw !important;
                margin-top: 10px !important;
            }
        }

        /* ─── Tablet tweaks — 2 columns instead of 4 ─── */
        @media (min-width: 769px) and (max-width: 1024px) {
            [style*="grid-template-columns:repeat(4,1fr)"],
            [style*="grid-template-columns: repeat(4,1fr)"],
            [style*="grid-template-columns:repeat(4, 1fr)"] {
                grid-template-columns: repeat(2, 1fr) !important;
            }
        }

        /* ─── Mobile bottom nav (hidden on desktop) ─── */
        #mobileBottomNav {
            display: none;
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            background: var(--surface);
            border-top: 1px solid var(--border);
            z-index: 50;
            justify-content: space-around;
            align-items: center;
            height: 58px;
            padding: 4px 0;
            box-shadow: 0 -2px 10px rgba(0,0,0,0.06);
        }

        /* ─── Mobile contact cards (hidden on desktop) ─── */
        .contact-cards-mobile { display: none; }
        .contact-table-desktop { display: table; }
        .mobile-contact-card {
            padding: 12px 16px;
            border-bottom: 1px solid var(--border);
            cursor: pointer;
            -webkit-tap-highlight-color: transparent;
        }
        .mobile-contact-card:active { background: var(--hover); }
        .mobile-contact-card:last-child { border-bottom: none; }

        /* ─── Mobile task cards (hidden on desktop) ─── */
        .task-cards-mobile { display: none; }
        .task-table-desktop { display: table; }
        .mobile-task-card {
            padding: 12px 16px;
            border-bottom: 1px solid var(--border);
            cursor: pointer;
            -webkit-tap-highlight-color: transparent;
        }
        .mobile-task-card:active { background: var(--hover); }

        /* ─── Line Edit Modal (mobile full-screen) ─── */
        .line-edit-modal {
            position: fixed;
            inset: 0;
            background: rgba(0,0,0,0.4);
            z-index: 70;
            display: flex;
        }
        .line-edit-modal-content {
            background: var(--surface);
            width: 100%;
            height: 100%;
            display: flex;
            flex-direction: column;
        }
        .line-modal-field {
            margin-bottom: 12px;
        }
        .line-modal-field label {
            display: block;
            font-size: 12px;
            font-weight: 600;
            color: var(--text-secondary);
            margin-bottom: 4px;
        }

        /* Line summary card (hidden on desktop, shown on mobile) */
        .spo-line-summary, .sso-line-summary, .qs-line-summary, .tr-line-summary, .ssi-line-summary, .ssr-line-summary, .ssh-line-summary, .est-line-summary, .rtv-line-summary, .pt-line-summary, .sir-line-summary, .cr-line-summary, .adj-line-summary { display: none; }

        /* ─── Sidebar overlay (mobile) ─── */
        .sidebar-overlay {
            display: none;
            position: fixed;
            inset: 0;
            background: rgba(0,0,0,0.35);
            z-index: 39;
        }
        .sidebar-overlay.open { display: block; }

        /* ─── Sidebar close button (hidden on desktop) ─── */
        .sidebar-close-btn {
            display: none;
            align-items: center;
            justify-content: center;
            width: 32px;
            height: 32px;
            border: none;
            background: none;
            cursor: pointer;
            color: var(--text-secondary);
            border-radius: 6px;
            -webkit-tap-highlight-color: transparent;
        }
        .sidebar-close-btn:active { background: var(--hover); }

        /* ─── Mobile header buttons ─── */
        .mobile-header-actions { display: none; }
        .mobile-header-btn {
            padding: 6px 12px;
            border-radius: 6px;
            border: none;
            font-size: 13px;
            font-weight: 600;
            cursor: pointer;
            -webkit-tap-highlight-color: transparent;
        }
        .mobile-crm-btn {
            background: var(--primary);
            color: #fff;
        }
        .mobile-crm-btn:active { opacity: 0.85; }
        .mobile-new-btn {
            background: var(--surface);
            color: var(--text);
            border: 1px solid var(--border) !important;
        }
        .mobile-new-btn:active { background: var(--hover); }
        .mobile-crm-menu, .mobile-new-menu {
            display: none;
            position: absolute;
            top: 100%;
            right: 0;
            margin-top: 6px;
            background: var(--surface);
            border: 1px solid var(--border);
            border-radius: 10px;
            box-shadow: 0 8px 24px rgba(0,0,0,0.12);
            min-width: 180px;
            max-height: 70vh;
            overflow-y: auto;
            z-index: 35;
            padding: 4px 0;
        }
        .mobile-crm-menu.open, .mobile-new-menu.open { display: block; }
        #mobileBottomNav .mob-nav-btn {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 2px;
            padding: 4px 8px;
            border: none;
            background: none;
            cursor: pointer;
            color: var(--text-secondary);
            font-size: 10px;
            font-weight: 500;
            -webkit-tap-highlight-color: transparent;
        }
        #mobileBottomNav .mob-nav-btn.active {
            color: var(--primary);
        }
        #mobileBottomNav .mob-nav-btn svg {
            width: 22px;
            height: 22px;
        }

        /* Quick action buttons */
        .quick-btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px;
                    border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer;
                    border: 1px solid var(--border); background: #fff; color: var(--text);
                    transition: all 0.15s; }
        .quick-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
        .quick-btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
        .quick-btn-primary:hover { background: var(--primary-hover); }

        /* Filter bar */
        .filter-select { padding: 7px 12px; border-radius: 8px; border: 1px solid var(--border);
                        font-size: 13px; background: #fff; color: var(--text); outline: none; }
        .filter-select:focus { border-color: var(--primary); }

        /* Smooth chart canvas */
        canvas { max-width: 100%; }

        /* Aging bar */
        .aging-bar { display: flex; height: 32px; border-radius: 8px; overflow: hidden; }
        .aging-segment { display: flex; align-items: center; justify-content: center;
                        font-size: 11px; font-weight: 600; color: #fff; min-width: 30px; }

        /* Scrollbar */
        ::-webkit-scrollbar { width: 6px; }
        ::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

        /* Modal */
        .modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 60;
                         display: none; align-items: center; justify-content: center; }
        .modal-overlay.open { display: flex; }
        .modal { background: #fff; border-radius: 16px; width: 90%; max-width: 700px; max-height: 90vh;
                 overflow: hidden; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
        .modal-header { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex;
                       justify-content: space-between; align-items: center; }
        .modal-header h2 { font-size: 18px; font-weight: 700; margin: 0; }
        .modal-body { padding: 24px; overflow-y: auto; flex: 1; }
        .modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex;
                       justify-content: flex-end; gap: 10px; }

        /* Form fields */
        .form-group { margin-bottom: 14px; }
        .form-label { font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 4px; display: block; }
        .form-input { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px;
                     font-size: 14px; font-family: 'DM Sans', sans-serif; outline: none; transition: border-color 0.15s; box-sizing: border-box; }
        .form-input:focus { border-color: var(--primary); }
        .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
        .form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
        .form-section { font-weight: 600; font-size: 14px; color: var(--primary); margin: 18px 0 10px;
                       padding-bottom: 6px; border-bottom: 1px solid var(--border); }
        .form-section:first-child { margin-top: 0; }

        /* Buttons */
        .btn { padding: 8px 18px; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer;
               border: 1px solid var(--border); font-family: 'DM Sans', sans-serif; transition: all 0.15s; }
        .btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
        .btn-primary:hover { background: var(--primary-hover); }
        .btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
        .btn-ghost { background: none; }
        .btn-ghost:hover { background: var(--surface-alt); }
        .btn:disabled { opacity: 0.5; cursor: not-allowed; }

        /* Diff table */
        .diff-table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 12px 0; }
        .diff-table th { text-align: left; padding: 8px 12px; background: var(--surface-alt); font-size: 11px;
                        text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--border); }
        .diff-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); }
        .diff-old { color: var(--danger); text-decoration: line-through; }
        .diff-new { color: var(--primary); font-weight: 600; }

        /* New button in sidebar */
        .new-btn-wrap { padding: 12px 16px; border-bottom: 1px solid var(--border); }
        .new-btn { width: 100%; padding: 9px 16px; border-radius: 8px; background: var(--primary); color: #fff;
                  font-size: 13px; font-weight: 600; cursor: pointer; border: none; display: flex;
                  align-items: center; justify-content: center; gap: 6px; font-family: 'DM Sans', sans-serif;
                  transition: background 0.15s; }
        .new-btn:hover { background: var(--primary-hover); }
        .new-dropdown { position: absolute; left: 16px; right: 16px; background: #fff; border: 1px solid var(--border);
                       border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,0.12); z-index: 50; overflow: hidden; }
        .new-dropdown-item { padding: 10px 16px; font-size: 13px; font-weight: 500; cursor: pointer;
                           display: flex; align-items: center; gap: 10px; transition: background 0.1s; }
        .new-dropdown-item:hover { background: var(--primary-light); }
        .new-dropdown-item.disabled { color: #bbb; cursor: default; }
        .new-dropdown-item.disabled:hover { background: none; }

        /* Row action dropdown items */
        .po-action-item { padding: 8px 14px; cursor: pointer; white-space: nowrap; }
        .po-action-item:hover { background: #f3f4f6; }
        .po-action-item:first-child { border-radius: 6px 6px 0 0; }
        .po-action-item:last-child { border-radius: 0 0 6px 6px; }
    </style>
</head>
<body>
