/* =============================================================================
 * LRES-UK Platform — main stylesheet
 *
 * Brand colours and typography per LRES-UK 2026 headed-paper standard
 * (see LRES-UK Global Instructions).
 *
 * v3 brand-direction primitives are layered ABOVE this file via the three
 * @imports below. They define new --v3-* tokens, opt-in utilities (.lres-*)
 * and component classes (.chip / .pill / .pill-small / .btn--primary etc.)
 * that activate when a page sets `data-brand="v3"` on its outer wrapper.
 * Existing classes in this file remain authoritative for legacy pages —
 * we migrate page-by-page; nothing here is removed yet.
 *
 * CSS @import must precede any other rules, so these stay at the very top.
 * ============================================================================= */

@import url('lres-v3-tokens.css');
@import url('lres-v3-base.css');
@import url('lres-v3-components.css');

:root {
    /* LRES brand colours — locked 14 May 2026 (reverted from BRG #0E4F33). */
    --lres-green: #009A42;            /* PRIMARY — v3 green (unified with --v3-green 22 May 2026; was #00B050). */
    --lres-values-green: #00B050;     /* values footer — kept matching primary for consistency */
    --lres-anthracite: #1F2937;       /* SECONDARY — replaces all legacy heading blues. */
    --lres-charcoal: #1F2937;         /* body anchor — anthracite */
    --lres-divider-grey: #BBBBBB;
    --lres-mid-grey: #6B7280;         /* secondary text, page nums */
    --lres-contact-grey: #9CA3AF;
    --lres-heading-1: #1F2937;        /* anthracite (was #1F4E79) */
    --lres-heading-2: #1F2937;        /* anthracite (was #2E75B6) */

    /* UI surfaces */
    --bg-page: #fafafa;
    --bg-surface: #ffffff;
    --border: #e5e5e5;
    --text-default: #1F2937;
    --text-muted: #6B7280;
}

* {
    box-sizing: border-box;
}

/* Make the [hidden] HTML attribute actually hide elements even when a more
 * specific rule sets display: flex/grid/block. Without this, .error-banner
 * (display: flex) would render visible despite hidden=""; same for .app,
 * .user-area, etc. Canonical fix for the HTML5 hidden-attribute specificity
 * trap. */
[hidden] {
    display: none !important;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    font-family: Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-default);
    background: var(--bg-page);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ----- Topbar ----- */

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 32px;
    background: var(--bg-surface);
    border-bottom: 3px solid var(--lres-green);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.brand {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* SVG wordmark — replaces the legacy .brand-name text span (22 May 2026 v3 topbar lift). */
.brand-lockup {
    height: 24px;
    width: auto;
    display: block;
}

/* Legacy — kept for graceful fallback; the span is now replaced by .brand-lockup img. */
.brand-name {
    font-family: var(--v3-t-display);
    font-weight: 800;
    font-size: 16px;
    color: var(--lres-green);
    letter-spacing: -0.01em;
}

.brand-divider {
    color: var(--lres-divider-grey);
}

.brand-tagline {
    font-family: var(--v3-t-display);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--v3-steel);
}

.user-area {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 13px;
}

.user-name {
    color: var(--text-muted);
}

/* ----- App shell (nav rail + main content) ----- */

.shell {
    flex: 1 0 auto;
    display: flex;
    align-items: stretch;
    width: 100%;
    /* Contain any residual child overflow so the page never scrolls sideways. */
    overflow-x: hidden;
}

/* ── Dark anthracite sidebar ─────────────────────────────────────────────── */

.nav-rail {
    flex: 0 0 220px;
    background: var(--lres-anthracite);   /* #1F2937 */
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    /* Custom scrollbar so it blends into dark bg */
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,.12) transparent;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 18px;
    color: rgba(255, 255, 255, 0.65);
    text-decoration: none;
    font-size: 13px;
    border-left: 3px solid transparent;
    transition: background 0.1s, border-color 0.1s, color 0.1s;
    line-height: 1.3;
}

.nav-link svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    opacity: 0.65;
    transition: opacity 0.1s;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
}

.nav-link:hover svg {
    opacity: 0.9;
}

.nav-link.active {
    border-left-color: var(--lres-green);
    background: rgba(0, 154, 66, 0.15);
    color: #fff;
    font-weight: 600;
}

.nav-link.active svg {
    opacity: 1;
}

.nav-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Section heading labels (Sales / Operations / Finance etc.) */
.nav-section {
    padding: 16px 18px 3px;
    font-size: 9.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.3px;
    color: rgba(255, 255, 255, 0.28);
    margin-top: 4px;
    user-select: none;
}

/* Division colour-coding — title text + a small left accent bar only.
   The individual nav tabs are deliberately left uncoloured. No blue family
   (brand rule); colours echo the per-page banner eyebrow. */
.nav-section--daily,
.nav-section--sales,
.nav-section--operations,
.nav-section--finance,
.nav-section--supply,
.nav-section--admin {
    position: relative;
    padding-left: 24px;
}
.nav-section--daily::before,
.nav-section--sales::before,
.nav-section--operations::before,
.nav-section--finance::before,
.nav-section--supply::before,
.nav-section--admin::before {
    content: "";
    position: absolute;
    left: 18px;
    top: 17px;
    width: 3px;
    height: 9px;
    border-radius: 2px;
    background: currentColor;
}
.nav-section--daily      { color: #4ade80; }  /* green (Daily = LRES brand) */
.nav-section--sales      { color: #86efac; }  /* green-muted (offset from Daily) */
.nav-section--operations { color: #fbbf24; }  /* amber  */
.nav-section--finance    { color: #2dd4bf; }  /* teal   */
.nav-section--supply     { color: #fb923c; }  /* copper */
.nav-section--admin      { color: #94a3b8; }  /* slate  */

/* Homepage quick-action pill buttons */
.home-qa-btn {
    padding: 9px 14px;
    font-size: 12px;
    font-weight: 600;
    color: #009A42;
    background: transparent;
    border: 1px solid rgba(0, 154, 66, 0.35);
    border-radius: 99px;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    width: 100%;
    letter-spacing: .01em;
}
.home-qa-btn:hover {
    background: #009A42;
    border-color: #009A42;
    color: #fff;
}

/* Notification / count badge on a nav item */
.nav-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    margin-left: auto;
    flex-shrink: 0;
}

/* Tagline footer at the bottom of the sidebar */
.nav-footer {
    margin-top: auto;
    padding: 14px 18px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.22);
    text-align: center;
    flex-shrink: 0;
}

/* ── Coming-soon stub page ────────────────────────────────────────────────── */

.module-stub {
    padding: 48px 40px;
}

.module-stub__title {
    font-size: 22px;
    font-weight: 700;
    color: var(--lres-anthracite);
    margin: 0 0 8px;
}

.module-stub__desc {
    color: var(--text-muted);
    font-size: 14px;
    margin: 0 0 24px;
    max-width: 480px;
    line-height: 1.6;
}

.module-stub__pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    background: #f0fdf4;
    border: 1px solid var(--lres-green);
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--lres-green);
}

/* ----- Main content ----- */

.container {
    flex: 1 1 auto;
    /* min-width:0 lets this flex child shrink below its content's intrinsic
       width — without it a wide grid/table forces the whole shell wider than
       the viewport (the constant horizontal scroll on smaller laptops). */
    min-width: 0;
    width: 100%;
    max-width: 1100px;
    margin: 32px auto;
    padding: 0 32px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-top: 3px solid var(--lres-green);
    padding: 28px 32px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.card h1 {
    font-family: Arial, sans-serif;
    font-size: 22px;
    font-weight: bold;
    color: var(--lres-heading-1);
    margin: 0 0 8px;
}

.card h2 {
    font-family: Arial, sans-serif;
    font-size: 16px;
    font-weight: bold;
    color: var(--lres-heading-2);
    margin: 0 0 6px;
}

.subtitle {
    margin: 0 0 20px;
    color: var(--text-muted);
    font-size: 13px;
}

/* ----- Meta grid (key/value) ----- */

.meta-grid {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 8px 24px;
    margin: 0;
    font-size: 14px;
}

.meta-grid dt {
    color: var(--text-muted);
    font-weight: normal;
}

.meta-grid dd {
    margin: 0;
    color: var(--text-default);
    font-family: 'Courier New', Consolas, monospace;
    font-size: 13px;
    word-break: break-all;
}

/* ----- Data table ----- */

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th {
    text-align: left;
    padding: 10px 12px;
    background: #f6f6f6;
    color: var(--text-muted);
    font-weight: bold;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
}

.data-table td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tr:hover td {
    background: #fafafa;
}

.data-table tr.row-clickable {
    cursor: pointer;
}

.data-table tr.row-clickable:hover td {
    background: #f0f8f3;
}

.muted {
    color: var(--text-muted);
    font-size: 12px;
}

.row-count {
    margin-top: 12px;
    margin-bottom: 0;
}

/* ----- Page header (title + breadcrumb) ----- */

.page-header {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 4px;
}

/* ── When the shared applyPageBanner is visible, suppress the per-page
 * duplicate title and top breadcrumb. Action buttons (.page-header-actions)
 * and deeper detail-page breadcrumbs stay visible.                      ── */
#pageBanner:not([hidden]) ~ #routeOutlet .page-title,
#pageBanner:not([hidden]) ~ #routeOutlet .page-header > .breadcrumb,
#pageBanner:not([hidden]) ~ #routeOutlet .page-header > nav.breadcrumb,
#pageBanner:not([hidden]) ~ #routeOutlet .module-stub__title {
    display: none !important;
}

.breadcrumb {
    font-size: 12px;
    color: var(--text-muted);
}

.breadcrumb a {
    color: var(--lres-heading-2);
    text-decoration: none;
}

.breadcrumb a:hover {
    text-decoration: underline;
}

.breadcrumb .sep {
    color: var(--lres-divider-grey);
    margin: 0 6px;
}

.page-title {
    font-family: Arial, sans-serif;
    font-size: 24px;
    font-weight: bold;
    color: var(--lres-heading-1);
    margin: 0;
}

/* ----- Key/value grid for detail pages ----- */

.kv-grid {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 10px 32px;
    margin: 0;
    font-size: 14px;
}

.kv-grid dt {
    color: var(--text-muted);
    font-weight: normal;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    align-self: center;
}

.kv-grid dd {
    margin: 0;
    color: var(--text-default);
}

/* ----- Empty state ----- */

.empty-state {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-muted);
    font-size: 13px;
    background: #fafafa;
    border: 1px dashed var(--border);
}

/* ----- Stage badges (Opportunities table) ----- */

.stage-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: bold;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    border: 1px solid transparent;
    white-space: nowrap;
}

/* enquiry — neutral grey */
.stage-badge.stage-enquiry {
    background: #eef0f2;
    color: #555;
    border-color: #d8dce0;
}

/* quoted — anthracite, "in flight with the client" */
.stage-badge.stage-quoted {
    background: #F3F4F6;
    color: #1F2937;
    border-color: #D1D5DB;
}

/* po-received — LRES brand green, "won" */
.stage-badge.stage-po-received {
    background: #e6f6ec;
    color: #0a6b30;
    border-color: #b6e0c4;
}

/* lost — red */
.stage-badge.stage-lost {
    background: #fbeaea;
    color: #8a2723;
    border-color: #f0c5c2;
}

/* withdrawn — muted grey, italic */
.stage-badge.stage-withdrawn {
    background: #f5f5f5;
    color: #888;
    border-color: #e0e0e0;
    font-style: italic;
}

/* ----- Inline error (route-level, not the top-level banner) ----- */

.route-error {
    background: #fff4f4;
    border-left: 3px solid #d9534f;
    padding: 14px 16px;
    color: #8a2723;
    font-size: 13px;
    margin: 0 0 16px;
}

/* ----- Loading / error / spinner ----- */

.loading {
    text-align: center;
    padding: 80px 16px;
    color: var(--text-muted);
}

.loading p {
    margin-top: 16px;
    font-size: 14px;
}

.spinner {
    width: 56px;
    height: 56px;
    margin: 0 auto;
    /* Unified with the brand motion system: same droplet artwork (handoff PNG),
       painted in LRES green via mask. Keeps legacy .spinner sites on-brand and
       consistent with the .lres-loader-fill page loaders. */
    background: #00B050;
    -webkit-mask: url('/motion/assets/droplet.png') center / contain no-repeat;
            mask: url('/motion/assets/droplet.png') center / contain no-repeat;
    animation: lres-pulse 1.6s ease-in-out infinite;
}

@keyframes lres-pulse {
    0%, 100% { opacity: 1;   transform: scale(1);    }
    50%       { opacity: 0.5; transform: scale(0.82); }
}

.error-banner {
    background: #fff4f4;
    border: 1px solid #f5c6cb;
    border-left: 3px solid #d9534f;
    padding: 16px 20px;
    color: #8a2723;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.error-banner strong {
    color: #6b1a17;
}

/* ----- Buttons ----- */

.btn {
    font-family: Arial, sans-serif;
    font-size: 13px;
    padding: 6px 14px;
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-default);
    cursor: pointer;
    border-radius: 2px;
    transition: background 0.1s, border-color 0.1s;
}

.btn:hover {
    background: #f3f3f3;
    border-color: #ccc;
}

.btn-ghost {
    border-color: var(--border);
    color: var(--text-muted);
}

/* Smaller variant — used inline next to a panel heading or row content. */
.btn-sm {
    font-size: 12px;
    padding: 3px 10px;
}

/* Quiet, low-contrast link — used on row-level actions (e.g. "Edit" link
   on a contact row in the contacts panel). Underlines on hover only. */
.link-quiet {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 12px;
}
.link-quiet:hover {
    color: var(--lres-green);
    text-decoration: underline;
}

/* Narrow trailing column for row-level action links. Keeps the column
   from expanding to fill leftover horizontal space. */
.row-action {
    width: 1%;
    white-space: nowrap;
    text-align: right;
}

/* Card panels that have a heading + an action button on the same row.
   Wraps the existing <h2> and a sibling button/link element. */
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}
.card-header h2 {
    margin: 0;
}

/* ----- Footer ----- */

.footer {
    flex-shrink: 0;
    padding: 16px 32px;
    border-top: 1px solid var(--lres-green);
    text-align: center;
    font-family: Calibri, Arial, sans-serif;
    font-size: 11px;
    color: var(--lres-contact-grey);
    background: var(--bg-surface);
    line-height: 1.7;
}

.footer-values {
    color: var(--lres-values-green);
    font-style: italic;
    font-size: 12px;
}

.footer-values strong {
    color: var(--lres-values-green);
}

.footer-contact {
    color: var(--lres-contact-grey);
    margin-top: 4px;
}

/* =============================================================================
 * Opportunities — view toggle (Board | Table) and Kanban board
 * (added Day 4)
 * ============================================================================= */

/* Header row that holds the page title alongside the view toggle */
.page-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

/* Group of action buttons on the right side of a page-header-row.
   Used when a page has more than one action (e.g. Edit + New opportunity). */
.page-header-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

/* RAMS template picker — select + button as a single grouped control on the
   Job detail page. The picker chooses which task pack drives the rendered
   docx; the button triggers POST /jobs/:id/rams/generate. */
.rams-picker {
    display: inline-flex;
    align-items: stretch;
    gap: 0;
}
.rams-picker-select {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    border-right: 0;
    min-width: 220px;
}
.rams-picker .btn {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

.page-summary {
    margin: 4px 0 0 0;
    font-size: 13px;
}

/* ----- View toggle (two buttons act as a segmented control) ----- */

.view-toggle {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 2px;
    overflow: hidden;
}

.view-toggle .btn {
    border: 0;
    border-radius: 0;
    padding: 6px 16px;
    font-size: 13px;
    background: var(--bg-surface);
}

.view-toggle .btn + .btn {
    border-left: 1px solid var(--border);
}

.view-toggle .btn.active {
    background: var(--lres-heading-1);
    color: #fff;
}

.view-toggle .btn.active:hover {
    background: var(--lres-heading-2);
}

/* ----- Kanban board ----- */

.kanban-board {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-top: 8px;
}

@media (max-width: 1100px) {
    .kanban-board { grid-template-columns: 1fr; }
}

.kanban-column {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    min-height: 200px;
    /* Each column stripe gets a top border in the stage colour. Default is
     * neutral; specific stages overridden below. */
    border-top: 3px solid var(--lres-divider-grey);
}

.kanban-col-enquiry     { border-top-color: #b6b6b6; }
.kanban-col-quoted      { border-top-color: var(--lres-heading-2); }
.kanban-col-po-received { border-top-color: var(--lres-green); }

.kanban-column-header {
    padding: 12px 16px 10px 16px;
    border-bottom: 1px solid var(--border);
}

.kanban-column-title {
    font-family: Arial, sans-serif;
    font-size: 14px;
    font-weight: bold;
    color: var(--lres-heading-1);
    margin: 0 0 4px 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.kanban-column-stats {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 12px;
    color: var(--text-muted);
}

.kanban-column-total {
    font-weight: bold;
    color: var(--text-default);
}

.kanban-column-body {
    padding: 8px;
    /* Cap the column at viewport-ish height; large stages (380 cards) scroll
     * inside their own column rather than blowing out the page. */
    max-height: 70vh;
    overflow-y: auto;
}

.kanban-column-empty {
    padding: 24px 8px;
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
}

/* ----- Kanban card ----- */

.kanban-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 10px 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: box-shadow 0.1s, border-color 0.1s, transform 0.05s;
    display: block;
}

.kanban-card:last-child {
    margin-bottom: 0;
}

.kanban-card:hover {
    border-color: var(--lres-heading-2);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
    transform: translateY(-1px);
}

.kanban-card-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 4px;
}

.kanban-card-ref {
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 11px;
    color: var(--text-muted);
}

.kanban-card-value {
    font-weight: bold;
    font-size: 13px;
    color: var(--lres-heading-1);
}

.kanban-card-name {
    font-size: 13px;
    font-weight: bold;
    color: var(--text-default);
    line-height: 1.35;
    margin: 2px 0 6px 0;
    /* Long names truncate to two lines so cards stay roughly equal-height */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.kanban-card-meta {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    font-size: 11px;
    color: var(--text-muted);
}

.kanban-card-company {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    flex: 1;
}

.kanban-card-due {
    flex-shrink: 0;
}

/* Salesperson chip — small rounded square with 1-2 letter initials.
 * Sits between the company name and the due date. Lives on Kanban cards
 * AND inline in the opp detail Salesperson row (with the full name beside it). */
.kanban-card-owner {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 4px;
    background: var(--lres-heading-2);
    color: #fff;
    font-size: 9px;
    font-weight: bold;
    letter-spacing: 0.3px;
    border-radius: 11px;
    flex-shrink: 0;
    cursor: default;
    /* Kill the user-select highlight on accidental clicks */
    user-select: none;
}

/* ----- Lost + Withdrawn collapsed section ----- */

.kanban-collapsed-section {
    margin-top: 24px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 4px;
}

.kanban-collapsed-section > summary {
    list-style: none;
    cursor: pointer;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: var(--text-muted);
}

.kanban-collapsed-section > summary::-webkit-details-marker { display: none; }

.kanban-collapsed-section > summary::before {
    content: '▸';
    margin-right: 8px;
    color: var(--lres-divider-grey);
    font-size: 11px;
}

.kanban-collapsed-section[open] > summary::before {
    content: '▾';
}

.kanban-collapsed-title {
    font-weight: bold;
    color: var(--text-default);
}

.kanban-collapsed-stats {
    color: var(--text-muted);
}

.kanban-collapsed-body {
    padding: 12px 16px 16px 16px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 8px;
    border-top: 1px solid var(--border);
}

.kanban-collapsed-body .kanban-card {
    margin-bottom: 0;
    /* Lost/withdrawn cards sit slightly muted */
    opacity: 0.85;
}

/* =============================================================================
 * Forms (Cluster 5 — POST /opportunities)
 *
 * Two-column label/field grid like the existing kv-grid on detail pages, but
 * editable. Validation errors render as a single red callout above the action
 * row. Spans-2 utility lets a single field stretch the full grid width
 * (used for the error block and the action row).
 * ============================================================================= */

.form-grid {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 14px 24px;
    align-items: center;
    margin: 0;
}

.form-label {
    color: var(--text-muted);
    font-weight: normal;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-label .required {
    color: #b91c1c;
    margin-left: 2px;
}

.form-input {
    font-family: Arial, sans-serif;
    font-size: 14px;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 2px;
    background: var(--bg-surface);
    color: var(--text-default);
    width: 100%;
    max-width: 480px;
    transition: border-color 0.1s, box-shadow 0.1s;
}

.form-input:focus {
    outline: none;
    border-color: var(--lres-heading-2);
    box-shadow: 0 0 0 3px rgba(46, 117, 182, 0.12);
}

.form-input:invalid {
    border-color: #d9534f;
}

.form-textarea {
    max-width: none;
    resize: vertical;
    min-height: 80px;
    font-family: Arial, sans-serif;
}

/* Inline checkbox + helper-label row, used where a single boolean field
   needs an explanatory caption next to it (e.g. is_primary on contacts). */
.form-checkbox-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.form-checkbox {
    width: 16px;
    height: 16px;
    cursor: pointer;
    flex-shrink: 0;
}
.form-checkbox-help {
    font-size: 12px;
    cursor: pointer;
    text-transform: none;
    letter-spacing: 0;
}

/* ----- Documents panel + upload form -----
   The Documents card lives under existing detail panels (company / opp).
   Upload form is collapsed by default behind the "+ Upload" button. */

.doc-upload-form {
    border: 1px dashed var(--border);
    background: #fafafa;
    padding: 14px 16px;
    margin-bottom: 12px;
    border-radius: 2px;
}

.doc-upload-grid {
    display: grid;
    grid-template-columns: 100px 1fr;
    gap: 10px 16px;
    align-items: center;
}

.doc-upload-hint {
    font-size: 11px;
    margin: 8px 0 0 0;
}

.doc-upload-actions {
    border-top: none;
    padding-top: 6px;
    margin-top: 4px;
}

/* The Download button on each row is rendered as a <button> styled like
   .link-quiet. Reset native button chrome so it inherits link styling. */
button.link-quiet {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    font-family: inherit;
}

.loading-inline {
    padding: 12px 0;
    font-size: 13px;
}

/* ----- Quote status pills ----- */

.quote-status {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border: 1px solid;
}
.quote-status-draft       { color: #666;     border-color: #ccc;     background: #f5f5f5; }
.quote-status-sent        { color: #1F2937;  border-color: #D1D5DB;  background: #F3F4F6; }
.quote-status-accepted    { color: #1f6f3f;  border-color: #b9e3c8;  background: #ecf8f0; }
.quote-status-rejected    { color: #8a2723;  border-color: #f3c1bd;  background: #fdecea; }
.quote-status-superseded  { color: #6a4d00;  border-color: #f0d999;  background: #fcf3dc; }
.quote-status-expired     { color: #6a4d00;  border-color: #f0d999;  background: #fcf3dc; }

/* ----- Job status pills (mirrors quote status, different lifecycle) ----- */

.job-status {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border: 1px solid;
}
.job-status-planned       { color: #1F2937;  border-color: #D1D5DB;  background: #F3F4F6; }
.job-status-mobilising    { color: #1F2937;  border-color: #D1D5DB;  background: #F3F4F6; }
.job-status-in-progress   { color: #6a4d00;  border-color: #f0d999;  background: #fcf3dc; }
.job-status-complete      { color: #1f6f3f;  border-color: #b9e3c8;  background: #ecf8f0; }
.job-status-invoiced      { color: #ffffff;  border-color: #00B050;  background: #00B050; }
.job-status-closed        { color: #ffffff;  border-color: #00B050;  background: #00B050; }
.job-status-cancelled     { color: #666;     border-color: #ccc;     background: #f5f5f5; }

/* ----- GPM% colour pills (used on quote rows + builder totals) ----- */

.gpm-pill {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 10px;
    font-weight: bold;
    font-size: 12px;
    border: 1px solid;
}
.gpm-red    { color: #8a2723; border-color: #f3c1bd; background: #fdecea; }
.gpm-amber  { color: #6a4d00; border-color: #f0d999; background: #fcf3dc; }
.gpm-green  { color: #1f6f3f; border-color: #b9e3c8; background: #ecf8f0; }
.gpm-none   { color: #888;    border-color: #ddd;    background: #f5f5f5; }

/* ----- Quote view page totals row in the lines table ----- */

.totals-row td {
    border-top: 2px solid var(--lres-green);
    background: #fafafa;
    font-weight: bold;
}
.totals-row .totals-label {
    text-align: right;
}

/* ----- Quote builder: line editor table ----- */

.line-editor-table input.line-input {
    font-family: Arial, sans-serif;
    font-size: 13px;
    padding: 4px 6px;
    border: 1px solid var(--border);
    border-radius: 2px;
    background: var(--bg-surface);
    color: var(--text-default);
    width: 100%;
}
.line-editor-table input.line-input:focus {
    outline: none;
    border-color: var(--lres-heading-2);
    box-shadow: 0 0 0 2px rgba(46, 117, 182, 0.12);
}
.line-editor-table .line-desc { min-width: 240px; }
.line-editor-table .line-num  { width: 90px;  text-align: right; }
.line-editor-table .line-unit { width: 80px; }
.line-editor-table .line-total { text-align: right; padding: 6px 8px; }

/* ----- Quote builder: live totals strip ----- */

.quote-totals {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 2px solid var(--lres-green);
}
.totals-grid {
    display: flex;
    gap: 32px;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
}
.totals-cell {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    font-size: 14px;
}
.totals-cell .muted {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ----- Rate card picker ----- */

.rate-card-picker {
    border: 1px dashed var(--border);
    background: #fafafa;
    padding: 12px 14px;
    margin-bottom: 14px;
    border-radius: 2px;
}
.rate-card-search-row {
    margin-bottom: 10px;
}
.rate-card-table {
    font-size: 12px;
}
.rate-card-table th {
    font-size: 11px;
}

/* Rate card grouped sections */
.rc-group {
    border: 1px solid var(--border);
    border-radius: 2px;
    margin-bottom: 6px;
    background: #fff;
}
.rc-group summary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary, #555);
    list-style: none;
    user-select: none;
    background: #f5f5f5;
    border-radius: 2px;
}
.rc-group summary::-webkit-details-marker { display: none; }
.rc-group summary::before {
    content: '▶';
    font-size: 9px;
    transition: transform 0.1s;
    color: var(--text-tertiary, #999);
    flex-shrink: 0;
}
.rc-group[open] summary::before { transform: rotate(90deg); }
.rc-group-count {
    margin-left: auto;
    font-size: 11px;
    font-weight: 400;
    color: var(--text-tertiary, #999);
}
.rc-group .rate-card-table {
    margin: 0;
    border-top: 1px solid var(--border);
}
.rc-group .rate-card-table td,
.rc-group .rate-card-table th {
    padding: 5px 8px;
}
.rc-group-more {
    font-size: 11px;
    color: var(--text-tertiary, #999);
    padding: 4px 10px 6px;
}

/* ----- Form-actions card (used on quote builder; just spacing) ----- */

.form-actions-card .form-actions {
    border-top: none;
    padding-top: 0;
    margin-top: 0;
}

/* ----- Search bar above list views (companies, contacts) -----
   Sits above the data table inside the same card. Single text input
   that filters the table client-side as the user types. */

.search-bar {
    margin-bottom: 14px;
}

.search-input {
    font-family: Arial, sans-serif;
    font-size: 14px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 2px;
    background: var(--bg-surface);
    color: var(--text-default);
    width: 100%;
    max-width: 480px;
    transition: border-color 0.1s, box-shadow 0.1s;
}

.search-input:focus {
    outline: none;
    border-color: var(--lres-heading-2);
    box-shadow: 0 0 0 3px rgba(46, 117, 182, 0.12);
}

/* Native search-input clear (X) — keep visible; browsers vary. */
.search-input::-webkit-search-cancel-button {
    cursor: pointer;
}

.form-error {
    grid-column: 1 / -1;
    background: #fff4f4;
    border-left: 3px solid #d9534f;
    color: #8a2723;
    padding: 10px 14px;
    font-size: 13px;
    border-radius: 2px;
}

.form-actions {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    margin-top: 8px;
}

/* ----- Primary button (used for the Create / Save action) ----- */

.btn-primary {
    background: var(--lres-green);
    color: #fff;
    border-color: var(--lres-green);
    font-weight: bold;
    text-decoration: none;       /* anchor variant */
    display: inline-block;
}

.btn-primary:hover {
    background: var(--lres-values-green);
    border-color: var(--lres-values-green);
    color: #fff;
}

.btn-primary:disabled,
.btn-primary[disabled] {
    background: #b8d8c4;
    border-color: #b8d8c4;
    cursor: not-allowed;
}

/* ----- Mobile / narrow viewport ----- */
@media (max-width: 720px) {
    .form-grid {
        grid-template-columns: 1fr;
        gap: 4px 0;
    }
    .form-label {
        margin-top: 8px;
    }
}

/* =============================================================================
 * Drag-drop on Kanban cards (Cluster 7)
 *
 * The cursor: grab makes it obvious the card is interactive even before drag
 * starts. .dragging fades the card while it's being moved. .drag-over on a
 * column body draws a dashed border in the column's stage colour, telling
 * the user "drop here". The transient-error toast appears bottom-right when
 * a PATCH fails — auto-dismisses after 5s.
 * ============================================================================= */

.kanban-card[draggable="true"] {
    cursor: grab;
}

.kanban-card[draggable="true"]:active {
    cursor: grabbing;
}

.kanban-card.dragging {
    opacity: 0.45;
    /* Hovering the card hover styles during drag would flash; suppress them */
    border-color: var(--border);
    box-shadow: none;
    transform: none;
}

.kanban-column-body {
    /* Reserve the dashed-border space at all times so adding the .drag-over
     * class doesn't shift the layout when the cursor enters. */
    border: 2px dashed transparent;
    border-radius: 3px;
    transition: background 0.1s, border-color 0.1s;
}

.kanban-column-body.drag-over {
    background: rgba(0, 176, 80, 0.04);
}

/* Per-stage drag-over border colour — matches each column's top-stripe */
.kanban-col-enquiry     .kanban-column-body.drag-over { border-color: #6b7280; background: rgba(107, 114, 128, 0.05); }
.kanban-col-quoted      .kanban-column-body.drag-over { border-color: var(--lres-heading-2); background: rgba(46, 117, 182, 0.05); }
.kanban-col-po-received .kanban-column-body.drag-over { border-color: var(--lres-green);    background: rgba(0, 176, 80, 0.05); }

/* ----- Transient error toast (bottom-right, auto-fade) ----- */

.transient-error {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: #fff4f4;
    border-left: 3px solid #d9534f;
    color: #8a2723;
    padding: 12px 18px;
    border-radius: 2px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    z-index: 9999;
    font-size: 13px;
    max-width: 420px;
    /* Slide in from below */
    animation: toast-in 0.18s ease-out;
}

.transient-success {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: #ecf8f0;
    border-left: 3px solid var(--lres-green);
    color: #1f6f3f;
    padding: 12px 18px;
    border-radius: 2px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    z-index: 9999;
    font-size: 13px;
    max-width: 420px;
    animation: toast-in 0.18s ease-out;
}

@keyframes toast-in {
    from { transform: translateY(12px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

/* =============================================================================
 * Fleet / Resources Vehicles tab
 * ============================================================================= */

.fleet-panel {
    padding: 0 4px;
}

.fleet-toolbar {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 14px;
    padding: 10px 0;
}

.fleet-toolbar .srch-input {
    flex: 1 1 200px;
    min-width: 160px;
    padding: 7px 10px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    font-size: 12px;
}

.fleet-toolbar .filter-sel {
    padding: 7px 10px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    font-size: 12px;
    background: #fff;
    cursor: pointer;
}

.fleet-alerts {
    margin-bottom: 12px;
}

/* Card grid */
.fleet-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
    margin-top: 4px;
}

.fleet-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: box-shadow 0.15s, border-color 0.15s;
}

.fleet-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.09);
    border-color: #009A42;
}

.fleet-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}

.fleet-card-reg {
    font-size: 17px;
    font-weight: 800;
    color: #1F2937;
    letter-spacing: 0.03em;
}

.fleet-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 7px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 700;
    white-space: nowrap;
}

.fleet-card-meta {
    font-size: 11px;
    color: #6B7280;
}

.fleet-card-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #374151;
}

.fleet-card-label {
    font-size: 10px;
    font-weight: 700;
    color: #9CA3AF;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    min-width: 56px;
}

.fleet-card-actions {
    display: flex;
    gap: 6px;
    margin-top: 6px;
    flex-wrap: wrap;
}

.fleet-card-btn {
    padding: 3px 10px;
    border: 1px solid #009A42;
    border-radius: 5px;
    background: #fff;
    color: #009A42;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}

.fleet-card-btn:hover {
    background: #009A42;
    color: #fff;
}

.fleet-card-btn--warn {
    border-color: #D97706;
    color: #D97706;
}

.fleet-card-btn--warn:hover {
    background: #D97706;
    color: #fff;
}

/* =============================================================================
 * Vehicle Popout & People Card — global overlay modals
 * ============================================================================= */

.vehicle-popout-overlay,
.people-card-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.vehicle-popout-panel {
    background: #fff;
    border-radius: 14px;
    width: 100%;
    max-width: 860px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.22);
    overflow: hidden;
}

.people-card-panel {
    background: #fff;
    border-radius: 14px;
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.22);
    overflow: hidden;
}

.popout-header {
    background: #1F2937;
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-shrink: 0;
}

.popout-title {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.vp-reg {
    font-size: 18px;
    font-weight: 800;
    color: #fff;
    letter-spacing: 0.04em;
}

.vp-make-model {
    font-size: 13px;
    color: #9CA3AF;
}

.popout-close {
    background: none;
    border: none;
    color: #9CA3AF;
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    line-height: 1;
    transition: color 0.12s;
}

.popout-close:hover {
    color: #fff;
}

.popout-tabs {
    display: flex;
    gap: 0;
    background: #F9FAFB;
    border-bottom: 1px solid #e5e7eb;
    overflow-x: auto;
    flex-shrink: 0;
}

.popout-tab {
    padding: 10px 16px;
    border: none;
    background: none;
    font-size: 12px;
    font-weight: 600;
    color: #6B7280;
    cursor: pointer;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    transition: color 0.12s, border-color 0.12s;
}

.popout-tab:hover {
    color: #1F2937;
}

.popout-tab.active {
    color: #009A42;
    border-bottom-color: #009A42;
    background: #fff;
}

.popout-body {
    overflow-y: auto;
    flex: 1;
    padding: 20px;
}

/* Popout internal layout helpers */
.vp-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

@media (max-width: 640px) {
    .vp-grid-2 { grid-template-columns: 1fr; }
}

.vp-section {
    background: #F9FAFB;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 12px 16px;
}

.vp-section-title {
    font-size: 11px;
    font-weight: 700;
    color: #6B7280;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 10px;
}

.vp-detail-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    font-size: 12px;
    border-bottom: 1px solid #f3f4f6;
}

.vp-detail-row:last-child {
    border-bottom: none;
}

.vp-detail-label {
    font-size: 11px;
    font-weight: 600;
    color: #9CA3AF;
    min-width: 110px;
    flex-shrink: 0;
}

/* Service history timeline */
.vp-timeline {
    position: relative;
    padding-left: 20px;
}

.vp-timeline::before {
    content: '';
    position: absolute;
    left: 6px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: #e5e7eb;
}

.vp-timeline-item {
    position: relative;
    margin-bottom: 14px;
}

.vp-timeline-dot {
    position: absolute;
    left: -17px;
    top: 3px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #009A42;
    border: 2px solid #fff;
    box-shadow: 0 0 0 2px #e5e7eb;
}

.vp-timeline-body {
    background: #F9FAFB;
    border: 1px solid #e5e7eb;
    border-radius: 7px;
    padding: 9px 12px;
    font-size: 12px;
}

/* ==========================================================================
   MAB-001 Agent A2 — job-page panels hosted inside the job card.
   The lifecycle rail, shift programme, field link, approvals and "More"
   panels were ported off the retired #/jobs/:uuid page unchanged, so they
   still emit <section class="card">. Inside the card overlay that reads as a
   card-in-a-card: strip the page-level chrome and tighten the padding.
   ========================================================================== */
#lresCardContent .card {
    border: none;
    border-top: none;
    box-shadow: none;
    padding: 0 0 4px;
    background: transparent;
}

#lresCardContent .card + .card {
    margin-top: 18px;
    border-top: 1px solid var(--border);
    padding-top: 16px;
}

#lresCardContent .card h2 {
    font-size: 13px;
    font-weight: 800;
    letter-spacing: .02em;
    margin: 0 0 8px;
}
