/* =============================================================================
   The work pipeline screens: requests, quotes, jobs, invoices and payments
   =============================================================================

   One stylesheet rather than five isolated ones, on purpose. These five screens are one
   family — a dealer moves between them in a single sitting, converting a quote into a job
   into an invoice — and five copies of the same rules is how the quote screen ends up
   half a space narrower than the invoice screen and nobody can say which one is right.

   Everything is nested under .work-page so none of it leaks into Bootstrap or into the
   components that have their own isolated styles. Blazor's CSS isolation would scope these
   to one component only, which is exactly what must not happen here.

   Colours, spacing and type come from tokens.css. Nothing here invents a value.
   ========================================================================== */

.work-page {
    /* Wide enough for a line table with five columns, bounded so a 27-inch monitor does
       not stretch a description to half a metre. Left-aligned, as asked. */
    max-width: 1100px;
}

/* ---- Page heading ------------------------------------------------------------------- */

.work-page .page-head { margin-bottom: var(--space-5); }

.work-page .back {
    display: inline-block;
    margin-bottom: var(--space-2);
    font-size: var(--text-sm);
    color: var(--primary);
    text-decoration: none;
}

.work-page .page-head h1 {
    margin: 0;
    font-size: var(--text-2xl);
    font-weight: var(--weight-bold);
    color: var(--text);
}

.work-page .head-row {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--space-3);
}

.work-page .sub {
    margin: var(--space-2) 0 0;
    font-size: var(--text-sm);
    color: var(--text-muted);
}

/* ---- Banners ------------------------------------------------------------------------ */

.work-page .banner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    margin-bottom: var(--space-4);
    border-radius: var(--radius);
    font-size: var(--text-sm);
}

.work-page .banner.blocked { background: var(--overdue-bg);  border: 1px solid var(--overdue-border);  color: var(--overdue); }
.work-page .banner.warn    { background: var(--due-soon-bg); border: 1px solid var(--due-soon-border); color: var(--due-soon); }
.work-page .banner.ok      { background: var(--healthy-bg);  border: 1px solid var(--healthy-border);  color: var(--healthy); }

.work-page .banner button {
    min-height: var(--touch-min);
    margin-left: auto;
    padding: 0 var(--space-4);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    color: inherit;
    background: transparent;
    border: 1px solid currentColor;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

/* ---- Cards -------------------------------------------------------------------------- */

.work-page .card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: var(--space-4);
    margin-bottom: var(--space-4);
    min-width: 0;
}

.work-page .card h2 {
    margin: 0 0 var(--space-3);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.work-page .card-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
}

.work-page .card-head h2 { margin-bottom: var(--space-3); }

/* ---- Fields ------------------------------------------------------------------------- */

.work-page .grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--space-3);
}

.work-page label {
    display: block;
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
}

.work-page label.full { grid-column: 1 / -1; }

.work-page input,
.work-page textarea,
.work-page select {
    display: block;
    width: 100%;
    margin-top: var(--space-1);
    min-height: var(--touch-min);
    padding: var(--space-2) var(--space-3);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    text-transform: none;
    letter-spacing: normal;
}

.work-page textarea { min-height: auto; resize: vertical; }

.work-page input:focus,
.work-page textarea:focus,
.work-page select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--focus-ring);
}

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

.work-page .actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-top: var(--space-4);
}

.work-page .actions button,
.work-page .actions .btn {
    min-height: var(--touch-min);
    padding: 0 var(--space-4);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    cursor: pointer;

    /* An <a> styled as a button needs these to sit on the same line as a real one. */
    display: inline-flex;
    align-items: center;
    text-decoration: none;
}

.work-page .actions button.primary,
.work-page .actions .btn.primary {
    color: var(--on-primary);
    background: var(--primary);
    border-color: var(--primary);
}

.work-page .actions button.primary:hover { background: var(--primary-hover); }

.work-page .actions button.danger { color: var(--overdue); border-color: var(--overdue-border); }

/* Pushed right so a destructive action is never next to the one somebody reaches for. */
.work-page .actions .spacer { flex: 1 1 auto; }

.work-page .actions button:disabled,
.work-page .actions .btn.disabled { opacity: 0.6; cursor: default; }

.work-page .link {
    padding: 0;
    min-height: var(--touch-min);
    font-family: var(--font-body);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--primary);
    background: none;
    border: none;
    cursor: pointer;
}

.work-page .link:disabled { opacity: 0.5; cursor: default; }

/* A label a screen reader reads and a sighted user does not need, because the field sits
   under a heading that already says what it is. Removed from the flow rather than hidden:
   display:none would take it out of the accessibility tree as well, which defeats it. */
.work-page .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ---- Status pills ------------------------------------------------------------------- */

/* Status is the first thing read on every one of these rows: whether a quote is still out,
   whether a job is booked, whether an invoice has been paid. It gets colour, and the colours
   mean the same thing on every screen.

   The ONLY rules here not nested under .work-page, on purpose: the pipeline panel on the
   client page shows the same statuses and is not a work page. A second copy of these colours
   scoped to that component is how amber on one screen becomes grey on the other. */
.pill {
    display: inline-block;
    padding: 2px var(--space-3);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    white-space: nowrap;
    border-radius: var(--radius-pill);
    color: var(--unknown);
    background: var(--unknown-bg);
    border: 1px solid var(--unknown-border);
}

.pill.open    { color: var(--scheduled); background: var(--scheduled-bg); border-color: var(--scheduled-border); }
.pill.good    { color: var(--healthy);   background: var(--healthy-bg);   border-color: var(--healthy-border); }
.pill.waiting { color: var(--due-soon);  background: var(--due-soon-bg);  border-color: var(--due-soon-border); }
.pill.bad     { color: var(--overdue);   background: var(--overdue-bg);   border-color: var(--overdue-border); }

/* A void document is struck through as well as greyed: colour alone is not a message. */
.pill.dead { text-decoration: line-through; }

/* ---- Rows --------------------------------------------------------------------------- */

.work-page .rows { display: block; }

.work-page .rows .row {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--space-3);
    padding: var(--space-3) 0;
    border-top: 1px solid var(--border);
    text-decoration: none;
    color: inherit;
}

.work-page .rows .row:first-child { border-top: none; }

.work-page a.row:hover { background: var(--primary-subtle); }

.work-page .rows .row .number {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    color: var(--text-muted);
    min-width: 4rem;
}

.work-page .rows .row .what {
    flex: 1 1 12rem;
    min-width: 0;
    font-size: var(--text-sm);
    color: var(--text);
}

.work-page .rows .row .when {
    font-size: var(--text-xs);
    color: var(--text-subtle);
}

.work-page .rows .row .money {
    margin-left: auto;
    font-size: var(--text-sm);
    font-variant-numeric: tabular-nums;
    color: var(--text);
}

.work-page .empty { margin: 0; font-size: var(--text-sm); color: var(--text-subtle); }

.work-page .state { color: var(--text-muted); font-size: var(--text-sm); }

.work-page .state.error {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
    max-width: 520px;
    padding: var(--space-4);
    background: var(--overdue-bg);
    border: 1px solid var(--overdue-border);
    border-radius: var(--radius);
    color: var(--overdue);
}

/* ---- The balance strip -------------------------------------------------------------- */

.work-page .balance {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
    gap: var(--space-3);
}

.work-page .balance div {
    padding: var(--space-3);
    background: var(--surface-sunken);
    border-radius: var(--radius);
}

.work-page .balance dt {
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-subtle);
}

.work-page .balance dd {
    margin: var(--space-1) 0 0;
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
    font-variant-numeric: tabular-nums;
    color: var(--text);
}

/* What is owed is the figure somebody came to this screen for. */
.work-page .balance div.owing { background: var(--overdue-bg); }
.work-page .balance div.owing dd { color: var(--overdue); }

.work-page .balance div.settled { background: var(--healthy-bg); }
.work-page .balance div.settled dd { color: var(--healthy); }

/* ---- Confirming something that cannot be undone ------------------------------------- */

/* Carries the warning shown before a cancel is sent (scheduling.md SC-5a, AC-19d). It uses
   the due-soon palette rather than the overdue one on purpose: this is a decision being
   checked, not a failure being reported, and a red panel next to a Confirm button reads as
   something having already gone wrong. */
.work-page .confirm {
    background: var(--due-soon-bg);
    border: 1px solid var(--due-soon-border);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    margin-bottom: var(--space-4);
}

.work-page .confirm .note { margin-top: 0; color: var(--due-soon); }

/* Who is already booked, and when. SC-6 wants the clash named rather than counted, so this is
   a list of sentences and not a badge. */
.work-page .confirm .conflicts {
    margin: var(--space-3) 0 0;
    padding-left: var(--space-5);
    font-size: var(--text-sm);
    line-height: var(--leading-normal);
    color: var(--text);
}

.work-page .confirm .conflicts li + li { margin-top: var(--space-1); }

/* ---- Notes -------------------------------------------------------------------------- */

.work-page .note {
    margin: var(--space-3) 0 0;
    font-size: var(--text-xs);
    line-height: var(--leading-normal);
    color: var(--text-muted);
}

.work-page .facts {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-5);
    margin: 0;
}

.work-page .facts dt {
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-subtle);
}

.work-page .facts dd {
    margin: 2px 0 0;
    font-size: var(--text-sm);
    color: var(--text);
}

@media (max-width: 720px) {
    /* A row stops being a row: the number and status stay together on one line and the
       money drops below, because four columns at 375px wraps into something unreadable. */
    .work-page .rows .row { gap: var(--space-2); }
    .work-page .rows .row .what { flex-basis: 100%; }
    .work-page .rows .row .money { margin-left: 0; }
    .work-page .actions { gap: var(--space-2); }
    .work-page .actions button,
    .work-page .actions .btn { flex: 1 1 auto; justify-content: center; }
    .work-page .actions .spacer { display: none; }
}
