/* Servicebok – design + mobilanpassning */

:root {
    --bobcat-orange: #ee7700;
    --bobcat-orange-dark: #c65f00;
    --bg: #f4f4f1;
    --card: #ffffff;
    --text: #1c1c1c;
    --muted: #6b6b6b;
    --border: #e3e3df;
    --status-red: #d62a2a;
    --status-yellow: #e2a900;
    --status-green: #2c8a3e;
    --status-blue: #2c6ea8;
}

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

html {
    width: 100%;
    max-width: 100%;
    /* Reservera plats för scrollbar permanent → menyn hoppar inte i sidled
       när olika sidor har olika höjd och scrollbaren visas/försvinner */
    scrollbar-gutter: stable;
    overflow-y: scroll;
}
body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

/* === Mjuk övergång mellan sidor === */

/* Modern: cross-document View Transitions (Chrome 126+, Safari TP).
   Topbar och sidomeny markeras så att de inte fadar – de håller sig still
   medan bara innehållet växlar in. Övriga webbläsare ignorerar reglerna. */
@view-transition { navigation: auto; }

.topbar  { view-transition-name: topbar; }
.sidenav { view-transition-name: sidenav; }

::view-transition-old(root),
::view-transition-new(root) {
    animation-duration: 180ms;
    animation-timing-function: ease;
}
::view-transition-old(topbar),
::view-transition-new(topbar),
::view-transition-old(sidenav),
::view-transition-new(sidenav) {
    animation: none;        /* nav + topbar håller sig still mellan sidor */
}

/* Fallback för äldre webbläsare: tona in .content vid sidladdning.
   På VT-stödjande browsers täcker VT-snapshoten denna animation. */
@media (prefers-reduced-motion: no-preference) {
    .content {
        animation: sb-fadein 160ms ease-out both;
    }
    @keyframes sb-fadein {
        from { opacity: 0; transform: translateY(3px); }
        to   { opacity: 1; transform: translateY(0); }
    }
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
    line-height: 1.45;
    -webkit-tap-highlight-color: rgba(238,119,0,0.15);
}

img, video, canvas, svg, picture {
    max-width: 100%;
    height: auto;
}

input, select, textarea, button { max-width: 100%; }

/* === Topbar === */
.topbar {
    background: #1c1c1c;
    color: #fff;
    border-bottom: 4px solid var(--bobcat-orange);
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar-inner {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    gap: 10px;
}
.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #fff;
    text-decoration: none;
    font-weight: 700;
    font-size: 16px;
}
.brand-mark {
    display: inline-flex;
    width: 32px; height: 32px;
    align-items: center; justify-content: center;
    background: var(--bobcat-orange);
    color: #000;
    border-radius: 4px;
    font-weight: 900;
}
.topbar-spacer { flex: 1; }
.vehicle-switch { margin: 0; flex-shrink: 1; min-width: 0; }
.vehicle-switch select {
    background: rgba(255,255,255,0.10);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.2);
    padding: 8px 10px;
    border-radius: 4px;
    font: inherit;
    max-width: 220px;
}
.vehicle-switch select option { color: #1c1c1c; }
.logout-form { display: flex; align-items: center; gap: 8px; margin: 0; }
.user-pill {
    background: rgba(255,255,255,0.08);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 13px;
}
.nav-toggle {
    display: none;
    background: var(--bobcat-orange);
    color: #000;
    border: 0;
    width: 44px; height: 40px;
    font-size: 20px;
    font-weight: 700;
    border-radius: 4px;
    cursor: pointer;
}

/* === Banners === */
.banner { padding: 10px 16px; font-size: 14px; }
.banner-warn { background: #fff5e6; border-bottom: 1px solid #f0c987; color: #663a00; }
.banner-info { background: #eef4fa; border-bottom: 1px solid #bcd6ed; color: #234d72; }
.banner-warn a, .banner-info a { color: var(--bobcat-orange-dark); font-weight: 700; }

/* === Layout === */
.layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    align-items: start;                   /* sidomenyn stretchas inte med content */
    min-height: calc(100vh - 56px);
}
.sidenav {
    background: #2a2a2a;
    color: #fff;
    padding: 16px 0;
    position: sticky;                     /* stannar kvar — inget hopp vid sidbyte */
    top: 56px;                            /* under topbar */
    height: calc(100vh - 56px);
    overflow-y: auto;
    align-self: start;
}
.sidenav nav { display: flex; flex-direction: column; }
.sidenav a {
    color: #ddd;
    text-decoration: none;
    padding: 12px 18px;
    border-left: 4px solid transparent;
    font-size: 15px;
    font-weight: 600;                     /* fast vikt → ingen layout-shift vid .active */
    min-height: 44px;
    display: flex;
    align-items: center;
}
.sidenav a:hover { background: rgba(255,255,255,0.05); color: #fff; }
.sidenav a.active {
    background: rgba(238,119,0,0.15);
    border-left-color: var(--bobcat-orange);
    color: #fff;
    /* font-weight ärvs (600) – ingen breddförändring */
}
.nav-backdrop { display: none; }

.content {
    padding: 20px;
    min-width: 0;
}
.page-title { margin: 0 0 16px 0; font-size: 26px; }

/* === Cards === */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 14px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.card h2 { margin: 0 0 10px 0; font-size: 18px; }
.card h3 { margin: 12px 0 6px 0; font-size: 16px; }
.card h4 { margin: 8px 0 4px 0; font-size: 15px; }
.card-warn { background: #fff5e6; border-color: #f0c987; }
.card-info { background: #eef4fa; border-color: #bcd6ed; }

.active-vehicle { border-left: 6px solid var(--status-green); }

/* === Grid === */
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

/* === Key/value === */
.kv {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    gap: 10px;
}
.kv:last-child { border-bottom: 0; }
.kv span { color: var(--muted); flex-shrink: 0; }
.kv strong { text-align: right; word-break: break-word; }
.kv .pre {
    white-space: pre-wrap;
    text-align: left;
    flex: 1;
    background: #fafafa;
    padding: 8px;
    border-radius: 4px;
    font-family: inherit;
}

/* === Status === */
.status-tag {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    margin-bottom: 6px;
}
.status-tag.status-red { background: var(--status-red); }
.status-tag.status-yellow { background: var(--status-yellow); }
.status-tag.status-green { background: var(--status-green); }
.status-tag.status-blue { background: var(--status-blue); }

.service-card { position: relative; }
.service-card.status-red { border-left: 6px solid var(--status-red); }
.service-card.status-yellow { border-left: 6px solid var(--status-yellow); }
.service-card.status-green { border-left: 6px solid var(--status-green); }
.service-card.status-blue { border-left: 6px solid var(--status-blue); }

.row-status-red td:first-child { box-shadow: inset 3px 0 0 var(--status-red); }
.row-status-yellow td:first-child { box-shadow: inset 3px 0 0 var(--status-yellow); }
.row-status-green td:first-child { box-shadow: inset 3px 0 0 var(--status-green); }
.row-status-blue td:first-child { box-shadow: inset 3px 0 0 var(--status-blue); }

.status-pill { display: inline-block; padding: 2px 8px; border-radius: 10px; background: #eee; font-size: 13px; }
.status-pill.status-planerad { background: #eef4fa; color: #2c6ea8; }
.status-pill.status-ägd { background: #e6f5ea; color: var(--status-green); }
.status-pill.status-såld { background: #f5e6e6; color: var(--status-red); }

/* === Buttons === */
.btn {
    display: inline-block;
    padding: 12px 18px;
    background: #eee;
    color: #1c1c1c;
    text-decoration: none;
    border: 0;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    font-size: 15px;
    min-height: 44px;
    line-height: 1.2;
}
.btn:hover { background: #ddd; }
.btn-primary { background: var(--bobcat-orange); color: #000; }
.btn-primary:hover { background: var(--bobcat-orange-dark); color: #fff; }
.btn-danger { background: var(--status-red); color: #fff; }
.btn-danger:hover { background: #aa1f1f; }
.btn.small { padding: 6px 12px; min-height: 0; font-size: 13px; }

/* === Forms === */
.form { display: grid; gap: 12px; max-width: 760px; }
.form label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-weight: 600;
    color: var(--text);
}
.form label.checkbox {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    font-weight: 500;
}
.form input[type="text"],
.form input[type="number"],
.form input[type="date"],
.form input[type="password"],
.form input[type="file"],
.form select,
.form textarea {
    padding: 12px;
    border: 1px solid #cfcfcc;
    border-radius: 6px;
    font: inherit;
    background: #fff;
    width: 100%;
    min-height: 44px;
}
.form textarea { min-height: 90px; }
.inline-form { display: flex; gap: 8px; margin-top: 10px; align-items: end; flex-wrap: wrap; }
.inline-form label { flex-direction: column; flex: 1 1 auto; }
.inline { display: inline; }

/* === Tables === */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    font-size: 14px;
}
.data-table th, .data-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}
.data-table th {
    background: #f7f7f4;
    font-weight: 700;
    color: var(--muted);
    position: sticky; top: 0;
}
.data-table.compact th, .data-table.compact td { padding: 6px 8px; }
.col-manual { background: #f4f6f9; }
.col-mine { background: #fff7ec; }

.muted { color: var(--muted); }
.group-title {
    margin: 22px 0 10px 0;
    font-size: 18px;
    color: var(--bobcat-orange-dark);
    border-bottom: 2px solid var(--bobcat-orange);
    padding-bottom: 4px;
}

/* === Källkort === */
.source-manual { border-left: 6px solid var(--status-blue); background: #fafcff; }
.source-plate { border-left: 6px solid var(--bobcat-orange); background: #fffaf3; }
.source-plate::before {
    content: "Källa: Maskinens typskylt";
    display: inline-block;
    font-size: 11px; font-weight: 700;
    color: var(--bobcat-orange-dark); background: #ffeacc;
    padding: 2px 8px; border-radius: 10px;
    margin-bottom: 8px; letter-spacing: 0.3px; text-transform: uppercase;
}

/* === Photo grid === */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.photo-card img { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }

/* === Auth === */
.auth-body { background: var(--bg); display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.auth-box { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 24px; max-width: 380px; width: 100%; box-shadow: 0 8px 30px rgba(0,0,0,0.08); }
.auth-brand { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; font-weight: 700; }
.auth-error { background: #fdecec; color: var(--status-red); padding: 10px; border-radius: 6px; margin-bottom: 12px; }
.auth-info { background: #e9f3fe; color: var(--status-blue); padding: 10px; border-radius: 6px; margin-bottom: 12px; }

.appfooter { text-align: center; color: var(--muted); padding: 16px; font-size: 13px; }

/* === Mobil (≤ 900 px) === */
@media (max-width: 900px) {
    body { overflow-x: hidden; }

    .layout {
        grid-template-columns: 1fr;
        width: 100%;
        max-width: 100%;
    }

    .content, main {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        padding: 14px 12px;
    }

    /* Sidomeny gömd off-canvas, slidar in över innehållet */
    .sidenav {
        position: fixed;
        top: 0; left: 0;
        width: min(82vw, 320px);
        max-width: 320px;
        height: 100vh;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        z-index: 1000;
        padding-top: 70px;
        overflow-y: auto;
    }
    .sidenav.open { transform: translateX(0); }
    .nav-toggle { display: inline-flex; align-items: center; justify-content: center; }
    .nav-backdrop {
        display: block;
        position: fixed; inset: 0;
        background: rgba(0,0,0,0); pointer-events: none;
        transition: background 0.2s;
        z-index: 900;
    }
    .nav-backdrop.open { background: rgba(0,0,0,0.4); pointer-events: auto; }

    /* Topbar – flex-wrap + alla barn får krympa */
    .topbar {
        width: 100%;
        max-width: 100%;
    }
    .topbar-inner {
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px 12px;
    }
    .topbar-inner > * { min-width: 0; }
    .brand-text { display: none; }
    .topbar-spacer { display: none; }
    .vehicle-switch {
        order: 10;
        flex-basis: 100%;
        width: 100%;
        max-width: 100%;
    }
    .vehicle-switch select {
        width: 100%;
        max-width: 100%;
        white-space: normal;
    }
    .logout-form { margin-left: auto; }

    .page-title { font-size: 22px; word-break: break-word; }

    /* Grids → en kolumn */
    .grid, .grid-2, .grid-3 {
        grid-template-columns: 1fr;
        width: 100%;
        max-width: 100%;
    }

    /* Kort fyller hela bredden, kan krympa */
    .card {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        padding: 14px;
    }

    /* Key/value-rader: tillåt brytning + krympning */
    .kv { flex-wrap: wrap; gap: 4px; }
    .kv span, .kv strong { min-width: 0; word-break: break-word; }
    .kv strong { text-align: left; flex: 1 1 100%; }

    /* Formulär */
    form, .form { width: 100%; max-width: 100%; }
    .form { display: grid; grid-template-columns: 1fr; }
    .form .grid, .form .grid-2 { grid-template-columns: 1fr; }
    .form input, .form select, .form textarea { width: 100%; max-width: 100%; }
    .inline-form { flex-wrap: wrap; }
    .inline-form > * { min-width: 0; flex: 1 1 auto; }

    /* Knappar – tillåt att stapla på smala skärmar */
    .btn { max-width: 100%; }

    /* Tabeller – wrappade i .table-scroll får scrolla horisontellt */
    .table-scroll {
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -2px;
    }
    .table-scroll table, .table-scroll .data-table {
        width: max-content;
        min-width: 100%;
    }
    .data-table { font-size: 13px; }

    .photo-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}

/* === Smal mobil (≤ 480 px – Galaxy S25 ligger i detta band) === */
@media (max-width: 480px) {
    .topbar-inner { padding: 8px 10px; }
    .user-pill { display: none; }
    .content, main { padding: 12px 10px; }
    .card { padding: 12px; }
    .brand { font-size: 15px; }
    .page-title { font-size: 20px; margin-bottom: 12px; }
    .photo-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .photo-card { padding: 10px; }
    .data-table { font-size: 12.5px; }
    .data-table th, .data-table td { padding: 6px; }
    .btn { padding: 11px 14px; font-size: 14px; }
}

/* === Mycket smal mobil (≤ 360 px) === */
@media (max-width: 360px) {
    .photo-grid { grid-template-columns: 1fr; }
    .vehicle-switch select { font-size: 14px; }
}
