/* FleetView design system.
 *
 * Mobile-first throughout: every rule below is written for a small screen
 * first, then widened/adjusted inside `min-width` media queries — never the
 * other way round. Two CSS custom properties (`--gutter`, on :root) drive the
 * side padding of both the nav bar and the main content column so their left
 * edges always line up; `--container-max` centers that column on wide
 * screens instead of letting it stretch edge to edge.
 *
 * No third-party fonts/icons/frameworks (project rule: no third-party
 * packages) — a system font stack and plain CSS only.
 */

:root {
    --font-sans: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

    --color-bg:        #f7f8fa;
    --color-surface:   #ffffff;
    --color-text:      #1f2933;
    --color-muted:     #52606d;
    --color-border:    #d9dee3;

    --color-primary:       #1d4ed8;
    --color-primary-hover: #1e40af;
    --color-danger:        #b91c1c;
    --color-danger-hover:  #991b1b;
    --color-create:        #15803d;
    --color-create-hover:  #16a34a;

    --color-nav-bg: #1f2933;

    --radius:    0.5rem;
    --radius-sm: 0.375rem;

    --container-max: 1100px;
    --gutter: 1rem; /* mobile default; widened below as the viewport grows */
}

@media ( min-width: 640px ) {
    :root {
        --gutter: 1.5rem;
    }
}

@media ( min-width: 1024px ) {
    :root {
        --gutter: 2rem;
    }
}

/* ---------- Reset / base ---------- */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var( --color-bg );
    color: var( --color-text );
    font-family: var( --font-sans );
    font-size: 1rem;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

img,
svg {
    max-width: 100%;
    display: block;
}

a {
    color: var( --color-primary );
}

a:hover {
    color: var( --color-primary-hover );
}

/* A single, visible focus style everywhere — keyboard users always see
   where they are. */
:focus-visible {
    outline: 3px solid var( --color-primary );
    outline-offset: 2px;
    border-radius: 2px;
}

.nav :focus-visible {
    outline-color: #fff; /* the default blue is too low-contrast on the dark nav */
}

@media ( prefers-reduced-motion: reduce ) {
    * {
        animation-duration: 0.001ms !important;
        transition-duration: 0.001ms !important;
    }
}

.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;
}

/* Keyboard-only "skip to content" link — invisible until focused. */
.skip-link {
    position: absolute;
    top: -3rem;
    left: 1rem;
    z-index: 100;
    background: var( --color-primary );
    color: #fff;
    padding: 0.6rem 1rem;
    border-radius: 0 0 var( --radius-sm ) var( --radius-sm );
    text-decoration: none;
    font-weight: 600;
}

.skip-link:focus {
    top: 0;
}

/* ---------- Layout ---------- */

main {
    max-width: var( --container-max );
    margin-inline: auto;
    padding: var( --gutter );
    width: 100%;
}

/* The login page: nothing else on the page is wide enough to visibly use a
   1100px-centered column, so it gets the conventional centered card instead
   (its own inner column, vertically offset, not stretched to the page's
   general content width). */
.auth-card {
    max-width: 24rem;
    margin: 10vh auto 0;
    background: var( --color-surface );
    border: 1px solid var( --color-border );
    border-radius: var( --radius );
    padding: 2rem;
    box-shadow: 0 1px 3px rgba( 0, 0, 0, 0.08 );
}

@media ( max-height: 700px ) {
    .auth-card {
        margin-top: 2rem;
    }
}

h1,
h2,
h3 {
    line-height: 1.25;
    margin: 0 0 1rem;
}

h1 {
    font-size: clamp( 1.5rem, 4vw, 1.875rem );
}

h2 {
    font-size: 1.25rem;
    margin-top: 2rem;
}

h3 {
    font-size: 1.0625rem;
}

p {
    margin: 0 0 1rem;
}

ul,
ol {
    margin: 0 0 1rem;
    padding-left: 1.25rem;
}

/* Detail lists (every "show" page): stacked label/value on mobile, a
   two-column grid once there is room for it side by side. */
dl {
    margin: 0 0 1.5rem;
    padding: 1rem 1.25rem;
    background: var( --color-surface );
    border: 1px solid var( --color-border );
    border-radius: var( --radius );
}

dt {
    font-weight: 600;
    color: var( --color-muted );
    margin-top: 0.75rem;
}

dt:first-of-type {
    margin-top: 0;
}

dd {
    margin: 0 0 0.25rem;
}

@media ( min-width: 560px ) {
    dl {
        display: grid;
        grid-template-columns: max-content 1fr;
        column-gap: 1.5rem;
        row-gap: 0.6rem;
    }

    dt {
        margin-top: 0;
    }

    dd {
        margin: 0;
    }
}

/* Informational asides (e.g. "this car is shared with N other fleets") —
   visually distinct from the alert/status banners below, no ARIA role
   (there is no such thing as role="note"; it is just supplementary text). */
.hint {
    background: var( --color-bg );
    border: 1px solid var( --color-border );
    border-left: 4px solid var( --color-muted );
    color: var( --color-text );
    padding: 0.75rem 1rem;
    border-radius: var( --radius-sm );
}

/* ---------- Flash / validation messages ---------- */

[role="alert"] {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-left: 4px solid var( --color-danger );
    color: #7f1d1d;
    padding: 0.85rem 1rem;
    border-radius: var( --radius-sm );
    margin: 0 0 1.25rem;
}

[role="status"] {
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    border-left: 4px solid #047857;
    color: #065f46;
    padding: 0.85rem 1rem;
    border-radius: var( --radius-sm );
    margin: 0 0 1.25rem;
}

/* ---------- Forms ---------- */

form {
    margin: 0 0 1rem;
}

form > p,
fieldset > p {
    margin: 0 0 1.1rem;
}

label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.35rem;
}

input[ type="text" ],
input[ type="email" ],
input[ type="password" ],
input[ type="number" ],
input[ type="date" ],
input[ type="tel" ],
input[ type="search" ],
select,
textarea {
    display: block;
    width: 100%;
    max-width: 32rem;
    padding: 0.55rem 0.75rem;
    background: var( --color-surface );
    color: var( --color-text );
    border: 1px solid var( --color-border );
    border-radius: var( --radius-sm );
    font: inherit;
    line-height: 1.4;
}

textarea {
    max-width: 100%;
    min-height: 6rem;
    resize: vertical;
}

select {
    cursor: pointer;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var( --color-primary );
}

input[ type="checkbox" ],
input[ type="radio" ] {
    width: auto;
    max-width: none;
    display: inline-block;
    margin: 0 0.5rem 0 0;
    accent-color: var( --color-primary );
    vertical-align: middle;
}

fieldset {
    border: 1px solid var( --color-border );
    border-radius: var( --radius );
    padding: 1rem 1.25rem 1.25rem;
    margin: 0 0 1.5rem;
    background: var( --color-surface );
}

fieldset > p:last-child {
    margin-bottom: 0;
}

/* A row of small, related fields (e.g. tyre width / height / radial) that
   should sit side by side and wrap as a unit, not stack one-per-line the way
   a standalone label/input pair does. */
.inline-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.25rem;
    align-items: flex-start;
}

.inline-fields > span {
    display: inline-flex;
    flex-direction: column;
}

legend {
    font-weight: 600;
    padding: 0 0.4rem;
}

/* An input with an explicit `size` opts out of the block/full-width default —
   the car form's tyre width/height/radial, and the brand page's inline
   model-rename field. `size` still drives the actual width (native browser
   behavior); this is just a sane ceiling. */
input[ size ] {
    display: inline-block;
    width: auto;
    max-width: 14rem;
}

/* Two small forms sitting side by side in one row (e.g. a model's inline
   rename + delete actions). */
.form-inline {
    display: inline-block;
    vertical-align: middle;
    margin: 0 0.5rem 0.5rem 0;
}

.form-inline:last-child {
    margin-right: 0;
}

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

button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: 2.75rem; /* >= 44px, a comfortable touch target */
    padding: 0.6rem 1.1rem;
    background: var( --color-primary );
    color: #fff;
    border: 1px solid transparent;
    border-radius: var( --radius-sm );
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

button:hover {
    background: var( --color-primary-hover );
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Inline "Delete" trigger in a table row: an outline, not a solid block of
   red for every row — the solid red is reserved for the modal's real
   confirmation below. */
.delete-trigger {
    background: transparent;
    color: var( --color-danger );
    border-color: var( --color-danger );
    min-height: 2.25rem;
    padding: 0.4rem 0.9rem;
}

.delete-trigger:hover {
    background: var( --color-danger );
    color: #fff;
}

/* A plain link (e.g. "Create new car") styled to look and behave like a
   button — same sizing/shape as <button>, just on an <a>. */
.btn-create {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: 2.75rem;
    padding: 0.6rem 1.1rem;
    background: var( --color-create );
    color: #fff;
    border-radius: var( --radius-sm );
    font-weight: 600;
    text-decoration: none;
}

.btn-create:hover {
    background: var( --color-create-hover );
    color: #fff;
}

/* ---------- Nav bar ---------- */

.nav {
    background: var( --color-nav-bg );
    color: #fff;
    position: relative;
}

.nav-inner {
    max-width: var( --container-max );
    margin-inline: auto;
    padding: 0.75rem var( --gutter );
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-toggle {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    min-width: 2.75rem;
    min-height: 2.75rem;
    background: none;
    border: 0;
    padding: 0.5rem;
}

.nav-toggle-bar {
    width: 22px;
    height: 2px;
    background: #fff;
}

/* Explicit hover/focus override: a bare `.nav-toggle` selector (specificity
   0,1,0) loses to the generic `button:hover` rule above (0,1,1) — pseudo-
   classes count toward specificity same as a class does — so without this,
   hovering/focusing the burger button paints it solid blue instead of the
   intended subtle highlight. */
.nav-toggle:hover,
.nav-toggle:focus-visible {
    background: rgba( 255, 255, 255, 0.1 );
}

.nav-links {
    list-style: none;
    margin: 0;
    padding: 0;
    display: none;
    flex-direction: column;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var( --color-nav-bg );
    z-index: 10;
}

.nav-links.is-open {
    display: flex;
}

.nav-links a,
.nav-link-button {
    display: block;
    width: 100%;
    min-height: 2.75rem;
    padding: 0.75rem 1rem;
    color: #fff;
    text-decoration: none;
    background: none;
    border: 0;
    font: inherit;
    font-weight: 400;
    text-align: left;
    cursor: pointer;
}

.nav-links a:hover,
.nav-link-button:hover {
    background: rgba( 255, 255, 255, 0.08 );
    color: #fff;
}

.nav-logout-form {
    margin: 0;
}

@media ( min-width: 640px ) {
    .nav-toggle {
        display: none;
    }

    .nav-links {
        display: flex;
        flex-direction: row;
        align-items: center;
        position: static;
        background: none;
    }

    .nav-links a,
    .nav-link-button {
        width: auto;
        min-height: auto;
        padding: 0.5rem 0.75rem;
        border-radius: var( --radius-sm );
    }
}

/* ---------- Tables ---------- */

/* A table wider than its column lets scroll horizontally on its own, rather
   than forcing the whole page to scroll or breaking the layout — the table's
   own semantics (headers, cells) stay intact for assistive tech. */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var( --color-border );
    border-radius: var( --radius );
    margin: 0 0 1.5rem;
}

.resource-table {
    width: 100%;
    min-width: 34rem;
    border-collapse: collapse;
    background: var( --color-surface );
}

.resource-table th,
.resource-table td {
    padding: 0.65rem 0.9rem;
    border-bottom: 1px solid var( --color-border );
    text-align: left;
    vertical-align: middle; /* rows mix plain text with taller bordered buttons — middle keeps them level */
}

/* The lone Delete <form> in a cell has no fields to space from anything else,
   so it shouldn't carry the page-wide "space below a form" margin — that
   margin still counts as part of the cell's content for vertical-align, and
   pushes the visible button off-center toward the top of the row. */
.resource-table form {
    margin: 0;
}

.resource-table thead th {
    background: var( --color-bg );
    font-weight: 600;
    border-bottom: 2px solid var( --color-border );
    white-space: nowrap;
}

.resource-table tbody tr:nth-child( even ) {
    background: rgba( 31, 41, 51, 0.02 );
}

.resource-table tbody tr:hover {
    background: rgba( 29, 78, 216, 0.05 );
}

.resource-table th a {
    color: inherit;
    text-decoration: none;
}

.resource-table th a:hover {
    text-decoration: underline;
}

.resource-table tbody tr:last-child td {
    border-bottom: 0;
}

/* ---------- Delete-confirm dialog ---------- */

dialog#delete-modal {
    border: 0;
    border-radius: var( --radius );
    padding: 1.5rem;
    background: var( --color-surface );
    color: var( --color-text );
    width: 90vw;
    max-width: 26rem;
    box-shadow: 0 10px 30px rgba( 0, 0, 0, 0.15 );
}

dialog#delete-modal::backdrop {
    background: rgba( 15, 23, 32, 0.55 );
}

dialog#delete-modal p:last-of-type {
    margin-bottom: 0;
}

.modal-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 1rem;
}

.modal-actions button:first-child {
    background: var( --color-surface );
    color: var( --color-text );
    border-color: var( --color-border );
}

.modal-actions button:first-child:hover {
    background: var( --color-bg );
}

#delete-modal-confirm {
    background: var( --color-danger );
}

#delete-modal-confirm:hover {
    background: var( --color-danger-hover );
}
