/* ==========================================================================
   Tournal application styles
   Mobile-first, light theme, Liquid-Glass-inspired floating bottom nav.
   Accessibility: visible focus, ≥44px touch targets, reduced-motion and
   reduced-transparency fallbacks, no information conveyed by colour alone.
   ========================================================================== */

/* ---- Design tokens -------------------------------------------------- */
:root {
    --color-bg: #f5f6f8;
    --color-surface: #ffffff;
    --color-surface-muted: #eef0f3;
    --color-border: #dfe3e8;
    --color-text: #191c20;
    --color-text-muted: #5a6472;
    --color-accent: #0a5bd3;
    --color-accent-strong: #0a4cae;
    --color-accent-contrast: #ffffff;
    --color-success: #17683a;
    --color-success-bg: #e5f4ea;
    --color-warning: #8a5a00;
    --color-warning-bg: #fdf3dc;
    --color-danger: #b3131f;
    --color-danger-bg: #fbe9ea;
    --color-info-bg: #e8f0fd;

    --radius-s: 8px;
    --radius-m: 14px;
    --radius-l: 22px;

    --shadow-card: 0 1px 2px rgba(20, 24, 31, 0.05), 0 1px 6px rgba(20, 24, 31, 0.06);
    --shadow-float: 0 10px 34px rgba(20, 24, 31, 0.16);

    --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

    --nav-height: 72px;
    --space-page: 16px;
}

/* ---- Base ------------------------------------------------------------ */
* {
    box-sizing: border-box;
}

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

body {
    margin: 0;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-stack);
    font-size: 16px;
    line-height: 1.5;
    min-height: 100vh;
}

h1, h2, h3 {
    line-height: 1.25;
    margin: 0 0 0.5em;
}

h1 { font-size: 1.45rem; font-weight: 700; }
h2 { font-size: 1.15rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 600; }

p { margin: 0 0 1em; }

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

img {
    max-width: 100%;
    height: auto;
}

/* Focus visibility (spec 25.8) */
:focus-visible {
    outline: 3px solid var(--color-accent);
    outline-offset: 2px;
    border-radius: 4px;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    top: -48px;
    left: 12px;
    z-index: 100;
    background: var(--color-surface);
    color: var(--color-text);
    padding: 10px 16px;
    border-radius: var(--radius-s);
    box-shadow: var(--shadow-float);
    transition: top 0.15s ease;
}

.skip-link:focus {
    top: 12px;
}

/* ---- Layout ---------------------------------------------------------- */
.app {
    max-width: 720px;
    margin: 0 auto;
    padding: calc(env(safe-area-inset-top) + 12px) var(--space-page)
        calc(var(--nav-height) + env(safe-area-inset-bottom) + 40px);
}

body.no-nav .app {
    padding-bottom: 32px;
}

.main:focus {
    outline: none;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 6px 0 16px;
    flex-wrap: wrap;
}

.page-header__title {
    margin: 0;
}

/* ---- Cards ----------------------------------------------------------- */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-m);
    padding: 16px;
    margin-bottom: 14px;
    box-shadow: var(--shadow-card);
}

.card__title {
    margin: 0 0 10px;
    font-size: 1rem;
}

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

/* ---- Flash messages -------------------------------------------------- */
.flashes {
    margin: 4px 0 14px;
}

.flash {
    border-radius: var(--radius-s);
    padding: 10px 14px;
    margin-bottom: 8px;
    border: 1px solid transparent;
    font-size: 0.95rem;
}

.flash__label {
    font-weight: 650;
}

.flash--success { background: var(--color-success-bg); color: var(--color-success); border-color: rgba(23, 104, 58, 0.25); }
.flash--error { background: var(--color-danger-bg); color: var(--color-danger); border-color: rgba(179, 19, 31, 0.25); }
.flash--info { background: var(--color-info-bg); color: var(--color-accent-strong); border-color: rgba(10, 91, 211, 0.2); }

/* ---- Forms ----------------------------------------------------------- */
.field {
    margin-bottom: 16px;
}

.field__label {
    display: block;
    font-weight: 600;
    font-size: 0.92rem;
    margin-bottom: 6px;
}

.field__hint {
    display: block;
    color: var(--color-text-muted);
    font-size: 0.85rem;
    margin-top: 5px;
}

.field__input,
.field__select,
.field__textarea {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    font: inherit;
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-s);
}

.field__textarea {
    min-height: 84px;
    resize: vertical;
}

.field__input:focus,
.field__select:focus,
.field__textarea:focus {
    border-color: var(--color-accent);
    outline: 2px solid var(--color-accent);
    outline-offset: 0;
}

.field__input.has-error,
.field__select.has-error,
.field__textarea.has-error {
    border-color: var(--color-danger);
}

.field__error {
    display: block;
    color: var(--color-danger);
    font-size: 0.88rem;
    font-weight: 600;
    margin: 6px 0 0;
}

.field--checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
}

.field--checkbox label {
    font-weight: 500;
}

.checkbox {
    width: 22px;
    height: 22px;
    accent-color: var(--color-accent);
    flex: none;
}

fieldset {
    border: 0;
    padding: 0;
    margin: 0 0 16px;
}

legend {
    font-weight: 650;
    padding: 0;
    margin-bottom: 8px;
}

/* ---- Buttons --------------------------------------------------------- */
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    min-width: 44px;
    padding: 10px 18px;
    font: inherit;
    font-weight: 600;
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 999px;
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.12s ease, border-color 0.12s ease;
}

.button:hover {
    background: var(--color-surface-muted);
}

.button--primary {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: var(--color-accent-contrast);
}

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

.button--danger {
    background: var(--color-danger);
    border-color: var(--color-danger);
    color: #fff;
}

.button--quiet {
    border-color: transparent;
    background: transparent;
    color: var(--color-accent);
}

.button--quiet:hover {
    background: var(--color-info-bg);
}

.button--block {
    display: flex;
    width: 100%;
}

.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 8px;
}

/* ---- Login ----------------------------------------------------------- */
.page-login .app {
    display: flex;
    min-height: calc(100vh - 40px);
    align-items: center;
    justify-content: center;
}

.auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-l);
    box-shadow: var(--shadow-card);
    padding: 28px 24px;
}

.auth-card__brand {
    text-align: center;
    margin-bottom: 22px;
}

.auth-card__title {
    font-size: 1.8rem;
    letter-spacing: -0.02em;
    margin-bottom: 4px;
}

.auth-card__tagline {
    color: var(--color-text-muted);
    margin: 0;
}

/* ---- Error pages ----------------------------------------------------- */
.error-page {
    text-align: center;
    padding: 48px 8px;
}

.error-page__code {
    font-size: 2.6rem;
    font-weight: 800;
    color: var(--color-text-muted);
    margin: 0;
}

.error-page__debug {
    text-align: left;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-s);
    padding: 12px;
    overflow-x: auto;
    font-size: 0.8rem;
}

/* ---- Floating bottom navigation (spec 26.1) -------------------------- */
.bottom-nav {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(env(safe-area-inset-bottom) + 10px);
    z-index: 50;
    display: flex;
    align-items: flex-end;
    width: min(430px, calc(100vw - 20px));
    padding: 6px 8px;
    border-radius: 28px;
    background: rgba(255, 255, 255, 0.72);
    -webkit-backdrop-filter: blur(18px) saturate(1.7);
    backdrop-filter: blur(18px) saturate(1.7);
    border: 1px solid rgba(25, 28, 32, 0.08);
    box-shadow: var(--shadow-float);
}

/* Opaque fallbacks: no backdrop-filter support or reduced transparency. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .bottom-nav {
        background: rgba(255, 255, 255, 0.98);
    }
}

@media (prefers-reduced-transparency: reduce) {
    .bottom-nav {
        background: #ffffff;
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
    }
}

.bottom-nav__item {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 56px;
    min-width: 44px;
    padding: 6px 2px;
    border-radius: 20px;
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: 0.72rem;
    font-weight: 600;
}

.bottom-nav__item.is-active {
    color: var(--color-accent-strong);
}

.bottom-nav__icon {
    position: relative;
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
}

.bottom-nav__icon svg {
    width: 24px;
    height: 24px;
}

.bottom-nav__badge {
    position: absolute;
    top: -4px;
    right: -8px;
    min-width: 17px;
    height: 17px;
    padding: 0 4px;
    display: grid;
    place-items: center;
    background: var(--color-danger);
    color: #fff;
    font-size: 0.62rem;
    font-weight: 700;
    border-radius: 999px;
}

/* Elevated central New Trip action */
.bottom-nav__item--primary {
    flex: 0 0 auto;
    margin: 0 4px;
    transform: translateY(-16px);
    background: var(--color-accent);
    color: var(--color-accent-contrast);
    width: 58px;
    height: 58px;
    min-height: 58px;
    border-radius: 50%;
    box-shadow: 0 6px 18px rgba(10, 91, 211, 0.42);
}

.bottom-nav__item--primary .bottom-nav__label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.bottom-nav__item--primary.is-active {
    background: var(--color-accent-strong);
    color: var(--color-accent-contrast);
}

.bottom-nav__item--primary svg {
    width: 28px;
    height: 28px;
}

/* ---- Vehicle cards --------------------------------------------------- */
.vehicle-card {
    display: flex;
    gap: 14px;
    align-items: center;
}

.vehicle-card__media {
    flex: 0 0 96px;
    height: 64px;
    display: grid;
    place-items: center;
    background: var(--color-surface-muted);
    border-radius: var(--radius-s);
    overflow: hidden;
    color: var(--color-text-muted);
}

.vehicle-card__media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.vehicle-card__fallback {
    width: 72px;
    height: 34px;
}

.vehicle-card__body {
    flex: 1;
    min-width: 0;
}

.vehicle-card__name {
    margin: 0 0 2px;
    font-size: 1.05rem;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.vehicle-card__name a {
    color: inherit;
    text-decoration: none;
}

.vehicle-card__name a:hover {
    text-decoration: underline;
}

/* ---- More menu ------------------------------------------------------- */
.menu-card {
    padding: 8px 0;
}

.menu-card .card__title {
    padding: 8px 16px 0;
}

.menu-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.menu-list__link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 48px;
    padding: 10px 16px;
    color: var(--color-text);
    text-decoration: none;
    font-weight: 500;
}

.menu-list__item + .menu-list__item .menu-list__link {
    border-top: 1px solid var(--color-border);
}

.menu-list__link:hover {
    background: var(--color-surface-muted);
}

.menu-list__link--disabled {
    color: var(--color-text-muted);
}

.menu-list__chevron {
    color: var(--color-text-muted);
    font-size: 1.2rem;
}

/* ---- Master data rows ------------------------------------------------ */
.md-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.md-row__body {
    flex: 1 1 240px;
    min-width: 0;
}

.md-row__title {
    margin: 0;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.md-row__secondary {
    margin: 4px 0 0;
    font-size: 0.9rem;
}

.md-row__actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

/* ---- Tables ---------------------------------------------------------- */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-s);
    background: var(--color-surface);
}

table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

table.data th,
table.data td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

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

table.data th {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    background: var(--color-surface-muted);
}

/* ---- Badges / status ------------------------------------------------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 650;
    border: 1px solid transparent;
}

.badge--neutral { background: var(--color-surface-muted); color: var(--color-text-muted); }
.badge--success { background: var(--color-success-bg); color: var(--color-success); }
.badge--warning { background: var(--color-warning-bg); color: var(--color-warning); }
.badge--danger { background: var(--color-danger-bg); color: var(--color-danger); }
.badge--info { background: var(--color-info-bg); color: var(--color-accent-strong); }

/* ---- Definition lists ------------------------------------------------ */
.kv {
    display: grid;
    grid-template-columns: minmax(120px, 38%) 1fr;
    gap: 6px 14px;
    margin: 0;
}

.kv dt {
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

.kv dd {
    margin: 0;
    font-weight: 500;
    overflow-wrap: anywhere;
}

/* ---- Segmented control ----------------------------------------------- */
.segmented {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.segmented__option {
    flex: 1 1 auto;
    position: relative;
}

.segmented__option input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: pointer;
}

.segmented__option span {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.92rem;
    background: var(--color-surface);
    color: var(--color-text-muted);
}

.segmented__option input:checked + span {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: var(--color-accent-contrast);
}

.segmented__option input:focus-visible + span {
    outline: 3px solid var(--color-accent);
    outline-offset: 2px;
}

/* ---- Trip form ------------------------------------------------------- */
.field-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 0 12px;
}

.details-card {
    padding: 0;
}

.details-card > *:not(summary) {
    margin-left: 16px;
    margin-right: 16px;
}

.details-card__summary {
    padding: 14px 16px;
    font-weight: 650;
    cursor: pointer;
    min-height: 44px;
    border-radius: var(--radius-m);
}

.details-card[open] .details-card__summary {
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 12px;
}

.details-card > form,
.details-card > .field:last-child,
.details-card > fieldset:last-child {
    padding-bottom: 14px;
}

.card--attention {
    border-color: var(--color-warning);
    background: var(--color-warning-bg);
}

.is-hidden {
    display: none !important;
}

/* ---- Trip rows and lists --------------------------------------------- */
.trip-list {
    display: flex;
    flex-direction: column;
}

.trip-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 10px 4px;
    min-height: 52px;
    color: inherit;
    text-decoration: none;
    border-radius: var(--radius-s);
}

.trip-row + .trip-row {
    border-top: 1px solid var(--color-border);
}

.trip-row:hover {
    background: var(--color-surface-muted);
}

.trip-row__main {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.trip-row__destination {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.trip-row__meta {
    color: var(--color-text-muted);
    font-size: 0.84rem;
}

.trip-row__side {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.trip-row__km {
    font-weight: 650;
    font-variant-numeric: tabular-nums;
}

.trip-hero {
    display: flex;
    align-items: baseline;
    gap: 14px;
    margin-bottom: 12px;
}

.trip-hero__km {
    font-size: 1.9rem;
    font-weight: 750;
    font-variant-numeric: tabular-nums;
}

.trip-hero__odos {
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
}

.post-save-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

/* ---- Tabs and month nav ---------------------------------------------- */
.tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
}

.tabs__tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 8px 10px;
    border-radius: 999px;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-muted);
    font-weight: 600;
    font-size: 0.92rem;
    text-decoration: none;
}

.tabs__tab.is-active {
    background: var(--color-text);
    border-color: var(--color-text);
    color: var(--color-surface);
}

.month-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}

.month-nav__label {
    font-weight: 700;
    font-size: 1.05rem;
}

.journey-card__head {
    margin-bottom: 8px;
}

.journey-card__title {
    margin: 0 0 2px;
    font-size: 1.02rem;
}

.journey-card__title a {
    color: inherit;
    text-decoration: none;
}

.journey-card__title a:hover {
    text-decoration: underline;
}

.logbook-filter .button {
    margin-top: 2px;
}

/* ---- Calendar -------------------------------------------------------- */
.calendar {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.calendar th,
.calendar td {
    border: 1px solid var(--color-border);
    vertical-align: top;
    padding: 4px;
    height: 58px;
    font-size: 0.78rem;
}

.calendar th {
    height: auto;
    text-align: center;
    color: var(--color-text-muted);
    background: var(--color-surface-muted);
}

.calendar__day {
    font-weight: 650;
}

.calendar__active {
    background: var(--color-info-bg);
}

.calendar__link {
    display: block;
    text-decoration: none;
    color: var(--color-accent-strong);
}

.calendar__count,
.calendar__km {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.allocation-row {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-s);
    padding: 12px;
    margin-bottom: 14px;
}

.allocation-row legend {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    padding: 0 6px;
    margin: 0;
}

.separator {
    border: 0;
    border-top: 1px solid var(--color-border);
    margin: 18px 0;
}

/* ---- History --------------------------------------------------------- */
.history-entry__head {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.history-entry__reason {
    margin-bottom: 8px;
}

.history-entry .table-wrap {
    margin-top: 6px;
}

.history-entry table.data td {
    white-space: normal;
    overflow-wrap: anywhere;
}

/* ---- Overview -------------------------------------------------------- */
.overview-vehicle {
    display: flex;
    gap: 16px;
    align-items: center;
}

.overview-vehicle__name {
    margin: 0 0 4px;
}

.overview-vehicle__odometer {
    margin: 0;
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.overview-vehicle__km {
    font-size: 1.9rem;
    font-weight: 750;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
}

.stat-row {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.stat {
    display: flex;
    flex-direction: column;
}

.stat__value {
    font-size: 1.4rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.stat__label {
    color: var(--color-text-muted);
    font-size: 0.82rem;
}

.distribution__bar {
    display: block;
    width: 100%;
    height: 10px;
    border-radius: 999px;
    overflow: hidden;
    background: var(--color-surface-muted);
}

.distribution__segment--business { fill: var(--color-accent); background: var(--color-accent); }
.distribution__segment--commute { fill: var(--color-success); background: var(--color-success); }
.distribution__segment--private { fill: #b3b9c2; background: #b3b9c2; }

.distribution__legend {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    margin-top: 8px;
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    margin-right: 3px;
}

.dot--business { background: var(--color-accent); }
.dot--commute { background: var(--color-success); }
.dot--private { background: #b3b9c2; }

/* ---- Review ----------------------------------------------------------- */
.review-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.review-list__item {
    padding: 9px 0;
    border-bottom: 1px solid var(--color-border);
    overflow-wrap: anywhere;
}

.review-list__item:last-child {
    border-bottom: 0;
}

.review-list__item a {
    color: inherit;
}

.quality-check {
    display: flex;
    gap: 10px;
    align-items: baseline;
}

/* ---- Motion ---------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ---- Wider screens --------------------------------------------------- */
@media (min-width: 760px) {
    body {
        font-size: 16.5px;
    }

    .app {
        padding-top: 28px;
    }
}
