/* ==================================================================
   MIDSOFT APP UI – DESKTOP-FIRST ADD-ON
   ------------------------------------------------------------------
   For office apps used mainly on a PC (e.g. haulage, accounts, admin).
   Load AFTER ui.css:
       <link rel="stylesheet" href="assets/css/ui.css">
       <link rel="stylesheet" href="assets/css/desktop.css">
   and put  class="app-page is-desktop"  on <body>.

   Same colours, font, cards, chips, sheets and forms as ui.css – this
   file only adds what an office app needs:
     - a top navigation bar (instead of the sidebar / phone bottom bar)
     - wide pages, page headers with action buttons, filter bars
     - data tables (sortable, selectable) and a batch action bar
     - tabs on record pages, side panels, dialogs, summary figures
     - print styles
   On small screens the top bar's menu folds into a slide-in panel and
   tables scroll sideways, so the app still works on a tablet or phone.
   Components are described in references/desktop-first.md and working
   in assets/desktop-showcase.html.
   ================================================================== */

.is-desktop {
    --desk-nav-height: 60px;
    --desk-content-max: 1480px;
    --desk-row-hover: rgb(var(--app-primary-rgb) / .06);
    --desk-row-selected: rgb(var(--app-primary-rgb) / .13);
}


/* ==================================================================
   PAGE SHELL: top bar on top, content underneath
   ================================================================== */
.is-desktop .app-shell { display: block; }

.is-desktop .app-content {
    max-width: var(--desk-content-max);
    padding: 1.5rem 1.25rem 3rem;
}
@media (min-width: 992px) {
    .is-desktop .app-content { padding: 1.75rem 2rem 3rem; }
}


/* ==================================================================
   TOP NAVIGATION BAR
   brand | sections (some with drop-downs) | search | user menu
   ================================================================== */
.desk-topnav {
    position: sticky;
    top: 0;
    z-index: 1030;
    height: var(--desk-nav-height);
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1.25rem;
    background: var(--app-surface);
    border-bottom: 1px solid var(--app-line);
    /* the house teal / red line, as on the phone top bar */
    box-shadow: inset 0 -3px 0 -1px var(--app-primary);
}
.desk-topnav::after {
    content: "";
    position: absolute;
    right: 0;
    bottom: 0;
    width: 22%;
    height: 2px;
    background: var(--app-alert);
}

.desk-brand {
    display: flex;
    align-items: center;
    gap: .55rem;
    flex-shrink: 0;
    color: var(--app-ink);
    text-decoration: none;
}
.desk-brand img { width: 34px; height: 34px; }
.desk-brand .brand-name { font-size: 1.3rem; }
.desk-brand .brand-edition { margin-left: 0; font-size: .68rem; }

/* Sections */
.desk-menu {
    display: flex;
    align-items: stretch;
    height: 100%;
    gap: .15rem;
    margin: 0;
    padding: 0 0 0 .5rem;
    list-style: none;
}
.desk-menu > li { display: flex; align-items: stretch; }

.desk-link {
    display: flex;
    align-items: center;
    gap: .45rem;
    padding: 0 .8rem;
    border: 0;
    background: none;
    color: var(--app-ink);
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    border-bottom: 3px solid transparent;
    margin-bottom: -1px;
}
.desk-link .bi { font-size: 1.05rem; color: var(--app-muted); }
.desk-link:hover { color: var(--app-accent-text); }
.desk-link:hover .bi { color: var(--app-accent-text); }
.desk-link.active {
    color: var(--app-accent-text);
    font-weight: 700;
    border-bottom-color: var(--app-primary);
}
.desk-link.active .bi { color: var(--app-accent-text); }
.desk-link.dropdown-toggle::after { margin-left: .15rem; opacity: .6; }

/* Drop-down menus (Bootstrap .dropdown-menu, house look) */
.is-desktop .dropdown-menu {
    min-width: 15rem;
    padding: .4rem;
    border: 1px solid var(--app-line);
    border-radius: 14px;
    background: var(--app-surface);
    box-shadow: 0 12px 32px rgba(0, 0, 0, .12);
}
.is-desktop .dropdown-item {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .55rem .7rem;
    border-radius: 10px;
    color: var(--app-ink);
    font-weight: 500;
}
.is-desktop .dropdown-item .bi { color: var(--app-muted); font-size: 1.05rem; }
.is-desktop .dropdown-item small { display: block; color: var(--app-muted); font-weight: 400; }
.is-desktop .dropdown-item:hover,
.is-desktop .dropdown-item:focus { background: var(--app-field); color: var(--app-ink); }
.is-desktop .dropdown-item.active,
.is-desktop .dropdown-item:active { background: rgb(var(--app-primary-rgb) / .12); color: var(--app-accent-text); }
.is-desktop .dropdown-item.is-danger,
.is-desktop .dropdown-item.is-danger .bi { color: var(--app-alert); }
.is-desktop .dropdown-divider { border-color: var(--app-line); margin: .35rem .3rem; }
.is-desktop .dropdown-header { color: var(--app-muted); font-size: .78rem; font-weight: 700; padding: .4rem .7rem .2rem; }

/* Right-hand side: quick search + user */
.desk-tools {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: .75rem;
}
.desk-search {
    position: relative;
    width: 15rem;
}
.desk-search .bi {
    position: absolute;
    left: .75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--app-muted);
    pointer-events: none;
}
.desk-search input {
    width: 100%;
    height: 2.4rem;
    padding: 0 .75rem 0 2.2rem;
    border: 1px solid transparent;
    border-radius: 12px;
    background: var(--app-field);
    color: var(--app-ink);
}
.desk-search input:focus {
    outline: 0;
    border-color: var(--app-primary);
    box-shadow: 0 0 0 .2rem var(--bs-focus-ring-color);
    background: var(--app-surface);
}
.desk-user {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .2rem .35rem .2rem .2rem;
    border: 0;
    border-radius: 999px;
    background: none;
    color: var(--app-ink);
}
.desk-user:hover { background: var(--app-field); }
.desk-user .avatar { width: 2.1rem; height: 2.1rem; font-size: .8rem; }
.desk-user-name { font-weight: 600; font-size: .92rem; }

/* Small screens: menu button opens the sections in a slide-in panel */
.desk-menu-button {
    display: none;
    border: 0;
    background: none;
    color: var(--app-ink);
    font-size: 1.5rem;
    padding: .25rem .4rem;
    border-radius: 10px;
}
.desk-menu-button:hover { background: var(--app-field); }

@media (max-width: 1199.98px) {
    .desk-search { width: 11rem; }
    .desk-user-name { display: none; }
}
@media (max-width: 991.98px) {
    .desk-menu, .desk-search { display: none; }
    .desk-menu-button { display: inline-flex; }
}

/* The slide-in panel (small screens) */
.desk-drawer { width: min(320px, 88vw); background: var(--app-surface); }
.desk-drawer .offcanvas-body { display: flex; flex-direction: column; gap: .15rem; }
.desk-drawer-group { margin: .9rem .85rem .2rem; color: var(--app-muted); font-size: .78rem; font-weight: 700; }
.desk-drawer .sidebar-link { padding: .6rem .85rem; }


/* ==================================================================
   PAGE HEADER: title + summary on the left, actions on the right
   ================================================================== */
.desk-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .75rem 1.5rem;
    margin-bottom: 1.25rem;
}
.desk-head h1 {
    margin: 0;
    font-stretch: 112%;
    font-weight: 800;
    font-size: 1.75rem;
    letter-spacing: -.01em;
}
.desk-head p { margin: .2rem 0 0; color: var(--app-muted); }
.desk-head-actions { display: flex; flex-wrap: wrap; gap: .5rem; }

/* Compact buttons for office pages (same colours as the big ones) */
.btn-desk {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    padding: .5rem .95rem;
    border-radius: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.btn-desk.btn-main-action { width: auto; min-height: 0; font-size: 1rem; }
.btn-desk.btn-setup { min-height: 0; }

/* Breadcrumb above a record's header: Customers › Carter Builders */
.desk-crumbs {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
    margin-bottom: .5rem;
    font-size: .9rem;
    color: var(--app-muted);
    list-style: none;
    padding: 0;
}
.desk-crumbs li + li::before { content: "›"; margin-right: .35rem; }
.desk-crumbs a { color: var(--app-accent-text); text-decoration: none; font-weight: 600; }
.desk-crumbs a:hover { text-decoration: underline; }


/* ==================================================================
   SUMMARY FIGURES (a row of small cards above a list)
   ================================================================== */
.stat-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: .75rem;
    margin-bottom: 1.25rem;
}
.stat {
    padding: .9rem 1.1rem;
    border: 1px solid var(--app-line);
    border-radius: 16px;
    background: var(--app-surface);
    color: inherit;
    text-decoration: none;
}
a.stat:hover { border-color: var(--app-primary); }
.stat small { display: block; color: var(--app-muted); font-weight: 600; }
.stat strong { display: block; margin-top: .15rem; font-size: 1.5rem; font-weight: 800; font-stretch: 108%; }
.stat.is-alert strong { color: var(--app-alert); }
.stat.is-good strong { color: var(--app-accent-text); }


/* ==================================================================
   FILTER BAR (above a table): search + drop-downs + dates + Search
   ================================================================== */
.desk-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: .6rem;
    margin-bottom: .9rem;
    padding: .85rem;
    border: 1px solid var(--app-line);
    border-radius: 16px;
    background: var(--app-surface);
}
.desk-toolbar .form-label { margin-bottom: .2rem; font-size: .82rem; font-weight: 600; color: var(--app-muted); }
.desk-toolbar .form-control,
.desk-toolbar .form-select {
    height: 2.5rem;
    min-height: 0;
    padding-top: .3rem;
    padding-bottom: .3rem;
    border-radius: 12px;
    background-color: var(--app-field);
    border-color: transparent;
}
.desk-toolbar .grow { flex: 1 1 16rem; }
.desk-toolbar .tool { flex: 0 1 11rem; }
.desk-toolbar .tool-actions { display: flex; gap: .4rem; align-items: center; }
.desk-toolbar .form-check { margin: 0 0 .55rem; }


/* ==================================================================
   DATA TABLE
   <div class="table-card"><div class="table-wrap"><table class="data-table">…
   - th.sortable > button   : click to sort (table.js, or links for server sorting)
   - td.num / th.num        : numbers and money, right-aligned
   - tr[data-href]          : click selects, double-click / Enter opens
   - td.pick                : tick box for batch actions
   ================================================================== */
.table-card {
    border: 1px solid var(--app-line);
    border-radius: 16px;
    background: var(--app-surface);
    overflow: hidden;
}
.table-wrap { overflow-x: auto; }

.data-table {
    width: 100%;
    margin: 0;
    border-collapse: separate;
    border-spacing: 0;
    font-size: .94rem;
}
.data-table th,
.data-table td {
    padding: .62rem .8rem;
    border-bottom: 1px solid var(--app-line);
    vertical-align: middle;
    text-align: left;
}
.data-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--app-field);
    color: var(--app-muted);
    font-size: .8rem;
    font-weight: 700;
    white-space: nowrap;
}
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table .nowrap { white-space: nowrap; }
.data-table .muted { color: var(--app-muted); }
.data-table td strong { font-weight: 700; }
.data-table td small { display: block; color: var(--app-muted); }
.data-table .chip { margin: 0; }

/* Coloured stripe on the first cell, like list cards (--row-colour on the tr) */
.data-table tbody tr[style*="--row-colour"] td:first-child { box-shadow: inset 4px 0 0 var(--row-colour); }

/* Rows you can open */
.data-table tbody tr[data-href] { cursor: pointer; }
.data-table tbody tr:hover td { background: var(--desk-row-hover); }
.data-table tbody tr.is-selected td,
.data-table tbody tr.is-picked td { background: var(--desk-row-selected); }
.data-table tbody tr:focus-visible { outline: 2px solid var(--app-primary); outline-offset: -2px; }
.data-table tbody tr.is-void td { color: var(--app-muted); text-decoration: line-through; }
.data-table tbody tr.is-done td { color: var(--app-muted); }

/* Sorting */
.data-table th.sortable { padding: 0; }
.data-table th.sortable > button,
.data-table th.sortable > a {
    display: flex;
    align-items: center;
    gap: .3rem;
    width: 100%;
    padding: .62rem .8rem;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-decoration: none;
    white-space: nowrap;
}
.data-table th.sortable.num > button,
.data-table th.sortable.num > a { justify-content: flex-end; }
.data-table th.sortable > :hover { color: var(--app-accent-text); }
.data-table th.sortable > ::after {
    content: "\F127";                    /* bi-arrow-down-up */
    font-family: "bootstrap-icons";
    font-size: .75rem;
    opacity: .35;
}
.data-table th[aria-sort="ascending"] > ::after  { content: "\F148"; opacity: 1; color: var(--app-accent-text); }  /* bi-arrow-up */
.data-table th[aria-sort="descending"] > ::after { content: "\F128"; opacity: 1; color: var(--app-accent-text); }  /* bi-arrow-down */
.data-table th[aria-sort] { color: var(--app-accent-text); }

/* Tick boxes for batch actions */
.data-table .pick { width: 2.6rem; padding-right: 0; }
.data-table .pick .form-check-input { margin: 0; cursor: pointer; width: 1.1rem; height: 1.1rem; }

/* Small buttons at the end of a row */
.row-actions { display: flex; justify-content: flex-end; gap: .25rem; white-space: nowrap; }
.row-actions .icon-btn { width: 2rem; height: 2rem; font-size: .95rem; }

/* Totals row */
.data-table tfoot td {
    background: var(--app-field);
    font-weight: 700;
    border-top: 1px solid var(--app-line);
    border-bottom: 0;
}

/* Under the table: "Showing 1–50 of 320" + pager */
.table-foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: .7rem .9rem;
    border-top: 1px solid var(--app-line);
    color: var(--app-muted);
    font-size: .9rem;
}
.table-foot .pager { margin: 0; }

/* Nothing found: reuse .empty-state inside the card */
.table-card .empty-state { margin: 0; border: 0; border-radius: 0; }


/* ==================================================================
   BATCH ACTION BAR – appears when rows are ticked
   "3 invoices selected · £1,240.00   [Email] [Print] [Clear]"
   ================================================================== */
.bulk-bar {
    position: sticky;
    bottom: 1rem;
    z-index: 1020;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .6rem 1rem;
    margin-top: 1rem;
    padding: .7rem .9rem .7rem 1.1rem;
    border-radius: 16px;
    background: var(--app-grey);
    color: #FFFFFF;
    box-shadow: 0 14px 34px rgba(0, 0, 0, .22);
}
[data-bs-theme="dark"] .bulk-bar { background: #2F3334; }
.bulk-bar[hidden] { display: none; }
.bulk-count { font-weight: 700; }
.bulk-count small { font-weight: 500; opacity: .8; margin-left: .35rem; }
.bulk-actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: .4rem; }
.bulk-bar .btn-desk { border: 0; }
.bulk-bar .btn-bulk { background: rgba(255, 255, 255, .14); color: #FFFFFF; }
.bulk-bar .btn-bulk:hover { background: rgba(255, 255, 255, .24); color: #FFFFFF; }
.bulk-bar .btn-main-action { background: var(--app-primary-dark); color: #FFFFFF; }


/* ==================================================================
   RECORD PAGES: heading card + tabs
   ================================================================== */
.is-desktop .job-hero { margin-bottom: 1rem; }
.record-head-grid {
    display: grid;
    gap: 1rem;
    align-items: start;
}
@media (min-width: 992px) {
    .record-head-grid { grid-template-columns: minmax(0, 1fr) auto; }
}
.record-facts {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem 1.5rem;
    margin: .5rem 0 0;
    color: var(--app-muted);
}
.record-facts strong { color: var(--app-ink); font-weight: 600; }

.desk-tabs {
    display: flex;
    gap: .25rem;
    margin: 0 0 1.1rem;
    padding: 0;
    list-style: none;
    border-bottom: 1px solid var(--app-line);
    overflow-x: auto;
}
.desk-tabs .nav-link {
    display: flex;
    align-items: center;
    gap: .45rem;
    padding: .65rem .95rem;
    border: 0;
    border-bottom: 3px solid transparent;
    border-radius: 0;
    background: none;
    color: var(--app-muted);
    font-weight: 600;
    white-space: nowrap;
}
.desk-tabs .nav-link:hover { color: var(--app-ink); }
.desk-tabs .nav-link.active {
    color: var(--app-accent-text);
    border-bottom-color: var(--app-primary);
    background: none;
}
.desk-tabs .count {
    padding: .05rem .5rem;
    border-radius: 999px;
    background: var(--app-field);
    color: var(--app-muted);
    font-size: .78rem;
    font-weight: 700;
}
.desk-tabs .nav-link.active .count { background: rgb(var(--app-primary-rgb) / .14); color: var(--app-accent-text); }

/* A tab's own small header: "Sites · 3"  [Add site] */
.tab-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: .75rem;
}
.tab-head h2 { margin: 0; font-size: 1.1rem; font-weight: 700; }


/* ==================================================================
   SIDE PANEL (Bootstrap .offcanvas-end): view / edit one row without
   leaving the list. DIALOG (Bootstrap .modal): confirm, short forms.
   ================================================================== */
.side-panel { width: min(560px, 94vw) !important; background: var(--app-page); border-left: 1px solid var(--app-line); }
.side-panel .offcanvas-header {
    background: var(--app-surface);
    border-bottom: 1px solid var(--app-line);
    padding: 1rem 1.25rem;
}
.side-panel .offcanvas-title { font-weight: 800; font-stretch: 108%; }
.side-panel .offcanvas-body { padding: 1.1rem 1.25rem; }
.side-panel .detail-card { margin-bottom: 1rem; }
.side-panel-foot {
    display: flex;
    gap: .5rem;
    justify-content: flex-end;
    padding: .9rem 1.25rem;
    border-top: 1px solid var(--app-line);
    background: var(--app-surface);
}

.is-desktop .modal-content {
    border: 1px solid var(--app-line);
    border-radius: 18px;
    background: var(--app-surface);
}
.is-desktop .modal-header { border-bottom: 1px solid var(--app-line); padding: 1rem 1.25rem; }
.is-desktop .modal-title { font-weight: 800; font-stretch: 108%; }
.is-desktop .modal-body { padding: 1.1rem 1.25rem; }
.is-desktop .modal-footer { border-top: 1px solid var(--app-line); padding: .8rem 1.25rem; gap: .4rem; }
.is-desktop .modal-footer > * { margin: 0; }


/* ==================================================================
   FORMS on a PC: labels beside or above, several boxes per row
   ================================================================== */
.form-grid {
    display: grid;
    gap: .9rem 1rem;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-all { grid-column: 1 / -1; }
@media (max-width: 575.98px) {
    .form-grid .span-2 { grid-column: auto; }
}
.is-desktop .sheet-input { min-height: 2.75rem; }
.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--app-line);
}


/* ==================================================================
   KEYBOARD: visible focus everywhere, and shortcut hints
   ================================================================== */
.is-desktop :focus-visible { outline: 2px solid var(--app-primary); outline-offset: 2px; }
kbd.key {
    padding: .05rem .35rem;
    border: 1px solid var(--app-line);
    border-bottom-width: 2px;
    border-radius: 6px;
    background: var(--app-surface);
    color: var(--app-muted);
    font-size: .75rem;
    font-family: inherit;
}


/* ==================================================================
   PRINT: just the content, no menus or buttons
   ================================================================== */
@media print {
    .desk-topnav, .desk-head-actions, .desk-toolbar, .bulk-bar, .row-actions,
    .table-foot .pager, .data-table .pick, .no-print, .flash { display: none !important; }
    .is-desktop .app-content { max-width: none; padding: 0; }
    .app-page { background: #FFFFFF; }
    .table-card, .detail-card, .stat { border-color: #BBBBBB; break-inside: avoid; }
    .data-table thead th { position: static; background: #EEEEEE !important; color: #333333; }
    .data-table tbody tr:hover td { background: none; }
}
