/* ==========================================================================
   Vehicle Maintenance - shared styles

   Phase 1 commits to writing our own CSS rather than relying entirely on a
   framework. Bootstrap may be added later for larger pages; these base styles
   stay small and readable.
   ========================================================================== */

:root {
    --colour-text:       #1f2933;
    --colour-muted:      #6b7785;
    --colour-border:     #d7dde3;
    --colour-background: #f4f6f8;
    --colour-surface:    #ffffff;
    --colour-primary:    #1a56a0;
    --colour-error-bg:   #fdecea;
    --colour-error-text: #8a1c13;
    --colour-ok-bg:      #e8f5ec;
    --colour-ok-text:    #1d5c33;
    --radius:            8px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--colour-text);
    background: var(--colour-background);
}

/* A page with one card in the middle, used for sign-in. */
.centered-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.card {
    width: 100%;
    max-width: 380px;
    padding: 32px;
    background: var(--colour-surface);
    border: 1px solid var(--colour-border);
    border-radius: var(--radius);
}

.card-title {
    margin: 0 0 4px;
    font-size: 22px;
}

.card-subtitle {
    margin: 0 0 24px;
    color: var(--colour-muted);
    font-size: 14px;
}

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */

label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 600;
}

input[type="email"],
input[type="password"],
input[type="text"],
input[type="number"],
textarea,
select {
    display: block;
    width: 100%;
    margin-bottom: 18px;
    padding: 10px 12px;
    font-size: 15px;
    font-family: inherit;
    color: var(--colour-text);
    background: var(--colour-surface);
    border: 1px solid var(--colour-border);
    border-radius: var(--radius);
}

input:focus,
textarea:focus,
select:focus {
    outline: 2px solid var(--colour-primary);
    outline-offset: 1px;
    border-color: var(--colour-primary);
}

/* A textarea takes the field styling above, plus the two things an input does
   not need: readable spacing for several lines of text, and a handle to drag
   when what someone is typing does not fit. Horizontal resizing stays off,
   because it would let the box break the column it sits in.

   Before this, the stylesheet had no textarea rule at all, so all five
   textareas in the application - the mechanic's service form, the correction
   form and the AI diagnosis screen - fell back to the browser default and
   rendered as small monospace boxes beside full-width inputs. */
textarea {
    line-height: 1.5;
    resize: vertical;
}

button {
    width: 100%;
    padding: 11px 16px;
    font-size: 15px;
    font-family: inherit;
    font-weight: 600;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
}

/*
   Used on <button> and on <a> alike. The base button rules above only match
   a real <button> element, so everything a link needs to look like a button
   is repeated here - otherwise an <a class="btn-primary"> renders as an
   ordinary underlined link.
*/
.btn-primary {
    display: inline-block;
    padding: 11px 16px;
    font-size: 15px;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    color: #fff;
    background: var(--colour-primary);
}

.btn-primary:hover {
    color: #fff;
}

.btn-primary:hover {
    background: #154785;
}

.btn-secondary {
    color: var(--colour-text);
    background: var(--colour-surface);
    border-color: var(--colour-border);
}

.btn-secondary:hover {
    background: var(--colour-background);
}

/* --------------------------------------------------------------------------
   Messages
   -------------------------------------------------------------------------- */

.alert {
    margin: 0 0 18px;
    padding: 10px 12px;
    font-size: 14px;
    border-radius: var(--radius);
}

.alert-error {
    color: var(--colour-error-text);
    background: var(--colour-error-bg);
}

.alert-success {
    color: var(--colour-ok-text);
    background: var(--colour-ok-bg);
}

/* --------------------------------------------------------------------------
   Detail lists
   -------------------------------------------------------------------------- */

.detail-list {
    margin: 0 0 20px;
}

.detail-list dt {
    font-size: 13px;
    font-weight: 600;
    color: var(--colour-muted);
}

.detail-list dd {
    margin: 0 0 12px;
    font-size: 15px;
    word-break: break-all;
}

.note {
    margin: 0 0 20px;
    font-size: 13px;
    color: var(--colour-muted);
}

/* --------------------------------------------------------------------------
   Form field messages
   -------------------------------------------------------------------------- */

/* Shown under a field that failed validation. */
.field-error {
    margin: -12px 0 14px;
    font-size: 13px;
    color: var(--colour-error-text);
}

/* Guidance shown before anything goes wrong, e.g. the password rule. */
.field-hint {
    margin: -12px 0 14px;
    font-size: 13px;
    color: var(--colour-muted);
}

.card-footer {
    margin: 20px 0 0;
    font-size: 14px;
    text-align: center;
    color: var(--colour-muted);
}

.card-footer a {
    color: var(--colour-primary);
}

/* --------------------------------------------------------------------------
   Page layout with a top bar (dashboards)
   -------------------------------------------------------------------------- */

.topbar {
    background: var(--colour-surface);
    border-bottom: 1px solid var(--colour-border);
}

.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    max-width: 900px;
    margin: 0 auto;
    padding: 12px 24px;
}

.topbar-title {
    font-weight: 600;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 14px;
}

.topbar-user {
    font-size: 14px;
    color: var(--colour-muted);
}

/* Lets a form sit inline in the top bar without taking a whole row. */
.inline-form {
    display: inline;
}

/* A button that reads as a link, for "Sign out" in the header. */
.btn-link {
    width: auto;
    padding: 4px 8px;
    font-size: 14px;
    color: var(--colour-primary);
    background: none;
    border: none;
    text-decoration: underline;
}

.page {
    max-width: 900px;
    margin: 0 auto;
    padding: 32px 24px;
}

.page-title {
    margin: 0 0 6px;
    font-size: 24px;
}

.page-intro {
    margin: 0 0 28px;
    color: var(--colour-muted);
}

.panel {
    padding: 20px 22px;
    background: var(--colour-surface);
    border: 1px solid var(--colour-border);
    border-radius: var(--radius);
}

.panel-title {
    margin: 0 0 8px;
    font-size: 16px;
}

.panel p {
    margin: 0;
    color: var(--colour-muted);
}

/* --------------------------------------------------------------------------
   Error pages
   -------------------------------------------------------------------------- */

.error-code {
    margin: 0 0 4px;
    font-size: 40px;
    font-weight: 700;
    line-height: 1;
    color: var(--colour-border);
}

.btn-link-block {
    display: inline-block;
    margin-top: 8px;
    font-size: 14px;
    color: var(--colour-primary);
}

/* --------------------------------------------------------------------------
   Data tables (workshop list, and the record lists that follow it)
   -------------------------------------------------------------------------- */

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table th,
.data-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--colour-border);
}

.data-table th {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--colour-muted);
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table a {
    color: var(--colour-primary);
}

/* The audit history prints its before and after payloads in <pre>, and a
   <pre> does not wrap. One long JSON line therefore stretched the table far
   past the width of the page: the After and Reason columns were pushed off
   the right-hand edge entirely, and the Before column was cut mid-value.
   Everything was there - it could not be read.

   Wrapping the payload is what fixes it, and it needs BOTH widths.

   pre-wrap plus overflow-wrap lets the JSON break mid-token, because it has
   long runs with no spaces to break at. But once text may break anywhere,
   the column's minimum content width drops to about one character, and a
   table that shares its width out will squeeze these two columns to a
   sliver: the first attempt at this fix wrapped the payload eight
   characters to a line and made every row as tall as the screen. min-width
   is what stops that. max-width stops the opposite - one long payload
   taking the whole table. */
.data-table pre {
    margin: 0;
    min-width: 220px;
    max-width: 320px;
    font-size: 12px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* The same squeeze happens to an ordinary prose cell next to two wide ones:
   English wraps at spaces, so a long sentence's minimum width is just its
   longest word, and the audit table was breaking the removal reason one word
   to a line. A floor of its own keeps the sentence readable. */
.data-table .reason-cell {
    min-width: 180px;
}

/* A table with many columns can still come out wider than its card on a
   narrow window. Scrolling it inside the panel keeps the card's edge intact
   and keeps the scrollbar beside the thing that is too wide, instead of
   putting a horizontal scrollbar on the whole page. */
.panel {
    overflow-x: auto;
}

/* --------------------------------------------------------------------------
   Radio choices (the account type on the registration form)
   -------------------------------------------------------------------------- */

.choice-group {
    margin: 0 0 14px;
    padding: 12px 14px;
    border: 1px solid var(--colour-border);
    border-radius: 6px;
}

.choice-group legend {
    padding: 0 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--colour-muted);
}

.choice {
    display: flex;
    gap: 8px;
    align-items: center;
    margin: 6px 0;
    font-size: 14px;
    font-weight: 400;
}

.choice input[type="radio"] {
    width: auto;
    margin: 0;
}

/* --------------------------------------------------------------------------
   Compact forms inside a table row (the mechanic review screen)
   -------------------------------------------------------------------------- */

.row-form {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.row-form select,
.row-form input[type="text"] {
    width: auto;
    min-width: 130px;
    margin-bottom: 0;
    padding: 6px 8px;
    font-size: 13px;
}

.row-form button {
    width: auto;
    padding: 6px 12px;
    font-size: 13px;
}

.muted {
    font-size: 13px;
    color: var(--colour-muted);
}

/* --------------------------------------------------------------------------
   Maintenance reminders (the owner's vehicle page)

   One block per service category: the category, a coloured badge carrying
   the status, and the sentences explaining where that status came from.
   The badge colour is chosen by a class the template builds from the status
   name, so adding a status never means editing a chain of conditions in the
   template.
   -------------------------------------------------------------------------- */

.reminder-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.reminder {
    padding: 14px 0;
    border-bottom: 1px solid var(--colour-border);
}

.reminder:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.reminder-head {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.reminder-category {
    font-weight: 600;
}

.reminder-badge {
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

.reminder-reason {
    margin: 6px 0 0;
    font-size: 14px;
}

/* Up to date - the same green the success messages use. */
.reminder-up-to-date {
    background: var(--colour-ok-bg);
    color: var(--colour-ok-text);
}

/* Due soon - a warning, not a failure, so amber rather than red. */
.reminder-due-soon {
    background: #fdf3e0;
    color: #8a5a00;
}

/* Due or overdue - the same red the error messages use. */
.reminder-due {
    background: var(--colour-error-bg);
    color: var(--colour-error-text);
}

/*
  Unknown and no reminder are deliberately grey, not red. Neither is a
  problem with the vehicle: one means nothing has been recorded yet, the
  other means the category has no interval configured (decision R-11).
  Colouring them as warnings would make missing information look like
  overdue maintenance.
*/
.reminder-unknown,
.reminder-no-reminder {
    background: var(--colour-background);
    color: var(--colour-muted);
    border: 1px solid var(--colour-border);
}

/* --------------------------------------------------------------------------
   The maintenance health score

   The number is large, and the coverage line sits directly under it so the
   two are read together. O-7 depends on that: the score on its own is not
   the whole answer.
   -------------------------------------------------------------------------- */

.score-head {
    margin-bottom: 18px;
}

.score-value {
    margin: 0;
    font-size: 40px;
    font-weight: 700;
    line-height: 1.1;
}

.score-outof {
    font-size: 20px;
    font-weight: 400;
    color: var(--colour-muted);
}

/* No score at all, when timeliness cannot be assessed. Deliberately not red:
   it is an absence of information, not a bad result. */
.score-unavailable {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: var(--colour-muted);
}

.score-table td p {
    margin: 4px 0 0;
}

.score-table td:last-child {
    white-space: nowrap;
    vertical-align: top;
}

/* ------------------------------------------------------------------
   The buyer-facing maintenance report.

   Build-order item 7. Phase 2 Day 6 section 7 settles the mechanism:
   print-friendly Thymeleaf HTML, printed or saved as PDF by the BROWSER.
   So everything that makes the report a document rather than a web page
   is here, in CSS, and not in Java. There is no PDF library.
   ------------------------------------------------------------------ */

/* The report's own heading block, above the sections. */
.report-header {
    margin: 0 0 20px;
}

.report-title {
    margin: 0 0 4px;
    font-size: 26px;
}

.report-subject {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.report-vin {
    margin: 2px 0 0;
    font-family: monospace;
    letter-spacing: 1px;
}

.report-generated {
    margin: 8px 0 0;
    color: var(--colour-muted);
}

/* The limits section carries the statements a reader must not miss, so it
   is bordered rather than left to look like another panel of data. */
.report-limits {
    border: 2px solid var(--colour-border);
}

/* ------------------------------------------------------------------
   Printing.

   Anything marked no-print is navigation or a control - it belongs to the
   application, not to the document somebody is handing to a buyer.
   ------------------------------------------------------------------ */
@media print {

    /* Browsers differ on default print margins, so the document states its
       own and looks the same wherever it is printed. */
    @page {
        margin: 14mm;
    }

    .no-print {
        display: none !important;
    }

    /* The shared header is navigation - a signed-in email address and a
       Sign out button - and belongs on no printed page.

       It is hidden by this rule rather than by a no-print class on the
       element that pulls it in, because th:replace REPLACES that element
       with the fragment and throws its class away. The first printed proof
       of this report carried the owner's email address across the top for
       exactly that reason. */
    .topbar {
        display: none !important;
    }

    /* Plain black on white. A printer should not be asked to reproduce the
       page background, and a grey that reads well on screen can come out
       as unreadable stippling on paper. */
    body {
        background: #ffffff;
        color: #000000;
        font-size: 11pt;
    }

    .page {
        max-width: none;
        margin: 0;
        padding: 0;
    }

    /* Panels become sections of one document instead of separate cards. */
    .panel {
        margin: 0 0 14px;
        padding: 0;
        border: none;
        box-shadow: none;
        background: transparent;

        /* On screen a panel scrolls a too-wide table sideways. Paper cannot
           be scrolled: a scroll container prints only the part that was
           visible, silently cutting the rest off the sheet. */
        overflow: visible;
    }

    .report-limits {
        border: 1px solid #000000;
        padding: 10px;
    }

    /* Keep a section and its heading together, and never split a service
       row across two sheets - half a service record reads like a different
       service. */
    .report-section,
    .reminder,
    tr {
        page-break-inside: avoid;
    }

    .panel-title {
        page-break-after: avoid;
    }

    /* A table that runs onto a second sheet repeats its header, so the
       columns stay identifiable. */
    thead {
        display: table-header-group;
    }

    /* The service history is eight columns wide. At the body size it
       overflowed the right edge of the sheet and lost the evidence column
       entirely, so on paper the table is set smaller and tighter and told to
       use the full width of the page. */
    .data-table {
        width: 100%;
        font-size: 9pt;
    }

    .data-table th,
    .data-table td {
        padding: 3px 4px;
        border-color: #000000;
    }

    /* Definition headings are the accent colour on screen. The limits
       section is the part of this document a reader must not skim past, so
       on paper it is plain black like everything else. */
    .detail-list dt {
        color: #000000;
    }

    /* The status badges are colour-coded on screen. On paper the colour may
       not survive, so the label itself has to carry the meaning - the badge
       keeps a visible outline and the text reads the same either way. */
    .reminder-badge {
        border: 1px solid #000000;
        background: transparent !important;
        color: #000000 !important;
    }

    /* Muted grey is a screen device; on paper it must still be readable. */
    .muted,
    .note,
    .report-generated {
        color: #333333;
    }
}

/* ==========================================================================
   AI diagnosis - Week 10.

   Added by decision R-27, which allows this file to take NEW classes for the
   diagnosis screen. Nothing above is redefined, so no other screen can change
   appearance as a side effect of these rules.

   The Week 8 audit-table lesson applies throughout: max-width alone makes a
   column collapsible, min-width is what reserves it space. Every rule below
   that constrains a width states both.
   ========================================================================== */

.diagnosis-subject {
    margin: 0 0 10px;
    font-size: 18px;
    font-weight: 600;
}

/* The four optional fields, set apart so the required description does not
   look like one of five equal questions. */
.diagnosis-optional {
    margin: 18px 0;
    padding: 14px 16px;
    border: 1px solid var(--colour-border);
    border-radius: var(--radius);
    background: var(--colour-background);
}

.diagnosis-optional-lead {
    margin-top: 0;
}

.diagnosis-wait-note {
    margin-top: 8px;
}

/* --------------------------------------------------------------------------
   The safety warning.

   This is the one thing on the page that must not be skimmed past. It is
   produced by the AI service's own screening of the owner's words, before
   the model is involved, so it appears even when no cause can be named -
   including on an answer that otherwise says "I need more information".

   A red border rather than a red fill: filled red reads as an error message,
   and this is not an error. It is a warning about the vehicle.
   -------------------------------------------------------------------------- */
.safety-panel {
    border: 2px solid var(--colour-error-text);
}

.safety-title {
    color: var(--colour-error-text);
}

.safety-warning {
    margin: 10px 0 0;
    font-weight: 600;
}

/* --------------------------------------------------------------------------
   The urgency band.

   Week 9 showed urgency as a sentence in the middle of a panel. It is the
   single most actionable thing the system returns, so it is now a band whose
   colour carries the level - but the WORD is always present too, because
   colour alone excludes anyone who cannot distinguish these hues and
   disappears entirely in print.

   One class per level, named from DiagnosisResult.getUrgencyCssSuffix, so
   the template holds no string comparisons.
   -------------------------------------------------------------------------- */
.urgency-panel {
    padding-top: 16px;
}

.urgency-band {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--radius);
    border: 1px solid transparent;
}

.urgency-label {
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.urgency-value {
    font-size: 20px;
    font-weight: 700;
}

.urgency-note {
    margin: 10px 0 0;
    font-weight: 600;
}

/* Low - the same green as "up to date". Nothing here is alarming. */
.urgency-low {
    background: var(--colour-ok-bg);
    color: var(--colour-ok-text);
    border-color: var(--colour-ok-text);
}

/* Medium - amber, the same tone "due soon" uses. A warning, not a failure. */
.urgency-medium {
    background: #fdf3e0;
    color: #8a5a00;
    border-color: #8a5a00;
}

/* High - the error red, matching "overdue". */
.urgency-high {
    background: var(--colour-error-bg);
    color: var(--colour-error-text);
    border-color: var(--colour-error-text);
}

/* Critical - the only filled band on the site. It is reserved for the one
   level the AI service can force from its own dangerous-symptom rules,
   independently of what the model said. If everything shouted, nothing
   would. */
.urgency-critical {
    background: var(--colour-error-text);
    color: #ffffff;
    border-color: var(--colour-error-text);
}

/* Unknown - grey, never red. INSUFFICIENT_INFORMATION and UNSUPPORTED may
   legitimately carry no urgency, and "we do not know" must not look like
   "this is fine" or like "this is serious". */
.urgency-unknown {
    background: var(--colour-background);
    color: var(--colour-muted);
    border-color: var(--colour-border);
}

/* --------------------------------------------------------------------------
   Ranked possible causes.

   An ordered list, because the ranking is part of the meaning: most likely
   first. The number is shown rather than left to the reading order.
   -------------------------------------------------------------------------- */
.cause-list {
    list-style: none;
    margin: 0;
    padding: 0;
    counter-reset: cause;
}

.cause {
    padding: 16px 0;
    border-bottom: 1px solid var(--colour-border);
}

.cause:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.cause-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.cause-rank {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    width: 28px;
    height: 28px;
    border-radius: 999px;
    background: var(--colour-primary);
    color: #ffffff;
    font-weight: 700;
    font-size: 14px;
}

.cause-name {
    font-size: 17px;
    font-weight: 600;
    min-width: 140px;
}

.cause-confidence {
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    background: var(--colour-background);
    color: var(--colour-muted);
    border: 1px solid var(--colour-border);
}

/* Confidence is deliberately quieter than urgency. High confidence in a
   POSSIBLE cause is still a possibility, and styling it like an alarm would
   present it as a finding - which the rules forbid. */
.confidence-high {
    color: var(--colour-text);
    border-color: var(--colour-muted);
}

.cause-explanation {
    margin: 10px 0 0 38px;
}

/* --------------------------------------------------------------------------
   Clarification questions.
   -------------------------------------------------------------------------- */
.question {
    margin-bottom: 14px;
}

/* --------------------------------------------------------------------------
   What your records contribute.

   The panel that makes the integration visible. It is bordered in the
   accent colour because it is the answer to the question a supervisor or a
   buyer actually asks: where did this come from?
   -------------------------------------------------------------------------- */
.records-panel {
    border-left: 4px solid var(--colour-primary);
}

.records-detail {
    margin: 6px 0 0;
    font-size: 14px;
}

/* "No service recorded" is grey, not red, for the same reason the UNKNOWN
   reminder badge is: missing information is not overdue maintenance. */
.records-unknown {
    color: var(--colour-muted);
}

.disclaimer {
    font-weight: 600;
}

/* --------------------------------------------------------------------------
   Narrow screens.

   The urgency band and the cause heading both use flex-wrap above, so they
   already fold. This keeps the explanation readable once the rank badge has
   wrapped away from it.
   -------------------------------------------------------------------------- */
@media (max-width: 480px) {
    .cause-explanation {
        margin-left: 0;
    }
}

/* The urgency band is colour-coded on screen. On paper the colour may not
   survive, so - exactly as the reminder badges already do - the band keeps a
   visible outline and the word itself carries the meaning. */
@media print {

    .urgency-band {
        border: 1px solid #000000;
        background: transparent !important;
        color: #000000 !important;
    }

    .safety-panel {
        border: 2px solid #000000;
    }

    .safety-title {
        color: #000000;
    }

    .cause-rank {
        border: 1px solid #000000;
        background: transparent !important;
        color: #000000 !important;
    }
}

/* ---------------------------------------------------------------------
   The registration card scanner (step 9)
   --------------------------------------------------------------------- */

/* The VIN in groups of four, R-16(b). Monospace so the groups line up and
   a single wrong character is visible; an unbroken seventeen-character
   string cannot be proofread by eye. */
.vin-grouped {
    font-family: ui-monospace, "Cascadia Mono", "Consolas", monospace;
    font-size: 1.25rem;
    letter-spacing: 0.08em;
    margin: 0.35rem 0 0.25rem;
    min-height: 1.5rem;
    color: #1f2d3d;
}

/* Marks a box the scan filled in, so the owner knows what to check against
   the document and what they typed themselves. */
.scanned-mark {
    color: #1a5632;
    font-weight: 600;
}

.scanned-mark::before {
    content: "\2713\00a0";
}
