:root {
    --red: #b91c1c;
    --red-dark: #991b1b;
    --ink: #172033;
    --muted: #667085;
    --line: #dfe3ea;
    --surface: #ffffff;
    --background: #f4f6f8;
    --success: #166534;
    --warning: #9a3412;
    --radius: 18px;
    --shadow: 0 10px 35px rgba(23, 32, 51, 0.08);
}

* { box-sizing: border-box; }
html { background: var(--background); }
body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background: var(--background);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.58; }

.app-header {
    position: sticky;
    top: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: max(16px, env(safe-area-inset-top)) 20px 16px;
    color: #fff;
    background: linear-gradient(135deg, var(--red-dark), var(--red));
    box-shadow: 0 4px 20px rgba(153, 27, 27, 0.25);
}
.app-header h1 { margin: 2px 0 0; font-size: clamp(1.4rem, 4vw, 2rem); }
.eyebrow {
    margin: 0;
    color: inherit;
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    opacity: 0.78;
}

.app-shell { width: min(980px, 100%); margin: 0 auto; padding: 16px 16px 42px; }
.tabs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding: 5px;
    margin-bottom: 16px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
}
.tab {
    min-height: 44px;
    border: 0;
    border-radius: 10px;
    color: var(--muted);
    background: transparent;
    font-weight: 750;
}
.tab.is-active { color: #fff; background: var(--red); }
.panel { display: none; }
.panel.is-active { display: block; }

.card, .warning-card, .map-card {
    margin-bottom: 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}
.card { padding: 18px; }
.route-form-card { position: relative; }

.field-group { margin-bottom: 14px; }
.field-group label, .vehicle-grid label {
    display: block;
    margin-bottom: 7px;
    font-size: 0.86rem;
    font-weight: 800;
}
input[type="search"], input[type="number"] {
    width: 100%;
    min-height: 48px;
    padding: 11px 13px;
    border: 1px solid #cfd5df;
    border-radius: 11px;
    color: var(--ink);
    background: #fff;
    outline: none;
}
input:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(185, 28, 28, 0.12); }
.input-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.location-field { position: relative; }
.suggestions {
    position: absolute;
    z-index: 1200;
    top: calc(100% - 7px);
    left: 0;
    right: 0;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: #fff;
    box-shadow: 0 12px 30px rgba(23, 32, 51, 0.16);
}
.suggestion {
    display: block;
    width: 100%;
    padding: 12px 13px;
    border: 0;
    border-bottom: 1px solid #eef0f4;
    color: var(--ink);
    background: #fff;
    text-align: left;
}
.suggestion:last-child { border-bottom: 0; }
.suggestion:hover, .suggestion:focus { background: #f8fafc; }
.suggestion small { display: block; margin-top: 3px; color: var(--muted); }

.swap-button {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    margin: -5px auto 4px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--red);
    background: #fff;
    font-size: 1.25rem;
    font-weight: 900;
}

.primary-button, .secondary-button, .nav-button, .icon-button {
    min-height: 46px;
    padding: 10px 16px;
    border-radius: 11px;
    font-weight: 800;
}
.primary-button { width: 100%; border: 0; color: #fff; background: var(--red); }
.primary-button:hover { background: var(--red-dark); }
.secondary-button { border: 1px solid var(--line); color: var(--ink); background: #fff; }
.compact { min-height: 42px; padding: 8px 12px; }
.icon-button { border: 1px solid rgba(255,255,255,.5); color: #fff; background: rgba(255,255,255,.12); }
.text-button { border: 0; color: var(--red); background: transparent; font-weight: 800; }

.route-options { margin: 5px 0 16px; }
.route-options summary, .directions-details summary { cursor: pointer; font-weight: 800; }
.checkbox-grid { display: grid; gap: 10px; padding-top: 12px; }
.checkbox-grid label { display: flex; align-items: center; gap: 9px; }
.checkbox-grid input { width: 18px; height: 18px; accent-color: var(--red); }
.form-message { min-height: 1.3em; margin: 10px 0 0; color: var(--muted); font-weight: 650; }
.form-message.is-error { color: #b42318; }
.form-message.is-success { color: var(--success); }

.map-card { overflow: hidden; }
#map { width: 100%; height: min(48vh, 470px); min-height: 320px; background: #e8edf2; }
.leaflet-control-attribution { font-size: 10px; }

.result-heading, .section-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}
.result-heading h2, .section-heading h2, #panel-vehicle h2 { margin: 3px 0 0; }
.summary-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 14px;
}
.summary-grid div { padding: 13px; border-radius: 12px; background: #f7f8fa; }
.summary-grid span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 0.76rem; font-weight: 750; }
.summary-grid strong { font-size: 1.08rem; }
.comparison-notice { padding: 12px 14px; border-radius: 11px; color: #7c2d12; background: #fff7ed; line-height: 1.45; }
.navigation-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.nav-button { border: 1px solid var(--line); color: var(--ink); background: #fff; }
.directions-details { margin-top: 17px; }

.summary-grid-four { grid-template-columns: repeat(4, 1fr); }

.follow-route-card {
    display: grid;
    gap: 13px;
    margin-top: 16px;
    padding: 16px;
    border: 2px solid rgba(185, 28, 28, .25);
    border-radius: 14px;
    background: #fffafa;
}
.follow-route-card h3 { margin: 3px 0 7px; }
.follow-route-card p { margin: 0; line-height: 1.5; }
.follow-route-card[data-status="blocked"] {
    border-color: #fbbf24;
    color: #713f12;
    background: #fffbeb;
}
.follow-route-card[data-status="blocked"] .primary-button { background: #9ca3af; }
.follow-route-card[data-status="allowed"] { border-color: rgba(185, 28, 28, .25); background: #fffafa; }
.route-tools { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.checkpoints-details, .destination-only-block { margin-top: 17px; }
.checkpoints-details summary { cursor: pointer; font-weight: 800; }
.checkpoint-list { display: grid; gap: 9px; margin-top: 12px; }
.checkpoint-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    padding: 11px 12px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: #fff;
}
.checkpoint-item strong, .checkpoint-item small { display: block; }
.checkpoint-item small { margin-top: 3px; color: var(--muted); }
.checkpoint-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 5px; }
.mini-nav-button {
    min-height: 34px;
    padding: 6px 9px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    background: #fff;
    font-size: .78rem;
    font-weight: 800;
}
.checkpoint-marker-shell { background: transparent; border: 0; }
.checkpoint-marker-shell span {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border: 2px solid #fff;
    border-radius: 999px;
    color: #fff;
    background: var(--red);
    box-shadow: 0 2px 8px rgba(23, 32, 51, .35);
    font-size: .78rem;
    font-weight: 900;
}
.directions-details ol { display: grid; gap: 7px; padding: 0; list-style: none; }
.directions-details li { margin: 0; }
.direction-step-button {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr);
    align-items: start;
    gap: 10px;
    width: 100%;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--ink);
    background: #fff;
    text-align: left;
}
.direction-step-button:hover, .direction-step-button:focus { border-color: var(--red); background: #fffafa; }
.direction-step-button:disabled { cursor: default; opacity: 1; }
.direction-number {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 999px;
    color: #fff;
    background: var(--ink);
    font-size: .78rem;
    font-weight: 900;
}
.direction-content strong, .direction-content small { display: block; }
.direction-content strong { line-height: 1.4; }
.direction-content small { margin-top: 4px; color: var(--muted); }

.warning-card { padding: 15px 17px; color: #7c2d12; background: #fff7ed; line-height: 1.5; }
.vehicle-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin: 18px 0; }
.small-print { color: var(--muted); font-size: .86rem; line-height: 1.5; }

.saved-list { display: grid; gap: 11px; }
.saved-empty { padding: 28px 10px; color: var(--muted); text-align: center; }
.saved-item { padding: 14px; border: 1px solid var(--line); border-radius: 12px; }
.saved-item h3 { margin: 0 0 5px; font-size: 1rem; }
.saved-item p { margin: 3px 0; color: var(--muted); font-size: .86rem; }
.saved-actions { display: flex; gap: 8px; margin-top: 12px; }
.saved-actions button { min-height: 38px; padding: 7px 11px; border-radius: 9px; font-weight: 750; }

.loading-overlay {
    position: fixed;
    z-index: 3000;
    inset: 0;
    display: grid;
    place-content: center;
    gap: 14px;
    padding: 30px;
    color: #fff;
    background: rgba(13, 18, 30, .72);
    text-align: center;
    backdrop-filter: blur(3px);
}
.loading-overlay[hidden] { display: none; }
.spinner {
    width: 48px;
    height: 48px;
    margin: 0 auto;
    border: 5px solid rgba(255,255,255,.28);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.noscript { padding: 12px; color: #fff; background: #b42318; text-align: center; }

@media (max-width: 680px) {
    .app-shell { padding: 12px 10px 32px; }
    .card { padding: 15px; }
    .input-row { grid-template-columns: 1fr; }
    .input-row .compact { width: 100%; }
    .summary-grid { grid-template-columns: 1fr; }
    .navigation-actions, .route-tools { grid-template-columns: 1fr; }
    .checkpoint-item { grid-template-columns: 1fr; }
    .checkpoint-actions { justify-content: flex-start; }
    .vehicle-grid { grid-template-columns: 1fr; }
    #map { min-height: 300px; height: 43vh; }
}

/* v1.3 additions */
.tabs { grid-template-columns: repeat(4, 1fr); }
.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.logout-link {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    padding: 8px 10px;
    border-radius: 9px;
    color: #fff;
    font-size: .82rem;
    font-weight: 800;
    text-decoration: none;
    background: rgba(255,255,255,.12);
}
.sync-pill {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 5px 9px;
    border-radius: 999px;
    color: #fff;
    background: rgba(255,255,255,.14);
    font-size: .72rem;
    font-weight: 850;
}
.sync-pill[data-status="offline"], .sync-pill[data-status="waiting"] { background: #9a3412; }
.sync-pill[data-status="online"] { background: #166534; }

input[type="text"], input[type="password"], input[type="url"], input[type="date"], select, textarea {
    width: 100%;
    min-height: 46px;
    padding: 10px 12px;
    border: 1px solid #cfd5df;
    border-radius: 11px;
    color: var(--ink);
    background: #fff;
    outline: none;
}
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(185, 28, 28, .12); }
button:disabled { cursor: not-allowed; opacity: .55; }

.restriction-card {
    margin: 15px 0;
    padding: 14px;
    border: 1px solid #bbf7d0;
    border-radius: 12px;
    color: #14532d;
    background: #f0fdf4;
}
.restriction-card[data-status="avoided"] { color: #7c2d12; border-color: #fed7aa; background: #fff7ed; }
.restriction-card[data-status="blocked"] { color: #7f1d1d; border-color: #fecaca; background: #fef2f2; }
.restriction-card[data-status="unavailable"] { color: #713f12; border-color: #fde68a; background: #fffbeb; }
.restriction-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.restriction-heading span { padding: 4px 8px; border-radius: 999px; background: rgba(255,255,255,.72); font-size: .74rem; font-weight: 900; }
.restriction-card p { margin: 8px 0 0; line-height: 1.48; }
.restriction-list { margin: 9px 0 0; padding-left: 20px; }
.restriction-list:empty { display: none; }

.poi-centre-row, .form-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin: 15px 0;
}
.poi-centre-row label, .form-grid label, .auth-form label, .place-dialog > form > label {
    display: block;
    font-size: .84rem;
    font-weight: 800;
}
.poi-centre-row label select, .form-grid label input, .form-grid label select, .form-grid label textarea, .auth-form label input {
    margin-top: 7px;
}
.compact-select { width: auto; min-width: 145px; min-height: 40px; padding: 7px 10px; }
.poi-results { display: grid; gap: 10px; margin-top: 16px; }
.poi-item { padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.poi-item h3 { margin: 0 0 6px; }
.poi-item p { margin: 0; color: var(--muted); font-size: .88rem; line-height: 1.45; }
.place-item-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.place-item-top h3 { min-width: 0; }
.acceptance-badge { flex: 0 0 auto; padding: 4px 8px; border-radius: 999px; font-size: .72rem; font-weight: 900; color: #713f12; background: #fef3c7; }
.acceptance-badge.is-confirmed { color: #14532d; background: #dcfce7; }
.acceptance-badge.is-refused { color: #7f1d1d; background: #fee2e2; }

.place-dialog {
    width: min(760px, calc(100% - 24px));
    max-height: calc(100vh - 28px);
    padding: 0;
    border: 0;
    border-radius: 18px;
    color: var(--ink);
    background: #fff;
    box-shadow: 0 24px 70px rgba(15, 23, 42, .32);
}
.place-dialog::backdrop { background: rgba(15, 23, 42, .64); backdrop-filter: blur(2px); }
.place-dialog form { padding: 20px; overflow-y: auto; max-height: calc(100vh - 28px); }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.dialog-heading h2 { margin: 3px 0 0; }
.dialog-close { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 999px; color: var(--ink); background: #fff; font-size: 1.5rem; line-height: 1; }
.full-width { grid-column: 1 / -1; }
.campsite-details { margin: 16px 0; padding: 13px; border: 1px solid var(--line); border-radius: 12px; background: #f8fafc; }
.campsite-details summary { cursor: pointer; font-weight: 850; }
.details-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.dialog-actions { display: grid; grid-template-columns: auto minmax(220px, 1fr); gap: 10px; align-items: center; margin-top: 16px; }
.danger-button { min-height: 46px; padding: 10px 14px; border: 1px solid #fecaca; border-radius: 11px; color: #b42318; background: #fff; font-weight: 850; }

.auth-page { display: grid; min-height: 100vh; place-items: center; padding: 18px; background: linear-gradient(145deg, #f8fafc, #fee2e2); }
.auth-shell { width: min(460px, 100%); }
.auth-card { padding: 24px; border: 1px solid var(--line); border-radius: 20px; background: #fff; box-shadow: var(--shadow); }
.auth-card h1 { margin: 4px 0 8px; }
.auth-card p { line-height: 1.5; }
.auth-form { display: grid; gap: 14px; margin-top: 18px; }
.remember-row { display: flex !important; align-items: center; gap: 9px; font-weight: 700 !important; }
.remember-row input { width: 18px; height: 18px; accent-color: var(--red); }
.alert { margin: 14px 0; padding: 12px 14px; border-radius: 11px; line-height: 1.45; }
.alert-error { color: #7f1d1d; border: 1px solid #fecaca; background: #fef2f2; }
.auth-card pre { overflow-x: auto; padding: 12px; border-radius: 10px; background: #111827; color: #f9fafb; font-size: .78rem; }

@media (max-width: 760px) {
    .app-header { align-items: flex-start; }
    .header-actions { flex-wrap: wrap; max-width: 48%; }
    .sync-pill { order: 3; }
    .tabs { display: flex; overflow-x: auto; scrollbar-width: none; }
    .tabs::-webkit-scrollbar { display: none; }
    .tab { flex: 0 0 auto; min-width: 112px; padding: 0 12px; }
    .poi-centre-row, .form-grid, .details-grid { grid-template-columns: 1fr; }
    .full-width { grid-column: auto; }
    .dialog-actions { grid-template-columns: 1fr; }
    .section-heading { align-items: stretch; flex-direction: column; }
    .compact-select { width: 100%; }
    .place-item-top { flex-direction: column; }
}

/* v1.4 stopover services and expanded place records */
.external-services-card {
    background: linear-gradient(145deg, #fff, #fff7ed);
}
.service-centre-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(190px, auto);
    gap: 12px;
    align-items: end;
    margin: 15px 0;
}
.service-centre-row label {
    display: block;
    font-size: .84rem;
    font-weight: 800;
}
.service-centre-row select { margin-top: 7px; }
.service-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}
.service-button {
    min-height: 78px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 5px;
    padding: 13px 14px;
    border: 1px solid #fed7aa;
    border-radius: 13px;
    color: #7c2d12;
    background: #fff;
    text-align: left;
    cursor: pointer;
}
.service-button:hover { border-color: #fb923c; background: #fff7ed; }
.service-button strong { font-size: 1rem; }
.service-button span { color: #6b7280; font-size: .78rem; line-height: 1.35; }
.source-link-button {
    display: inline-flex;
    align-items: center;
    min-height: 42px;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--ink);
    background: #fff;
    font-weight: 800;
    text-decoration: none;
}

@media (max-width: 680px) {
    .service-centre-row, .service-grid { grid-template-columns: 1fr; }
}

/* v1.4.4 safety and mobile performance refinements */
select:disabled, input:disabled { cursor: not-allowed; background: #f3f4f6; color: #6b7280; }
.route-results, .poi-item, .saved-item { overflow-wrap: anywhere; }
@media (max-width: 430px) {
    .app-header { gap: 10px; padding-left: 14px; padding-right: 14px; }
    .app-header h1 { font-size: 1.55rem; }
    .header-actions { max-width: 52%; justify-content: flex-end; }
    .summary-grid-four { grid-template-columns: 1fr 1fr; }
}

.app-version { width: min(980px, 100%); margin: -22px auto 24px; padding: 0 16px; color: var(--muted); font-size: .75rem; font-weight: 750; text-align: center; }
