/* Grundläggande styling */
:root {
    --app-bg: #0b1110;
    --app-border: rgba(151, 176, 164, 0.18);
    --app-text: #f5faf7;
    --app-muted: #aabdb4;
    --app-accent: #5bd0ad;
    --app-sidebar-width: 264px;
}

* {
    box-sizing: border-box;
}

body {
    background:
        radial-gradient(circle at top left, rgba(91, 208, 173, 0.08), transparent 26%),
        radial-gradient(circle at top right, rgba(91, 208, 173, 0.05), transparent 22%),
        linear-gradient(180deg, #0f1715 0%, #090d0c 100%);
    color: #ffffff;
    font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    margin: 0;
    padding: 0;
}

a {
    color: inherit;
}

.app-shell-ready {
    padding-left: var(--app-sidebar-width);
}

.app-shell-ready > .app-header {
    display: none;
}

.app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1500;
    width: var(--app-sidebar-width);
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 12px;
    background: linear-gradient(180deg, rgba(11, 17, 16, 0.98) 0%, rgba(8, 13, 12, 0.96) 100%);
    border-right: 1px solid var(--app-border);
    box-shadow: 12px 0 36px rgba(0, 0, 0, 0.28);
    backdrop-filter: blur(18px);
}

.shell-brand {
    padding: 20px 18px 14px;
    border-bottom: 1px solid var(--app-border);
}

.shell-brand strong,
.app-mobile-bar strong {
    display: block;
    font-size: 0.96rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.shell-brand span {
    display: block;
    margin-top: 4px;
    color: var(--app-muted);
    font-size: 0.78rem;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.shell-nav-scroll {
    overflow-y: auto;
    padding: 8px 10px 12px;
}

.shell-nav-section {
    display: grid;
    gap: 6px;
    margin-top: 14px;
}

.shell-nav-section h2 {
    margin: 0;
    padding: 0 10px;
    color: var(--app-muted);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.shell-nav-section nav,
.shell-submenu-items {
    display: grid;
    gap: 4px;
}

.shell-nav-link {
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 0 12px;
    border-radius: 12px;
    color: #dbe8e1;
    text-decoration: none;
    border: 1px solid transparent;
    background: transparent;
    font-size: 0.88rem;
    font-weight: 650;
    letter-spacing: 0.01em;
}

.shell-nav-link:hover,
.shell-nav-link.is-active {
    color: #06100d;
    background: linear-gradient(180deg, rgba(91, 208, 173, 0.98) 0%, rgba(91, 208, 173, 0.88) 100%);
    border-color: rgba(91, 208, 173, 0.42);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.24);
}

.shell-nav-link.is-disabled,
.shell-nav-link.is-disabled:hover {
    color: rgba(219, 232, 225, 0.45);
    background: transparent;
    cursor: not-allowed;
}

.shell-submenu {
    display: grid;
    gap: 4px;
}

.shell-submenu summary {
    cursor: pointer;
    list-style: none;
}

.shell-submenu summary::-webkit-details-marker {
    display: none;
}

.shell-caret {
    font-size: 1.2rem;
    line-height: 1;
    transition: transform 0.16s ease;
}

.shell-submenu[open] .shell-caret {
    transform: rotate(90deg);
}

.shell-submenu-items {
    padding-left: 10px;
    border-left: 1px solid var(--app-border);
    margin-left: 10px;
}

.shell-submenu-items .shell-nav-link {
    min-height: 32px;
    font-size: 0.84rem;
}

.shell-footer {
    padding: 12px;
    border-top: 1px solid var(--app-border);
}

.shell-logout,
.shell-menu-button {
    border-color: var(--app-border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--app-text);
    border-radius: 8px;
}

.shell-logout {
    width: 100%;
    min-height: 38px;
}

.app-mobile-bar,
.shell-scrim {
    display: none;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: #1a1a1a;
    border-bottom: 2px solid #333;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 1000;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    backdrop-filter: blur(10px);
    background: rgba(14, 20, 20, 0.92);
}

.app-header h1 {
    margin: 0;
    font-size: 1.25rem;
}

.app-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.nav-link,
.nav-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 0 12px;
    border-radius: 999px;
    text-decoration: none;
    border: 1px solid rgba(0, 255, 204, 0.35);
    background: rgba(255, 255, 255, 0.04);
    color: #9fffe9;
    font-weight: 600;
    font-size: 0.88rem;
    cursor: pointer;
}

.nav-link:hover,
.nav-button:hover {
    background: rgba(91, 208, 173, 0.95);
    color: #06100d;
    transform: translateY(-1px);
}

.page-shell {
    width: min(1440px, calc(100% - 24px));
    margin: 0 auto;
    padding: 16px 0 24px;
}

.page-subnav {
    width: min(1440px, calc(100% - 24px));
    margin: 0 auto 14px;
    padding: 0 0 4px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.page-subnav-link {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid rgba(151, 176, 164, 0.16);
    background: rgba(255, 255, 255, 0.04);
    color: #dbe8e1;
    text-decoration: none;
    font-size: 0.84rem;
    font-weight: 650;
}

.page-subnav-link:hover,
.page-subnav-link.is-active {
    color: #05100d;
    background: rgba(91, 208, 173, 0.95);
    border-color: rgba(91, 208, 173, 0.34);
}

.page-subnav-copy {
    color: var(--app-muted);
    font-size: 0.82rem;
    margin-left: 4px;
}

.page-intro {
    margin: 0 0 16px;
    padding: 16px 18px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(0, 255, 204, 0.16);
    color: #cbe9dd;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
}

.page-intro p {
    margin: 0;
}

.page-panel {
    margin: 0 auto 16px;
    width: min(1440px, calc(100% - 24px));
}

.page-panel .panel-card,
.page-panel .fleet-section,
.page-panel .fleet-hero,
.page-panel .fleet-empty {
    border-radius: 16px;
}

.page-panel .nav-link,
.page-panel .nav-button {
    min-height: 34px;
    padding: 0 12px;
    font-size: 0.84rem;
}

.dashboard-header {
    position: sticky;
    top: 0;
    z-index: 1000;
    backdrop-filter: blur(10px);
    background: rgba(14, 20, 20, 0.92);
}

.dashboard-main {
    width: min(1480px, calc(100% - 24px));
    margin: 0 auto;
    padding: 16px 0 24px;
}

.dashboard-section {
    width: min(1480px, calc(100% - 24px));
    margin: 0 0 16px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(0, 255, 204, 0.14);
    border-radius: 16px;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.22);
}

.dashboard-section-title {
    width: min(1480px, calc(100% - 24px));
    margin: 0 auto 12px;
    color: #9fffe9;
    letter-spacing: 0.02em;
}

.dashboard-section h3 {
    margin: 0;
    font-size: 1rem;
}

.dashboard-section .nav-link,
.dashboard-section .nav-button {
    min-height: 32px;
    padding: 0 10px;
    font-size: 0.82rem;
}

.dashboard-section select,
.dashboard-section input[type="text"],
.dashboard-section input[type="number"],
.dashboard-section textarea {
    min-height: 36px;
    padding: 8px 10px;
    border-radius: 10px;
}

.tool-page .container {
    display: flex;
    gap: 20px;
    align-items: stretch;
}

.tool-page .control-panel {
    flex: 1;
    min-width: 320px;
    padding: 18px;
    background: rgba(0, 255, 204, 0.08);
    border: 1px solid rgba(0, 255, 204, 0.18);
    border-radius: 16px;
    color: white;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.22);
}

.tool-page .map-container {
    flex: 2;
    min-height: 70vh;
    height: 70vh;
    border-radius: 16px;
    border: 1px solid rgba(0, 255, 204, 0.18);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.22);
}

.tool-page .fields-container,
.tool-page .result-panel,
.tool-page .scenario-panel {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(0, 255, 204, 0.16);
    border-radius: 16px;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
}

.tool-page .fields-container {
    margin-top: 18px;
    padding: 16px;
}

.tool-page .result-panel,
.tool-page .scenario-panel {
    padding: 12px;
}

.tool-page input[type="text"],
.tool-page input[type="number"],
.tool-page select,
.tool-page textarea {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid rgba(0, 255, 204, 0.35);
    background: rgba(255, 255, 255, 0.04);
    color: white;
}

.tool-page label {
    display: grid;
    gap: 6px;
    color: #cbe9dd;
    font-size: 0.94rem;
}

.tool-page .control-panel button {
    min-height: 46px;
    font-weight: 700;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-card {
    width: min(440px, 100%);
    padding: 28px;
    border-radius: 20px;
    background: rgba(10, 25, 22, 0.88);
    border: 1px solid rgba(0, 255, 204, 0.18);
    box-shadow: 0 18px 38px rgba(0, 0, 0, 0.28);
}

.login-card h2 {
    margin: 0 0 8px;
    font-size: 1.8rem;
}

.login-card p {
    margin: 0 0 18px;
    color: #cbe9dd;
    line-height: 1.6;
}

.login-form {
    display: grid;
    gap: 12px;
}

.login-form input {
    width: 100%;
    min-height: 46px;
    padding: 0 12px;
    border-radius: 10px;
    border: 1px solid rgba(0, 255, 204, 0.35);
    background: rgba(255, 255, 255, 0.04);
    color: white;
}

.login-form button {
    min-height: 48px;
    font-weight: 700;
}

.login-links {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 14px;
}

.header-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
}

header h1 {
    font-size: 24px;
    margin: 0;
}

header button {
    background: rgba(0, 255, 204, 0.1);
    color: #00ffcc;
    border: 1px solid #00ffcc;
    padding: 10px 15px;
    cursor: pointer;
    border-radius: 5px;
    transition: background 0.3s, color 0.3s;
}

header button:hover {
    background: #00ffcc;
    color: black;
}

/* Knappar */
button {
    background: rgba(0, 255, 204, 0.1);
    color: #00ffcc;
    border: 1px solid #00ffcc;
    padding: 10px;
    cursor: pointer;
    border-radius: 5px;
    transition: background 0.3s, color 0.3s;
}

button:hover {
    background: #00ffcc;
    color: black;
}

/* Container för traktor och kartor */
.device-container {
    background: rgba(0, 255, 204, 0.08);
    border: 1px solid rgba(0, 255, 204, 0.22);
    padding: 18px;
    border-radius: 18px;
    margin-bottom: 20px;
    box-shadow: 0 16px 34px rgba(0, 0, 0, 0.22);
}

/* Grid-layout för traktordata */
.device-grid {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 20px;
    margin-top: 15px;
}

.device-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.device-header h2 {
    margin: 0;
    font-size: 1.4rem;
}

.button-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.command-buttons {
    display: grid;
    gap: 12px;
    margin: 12px 0 10px;
}

.command-cluster {
    display: grid;
    gap: 10px;
}

.command-cluster-primary {
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.command-cluster-secondary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.command-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: end;
}

.command-btn {
    min-height: 52px;
    font-weight: 700;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.04);
}

.command-danger {
    background: rgba(255, 90, 90, 0.12);
    border-color: rgba(255, 120, 120, 0.75);
    color: #ff9f9f;
}

.command-warning {
    background: rgba(255, 192, 92, 0.12);
    border-color: rgba(255, 197, 106, 0.7);
    color: #ffd28a;
}

.command-success {
    background: rgba(111, 214, 170, 0.12);
    border-color: rgba(111, 214, 170, 0.7);
    color: #9fffe9;
}

.command-accent {
    background: rgba(213, 255, 119, 0.12);
    border-color: rgba(213, 255, 119, 0.65);
    color: #e7ff9d;
}

.inline-field {
    display: grid;
    gap: 6px;
    min-width: 110px;
    color: #9fffe9;
    font-size: 0.9rem;
}

.inline-field input,
.dropdown-container select,
#manualBearing {
    min-height: 44px;
    padding: 0 12px;
    border-radius: 10px;
    border: 1px solid rgba(0, 255, 204, 0.35);
    background: rgba(255, 255, 255, 0.04);
    color: white;
}

/* Mobil-anpassning: tabellen ovanför kartan */
@media (max-width: 768px) {
    header {
        align-items: flex-start;
        flex-direction: column;
        gap: 12px;
    }

    .header-buttons {
        width: 100%;
    }

    .header-buttons button {
        flex: 1 1 calc(50% - 10px);
    }

    .device-grid {
        flex-direction: column;
    }

    .device-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .button-group {
        width: 100%;
    }

    .button-group .tab-button {
        flex: 1 1 calc(50% - 10px);
    }

    .command-cluster-primary {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .command-cluster-secondary {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .command-toolbar {
        display: grid;
        grid-template-columns: 1fr;
    }

    .command-btn {
        min-height: 58px;
        font-size: 0.98rem;
    }

    .dashboard-section,
    .dashboard-main {
        width: min(100% - 16px, 1480px);
        margin: 0 auto;
        padding: 14px;
    }

    .dashboard-section-title {
        width: min(100% - 16px, 1480px);
        margin: 0 auto 10px;
    }

    .app-header {
        position: static !important;
        align-items: flex-start;
        flex-direction: column;
    }

    .dashboard-header {
        position: static !important;
    }

    .app-nav {
        width: 100%;
    }

    .nav-link,
    .nav-button {
        flex: 1 1 calc(50% - 10px);
    }

    .page-shell {
        width: min(100%, calc(100% - 16px));
        padding: 12px 0 20px;
    }

    .tool-page .container {
        flex-direction: column;
    }

    .tool-page .control-panel,
    .tool-page .map-container {
        min-width: 0;
        width: 100%;
    }

    .tool-page .map-container {
        min-height: 52vh;
        height: 52vh;
    }

    .login-page {
        padding: 16px;
    }

    #mqtt-messages,
    .fields-container,
    .snapshot-container {
        margin: 14px;
    }
}

.command-response {
    margin-top: 10px;
    font-weight: bold;
    font-size: 14px;
}


/* Kartan */
.map-container {
    flex: 1 1 100%;
    min-height: 420px;
    height: 420px;
    width: 100%;
    border-radius: 14px;
    position: relative;
    overflow: hidden;
}


.tractor-icon {
    text-align: center;
    line-height: 1;
}

/* Kontrollpanel */
.control-panel {
    background: rgba(43, 43, 43, 0.8);
    color: #ffffff;
    border: 1px solid #00ffcc;
    padding: 15px;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Tabeller */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
    background: rgba(0, 255, 204, 0.05);
    border-radius: 12px;
    overflow: hidden;
}

table th, table td {
    border: 1px solid #00ffcc;
    padding: 10px;
    text-align: left;
}

table th {
    background: rgba(0, 255, 204, 0.1);
    color: #00ffcc;
}

table td {
    color: white;
}

/* Flikar */
.tab-button {
    background-color: rgba(0, 255, 204, 0.1);
    border: 1px solid #00ffcc;
    color: #00ffcc;
    padding: 8px 15px;
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.3s, color 0.3s;
    min-height: 44px;
}

.tab-button:hover, .tab-button.active {
    background-color: #00ffcc;
    color: black;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Mobilanpassad popup för fältval */
@media (max-width: 768px) {
    .responsive-popup {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100vw;
        height: 85vh;
        max-height: 85vh;
        overflow-y: auto;
        border-radius: 10px 10px 0 0;
        background: #222;
        z-index: 999;
        padding: 20px;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.6);
    }

    .responsive-popup table {
        font-size: 14px;
        width: 100%;
    }

    .responsive-popup button {
        width: 100%;
        margin-top: 10px;
    }

    #popupLanesTable {
        overflow-x: auto;
        max-width: 100%;
        display: block;
    }
}

#tractor-camera,
#tractor-analysis {
  max-width: 100%;   /* fyller bredden */
  height: auto;      /* behåller proportioner */
  display: block;
  margin: 0 auto;    /* centrerar */
  border-radius: 14px;
  border: 1px solid rgba(0, 255, 204, 0.18);
}

/* Samlat designsystem: striktare hierarki, tätare ytor och tydligare fokus */
:root {
    --app-bg: #0a0f0e;
    --app-surface: #111918;
    --app-surface-raised: #17211f;
    --app-border: #263532;
    --app-border-strong: #38504a;
    --app-text: #f1f6f3;
    --app-muted: #8fa49d;
    --app-accent: #a7e36f;
    --app-accent-soft: rgba(167, 227, 111, 0.12);
    --app-sidebar-width: 248px;
    --app-radius: 12px;
    --app-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
}

body {
    background: var(--app-bg);
    color: var(--app-text);
    font-size: 15px;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(115deg, rgba(167, 227, 111, 0.035), transparent 30%);
    z-index: -1;
}

.app-sidebar {
    background: #0d1413;
    border-right: 1px solid var(--app-border);
    box-shadow: none;
    backdrop-filter: none;
}

.shell-brand {
    padding: 22px 20px 18px;
    border-bottom-color: var(--app-border);
}

.shell-brand strong {
    color: var(--app-accent);
    letter-spacing: 0.08em;
}

.shell-nav-scroll {
    padding: 12px 12px 18px;
}

.shell-nav-section {
    gap: 7px;
    margin-top: 18px;
}

.shell-nav-section:first-child {
    margin-top: 0;
}

.shell-nav-section h2 {
    padding: 0 11px;
    color: #6f827a;
    font-size: 0.66rem;
}

.shell-nav-link {
    min-height: 40px;
    border-radius: 9px;
    color: #c6d2cd;
    font-size: 0.86rem;
}

.shell-nav-link:hover {
    color: var(--app-text);
    background: #182522;
    border-color: var(--app-border);
    box-shadow: none;
}

.shell-nav-link.is-active {
    color: #0c140d;
    background: var(--app-accent);
    border-color: var(--app-accent);
    box-shadow: 0 4px 12px rgba(167, 227, 111, 0.16);
}

.shell-submenu-items {
    border-left-color: var(--app-border-strong);
}

.shell-footer {
    padding: 14px 12px;
    border-top-color: var(--app-border);
}

.shell-logout {
    min-height: 36px;
    border-radius: 9px;
    color: var(--app-muted);
}

.shell-topbar {
    position: sticky;
    top: 0;
    z-index: 900;
    min-height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 28px;
    background: rgba(10, 15, 14, 0.94);
    border-bottom: 1px solid var(--app-border);
    backdrop-filter: blur(14px);
}

.shell-topbar > div {
    display: grid;
    gap: 2px;
}

.shell-topbar-kicker {
    color: var(--app-muted);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.shell-topbar strong {
    font-size: 1.05rem;
    letter-spacing: -0.01em;
}

.shell-live-indicator {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--app-muted);
    font-size: 0.76rem;
    font-weight: 650;
}

.shell-live-indicator i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--app-accent);
    box-shadow: 0 0 0 4px var(--app-accent-soft);
}

.page-subnav {
    width: min(1480px, calc(100% - 56px));
    margin: 18px auto 0;
    padding: 0 0 12px;
    gap: 6px;
    border-bottom: 1px solid var(--app-border);
}

.page-subnav-link {
    min-height: 30px;
    padding: 0 10px;
    border-radius: 7px;
    border-color: transparent;
    background: transparent;
    color: var(--app-muted);
    font-size: 0.78rem;
}

.page-subnav-link:hover,
.page-subnav-link.is-active {
    color: var(--app-text);
    background: var(--app-surface-raised);
    border-color: var(--app-border);
}

.page-subnav-link.is-active {
    color: var(--app-accent);
}

.page-subnav-copy {
    color: #667a72;
    font-size: 0.76rem;
}

.page-shell,
.fleet-shell,
.dashboard-main,
.dashboard-section,
.dashboard-section-title {
    width: min(1480px, calc(100% - 56px));
}

.page-shell,
.fleet-shell,
.dashboard-main {
    padding-top: 22px;
}

.dashboard-section,
.page-intro,
.fleet-hero,
.fleet-section,
.tool-page .control-panel,
.tool-page .fields-container,
.tool-page .result-panel,
.tool-page .scenario-panel,
.device-container {
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    background: var(--app-surface);
    box-shadow: var(--app-shadow);
}

.dashboard-section {
    padding: 18px;
    margin-bottom: 14px;
}

.dashboard-section h3,
.dashboard-section-title {
    color: var(--app-text);
}

.dashboard-section-title {
    margin: 20px auto 8px;
    color: var(--app-muted);
    font-size: 0.72rem;
    font-weight: 750;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.fleet-hero {
    background: var(--app-surface);
    border-radius: var(--app-radius);
    box-shadow: var(--app-shadow);
}

.fleet-section {
    padding: 18px;
    background: var(--app-surface);
}

.metric-card,
.fleet-card {
    background: var(--app-surface-raised);
    border-color: var(--app-border);
    border-radius: 10px;
}

button,
.nav-button,
.nav-link {
    border-radius: 8px;
}

button,
.nav-button {
    background: var(--app-accent-soft);
    border-color: rgba(167, 227, 111, 0.45);
    color: var(--app-accent);
}

button:hover,
.nav-button:hover {
    background: var(--app-accent);
    border-color: var(--app-accent);
    color: #0c140d;
}

table {
    background: var(--app-surface-raised);
}

table th,
table td {
    border-color: var(--app-border);
}

table th {
    background: #1c2a26;
    color: var(--app-accent);
}

@media (max-width: 768px) {
    .shell-topbar {
        position: static;
        padding: 12px 16px;
    }

    .shell-live-indicator {
        display: none;
    }

    .page-subnav,
    .page-shell,
    .fleet-shell,
    .dashboard-main,
    .dashboard-section,
    .dashboard-section-title {
        width: min(100% - 28px, 1480px);
    }

    .page-subnav {
        margin-top: 12px;
    }
}

.snapshot-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (min-width: 768px) {
  .snapshot-container {
    flex-direction: row; /* visar bilder sida vid sida på större skärm */
    justify-content: center;
  }
  #tractor-camera,
  #tractor-analysis {
    max-width: 48%;  /* båda ryms bredvid varandra */
  }
}

.fleet-page {
    color: #f3fff9;
}

.fleet-shell {
    width: min(1480px, calc(100% - 24px));
    margin: 0 auto;
    padding: 16px 0 28px;
}

.fleet-hero {
    display: grid;
    gap: 18px;
    grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
    padding: 24px;
    border-radius: 24px;
    background:
        radial-gradient(circle at top right, rgba(0, 255, 204, 0.16), transparent 28%),
        linear-gradient(135deg, rgba(8, 18, 16, 0.96), rgba(9, 13, 12, 0.92));
    border: 1px solid rgba(0, 255, 204, 0.18);
    box-shadow: 0 24px 44px rgba(0, 0, 0, 0.32);
}

.fleet-kicker {
    margin: 0 0 8px;
    color: #8fe8d0;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 0.76rem;
    font-weight: 700;
}

.fleet-hero h2,
.fleet-section h3 {
    margin: 0;
}

.fleet-hero-copy {
    display: grid;
    gap: 12px;
}

.fleet-hero-copy p {
    margin: 0;
    color: #cbe9dd;
    line-height: 1.6;
}

.fleet-hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.fleet-badge-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.status-chip,
.sensor-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 32px;
    padding: 0 10px;
    border-radius: 999px;
    border: 1px solid rgba(0, 255, 204, 0.24);
    background: rgba(255, 255, 255, 0.04);
    color: #d4fff1;
    font-size: 0.82rem;
    font-weight: 700;
}

.status-chip.is-good {
    background: rgba(0, 255, 204, 0.12);
    color: #00ffcc;
}

.status-chip.is-warn {
    background: rgba(255, 176, 32, 0.12);
    color: #ffd08f;
}

.status-chip.is-offline {
    background: rgba(255, 88, 88, 0.12);
    color: #ffb8b8;
}

.fleet-metric-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.metric-card,
.fleet-section,
.device-card,
.capture-card,
.config-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(0, 255, 204, 0.16);
    border-radius: 18px;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
}

.metric-card {
    padding: 14px;
}

.metric-label {
    margin: 0 0 8px;
    color: #8fe8d0;
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.metric-value {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
    color: #f6fff9;
}

.metric-value.is-good {
    color: #00ffcc;
}

.metric-value.is-warn {
    color: #ffd08f;
}

.metric-value.is-offline {
    color: #ffb8b8;
}

.metric-subtext {
    margin: 6px 0 0;
    color: #c0dfd2;
    font-size: 0.88rem;
    line-height: 1.5;
}

.fleet-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(340px, 0.85fr);
    gap: 16px;
    margin-top: 16px;
}

.fleet-section {
    padding: 18px;
}

.fleet-section + .fleet-section {
    margin-top: 16px;
}

.fleet-section-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
    margin-bottom: 14px;
}

.fleet-section-header p,
.fleet-section > p {
    margin: 6px 0 0;
    color: #cbe9dd;
    line-height: 1.55;
}

.fleet-list {
    display: grid;
    gap: 10px;
}

.device-card,
.capture-card,
.config-card {
    padding: 14px;
}

.device-card h4,
.capture-card h4,
.config-card h4 {
    margin: 0 0 8px;
}

.device-card p,
.capture-card p,
.config-card p {
    margin: 0;
    color: #cbe9dd;
}

.split-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.stacked-fields {
    display: grid;
    gap: 10px;
}

.stacked-fields label {
    display: grid;
    gap: 6px;
}

.stacked-fields input,
.stacked-fields select,
.stacked-fields textarea {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(0, 255, 204, 0.28);
    background: rgba(5, 12, 10, 0.82);
    color: #f3fff9;
    box-sizing: border-box;
}

.stacked-fields textarea {
    min-height: 120px;
    resize: vertical;
}

.detail-raw {
    margin-top: 12px;
    padding: 12px;
    border-radius: 12px;
    background: rgba(7, 11, 10, 0.92);
    color: #9ef7d0;
    border: 1px solid rgba(0, 255, 204, 0.14);
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

.fleet-empty {
    padding: 18px;
    border: 1px dashed rgba(0, 255, 204, 0.24);
    border-radius: 16px;
    color: #bfe9db;
    background: rgba(255, 255, 255, 0.02);
}

@media (max-width: 1100px) {
    .fleet-hero,
    .fleet-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .fleet-shell {
        width: min(100% - 16px, 1480px);
    }

    .fleet-hero {
        padding: 16px;
    }

    .fleet-metric-grid,
    .split-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 900px) {
    .app-shell-ready {
        padding-left: 0;
        padding-top: 54px;
    }

    .app-mobile-bar {
        position: fixed;
        inset: 0 0 auto 0;
        z-index: 1600;
        height: 54px;
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 0 12px;
        background: rgba(16, 22, 20, 0.96);
        border-bottom: 1px solid var(--app-border);
        backdrop-filter: blur(10px);
    }

    .shell-menu-button {
        width: 40px;
        height: 38px;
        display: inline-grid;
        align-content: center;
        gap: 4px;
        padding: 0 10px;
    }

    .shell-menu-button span {
        height: 2px;
        border-radius: 99px;
        background: var(--app-text);
    }

    .app-sidebar {
        transform: translateX(-100%);
        transition: transform 0.18s ease;
    }

    .app-shell-open .app-sidebar {
        transform: translateX(0);
    }

    .app-shell-open .shell-scrim {
        display: block;
        position: fixed;
        inset: 54px 0 0 0;
        z-index: 1400;
        padding: 0;
        border: 0;
        border-radius: 0;
        background: rgba(0, 0, 0, 0.34);
    }

    .page-shell,
    .fleet-shell {
        width: min(100% - 16px, 1480px);
    }
}

/* Final shell pass: keep the common surface language after page-specific rules. */
.fleet-hero,
.fleet-section,
.device-container,
.tool-page .control-panel,
.tool-page .fields-container,
.tool-page .result-panel,
.tool-page .scenario-panel {
    border-color: var(--app-border);
    border-radius: var(--app-radius);
    background: var(--app-surface);
    box-shadow: var(--app-shadow);
}

.fleet-hero {
    background: var(--app-surface);
}

/* Path Planner: arbetsflödet läses uppifrån och ned. */
.tool-page .container {
    display: grid;
    grid-template-areas:
        "controls"
        "map"
        "result";
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
}

.tool-page .control-panel {
    display: contents;
}

.tool-page .control-panel > .scenario-panel:first-child {
    grid-area: controls;
}

.tool-page .planner-panel-lead {
    margin: -2px 0 10px;
    color: var(--app-muted);
    font-size: 0.86rem;
}

.tool-page .map-wrapper {
    grid-area: map;
}

.tool-page .result-panel {
    grid-area: result;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px 18px;
}

.tool-page .result-panel h2,
.tool-page .result-panel details {
    grid-column: 1 / -1;
}

.tool-page .result-panel p {
    margin: 0;
    padding: 8px 10px;
    border: 1px solid var(--app-border);
    border-radius: 8px;
    background: var(--app-surface-raised);
    font-size: 0.82rem;
}

/* Snabbtester är en utvecklingsyta och ska inte ligga i operatörsflödet. */
.tool-page .control-panel > .scenario-panel + .scenario-panel {
    display: none;
}

.tool-page .map-container {
    min-height: 62vh;
    height: 62vh;
}

/* Gemensam, kompakt kontrollnivå för navigation och vardagsåtgärder. */
button:not(.command-btn),
.nav-button,
.nav-link,
.tab-button {
    min-height: 32px;
    padding: 0 10px;
    border-radius: 7px;
    font-size: 0.8rem;
    font-weight: 650;
}

.tool-page .scenario-row button:not(.command-btn) {
    min-height: 32px;
}

.fleet-card-footer .nav-link,
.fleet-hero-actions .nav-link {
    min-height: 30px;
    padding-inline: 9px;
    font-size: 0.78rem;
}

.fleet-section-header .nav-button {
    min-height: 30px;
}

/* Luft mellan kontroller: varje kontroll får en tydlig egen tryckyta. */
.tool-page .scenario-panel > .scenario-row {
    column-gap: 12px;
    row-gap: 10px;
    margin-top: 10px;
}

.tool-page .scenario-panel > .scenario-row:first-of-type {
    margin-top: 0;
}

.tool-page .scenario-panel > details {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--app-border);
}

.tool-page .scenario-panel details .scenario-row {
    column-gap: 14px;
    row-gap: 12px;
}

.tool-page .scenario-panel details .scenario-row + .scenario-row {
    margin-top: 12px;
}

.tool-page .animation-speed-control {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: auto;
    margin: 0;
}

.tool-page .animation-speed-control input {
    width: 76px;
    min-height: 32px;
    height: 32px;
    padding: 0 8px;
    line-height: 1;
}

.tool-page .scenario-row select,
.tool-page .scenario-row input,
.tool-page .scenario-row button {
    margin: 0;
}

.dropdown-container {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px 12px;
    margin-top: 12px;
}

.dropdown-container label {
    margin: 0;
}

.button-group,
.header-buttons,
.fleet-card-footer {
    gap: 10px 12px;
}

@media (max-width: 900px) {
    .tool-page .result-panel {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 560px) {
    .tool-page .result-panel {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 900px) {
    .page-shell,
    .fleet-shell,
    .dashboard-main,
    .dashboard-section,
    .dashboard-section-title,
    .page-subnav {
        width: min(100% - 28px, 1480px);
    }
}
