/* ==========================================================================
   WattWorks Field — application styles.
   Carries over the original app's visual language: dark ink sidebar, amber
   accent, soft cards, coloured status pills. One stylesheet, no framework.
   ========================================================================== */

:root {
    --ink: #14181d;
    --ink-2: #1b2027;
    --paper: #f3f5f7;
    --card: #ffffff;
    --border: #dfe4e9;
    --text: #14181d;
    --muted: #5d6773;
    --faint: #98a2ad;
    --amber: #e8930c;
    --amber-dark: #c97c07;
    --blue: #3b7bd4;
    --green: #1f9d6b;
    --red: #d64545;
    --purple: #9b59b6;
    --grey: #8a97a5;
    --shadow: 0 1px 2px rgba(20, 24, 29, .06), 0 1px 3px rgba(20, 24, 29, .08);
    --shadow-lg: 0 10px 30px rgba(20, 24, 29, .18);
    --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--paper);
    -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4 { margin: 0; font-weight: 700; }
h2 { font-size: 20px; }
h3 { font-size: 15px; }
a { color: var(--blue); text-decoration: none; cursor: pointer; }
a:hover { text-decoration: underline; }

.num { font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.small { font-size: 12.5px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.right { text-align: right; }
.center { text-align: center; }
.mt8 { margin-top: 8px; }
.mt12 { margin-top: 12px; }
.mt16 { margin-top: 16px; }
.mb12 { margin-bottom: 12px; }
.spacer { flex: 1; }
.nowrap { white-space: nowrap; }

/* ---------- boot / loading ---------- */
.boot {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
    justify-content: center;
    color: var(--muted);
}
.bolt-big { font-size: 34px; }

/* ---------- app shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 232px;
    flex: 0 0 232px;
    background: var(--ink);
    color: #cfd6de;
    display: flex;
    flex-direction: column;
    padding: 14px 10px;
    gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 14px; }
.brand-logo { width: 34px; height: 34px; object-fit: contain; flex: 0 0 auto; }
.bname { color: #fff; font-weight: 700; font-size: 15px; }
.btag { color: #7d8794; font-size: 11px; }

.nav { display: flex; flex-direction: column; gap: 1px; overflow-y: auto; }
.nav-group-label {
    color: #6b7480; font-size: 10.5px; text-transform: uppercase;
    letter-spacing: .07em; padding: 12px 8px 4px; font-weight: 700;
}
.nav a {
    display: flex; align-items: center; gap: 9px;
    padding: 8px 9px; border-radius: 9px;
    color: #cfd6de; font-size: 13.5px; text-decoration: none;
}
.nav a:hover { background: var(--ink-2); color: #fff; text-decoration: none; }
.nav a.active { background: var(--amber); color: #1a1205; font-weight: 600; }
.nav a .ic { width: 17px; text-align: center; opacity: .9; }
.badge-count {
    margin-left: auto; background: var(--red); color: #fff;
    border-radius: 999px; padding: 0 6px; font-size: 11px; font-weight: 700;
}
.nav a.active .badge-count { background: #1a1205; color: var(--amber); }

.sidebar-foot {
    margin-top: auto; padding: 10px 8px 4px;
    border-top: 1px solid #262c34; color: #8b95a1; font-size: 12px;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 18px; background: var(--card);
    border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.page-title { font-weight: 700; font-size: 15px; }
.hamburger { display: none; }

.search { display: flex; align-items: center; gap: 6px; background: var(--paper);
    border: 1px solid var(--border); border-radius: 9px; padding: 4px 9px; }
.search input { border: none; background: transparent; outline: none; width: 190px; font-size: 13px; }

.content { padding: 18px; flex: 1; }

.mobile-nav { display: none; }

/* ---------- page furniture ---------- */
.page-head { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

.detail-head { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--border); }
.card-body { padding: 14px; }
.card-body.tight { padding: 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full, .field.full { grid-column: 1 / -1; }

/* ---------- pipeline ---------- */
.pipeline { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.pipe-step {
    flex: 1; min-width: 130px; background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 11px 13px; cursor: pointer; box-shadow: var(--shadow);
}
.pipe-step:hover { border-color: var(--amber); }
.pipe-step .pl { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }
.pipe-step .pv { font-size: 22px; font-weight: 700; }
.pipe-step .pm { color: var(--muted); font-size: 12px; min-height: 16px; }

/* ---------- stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--border); border-left: 3px solid var(--grey);
    border-radius: var(--radius); padding: 11px 13px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.stat .value { font-size: 20px; font-weight: 700; }
.stat .foot { color: var(--muted); font-size: 11.5px; }
.stat.blue { border-left-color: var(--blue); }
.stat.green { border-left-color: var(--green); }
.stat.amber { border-left-color: var(--amber); }
.stat.red { border-left-color: var(--red); }
.stat.grey { border-left-color: var(--grey); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.tbl, table.li-table { width: 100%; border-collapse: collapse; }
.tbl th, .li-table th {
    text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
    color: var(--muted); font-weight: 700; padding: 8px 12px;
    border-bottom: 1px solid var(--border); background: #fafbfc; white-space: nowrap;
}
.tbl td, .li-table td { padding: 9px 12px; border-bottom: 1px solid #eef1f4; vertical-align: middle; }
.tbl tbody tr:last-child td, .li-table tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl tbody tr.clickable:hover { background: #fafbfc; }
.li-table td { padding: 5px 6px; }
.li-table input, .li-table select { width: 100%; }

/* Per-line cost/markup/margin — sits under the description input rather than adding its own
   table columns, so a long description or a narrow (mobile) viewport just wraps this onto
   its own line instead of forcing the whole table wider. Each label+input is its own
   inline-flex "pair" so a cramped cell wraps whole pairs onto their own line rather than
   splitting a label from its input. */
.li-margin-row { display: flex; flex-wrap: wrap; align-items: center; gap: 3px 8px; margin-top: 4px; }
.li-margin-pair { display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }
.li-table .li-margin-row input.li-margin-input { width: 56px; padding: 2px 4px; font-size: 12px; }

/* A named part/section header or subtotal row within the line editor — a light band so a
   part's lines read as visually grouped without needing a nested table. */
.li-section-row td { background: #fafbfc; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.li-section-row input[type="text"] { width: auto; min-width: 140px; }

.totals { margin-top: 10px; margin-left: auto; width: 260px; }
.trow { display: flex; justify-content: space-between; padding: 3px 0; }
.trow.grand { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 6px; font-weight: 700; font-size: 15px; }

/* ---------- pills ---------- */
.pill {
    display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
    padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
    background: #eef1f4; color: #4a5560;
}
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.green { background: #e4f6ee; color: #14714c; }
.pill.blue { background: #e8f0fb; color: #2a5da4; }
.pill.amber { background: #fdf1dc; color: #96620a; }
.pill.red { background: #fbe8e8; color: #a32e2e; }
.pill.purple { background: #f2e8f7; color: #6f3d88; }
.pill.grey { background: #eef1f4; color: #4a5560; }

/* ---------- buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 6px; justify-content: center;
    padding: 7px 13px; border-radius: 9px; border: 1px solid var(--border);
    background: var(--card); color: var(--text); font-size: 13px; font-weight: 600;
    cursor: pointer; text-decoration: none; font-family: inherit;
}
.btn:hover { background: #f7f9fa; text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--amber); border-color: var(--amber); color: #1a1205; }
.btn.primary:hover { background: var(--amber-dark); border-color: var(--amber-dark); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.danger:hover { background: #bf3a3a; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: #eef1f4; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); }
.field .hint { font-size: 11.5px; color: var(--faint); }
input, select, textarea {
    font-family: inherit; font-size: 13.5px; color: var(--text);
    padding: 7px 9px; border: 1px solid var(--border); border-radius: 9px;
    background: var(--card); outline: none; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--amber); box-shadow: 0 0 0 3px rgba(232, 147, 12, .14); }
textarea { min-height: 80px; resize: vertical; }
input[type=checkbox] { width: auto; }
.inline-check { display: inline-flex; align-items: center; gap: 7px; font-size: 13.5px; font-weight: 500; color: var(--text); }
.validation-message, .field-error { color: var(--red); font-size: 12px; }

/* ---------- modal ---------- */
.modal-back {
    position: fixed; inset: 0; background: rgba(20, 24, 29, .55);
    display: flex; align-items: flex-start; justify-content: center;
    padding: 34px 14px; z-index: 200; overflow-y: auto;
}
.modal {
    background: var(--card); border-radius: 14px; box-shadow: var(--shadow-lg);
    width: 100%; max-width: 520px; max-height: calc(100vh - 68px); display: flex; flex-direction: column;
}
.modal.wide { max-width: 860px; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-head h3 { flex: 1; }
.modal-body { padding: 16px; overflow-y: auto; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.modal .close { background: none; border: none; font-size: 19px; cursor: pointer; color: var(--muted); }

/* ---------- toasts ---------- */
.toast-wrap { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 400;
    display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
    background: var(--ink); color: #fff; padding: 9px 15px; border-radius: 999px;
    font-size: 13px; box-shadow: var(--shadow-lg); pointer-events: auto; max-width: 90vw;
}
.toast.good { background: var(--green); }
.toast.bad { background: var(--red); }

/* ---------- misc blocks ---------- */
.empty { text-align: center; padding: 34px 16px; color: var(--muted); }
.empty .big { font-size: 30px; margin-bottom: 8px; opacity: .5; }

.note-item { border-left: 3px solid var(--border); padding: 7px 11px; margin-bottom: 7px; background: #fafbfc; border-radius: 0 8px 8px 0; }
.note-item .meta { color: var(--faint); font-size: 11.5px; margin-top: 2px; }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 5px 12px; font-size: 13.5px; }
.kv .k { color: var(--muted); }

.tabs { display: flex; gap: 3px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab { padding: 8px 13px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted);
    border-bottom: 2px solid transparent; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--amber-dark); border-bottom-color: var(--amber); }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.photo-grid img { width: 100%; height: 110px; object-fit: cover; border-radius: 9px; border: 1px solid var(--border); }

.sig-pad { width: 100%; height: 150px; border: 1px dashed var(--border); border-radius: 9px; background: #fff; touch-action: none; }

.timer-live { color: var(--green); font-weight: 700; }

.month-chart { display: flex; align-items: flex-end; gap: 10px; height: 170px; }
.month-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; }
.month-bars { flex: 1; display: flex; align-items: flex-end; gap: 3px; }
.month-bar { width: 16px; border-radius: 3px 3px 0 0; min-height: 1px; }
.month-bar.invoiced { background: var(--blue); }
.month-bar.paid { background: var(--green); }
.month-label { font-size: 11px; color: var(--faint); padding-top: 5px; }

.bar-row { margin-bottom: 9px; }
.bar-row .bar-head { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 3px; }
.bar-track { height: 8px; background: var(--paper); border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--green); }
.bar-fill.neg { background: var(--red); }

.offline-chip { background: #fdf1dc; color: #96620a; border: 1px solid #f0d9ae;
    padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }

/* ---------- schedule ---------- */
.sched-grid { display: grid; grid-template-columns: 58px repeat(7, 1fr); border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden; background: var(--card); }
.sh { background: #fafbfc; padding: 7px 4px; text-align: center; font-size: 12px; font-weight: 700;
    border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); }
.sh.corner { background: #f3f5f7; }
.sched-time { padding: 5px 6px; font-size: 11.5px; color: var(--muted); text-align: right;
    border-right: 1px solid var(--border); border-bottom: 1px solid #eef1f4; }
.sched-cell { min-height: 34px; border-right: 1px solid #eef1f4; border-bottom: 1px solid #eef1f4; padding: 2px; }
.sched-ev { color: #fff; font-size: 11.5px; border-radius: 6px; padding: 2px 5px; margin-bottom: 2px;
    cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- login ---------- */
.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; background: var(--ink); padding: 20px; }
.auth-logo { height: 84px; width: auto; margin-bottom: 22px; }
.auth-card { width: 100%; max-width: 380px; background: var(--card); border-radius: 14px; box-shadow: var(--shadow-lg); padding: 26px; }

/* ---------- blazor error ---------- */
#blazor-error-ui {
    background: #fdf1dc; color: #96620a; bottom: 0; display: none; left: 0;
    padding: 10px 14px; position: fixed; width: 100%; z-index: 1000; box-shadow: 0 -1px 2px rgba(0,0,0,.2);
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 14px; top: 10px; }

/* ---------- print ---------- */
@media print {
    .sidebar, .topbar, .mobile-nav, .no-print, .toast-wrap { display: none !important; }
    .content { padding: 0; }
    .card { border: none; box-shadow: none; }
}

/* ---------- responsive ---------- */
@media (max-width: 900px) {
    .grid-2, .grid-3, .form-grid { grid-template-columns: 1fr; }
    .totals { width: 100%; }
}

@media (max-width: 760px) {
    .sidebar { display: none; }
    .hamburger { display: inline-flex; }
    .search { display: none; }
    .content { padding: 12px 12px 76px; }
    .kv { grid-template-columns: 1fr; gap: 1px 0; }
    .kv .k { margin-top: 7px; }

    .mobile-nav {
        display: flex; position: fixed; bottom: 0; left: 0; right: 0;
        background: var(--card); border-top: 1px solid var(--border);
        padding: 5px 4px calc(5px + env(safe-area-inset-bottom)); z-index: 50;
    }
    .mobile-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
        font-size: 10.5px; color: var(--muted); padding: 4px 0; text-decoration: none; }
    .mobile-nav a.active { color: var(--amber-dark); font-weight: 700; }
    .mobile-nav a .ic { font-size: 16px; }

    .drawer-back { position: fixed; inset: 0; background: rgba(20,24,29,.5); z-index: 90; }
    .drawer { position: fixed; top: 0; bottom: 0; left: 0; width: 250px; background: var(--ink);
        z-index: 100; padding: 14px 10px; overflow-y: auto; }

    /* ---------- responsive list rows: status visible without opening the item ----------
       A wide multi-column table has nowhere to put a rightmost "Status" column on a phone —
       it either scrolls off-screen or gets so cramped it's unreadable, so the only way to
       see a job/quote/invoice's status was to open it. Turning each <tr> into a flex row
       (via `order`, not by changing markup or column count, so desktop's <table> layout is
       completely untouched above this breakpoint) puts the title and status pill on the same
       first line — status right there at a glance — with every other column dropping to its
       own compact line below. Opt-in per table via `tbl-responsive`; the two cells that get
       promoted onto that first line are tagged `mc-title` / `mc-status`, everything else
       needs no markup change at all. */
    .tbl-responsive thead { display: none; }
    .tbl-responsive, .tbl-responsive tbody { display: block; width: 100%; }
    .tbl-responsive tbody tr {
        display: flex; flex-wrap: wrap; align-items: flex-start;
        gap: 3px 10px; padding: 12px; border-bottom: 1px solid #eef1f4;
    }
    .tbl-responsive tbody tr:last-child { border-bottom: none; }
    .tbl-responsive td {
        display: block; order: 3; flex: 1 1 100%;
        padding: 0; border: none; text-align: left;
        font-size: 12.5px; color: var(--muted);
    }
    .tbl-responsive td.mc-title {
        /* flex-basis 0 (not auto) so a long title's natural width can't push flex-wrap into
           starting a whole new line for the status pill — the pill must always land on the
           title's own first line. Overflow truncates a too-long single-line title instead of
           wrapping it (the full text is one tap away); a naturally multi-line cell, like
           Enquiries' name-plus-contact block, still renders both of its own lines fine since
           white-space:nowrap only stops in-line text from wrapping, not a nested <div> from
           starting its own line. */
        order: 1; flex: 1 1 0; min-width: 0;
        font-weight: 700; font-size: 13.5px; color: var(--text);
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .tbl-responsive td.mc-status { order: 2; flex: 0 0 auto; }
}
