@{
    ViewData["Title"] = "Settings";
}

<div class="d-flex align-items-center gap-2 mb-3">
    <a asp-controller="Help" asp-action="Index" class="btn btn-sm btn-outline-secondary"><i class="bi bi-arrow-left"></i></a>
    <nav aria-label="breadcrumb">
        <ol class="breadcrumb mb-0">
            <li class="breadcrumb-item"><a asp-controller="Help" asp-action="Index">Help</a></li>
            <li class="breadcrumb-item active">Settings</li>
        </ol>
    </nav>
</div>

<div class="row g-4">
    <div class="col-lg-9">

        <section id="overview" class="mb-5">
            <h2 class="h4 fw-bold border-bottom pb-2 mb-3">
                <i class="bi bi-info-circle text-primary me-2"></i>Overview
            </h2>
            <p>
                The Settings section is where Administrators and Managers configure how the system behaves for
                your company. Settings control everything from the company name that appears on your printed
                documents to the pricing rates used in every quote the system generates.
            </p>
            <p>
                Changes in Settings take effect immediately and apply to all users in your company. Because
                changes are company-wide, only users with the <strong>Administrator</strong> or
                <strong>Manager</strong> role can access the Settings section. Users with lower permission
                levels will not see the Settings link in the navigation.
            </p>
            <p>
                You can find Settings under <strong>Settings</strong> in the left sidebar.
            </p>
            <div class="alert alert-permanent alert-warning d-flex gap-2 mb-0" role="alert">
                <i class="bi bi-exclamation-triangle-fill flex-shrink-0 mt-1"></i>
                <div>
                    Take care when changing pricing rates (labor, equipment, overhead, margins) in Settings.
                    Existing quotes and invoices are not retroactively recalculated &mdash; only new quotes created
                    after the change will use the updated rates. If you need to reprice an existing quote,
                    open it and recalculate manually.
                </div>
            </div>
        </section>

        <section id="company-information" class="mb-5">
            <h2 class="h4 fw-bold border-bottom pb-2 mb-3">
                <i class="bi bi-building text-primary me-2"></i>Company Information
            </h2>
            <p>
                Set your company's basic contact information. This data appears on all customer-facing documents
                &mdash; quotes, invoices, and PDFs &mdash; so it is important to keep it accurate and professional.
            </p>
            <ul class="mb-3">
                <li class="mb-1"><strong>Company Name</strong> &mdash; appears in the page header and on all printed documents.</li>
                <li class="mb-1"><strong>Address</strong> &mdash; your shop's street address, city, state, and ZIP code. Printed on quotes and invoices.</li>
                <li class="mb-1"><strong>Phone</strong> &mdash; your main business phone number.</li>
                <li class="mb-1"><strong>Email</strong> &mdash; your business email address. Used as the reply-to address for notifications sent to customers.</li>
                <li class="mb-1"><strong>Website</strong> &mdash; optional. Shown on printed documents if entered.</li>
                <li class="mb-1"><strong>Company Logo</strong> &mdash; upload a logo image (PNG or JPG recommended). The logo appears in the top-left corner of the sidebar and at the top of all printed quotes, invoices, and PDFs.</li>
            </ul>
            <div class="alert alert-permanent alert-info d-flex gap-2 mb-0" role="alert">
                <i class="bi bi-lightbulb-fill flex-shrink-0 mt-1"></i>
                <div>
                    For the best appearance on printed documents, use a logo image with a transparent background
                    (PNG format) and a minimum width of 300 pixels. Very small or low-resolution logos may
                    appear blurry on PDF printouts.
                </div>
            </div>
        </section>

        <section id="pricing-configuration" class="mb-5">
            <h2 class="h4 fw-bold border-bottom pb-2 mb-3">
                <i class="bi bi-sliders text-primary me-2"></i>Pricing Configuration
            </h2>
            <p>
                Pricing Configuration defines the rates used by the quoting engine to automatically calculate
                the cost of every quote. You can find these settings under <strong>Settings &rsaquo; Company Settings &rsaquo; Operating Costs</strong>.
                These are your shop's default rates &mdash; individual quotes reflect these settings at the time they are created.
            </p>

            <h3 class="h6 fw-semibold mt-3 mb-2">Labor</h3>
            <ul class="mb-3">
                <li class="mb-1"><strong>Standard Labor Rate ($/hr)</strong> &mdash; the hourly labor cost applied to all coating work. Sandblasting prep is calculated at 1.5× this rate; masking at 0.5× &mdash; these multipliers are built into the pricing engine and are not separately configurable.</li>
                <li class="mb-1"><strong>Additional Coat Labor (%)</strong> &mdash; the percentage of the base labor cost charged for each coat beyond the first. For example, at 30%, a two-coat job charges 100% labor for the first coat and 30% for the second.</li>
                <li class="mb-1"><strong>Per-Role Labor Rates</strong> &mdash; you can optionally set a different hourly rate for each shop worker role (Coater, Sandblaster, Masker, etc.). When set, the role-specific rate overrides the standard rate for that type of work. If no role rate is configured, the standard rate is used as the fallback.</li>
            </ul>

            <h3 class="h6 fw-semibold mt-3 mb-2">Equipment Hourly Rates</h3>
            <ul class="mb-3">
                <li class="mb-1"><strong>Default Oven Rate ($/hr)</strong> &mdash; the cost of running your curing oven per hour. Used when no specific named oven is selected on a quote.</li>
                <li class="mb-1"><strong>Sandblaster Rate ($/hr)</strong> &mdash; the cost of running the sandblasting equipment per hour.</li>
                <li class="mb-1"><strong>Coating Booth Rate ($/hr)</strong> &mdash; the cost of running the spray booth per hour.</li>
                <li class="mb-1"><strong>Named Ovens</strong> &mdash; if your shop has multiple ovens with different capacities or costs, you can add them individually (e.g., "Large Oven &mdash; $18/hr, 200 sq ft"). When a named oven is selected on a quote the correct rate is applied automatically.</li>
            </ul>

            <h3 class="h6 fw-semibold mt-3 mb-2">Material &amp; Shop Supplies</h3>
            <ul class="mb-3">
                <li class="mb-1"><strong>Powder Coating Cost per Sq Ft ($/sq ft)</strong> &mdash; the baseline material cost per square foot of surface area, representing your average powder and consumables cost.</li>
                <li class="mb-1"><strong>Shop Supplies Rate (%)</strong> &mdash; a percentage applied to material and labor costs to cover miscellaneous shop supplies (abrasives, tape, fasteners, etc.) that are not tracked per-job.</li>
            </ul>

            <h3 class="h6 fw-semibold mt-3 mb-2" id="facility-overhead">Facility Overhead (Rent &amp; Utilities)</h3>
            <p>
                Facility overhead lets you recover your shop's fixed occupancy costs on every quote automatically.
                Rather than burying rent and utilities in your General Markup, entering them here makes the cost
                transparent in the pricing breakdown and ensures accurate job costing.
            </p>
            <ul class="mb-3">
                <li class="mb-1"><strong>Monthly Rent ($)</strong> &mdash; your monthly shop lease or mortgage payment for the production facility.</li>
                <li class="mb-1"><strong>Monthly Utilities ($)</strong> &mdash; monthly gas, electricity, and water costs for the shop. Do not include costs already captured in your oven/equipment hourly rates.</li>
                <li class="mb-1"><strong>Monthly Billable Hours</strong> &mdash; the number of productive labor hours your shop operates per month (default: 160 &mdash; roughly one full-time worker for a month). This is used to convert the combined rent + utilities into a per-hour overhead rate.</li>
            </ul>
            <p>
                <strong>How it is applied:</strong> The system calculates a per-hour overhead rate as
                <code>(Monthly Rent + Monthly Utilities) ÷ Monthly Billable Hours</code>. For each quote, it
                multiplies that rate by the total estimated labor hours across all line items and adds the result
                as a separate line in the pricing breakdown. If rent and utilities are both $0, no overhead charge
                is added.
            </p>
            <div class="alert alert-permanent alert-info d-flex gap-2 mb-3" role="alert">
                <i class="bi bi-lightbulb-fill flex-shrink-0 mt-1"></i>
                <div>
                    <strong>Example:</strong> $2,000/month rent + $800/month utilities ÷ 160 billable hours =
                    <strong>$17.50/hr overhead rate</strong>. A quote with 4 total estimated hours would add
                    $70 to the price as "Facility Overhead."
                </div>
            </div>

            <h3 class="h6 fw-semibold mt-3 mb-2">Pricing Mode, Markup, Minimums &amp; Rush Charges</h3>
            <ul class="mb-3">
                <li class="mb-1">
                    <strong>Pricing Mode</strong> &mdash; controls how the General Markup % is applied:
                    <ul class="mt-1">
                        <li><em>Markup on Materials</em> (default) &mdash; markup is added on top of costs: <code>price = cost &times; (1 + markup%)</code>. A 25% markup on $100 = $125.</li>
                        <li><em>Target Margin on Total Cost</em> &mdash; markup % is treated as a gross-margin target: <code>price = cost &divide; (1 &minus; margin%)</code>. A 25% margin on $100 = $133.33. Use this mode if you think in terms of gross margin rather than markup.</li>
                    </ul>
                </li>
                <li class="mb-1"><strong>General Markup (%)</strong> &mdash; your profit percentage. Its exact effect depends on the Pricing Mode selected above.</li>
                <li class="mb-1"><strong>Shop Minimum Charge ($)</strong> &mdash; a floor price for any job. If the calculated total falls below this amount the minimum charge is used instead. Set to 0 to disable.</li>
                <li class="mb-1"><strong>Rush Charge</strong> &mdash; an automatic surcharge applied to jobs with Rush or Urgent priority. Choose between a percentage of the quote total or a fixed dollar amount.</li>
            </ul>

            <h3 class="h6 fw-semibold mt-3 mb-2">Part Complexity Multipliers</h3>
            <p>
                Each item on a quote is assigned a complexity rating (Simple, Moderate, Complex, or Extreme).
                These multipliers add a percentage to the calculated item price to account for the extra handling
                and prep time involved with intricate parts.
            </p>
            <ul class="mb-3">
                <li class="mb-1"><strong>Simple (%)</strong> &mdash; flat panels, basic shapes. Default: 0% (no adjustment).</li>
                <li class="mb-1"><strong>Moderate (%)</strong> &mdash; standard brackets, moderate curves. Default: 5%.</li>
                <li class="mb-1"><strong>Complex (%)</strong> &mdash; intricate assemblies, deep recesses. Default: 15%.</li>
                <li class="mb-1"><strong>Extreme (%)</strong> &mdash; highly ornate, heavy prep required. Default: 25%.</li>
            </ul>

            <h3 class="h6 fw-semibold mt-3 mb-2">Tax &amp; Oven Defaults</h3>
            <ul class="mb-3">
                <li class="mb-1"><strong>Default Tax Rate (%)</strong> &mdash; the sales tax percentage applied to quote and invoice totals. Set to 0 if you do not charge tax or handle it separately. Individual customers marked as Tax Exempt will always default to 0% regardless of this setting.</li>
                <li class="mb-1"><strong>Default Oven Cycle (minutes)</strong> &mdash; the default cure time used when scheduling oven batches. Individual named ovens can have their own default cycle time.</li>
            </ul>

            <div class="alert alert-permanent alert-warning d-flex gap-2 mb-0" role="alert">
                <i class="bi bi-exclamation-triangle-fill flex-shrink-0 mt-1"></i>
                <div>
                    Review your powder cost per sq ft and labor rate at least quarterly. If costs increase and
                    you do not update these settings, new quotes will underestimate costs and erode your margin.
                    Existing quotes and invoices are <strong>not</strong> retroactively recalculated when rates change.
                </div>
            </div>
        </section>

        <section id="pricing-tiers" class="mb-5">
            <h2 class="h4 fw-bold border-bottom pb-2 mb-3">
                <i class="bi bi-award text-primary me-2"></i>Pricing Tiers
            </h2>
            <p>
                Pricing Tiers let you offer volume discounts to commercial customers who send you regular work.
                You define each tier once in Settings, then assign a tier to each qualifying customer on their
                customer record. The quoting engine applies the discount automatically when generating a quote
                for that customer &mdash; no manual adjustment needed.
            </p>

            <h3 class="h6 fw-semibold mt-3 mb-2">Creating a Pricing Tier</h3>
            <ol class="mb-3">
                <li class="mb-2">Go to <strong>Settings &rsaquo; Pricing Tiers</strong> and click <strong>New Tier</strong>.</li>
                <li class="mb-2">Enter a <strong>Tier Name</strong> (e.g., "Preferred Shop", "Volume Partner", "Wholesale").</li>
                <li class="mb-2">Enter the <strong>Discount Percentage</strong> (e.g., 10 for a 10% discount).</li>
                <li class="mb-2">Add an optional <strong>Description</strong> explaining the criteria for this tier.</li>
                <li class="mb-2">Click <strong>Save Tier</strong>.</li>
            </ol>

            <h3 class="h6 fw-semibold mt-3 mb-2">Assigning a Tier to a Customer</h3>
            <p>
                Open the customer record you want to assign the tier to, click <strong>Edit</strong>, and select
                the pricing tier from the <strong>Pricing Tier</strong> dropdown. Save the customer record. From
                that point on, any new quote created for that customer will automatically show the tier discount
                in the pricing breakdown.
            </p>
            <div class="alert alert-permanent alert-info d-flex gap-2 mb-0" role="alert">
                <i class="bi bi-lightbulb-fill flex-shrink-0 mt-1"></i>
                <div>
                    Pricing tiers only apply to <strong>Commercial</strong> customers. Non-commercial (individual)
                    customers are always priced at standard rates. If you need to offer a one-off discount to
                    a non-commercial customer, use a Custom Work item with a manually adjusted price on that
                    specific quote.
                </div>
            </div>
        </section>

        <section id="chart-of-accounts" class="mb-5">
            <h2 class="h4 fw-bold border-bottom pb-2 mb-3">
                <i class="bi bi-journal-text text-primary me-2"></i>Chart of Accounts
            </h2>
            <p>
                The Chart of Accounts is the master list of all accounting categories used in the system for
                tracking income, expenses, and liabilities. Every bill line item is assigned to an account from
                this list; every invoice generates an entry in Accounts Receivable; every payment records a
                credit to the relevant bank account.
            </p>
            <p>
                Typical accounts for a powder coating shop include:
            </p>
            <ul class="mb-3">
                <li class="mb-1"><strong>Accounts Receivable</strong> &mdash; money customers owe you (created automatically from invoices).</li>
                <li class="mb-1"><strong>Accounts Payable</strong> &mdash; money you owe vendors (created automatically from bills).</li>
                <li class="mb-1"><strong>Cost of Goods Sold</strong> &mdash; direct material costs: powder, primer, consumables used in jobs.</li>
                <li class="mb-1"><strong>Shop Supplies</strong> &mdash; indirect shop materials not tied to a specific job.</li>
                <li class="mb-1"><strong>Equipment Maintenance</strong> &mdash; service and repair costs for shop machinery.</li>
                <li class="mb-1"><strong>Utilities</strong> &mdash; gas, electricity, and water.</li>
                <li class="mb-1"><strong>Rent / Occupancy</strong> &mdash; monthly rent or lease payments for the shop premises.</li>
                <li class="mb-1"><strong>Operating Expenses</strong> &mdash; general overhead not covered by other categories.</li>
                <li class="mb-1"><strong>Revenue / Sales Income</strong> &mdash; income from completed jobs (created automatically from paid invoices).</li>
            </ul>
            <p>
                The chart of accounts is typically configured once during initial setup. You can add new accounts
                at any time if your accounting needs expand.
            </p>

            <h3 class="h6 fw-semibold mt-3 mb-2">Default Accounts</h3>
            <p>
                The <strong>Default Accounts</strong> card at the top of the Chart of Accounts page lets you choose a
                default <strong>Revenue</strong>, <strong>COGS</strong>, and <strong>Inventory Asset</strong> account
                for your company. These are used automatically when an item or invoice line doesn&apos;t specify its own:
            </p>
            <ul class="mb-3">
                <li class="mb-1"><strong>Revenue</strong> &mdash; invoice lines without a specific revenue account fall back to this one (and to account 4000 if you haven&apos;t set a default).</li>
                <li class="mb-1"><strong>COGS</strong> and <strong>Inventory Asset</strong> &mdash; new inventory and catalog items are pre-filled with these, so you don&apos;t have to pick them every time. You can still change or clear them on each item.</li>
            </ul>
            <p>
                Leave any of them blank to keep the current behavior. Click <strong>Set Defaults</strong> to expand the
                card, choose your accounts, and save.
            </p>
            <div class="alert alert-permanent alert-warning d-flex gap-2 mb-3" role="alert">
                <i class="bi bi-exclamation-triangle-fill flex-shrink-0 mt-1"></i>
                <div>
                    Setting <strong>both</strong> a COGS and an Inventory Asset default makes new items record
                    inventory-consumption cost (COGS) to the general ledger as they&apos;re used &mdash; this is
                    perpetual-inventory accounting. If you expense materials when you <em>purchase</em> them, leave
                    these two blank to avoid double-counting.
                </div>
            </div>

            <div class="alert alert-permanent alert-warning d-flex gap-2 mb-0" role="alert">
                <i class="bi bi-exclamation-triangle-fill flex-shrink-0 mt-1"></i>
                <div>
                    <strong>Ask your accountant</strong> to review and approve your chart of accounts before
                    you start entering bills and invoices in production. Changing account names or categories
                    after transactions have been posted can complicate bookkeeping and tax reporting.
                    Do not delete accounts that have transactions recorded against them.
                </div>
            </div>
        </section>

        <section id="notifications" class="mb-5">
            <h2 class="h4 fw-bold border-bottom pb-2 mb-3">
                <i class="bi bi-bell text-primary me-2"></i>Notification Settings
            </h2>
            <p>
                The system has two notification channels: the <strong>in-app notification bell</strong> for
                real-time activity alerts inside the application, and <strong>email/SMS notifications</strong>
                for outbound customer and team communications.
            </p>

            <h3 class="h6 fw-semibold mt-3 mb-2">In-App Notification Bell</h3>
            <p>
                The bell icon (<i class="bi bi-bell-fill"></i>) in the top-right header appears for all logged-in
                users. A badge shows the count of unread notifications. Click it to open the dropdown showing your
                20 most recent notifications &mdash; both read and unread.
            </p>
            <ul class="mb-3">
                <li class="mb-1"><strong>Unread</strong> notifications have a purple left border, a light indigo background, and a blue dot.</li>
                <li class="mb-1"><strong>Read</strong> notifications are dimmed with no border.</li>
                <li class="mb-1">Click any notification to open a detail modal. If there is a linked record, click <strong>View</strong> to navigate to it.</li>
                <li class="mb-1">Use <strong>Mark all read</strong> to mark everything as read at once.</li>
                <li class="mb-1">Click <strong>View all notifications</strong> at the bottom of the dropdown to see your full notification history.</li>
            </ul>
            <p>The bell fires automatically for <strong>external customer actions</strong> only:</p>
            <ul class="mb-3">
                <li class="mb-1">Customer <strong>approves</strong> a quote online</li>
                <li class="mb-1">Customer <strong>declines</strong> a quote online</li>
                <li class="mb-1">Customer <strong>pays an invoice</strong> online via Stripe</li>
                <li class="mb-1">Customer <strong>pays a deposit</strong> online via Stripe</li>
                <li class="mb-1"><strong>Platform announcement</strong> sent by the Powder Coating Logix team</li>
            </ul>
            <div class="alert alert-permanent alert-info d-flex gap-2 mb-3" role="alert">
                <i class="bi bi-lightbulb-fill flex-shrink-0 mt-1"></i>
                <div>
                    Staff-recorded payments and deposits do <strong>not</strong> trigger bell notifications &mdash; those
                    are internal actions the staff member is already performing and does not need to be notified about.
                </div>
            </div>

            <h3 class="h6 fw-semibold mt-3 mb-2">Notification History</h3>
            <p>
                The <a href="/InAppNotifications">Notification History</a> page shows a full paginated list of all
                in-app notifications. Unread rows are highlighted. Click any row to open the detail modal, which
                also marks the notification as read. Email and SMS notification history is available separately at
                <a href="/NotificationLogs">Notification Logs</a>.
            </p>

            <h3 class="h6 fw-semibold mt-3 mb-2">Platform Announcements</h3>
            <p>
                The Powder Coating Logix platform team can send announcements to your company. These are delivered
                directly to your notification bell &mdash; not as page banners. Announcements may cover scheduled
                maintenance, new features, or policy updates. They appear as <strong>Announcement</strong> type
                items in your bell dropdown and can be cleared with "Mark all read."
            </p>

            <h3 class="h6 fw-semibold mt-3 mb-2">Email Sender Identity</h3>
            <p>
                Set the <strong>From Email Address</strong> and <strong>From Display Name</strong> used on all
                outgoing emails. If left blank, the system-wide SendGrid sender address is used. Using a
                domain-verified address (e.g., <code>billing@yourshop.com</code>) greatly reduces the chance of
                your emails landing in customers' spam folders.
            </p>

            <h3 class="h6 fw-semibold mt-3 mb-2">Notify On</h3>
            <p>
                Each toggle controls whether that event type sends a customer-facing or internal notification email:
            </p>
            <ul class="mb-3">
                <li class="mb-1"><strong>New Job</strong> &mdash; emails your team when a new job is created.</li>
                <li class="mb-1"><strong>New Quote</strong> &mdash; emails your team when a new quote is created.</li>
                <li class="mb-1"><strong>Job Status Change</strong> &mdash; notifies the customer when a job's status changes.</li>
                <li class="mb-1"><strong>Quote Approval</strong> &mdash; notifies the customer when a quote is approved.</li>
                <li class="mb-1"><strong>Payment Received</strong> &mdash; sends the customer a payment confirmation email when a payment is recorded against their invoice.</li>
            </ul>

            <h3 class="h6 fw-semibold mt-3 mb-2">Alert Thresholds</h3>
            <p>
                These values control how many days <em>before</em> an event the system highlights it as upcoming
                in the UI (for example, flagging a quote as expiring soon in the quotes list).
            </p>
            <ul class="mb-3">
                <li class="mb-1"><strong>Quote Expiry Warning (days before)</strong> &mdash; quotes expiring within this many days are flagged in the quotes list.</li>
                <li class="mb-1"><strong>Due Date Warning (days before)</strong> &mdash; invoices coming due within this many days are highlighted.</li>
                <li class="mb-1"><strong>Maintenance Alert (days ahead)</strong> &mdash; upcoming maintenance tasks scheduled within this many days are highlighted.</li>
            </ul>

            <h3 class="h6 fw-semibold mt-3 mb-2">Automated Payment Reminders</h3>
            <p>
                The payment reminder system automatically emails customers when their invoices become overdue.
                You control whether this feature is active and exactly how many days past due each reminder fires.
            </p>
            <ul class="mb-3">
                <li class="mb-2">
                    <strong>Enable Payment Reminders</strong> &mdash; master on/off toggle. When off, no automated
                    reminder emails are sent regardless of the day settings below.
                </li>
                <li class="mb-2">
                    <strong>Reminder Days</strong> &mdash; a comma-separated list of day milestones (days past the invoice due date)
                    at which a reminder email is sent. For example, <code>7,14,30</code> sends one reminder at
                    7 days overdue, another at 14 days, and a final one at 30 days. You can use any positive
                    whole numbers (e.g., <code>3,10,21,45</code>).
                </li>
            </ul>

            <h3 class="h6 fw-semibold mt-3 mb-2">How Payment Reminders Work</h3>
            <ol class="mb-3">
                <li class="mb-2">Every morning the system checks all invoices that have a due date in the past and are in <strong>Sent</strong>, <strong>Partially Paid</strong>, or <strong>Overdue</strong> status.</li>
                <li class="mb-2">For each invoice, it calculates how many days past due it is and checks whether that number matches one of your configured reminder day thresholds.</li>
                <li class="mb-2">If a match is found and a reminder has <em>not already been sent today</em> for that invoice and that milestone, the reminder email is sent to the customer.</li>
                <li class="mb-2">Customers who have opted out of email notifications are never contacted.</li>
                <li class="mb-2">Each reminder sent is recorded in the notification log, visible via <strong>Settings &rsaquo; Notification Templates &amp; Logs</strong>.</li>
            </ol>

            <div class="alert alert-permanent alert-info d-flex gap-2 mb-3" role="alert">
                <i class="bi bi-lightbulb-fill flex-shrink-0 mt-1"></i>
                <div>
                    Payment reminders are sent once per threshold per invoice &mdash; if you have <code>7,14,30</code>
                    configured, a single invoice will receive at most three reminder emails over the course of its
                    collection cycle, one at each milestone. An invoice that gets paid between milestones will not
                    receive any further reminders (its status changes to Paid and it is excluded from future checks).
                </div>
            </div>

            <h3 class="h6 fw-semibold mt-3 mb-2">SMS Notifications</h3>
            <p>
                SMS text messages are an opt-in feature at both the company level and the customer level.
                When SMS is not available on your plan the toggle will not appear.
            </p>
            <ul class="mb-3">
                <li class="mb-2">
                    <strong>Enable SMS Notifications</strong> &mdash; master company toggle. The first time you enable it
                    you must agree to the SMS terms of service, which covers your obligation to obtain prior written
                    customer consent before texting them (required by FCC/TCPA regulations). Once agreed, you can
                    toggle SMS on and off freely without re-agreeing unless the terms are updated.
                </li>
                <li class="mb-2">
                    <strong>Per-customer opt-in</strong> &mdash; even with SMS enabled here, a customer will only receive
                    texts if their record has a <strong>Mobile Phone</strong> number and the <strong>SMS Opt-In</strong>
                    box checked. You are responsible for obtaining each customer's consent before enabling this on
                    their record.
                </li>
            </ul>
            <h4 class="h6 fw-semibold mt-3 mb-2" style="font-size:.85rem;">What events send an SMS</h4>
            <ul class="mb-3">
                <li class="mb-1">
                    <strong>Quote Sent</strong> &mdash; sends the customer a link to review and approve or decline their
                    quote directly from their phone. Click <strong>Send Quote via SMS</strong> on any quote's Details
                    page. If an email was already sent for the same quote, the existing approval link is reused so both
                    delivery methods work simultaneously.
                </li>
                <li class="mb-1"><strong>Job Completed</strong> &mdash; notifies the customer their job is done and ready for pickup.</li>
            </ul>
            <p class="small text-muted mb-3">
                Both SMS message templates can be customised at
                <strong>Company Settings &rsaquo; Notification Templates</strong>.
            </p>
            <h4 class="h6 fw-semibold mt-3 mb-2" style="font-size:.85rem;">Compose-before-send vs. auto-send</h4>
            <p>
                When a <strong>Company Admin or Manager</strong> marks a job complete, the system pre-fills a draft
                SMS from your notification template and opens a compose window so you can personalize the message
                before it sends. A <strong>Send SMS</strong> button on the job details page lets you send a follow-up
                at any time.
            </p>
            <p>
                When a <strong>Shop Floor</strong> worker marks a job complete the SMS is sent automatically using
                the template &mdash; no compose step.
            </p>
            <div class="alert alert-permanent alert-info d-flex gap-2 mb-0" role="alert">
                <i class="bi bi-lightbulb-fill flex-shrink-0 mt-1"></i>
                <div>
                    Every outbound SMS automatically includes opt-out instructions ("Reply STOP to opt out"). If a
                    customer replies STOP, they are immediately opted out and will receive no further messages.
                    If they change their mind, they can reply <strong>START</strong>, <strong>YES</strong>, or <strong>UNSTOP</strong>
                    to re-subscribe automatically &mdash; no action needed from your staff. You can also manually re-enable
                    SMS on their customer record.
                </div>
            </div>
        </section>

        <section id="named-ovens" class="mb-5">
            <h2 class="h4 fw-bold border-bottom pb-2 mb-3">
                <i class="bi bi-fire text-primary me-2"></i>Named Ovens
            </h2>
            <p>
                If your shop has more than one curing oven, or if you want to assign specific costs and
                capacities to your oven for the Oven Scheduler, configure each oven individually under
                <strong>Settings &rsaquo; Company Settings &rsaquo; Named Ovens</strong>.
            </p>
            <p>For each named oven you can set:</p>
            <ul class="mb-3">
                <li class="mb-1"><strong>Oven Name</strong> &mdash; e.g., "Main Oven", "Small Parts Oven".</li>
                <li class="mb-1"><strong>Operating Cost ($/hr)</strong> &mdash; the hourly cost to run this specific oven.</li>
                <li class="mb-1"><strong>Max Load Capacity (sq ft)</strong> &mdash; the maximum total surface area that fits in one batch. The Oven Scheduler uses this to show remaining capacity as you add jobs.</li>
                <li class="mb-1"><strong>Default Cycle Time (minutes)</strong> &mdash; the default cure duration for this oven, used when scheduling batches.</li>
            </ul>
            <p>
                When a named oven is selected on a quote or job, its specific cost rate is used instead of
                the default oven rate. The Oven Scheduler at <strong>/OvenScheduler</strong> uses named ovens
                to group and track job batches.
            </p>
        </section>

        <section id="data-lookups" class="mb-5">
            <h2 class="h4 fw-bold border-bottom pb-2 mb-3">
                <i class="bi bi-list-ul text-primary me-2"></i>Data Lookups
            </h2>
            <p>
                The <strong>Data Lookups</strong> tab in Company Settings lets you customize the dropdown
                options that appear throughout the application &mdash; job statuses, job priorities, quote statuses,
                appointment types, and inventory categories. You can rename labels, change colours, reorder
                items, and add new ones to match your shop's terminology.
            </p>
            <div class="alert alert-permanent alert-warning d-flex gap-2 mb-3" role="alert">
                <i class="bi bi-exclamation-triangle-fill flex-shrink-0 mt-1"></i>
                <div>
                    <strong>Status codes drive workflow logic</strong> &mdash; the underlying code value (e.g.
                    <code>IN_PROGRESS</code>, <code>COMPLETED</code>) is what the system uses internally.
                    You can safely rename the display label, but do not change the code of a built-in
                    status unless you understand the impact on automation and reporting.
                </div>
            </div>

            <h3 class="h6 fw-semibold mt-3 mb-2">Adding a New Lookup Item</h3>
            <ol class="mb-3">
                <li class="mb-2">Go to <strong>Settings &rsaquo; Company Settings &rsaquo; Data Lookups</strong>.</li>
                <li class="mb-2">Select the sub-tab for the lookup type (e.g., Job Statuses, Job Priorities).</li>
                <li class="mb-2">Click <strong>Add</strong> to open the form.</li>
                <li class="mb-2">Type a <strong>Display Name</strong> &mdash; the Code field auto-fills as you type
                    (e.g., "In Progress" → <code>IN_PROGRESS</code>). You can override it if needed.</li>
                <li class="mb-2">Choose a color and fill in any additional fields.</li>
                <li class="mb-2">Click <strong>Save</strong>.</li>
            </ol>

            <h3 class="h6 fw-semibold mt-3 mb-2">About the Code Field</h3>
            <p>
                Each lookup item has a <strong>Code</strong> &mdash; a short uppercase identifier used internally
                (e.g., <code>QUALITY_CHECK</code>, <code>URGENT</code>). When adding a new item:
            </p>
            <ul class="mb-3">
                <li class="mb-1">The Code auto-derives from the Display Name as you type &mdash; spaces become underscores, everything is uppercased.</li>
                <li class="mb-1">You can edit the Code directly; it will stay uppercase and only allow letters, numbers, and underscores.</li>
                <li class="mb-1">Once saved, the Code cannot be changed &mdash; it is locked to prevent breaking existing records that reference it.</li>
            </ul>

            <h3 class="h6 fw-semibold mt-3 mb-2">Inventory Categories &mdash; Is Coating Flag</h3>
            <p>
                The <strong>Inventory Categories</strong> sub-tab includes an important flag: <strong>Is Coating</strong>.
                Only inventory items whose category has this flag enabled will appear in the powder color dropdown
                when building a quote or job. If your powder colors are not showing up in the quote wizard,
                go to Data Lookups &rsaquo; Inventory Categories, find the category that holds your powders,
                and enable <strong>Is Coating</strong>.
            </p>
        </section>

        <section id="ai-profile" class="mb-5">
            <h2 class="h4 fw-bold border-bottom pb-2 mb-3">
                <i class="bi bi-robot text-primary me-2"></i>AI Profile
            </h2>
            <p>
                The <strong>AI Profile</strong> tab in Company Settings lets you describe your shop's
                specialties, typical work, and pricing preferences in plain text. This context is automatically
                included in the system prompt sent to AI for photo quoting &mdash; resulting in more accurate and
                relevant estimates.
            </p>
            <p>Examples of useful AI Profile content:</p>
            <ul class="mb-3">
                <li class="mb-1">"We specialize in automotive parts and wheels. Most items are steel or aluminum."</li>
                <li class="mb-1">"Our minimum charge is $75. We charge a 20% premium for intricate wrought iron."</li>
                <li class="mb-1">"We rarely do sandblasting in-house &mdash; assume parts arrive pre-blasted."</li>
            </ul>
            <p>
                The AI Profile is optional but recommended. The more specific you are, the better the AI
                quotes will match your actual pricing. Update it whenever your shop's focus or pricing
                strategy changes.
            </p>
        </section>

        <section id="user-management" class="mb-5">
            <h2 class="h4 fw-bold border-bottom pb-2 mb-3">
                <i class="bi bi-people text-primary me-2"></i>User Management
            </h2>
            <p>
                Manage who has access to your company's account under <strong>Settings &rsaquo; Users</strong>
                (or navigate to <a href="/CompanyUsers">/CompanyUsers</a>).
            </p>

            <h3 class="h6 fw-semibold mt-3 mb-2">Adding a User</h3>
            <ol class="mb-3">
                <li class="mb-2">Go to <strong>Settings &rsaquo; Users</strong> and click <strong>New User</strong>.</li>
                <li class="mb-2">Enter the user's name, email address, and select their role.</li>
                <li class="mb-2">The system sends an invitation email. The user follows the link to set their password.</li>
            </ol>

            <h3 class="h6 fw-semibold mt-3 mb-2">Roles</h3>
            <div class="table-responsive mb-3">
                <table class="table table-sm table-bordered mb-0">
                    <thead class="table-light">
                        <tr><th style="width:25%">Role</th><th>Access level</th></tr>
                    </thead>
                    <tbody>
                        <tr><td><span class="badge bg-danger">Company Admin</span></td><td>Full company access including settings, users, and billing. All permissions granted automatically.</td></tr>
                        <tr><td><span class="badge bg-warning text-dark">Manager</span></td><td>Jobs, quotes, invoices, customers, inventory, vendors, reports &mdash; no settings or user management.</td></tr>
                        <tr><td><span class="badge bg-success">Accountant</span></td><td>Financial focus: bills &amp; AP, invoices, bank reconciliations, chart of accounts, vendors, purchase orders, and reports. No job management or settings access.</td></tr>
                        <tr><td><span class="badge bg-primary">Worker</span></td><td>Create and edit jobs and quotes; no settings, billing, or user management.</td></tr>
                        <tr><td><span class="badge bg-secondary">Viewer</span></td><td>Read-only access to most data.</td></tr>
                    </tbody>
                </table>
            </div>
            <p class="small text-muted mb-3">
                When you select <strong>Accountant</strong> in the role dropdown, the permissions form automatically
                pre-checks the five relevant permissions (Invoices, Reports, Vendors, Bills &amp; AP, Accounting).
                You can adjust the individual checkboxes for users whose needs differ from the default.
            </p>

            <h3 class="h6 fw-semibold mt-3 mb-2">Fine-Grained Permissions</h3>
            <p>
                Below the role dropdown, each user has individual permission checkboxes. These let you grant
                specific capabilities independently of the role &mdash; for example, giving a Worker access to view
                reports without making them a Manager. Company Admins always have all permissions and the
                checkboxes are locked.
            </p>
            <div class="table-responsive mb-3">
                <table class="table table-sm table-bordered mb-0">
                    <thead class="table-light">
                        <tr><th style="width:35%">Permission</th><th>What it unlocks</th></tr>
                    </thead>
                    <tbody>
                        <tr><td>Can Manage Jobs</td><td>Create, edit, and update job status.</td></tr>
                        <tr><td>Can Manage Inventory</td><td>Add, edit, and adjust inventory items and stock levels.</td></tr>
                        <tr><td>Can Manage Customers</td><td>Create and edit customer records.</td></tr>
                        <tr><td>Can Create Quotes</td><td>Build and send quotes to customers.</td></tr>
                        <tr><td>Can Approve Quotes</td><td>Internally approve quotes on behalf of the customer.</td></tr>
                        <tr><td>Can Manage Calendar</td><td>Create and edit appointments.</td></tr>
                        <tr><td>Can View Calendar</td><td>View the appointments calendar (read-only).</td></tr>
                        <tr><td>Can Manage Products</td><td>Create and edit catalog items.</td></tr>
                        <tr><td>Can View Products</td><td>Browse the catalog item list (read-only).</td></tr>
                        <tr><td>Can Manage Equipment</td><td>Add equipment records and log maintenance.</td></tr>
                        <tr><td>Can Manage Vendors</td><td>Create and edit vendor records.</td></tr>
                        <tr><td>Can Manage Maintenance</td><td>Schedule and complete maintenance tasks.</td></tr>
                        <tr><td>Can Manage Invoices</td><td>Create invoices and record payments.</td></tr>
                        <tr><td>Can View Reports</td><td>Access all reports and AI analytics features.</td></tr>
                        <tr><td><strong>Can Manage Bills &amp; AP</strong></td><td>Create and pay vendor bills, record expenses, and use recurring bill detection. Grants access to the full Accounts Payable section.</td></tr>
                        <tr><td><strong>Can Manage Accounting</strong></td><td>Access the chart of accounts, bank reconciliations, and manual journal entries.</td></tr>
                    </tbody>
                </table>
            </div>

            <h3 class="h6 fw-semibold mt-3 mb-2">Resetting a Password</h3>
            <p>
                Select a user from the list and click <strong>Reset Password</strong>. The user receives
                an email with a link to set a new password.
            </p>

            <h3 class="h6 fw-semibold mt-3 mb-2">Deactivating a User</h3>
            <p>
                Use the active/inactive toggle on the user list or the edit form to deactivate a user.
                Deactivated users cannot log in but their records and activity history are preserved.
            </p>
        </section>

        <section id="data-export" class="mb-5">
            <h2 class="h4 fw-bold border-bottom pb-2 mb-3">
                <i class="bi bi-download text-primary me-2"></i>Download Your Data
            </h2>
            <p>
                Company Administrators can export a complete copy of their company's data at any time from
                <a href="/AccountDataExport">Settings &rsaquo; Download Your Data</a> (or navigate directly to
                <code>/AccountDataExport</code>). This feature is available even when a subscription has
                expired &mdash; your data is never locked away.
            </p>

            <h3 class="h6 fw-semibold mt-3 mb-2">What Can Be Exported</h3>
            <p>Choose any combination of the following data types:</p>
            <ul class="mb-3">
                <li class="mb-1"><strong>Customers</strong> &mdash; all customer records including contact info, type, and credit settings.</li>
                <li class="mb-1"><strong>Jobs</strong> &mdash; all job records with status, priority, assigned worker, and dates.</li>
                <li class="mb-1"><strong>Quotes</strong> &mdash; all quote records with status and pricing.</li>
                <li class="mb-1"><strong>Invoices</strong> &mdash; all invoice records with amounts paid and status.</li>
                <li class="mb-1"><strong>Inventory</strong> &mdash; all inventory items with quantities and costs.</li>
                <li class="mb-1"><strong>Equipment</strong> &mdash; all equipment records and statuses.</li>
                <li class="mb-1"><strong>Vendors</strong> &mdash; all vendor/supplier records.</li>
                <li class="mb-1"><strong>Shop Workers</strong> &mdash; all shop worker records.</li>
                <li class="mb-1"><strong>Users / Logins</strong> &mdash; all user accounts and their roles.</li>
            </ul>

            <h3 class="h6 fw-semibold mt-3 mb-2">Export Formats</h3>
            <ul class="mb-3">
                <li class="mb-1"><strong>Excel (.xlsx)</strong> &mdash; all selected data types in a single workbook, one tab per data type. Best for viewing in Excel or Google Sheets.</li>
                <li class="mb-1"><strong>CSV (.zip)</strong> &mdash; one CSV file per selected data type, bundled into a single ZIP archive. Best for importing into other software.</li>
            </ul>

            <p>
                The export is generated on-demand and delivered directly to your browser. Nothing is stored
                on the server &mdash; each export is a fresh snapshot of your current data.
            </p>

            <div class="alert alert-permanent alert-info d-flex gap-2 mb-0" role="alert">
                <i class="bi bi-lightbulb-fill flex-shrink-0 mt-1"></i>
                <div>
                    If your subscription has expired and you see the "Subscription Expired" screen, look for the
                    <strong>Download Your Data</strong> button on that page to access your export without needing
                    to renew first. Only Company Administrators have access to the data export.
                </div>
            </div>
        </section>

        <section id="default-settings" class="mb-5">
            <h2 class="h4 fw-bold border-bottom pb-2 mb-3">
                <i class="bi bi-toggles text-primary me-2"></i>Default Settings
            </h2>
            <p>
                Default Settings configure system-wide values that are applied automatically whenever a new
                record is created. These save time on data entry and ensure consistency across your documents.
                You can always override defaults on individual records.
            </p>
            <ul class="mb-3">
                <li class="mb-2">
                    <strong>Default Quote Validity Period (days)</strong> &mdash; the number of days after creation before
                    a quote expires. For example, a value of 30 means all new quotes expire 30 days after their
                    quote date. Expired quotes are flagged in the quote list and customers cannot act on them without
                    you creating a revised quote. Adjust this based on how stable your pricing is &mdash; shops with
                    volatile powder costs may want a shorter validity period (e.g., 14 days).
                </li>
                <li class="mb-2">
                    <strong>Default Payment Terms</strong> &mdash; the payment terms applied to new customer records
                    and new invoices (e.g., "Net 30", "Net 15", "Due on Receipt"). This determines when invoices
                    become due and affects the AR Aging report. The default can be overridden on each customer
                    record and on individual invoices.
                </li>
                <li class="mb-2">
                    <strong>Currency</strong> &mdash; the currency symbol and formatting used throughout the system for
                    all monetary values (e.g., USD, CAD, AUD, GBP). This is a display setting only and does not
                    perform any currency conversion. Set this once during initial setup to match your local currency.
                </li>
            </ul>
            <div class="alert alert-permanent alert-secondary d-flex gap-2 mb-0" role="alert">
                <i class="bi bi-info-circle flex-shrink-0 mt-1"></i>
                <div>
                    Default settings apply only to new records created after the setting is changed. Existing
                    customers, quotes, and invoices retain whatever payment terms and expiry dates were set
                    at the time they were created.
                </div>
            </div>
        </section>

    </div>

    <div class="col-lg-3 d-none d-lg-block">
        @{ await Html.RenderPartialAsync("_HelpNav"); }
        <div class="card border-0 shadow-sm sticky-top" style="top:80px">
            <div class="card-header bg-transparent fw-semibold small text-muted text-uppercase" style="letter-spacing:.05em; font-size:.7rem;">On this page</div>
            <div class="card-body p-0">
                <nav class="nav flex-column">
                    <a class="nav-link py-1 px-3 small text-body" href="#overview">Overview</a>
                    <a class="nav-link py-1 px-3 small text-body" href="#company-information">Company Information</a>
                    <a class="nav-link py-1 px-3 small text-body" href="#pricing-configuration">Pricing Configuration</a>
                    <a class="nav-link py-1 px-3 small text-body" href="#pricing-tiers">Pricing Tiers</a>
                    <a class="nav-link py-1 px-3 small text-body" href="#chart-of-accounts">Chart of Accounts</a>
                    <a class="nav-link py-1 px-3 small text-body" href="#notifications">Notification Settings</a>
                    <a class="nav-link py-1 px-3 small text-body" href="#named-ovens">Named Ovens</a>
                    <a class="nav-link py-1 px-3 small text-body" href="#data-lookups">Data Lookups</a>
                    <a class="nav-link py-1 px-3 small text-body" href="#ai-profile">AI Profile</a>
                    <a class="nav-link py-1 px-3 small text-body" href="#user-management">User Management</a>
                    <a class="nav-link py-1 px-3 small text-body" href="#data-export">Download Your Data</a>
                    <a class="nav-link py-1 px-3 small text-body" href="#default-settings">Default Settings</a>
                </nav>
            </div>
        </div>
    </div>
</div>
