/* =========================================================
   CSS Custom Properties — design tokens
   Change these to retheme the entire app.
   ========================================================= */

:root {
    --nav-bg:           #0f2942;
    --color-primary:    #1167b1;
    --color-primary-h:  #0d5795;
    --color-accent:     #2563eb;
    --color-focus-ring: rgba(37, 99, 235, 0.15);
    --color-body-bg:    #f4f6f8;
    --color-border-in:  #ccd4dc;
    --color-text:       #1d2733;
    --radius-card:      14px;
    --radius-btn:       10px;
    --radius-input:     9px;
}

* {
    box-sizing: border-box;
}

html {
    overflow-x: hidden;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    background: var(--color-body-bg);
    color: var(--color-text);
    overflow-x: hidden;
}

/* =========================================================
   Topbar / grundlayout
   ========================================================= */

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    background: var(--nav-bg);
    color: #fff;
    gap: 16px;
    flex-wrap: nowrap;
}

.topbar a {
    color: #fff;
    text-decoration: none;
    margin-left: 12px;
}

.brand a {
    font-weight: 700;
    font-size: 18px;
}

.container {
    max-width: 96vw;
    margin: 24px auto;
    padding: 0 16px;
}

.card {
    background: #fff;
    border-radius: 14px;
    padding: 20px;
    margin-bottom: 18px;
    box-shadow: 0 1px 7px rgba(0, 0, 0, .08);
}

.narrow {
    max-width: 480px;
    margin: 50px auto;
}

.page-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.card > .page-title {
    margin-bottom: 14px;
}

.muted {
    color: #64748b;
    font-size: 14px;
}

/* =========================================================
   Formul채r
   ========================================================= */

.grid-form,
.production-filter-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

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

.form-grid-3,
.grid-form-3 {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

.form-grid-4,
.grid-form-4 {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}

.full-width {
    grid-column: 1 / -1;
}

label {
    display: flex;
    flex-direction: column;
    font-weight: 600;
    gap: 6px;
}

input,
select,
textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--color-border-in);
    border-radius: var(--radius-input);
    font: inherit;
    background: #fff;
}

textarea {
    min-height: 80px;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-focus-ring);
}

.form-actions {
    grid-column: 1 / -1;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.inline {
    flex-direction: row;
    align-items: center;
    font-weight: 500;
}

.inline input {
    width: auto;
}

/* =========================================================
   Knappar / feedback
   ========================================================= */

.primary,
.button,
button,
.secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    padding: 10px 14px;
    text-decoration: none;
    cursor: pointer;
    font-weight: 700;
    border: 0;
}

.primary,
button.primary,
.button.primary,
a.button.primary {
    background: var(--color-primary);
    color: #fff;
}

.button,
a.button,
.secondary,
button.secondary {
    background: #e8eef5;
    color: #102a43;
    border: 1px solid #cbd5e1;
}

.primary:hover,
button.primary:hover,
.button.primary:hover,
a.button.primary:hover {
    background: var(--color-primary-h);
}

.button:hover,
a.button:hover,
.secondary:hover,
button.secondary:hover {
    background: #dbe3ee;
}

.error {
    background: #ffe6e8;
    color: #8a1020;
    padding: 12px;
    border-radius: 10px;
    margin-bottom: 12px;
}

.flash {
    background: #e8f7ed;
    color: #145c2e;
    padding: 12px;
    border-radius: 10px;
    margin-bottom: 16px;
}

/* Toast notification — replaces inline flash banner */
.toast {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 9000;
    background: #166534;
    color: #fff;
    padding: 14px 20px;
    border-radius: 14px;
    font-weight: 700;
    font-size: 14px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.20);
    max-width: 360px;
    line-height: 1.4;
    animation: toast-in 0.25s ease;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* =========================================================
   Tabeller / badges
   ========================================================= */

.table-wrap {
    overflow-x: auto;
    width: 100%;
    max-width: 100%;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 10px;
    border-bottom: 1px solid #e5e9ef;
    text-align: left;
    vertical-align: top;
}

th {
    background: #f5f7fa;
}

.actions a {
    margin-right: 8px;
}

.pill,
.status-pill,
.dash-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 9px;
    border-radius: 999px;
    background: #e8eef5;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.status-ok,
.pill-ok,
.dash-badge-ok {
    background: #dcfce7;
    color: #166534;
}

.status-nok,
.pill-nok,
.dash-badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

.status-na,
.pill-na,
.dash-badge-neutral {
    background: #e2e8f0;
    color: #475569;
}

.dash-badge-info {
    background: #dbeafe;
    color: #1d4ed8;
}

.dash-badge-warn {
    background: #ffedd5;
    color: #9a3412;
}

/* =========================================================
   Details
   ========================================================= */

.details {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 8px;
}

.details dt {
    font-weight: 700;
}

.details dd {
    margin: 0;
}

/* =========================================================
   Individdokument layout
   ========================================================= */

.document-edit-page {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.document-edit-hero {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-start;
    gap: 14px;
    padding: 18px;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    background: linear-gradient(135deg, #f8fafc, #eef2ff);
    margin-bottom: 18px;
}

.document-edit-hero h1 {
    margin: 0 0 6px 0;
    font-size: 24px;
    line-height: 1.2;
}

.document-edit-hero p {
    margin: 0;
    color: #475569;
}

.document-edit-hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.document-edit-page .card,
.document-section {
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    background: #ffffff;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.05);
    padding: 18px;
    margin-bottom: 16px;
}

.document-section h2,
.document-edit-page .card h2 {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 0;
    margin-bottom: 14px;
    font-size: 20px;
}

.document-section h2 small,
.document-edit-page .card h2 small {
    font-size: 13px;
    color: #64748b;
    font-weight: 500;
}

.section-main {
    border-left: 6px solid var(--color-accent);
}

.section-production {
    border-left: 6px solid #0f766e;
}

.section-overview {
    border-left: 6px solid #7c3aed;
}

.section-inspection {
    border-left: 6px solid #16a34a;
}

.section-restpoints {
    border-left: 6px solid #f97316;
}

.section-mounting {
    border-left: 6px solid #0891b2;
}

.section-commissioning {
    border-left: 6px solid #4f46e5;
}

.section-function {
    border-left: 6px solid #9333ea;
}

.section-final {
    border-left: 6px solid #334155;
}

.check-row {
    display: grid;
    grid-template-columns: 1fr 150px 1fr;
    gap: 10px;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #edf0f3;
}

.repeat-row {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 10px;
    align-items: start;
    border: 1px solid #e5e9ef;
    background: #fafbfc;
    padding: 12px;
    border-radius: 12px;
    margin-bottom: 10px;
}

.function-check-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.function-check-row {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) 160px minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #e5e7eb;
}

.function-check-row:last-child {
    border-bottom: 0;
}

.function-check-label {
    font-weight: 600;
    color: #111827;
}

.function-check-status select,
.function-check-comment input {
    width: 100%;
}

.sticky-actions {
    position: sticky;
    bottom: 0;
    z-index: 50;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
    align-items: center;
    padding: 12px;
    margin-top: 20px;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid #e5e7eb;
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -8px 20px rgba(15, 23, 42, 0.08);
}

.sticky-actions .save-hint {
    margin-right: auto;
    color: #64748b;
    font-size: 13px;
}

/* =========================================================
   Drifts채ttning - klustrad edit-layout
   ========================================================= */

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

.commissioning-cluster {
    border: 1px solid #dbe3ee;
    border-radius: 14px;
    padding: 14px;
    background: #f8fafc;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.04);
}

.commissioning-cluster h3 {
    margin: 0 0 12px 0;
    padding-bottom: 8px;
    border-bottom: 1px solid #dbe3ee;
    font-size: 17px;
    color: var(--nav-bg);
}

.commissioning-cluster-wide {
    margin-top: 16px;
    background: #ffffff;
    border-left: 6px solid #dc2626;
}

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

.commissioning-cluster label {
    font-size: 13px;
}

.commissioning-cluster input,
.commissioning-cluster select,
.commissioning-cluster textarea {
    background: #ffffff;
}

.commissioning-cluster-grid .commissioning-cluster:nth-child(1) {
    border-left: 6px solid #2563eb;
}

.commissioning-cluster-grid .commissioning-cluster:nth-child(2) {
    border-left: 6px solid #0f766e;
}

.commissioning-cluster-grid .commissioning-cluster:nth-child(3) {
    border-left: 6px solid #7c3aed;
}

.commissioning-cluster-grid .commissioning-cluster:nth-child(4) {
    border-left: 6px solid #ea580c;
}

.commissioning-cluster-grid .commissioning-cluster:nth-child(5) {
    border-left: 6px solid #334155;
}

.commissioning-cluster-grid .commissioning-cluster:nth-child(6) {
    border-left: 6px solid #16a34a;
}

/* =========================================================
   Document view - klustrad drifts채ttning
   ========================================================= */

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

.commissioning-view-cluster {
    border: 1px solid #dbe3ee;
    border-radius: 14px;
    padding: 14px;
    background: #f8fafc;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.04);
}

.commissioning-view-cluster h3 {
    margin: 0 0 12px 0;
    padding-bottom: 8px;
    border-bottom: 1px solid #dbe3ee;
    font-size: 17px;
    color: #0f2942;
}

.commissioning-view-wide {
    margin-top: 16px;
    background: #ffffff;
    border-left: 6px solid #dc2626;
}

.commissioning-view-grid .commissioning-view-cluster:nth-child(1) {
    border-left: 6px solid #2563eb;
}

.commissioning-view-grid .commissioning-view-cluster:nth-child(2) {
    border-left: 6px solid #0f766e;
}

.commissioning-view-grid .commissioning-view-cluster:nth-child(3) {
    border-left: 6px solid #7c3aed;
}

.commissioning-view-grid .commissioning-view-cluster:nth-child(4) {
    border-left: 6px solid #ea580c;
}

.commissioning-view-grid .commissioning-view-cluster:nth-child(5) {
    border-left: 6px solid #334155;
}

.commissioning-view-grid .commissioning-view-cluster:nth-child(6) {
    border-left: 6px solid #16a34a;
}

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

.view-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 9px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #ffffff;
    min-height: 58px;
}

.view-field-label {
    font-size: 12px;
    font-weight: 800;
    color: #64748b;
}

.view-field-value {
    font-size: 14px;
    font-weight: 700;
    color: #0f172a;
    word-break: break-word;
}

.view-status-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: fit-content;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 900;
    border: 1px solid transparent;
}

.view-status-ok {
    background: #dcfce7;
    color: #166534;
    border-color: #86efac;
}

.view-status-nok {
    background: #fee2e2;
    color: #991b1b;
    border-color: #fca5a5;
}

.view-status-na {
    background: #e2e8f0;
    color: #334155;
    border-color: #94a3b8;
}

.view-status-wip {
    background: #fef3c7;
    color: #92400e;
    border-color: #facc15;
}

.view-status-empty {
    background: #f8fafc;
    color: #64748b;
    border-color: #cbd5e1;
}

.view-long-text {
    min-height: 70px;
    padding: 12px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #ffffff;
    white-space: normal;
    line-height: 1.45;
}

/* =========================================================
   Production dashboard
   ========================================================= */

.dashboard-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.dashboard-kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.kpi-card {
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    background: #ffffff;
    padding: 16px;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.05);
}

.kpi-card span {
    display: block;
    color: #64748b;
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 6px;
}

.kpi-card strong {
    display: block;
    font-size: 28px;
    line-height: 1;
    color: #0f172a;
}

.kpi-ok {
    border-left: 6px solid #16a34a;
}

.kpi-warn {
    border-left: 6px solid #f97316;
}

.kpi-danger {
    border-left: 6px solid #dc2626;
}

.production-table-wrap {
    overflow-x: auto;
    width: 100%;
    max-width: 100%;
}

.production-dashboard-table {
    min-width: 1200px;
}

/* Sticky headers */
.production-dashboard-table thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #f5f7fa;
    white-space: nowrap;
}

/* Sortable column links */
.sort-link {
    color: inherit;
    text-decoration: none;
    font-weight: 700;
    white-space: nowrap;
}

.sort-link:hover {
    color: #1167b1;
    text-decoration: underline;
}

/* Row status tints */
.production-dashboard-table tbody tr.row-status-ok td     { background: #f0fdf4; }
.production-dashboard-table tbody tr.row-status-danger td { background: #fff5f5; }
.production-dashboard-table tbody tr.row-status-warn td   { background: #fffbf0; }
.production-dashboard-table tbody tr.row-status-info td   { background: #eff6ff; }

/* Overdue row — takes priority over status tint */
.production-dashboard-table tbody tr.row-overdue td               { background: #fff1f0; }
.production-dashboard-table tbody tr.row-overdue td:first-child   { box-shadow: inset 4px 0 0 #dc2626; }

.overdue-date {
    color: #dc2626;
    font-weight: 700;
}

.production-dashboard-table small {
    color: #64748b;
}

.progress-mini {
    font-size: 12px;
    white-space: nowrap;
}

.progress-mini span {
    display: block;
    line-height: 1.6;
}

/* =========================================================
   Platform Matrix Dashboard
   ========================================================= */

.matrix-scroll {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    border: 1px solid #cbd5e1;
    border-radius: 16px;
    background: #ffffff;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

table.platform-matrix {
    width: max-content;
    min-width: 1650px;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
    line-height: 1.35;
    background: #ffffff;
}

table.platform-matrix th {
    position: sticky;
    top: 0;
    z-index: 20;
    background: #0f7fa3;
    color: #ffffff;
    font-weight: 900;
    text-align: center;
    padding: 10px 8px;
    border-right: 1px solid #0b5f7a;
    border-bottom: 2px solid #083f52;
    white-space: normal;
    vertical-align: middle;
}

table.platform-matrix td {
    padding: 8px 8px;
    border-right: 1px solid #e2e8f0;
    border-bottom: 1px solid #dbeafe;
    vertical-align: middle;
    background: #ffffff;
    white-space: nowrap;
}

table.platform-matrix tbody tr:nth-child(even) td {
    background: #f8fbff;
}

table.platform-matrix tbody tr:hover td {
    background: #eef6ff;
}

table.platform-matrix th:last-child,
table.platform-matrix td:last-child {
    border-right: 0;
}

table.platform-matrix .sticky-col {
    position: sticky;
    left: 0;
    z-index: 15;
    background: #ffffff;
    min-width: 120px;
    max-width: 150px;
    box-shadow: 2px 0 0 #cbd5e1;
}

table.platform-matrix thead .sticky-col {
    z-index: 25;
    background: #0f7fa3;
    color: #ffffff;
}

.matrix-platform-main {
    display: block;
    font-weight: 900;
    font-size: 15px;
    color: #0f172a;
}

.matrix-platform-sub {
    display: block;
    margin-top: 3px;
    font-size: 11px;
    font-weight: 700;
    color: #64748b;
}

.platform-matrix .matrix-cell {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 82px;
    min-height: 38px;
    padding: 5px 8px;
    border-radius: 7px;
    border: 1px solid transparent;
    font-weight: 900;
    text-align: center;
    white-space: normal;
    box-sizing: border-box;
}

.platform-matrix .matrix-cell .matrix-main {
    display: block;
    font-size: 13px;
    line-height: 1.1;
}

.platform-matrix .matrix-cell .matrix-sub {
    display: block;
    margin-top: 2px;
    font-size: 11px;
    line-height: 1.15;
    font-weight: 700;
    opacity: 0.9;
}

.platform-matrix .matrix-cell small {
    display: block;
    margin-top: 2px;
    font-size: 11px;
    line-height: 1.15;
    font-weight: 700;
    color: inherit;
}

.platform-matrix .matrix-ok {
    background: #c9f7d3;
    color: #065f26;
    border-color: #86efac;
}

.platform-matrix .matrix-nok {
    background: #ffc4cf;
    color: #991b1b;
    border-color: #fb7185;
}

.platform-matrix .matrix-na {
    background: #b8c0c8;
    color: #1f2937;
    border-color: #94a3b8;
}

.platform-matrix .matrix-wip {
    background: #fef3c7;
    color: #92400e;
    border-color: #facc15;
}

.platform-matrix .matrix-empty {
    background: #f8fafc;
    color: #64748b;
    border-color: #cbd5e1;
}

.platform-matrix .matrix-info {
    min-width: 190px;
    max-width: 260px;
    white-space: normal;
    color: #0f172a;
    font-size: 12px;
    line-height: 1.35;
}

.matrix-info-line {
    display: block;
    margin-bottom: 3px;
}

.platform-matrix td.actions {
    min-width: 150px;
}

.action-stack {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 140px;
}

.action-stack a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 28px;
    padding: 5px 8px;
    border-radius: 8px;
    background: #f1f5f9;
    color: #1d4ed8;
    text-decoration: none;
    font-size: 12px;
    font-weight: 800;
    border: 1px solid #dbe3ee;
}

.action-stack a:hover {
    background: #dbeafe;
    border-color: #93c5fd;
}

.platform-matrix th:nth-child(2),
.platform-matrix td:nth-child(2) {
    min-width: 110px;
}

.platform-matrix th:nth-child(3),
.platform-matrix td:nth-child(3) {
    min-width: 115px;
}

.platform-matrix th:nth-child(4),
.platform-matrix td:nth-child(4) {
    min-width: 95px;
}

.platform-matrix th:nth-child(5),
.platform-matrix td:nth-child(5) {
    min-width: 95px;
}

.platform-matrix th:nth-child(n+6):nth-child(-n+15),
.platform-matrix td:nth-child(n+6):nth-child(-n+15) {
    text-align: center;
    min-width: 100px;
}

.platform-matrix th:nth-child(16),
.platform-matrix td:nth-child(16) {
    min-width: 200px;
}

/* =========================================================
   Responsivt
   ========================================================= */

@media (max-width: 1100px) {
    .dashboard-kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .production-filter-grid,
    .grid-form {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .form-grid-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .form-grid-3,
    .grid-form-3 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 1000px) {
    .commissioning-view-grid,
    .commissioning-cluster-grid {
        grid-template-columns: 1fr;
    }

    .view-field-grid,
    .commissioning-cluster .form-grid-2 {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 800px) {
    .grid-form,
    .production-filter-grid,
    .dashboard-kpi-grid,
    .form-grid-2,
    .form-grid-3,
    .form-grid-4,
    .grid-form-2,
    .grid-form-3,
    .grid-form-4 {
        grid-template-columns: 1fr;
    }

    .check-row,
    .function-check-row,
    .repeat-row {
        grid-template-columns: 1fr;
    }

    .status-grid {
        grid-template-columns: 1fr 1fr;
    }

    .details {
        grid-template-columns: 1fr;
    }

    .page-title {
        align-items: flex-start;
    }

    .dashboard-actions {
        justify-content: stretch;
    }

    .dashboard-actions .button {
        flex: 1 1 auto;
    }

    .document-edit-hero {
        padding: 14px;
    }

    .document-edit-hero-actions {
        width: 100%;
        justify-content: stretch;
    }

    .document-edit-hero-actions .button,
    .document-edit-hero-actions button {
        flex: 1 1 auto;
    }

    .sticky-actions {
        justify-content: stretch;
    }

    .sticky-actions .button,
    .sticky-actions button {
        flex: 1 1 auto;
    }

    .sticky-actions .save-hint {
        width: 100%;
        margin-right: 0;
    }

    table.platform-matrix {
        min-width: 1500px;
    }
}

/* =========================================================
   Print
   ========================================================= */

@media print {
    body {
        background: #fff;
    }

    .card {
        box-shadow: none;
        border-radius: 0;
    }

    .button,
    button,
    .topbar {
        display: none !important;
    }

    .container {
        margin: 0;
        padding: 0;
        max-width: none;
    }

    th {
        background: #eee !important;
    }
}

/* =========================================================
   Document view - Slutkontroll svensk läsvy
   ========================================================= */

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

.final-view-deviations {
    margin-top: 16px;
    border: 1px solid #dbe3ee;
    border-left: 6px solid #dc2626;
    border-radius: 14px;
    padding: 14px;
    background: #ffffff;
}

.final-view-deviations h3 {
    margin: 0 0 12px 0;
    padding-bottom: 8px;
    border-bottom: 1px solid #dbe3ee;
    font-size: 17px;
    color: #0f2942;
}

@media (max-width: 1100px) {
    .final-view-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 700px) {
    .final-view-grid {
        grid-template-columns: 1fr;
    }
}

/* =========================================================
   Paginering
   ========================================================= */

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 16px 0 4px;
}

.pagination-info {
    font-size: 14px;
    font-weight: 700;
    color: #475569;
}

.pagination-disabled {
    opacity: 0.35;
    cursor: default;
    pointer-events: none;
}

/* =========================================================
   Granskningslogg
   ========================================================= */

.audit-time {
    white-space: nowrap;
    font-size: 13px;
    color: #475569;
}

.audit-action {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 6px;
    background: #e8eef5;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.muted {
    color: #94a3b8;
    font-size: 12px;
}

/* =========================================================
   Subsection box (Produktionsbeslut inside Inbesiktning)
   ========================================================= */

.subsection-box {
    margin-top: 20px;
    padding: 16px;
    border: 1px solid #e5e7eb;
    border-left: 4px solid #7c3aed;
    border-radius: 12px;
    background: #fafbfc;
}

.subsection-box h3 {
    margin: 0 0 14px;
    font-size: 16px;
    font-weight: 700;
    color: #1e1b4b;
}

/* =========================================================
   Document dashboard — row hover
   ========================================================= */

.card table tbody tr:hover td {
    background: #f8fafc;
}

/* =========================================================
   Mobile — catch-all for narrow viewports
   ========================================================= */

@media (max-width: 600px) {
    /* Page title: wrap so buttons don't squeeze the heading */
    .page-title {
        flex-wrap: wrap;
        gap: 10px;
    }
    .page-title h1 {
        width: 100%;
        font-size: 20px;
        word-break: break-word;
    }

    /* KPI grid: 2 columns instead of 5 on phones */
    .dashboard-kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    /* Section jump bar: remove negative margin that bleeds off-screen */
    .section-jump-bar {
        margin-left: 0;
        margin-right: 0;
        border-radius: 0;
        overflow-x: auto;
        flex-wrap: nowrap;
    }

    /* Progress steps: hide text labels, keep dots + connectors */
    .progress-step-label {
        display: none;
    }
    .progress-step-connector {
        min-width: 16px;
    }

    /* Cards: tighter padding on phones */
    .card {
        padding: 14px 12px;
    }

    /* Document hero: break long individnummer */
    .document-edit-hero h1 {
        word-break: break-word;
        font-size: 18px;
    }

    /* Breadcrumb: allow wrapping */
    .breadcrumb {
        flex-wrap: wrap;
        gap: 2px;
    }

    /* Subsection boxes: tighter on mobile */
    .subsection-box {
        padding: 12px;
    }
}

/* Colored rows should darken slightly on hover, not go white */
.production-dashboard-table tbody tr.row-status-ok:hover td     { background: #dcfce7; }
.production-dashboard-table tbody tr.row-status-danger:hover td  { background: #fecaca; }
.production-dashboard-table tbody tr.row-status-warn:hover td    { background: #fed7aa; }
.production-dashboard-table tbody tr.row-status-info:hover td    { background: #bfdbfe; }
.production-dashboard-table tbody tr.row-overdue:hover td        { background: #fecdd3; }

/* =========================================================
   Document progress steps
   ========================================================= */

.doc-progress-steps {
    display: flex;
    align-items: center;
    gap: 0;
    margin-top: 12px;
}

.progress-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.progress-step-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #cbd5e1;
    border: 2px solid #e2e8f0;
    flex-shrink: 0;
}

.progress-step-label {
    font-size: 11px;
    font-weight: 700;
    color: #94a3b8;
    white-space: nowrap;
}

.progress-step-connector {
    flex: 1;
    height: 2px;
    background: #e2e8f0;
    min-width: 24px;
    margin-bottom: 16px;
}

.progress-step-connector.connector-done {
    background: #16a34a;
}

.progress-step.step-done .progress-step-dot {
    background: #16a34a;
    border-color: #86efac;
}

.progress-step.step-done .progress-step-label {
    color: #166534;
}

.progress-step.step-active .progress-step-dot {
    background: var(--color-primary);
    border-color: #93c5fd;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
    width: 14px;
    height: 14px;
}

.progress-step.step-active .progress-step-label {
    color: var(--color-primary);
    font-weight: 900;
}

/* =========================================================
   Mobile nav — hamburger
   ========================================================= */

.nav-hamburger {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    background: transparent;
    border: none;
    padding: 8px 6px;
    cursor: pointer;
    border-radius: 8px;
    margin-left: auto;
    flex-shrink: 0;
}

.nav-hamburger span {
    display: block;
    width: 22px;
    height: 2px;
    background: #fff;
    border-radius: 2px;
    transition: transform 0.22s ease, opacity 0.22s ease;
}

.topbar.nav-open .nav-hamburger span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.topbar.nav-open .nav-hamburger span:nth-child(2) { opacity: 0; transform: scaleX(0); }
.topbar.nav-open .nav-hamburger span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

@media (max-width: 900px) {
    .nav-hamburger { display: flex; }

    .topbar { position: relative; flex-wrap: nowrap; align-items: center; }

    .top-nav {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        z-index: 200;
        flex-direction: column;
        align-items: flex-start;
        padding: 10px 20px 16px;
        background: var(--nav-bg);
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
        gap: 4px;
    }

    .topbar.nav-open .top-nav { display: flex; }

    .top-nav .nav-link { padding: 7px 0; font-size: 15px; margin-left: 0; }
    .nav-sep { display: none; }
    .nav-admin-label { margin-left: 0; padding-top: 8px; }
    .nav-user-badge { margin-left: 0; background: transparent; }
    .nav-search { width: 100%; margin: 6px 0; }
    .nav-search-input { width: 100%; }
}

/* =========================================================
   Global nav search
   ========================================================= */

.nav-search {
    display: inline-flex;
    align-items: center;
    margin-left: 4px;
}

.nav-search-input {
    width: 170px;
    padding: 5px 12px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.10);
    color: #fff;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: width 0.25s ease, background 0.2s;
}

.nav-search-input::placeholder { color: rgba(255, 255, 255, 0.50); }

.nav-search-input:focus {
    background: rgba(255, 255, 255, 0.20);
    border-color: rgba(255, 255, 255, 0.50);
    width: 230px;
    box-shadow: none;
}

/* =========================================================
   Inline status select (production dashboard)
   ========================================================= */

.inline-status-select {
    appearance: none;
    -webkit-appearance: none;
    padding: 4px 22px 4px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    cursor: pointer;
    font-family: inherit;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%23555' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 7px center;
    background-size: 8px;
    transition: box-shadow 0.15s;
    width: auto;
}

.inline-status-select:focus {
    box-shadow: 0 0 0 3px var(--color-focus-ring);
    outline: none;
}

/* Toast variants */
.toast-error {
    background: #991b1b;
}

/* =========================================================
   Nav improvements
   ========================================================= */

.top-nav .nav-link {
    position: relative;
    padding-bottom: 2px;
}

.top-nav .nav-active {
    font-weight: 900;
}

.top-nav .nav-active::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    right: 0;
    height: 2px;
    background: #fff;
    border-radius: 2px;
}

.nav-sep {
    display: inline-block;
    width: 1px;
    height: 18px;
    background: rgba(255, 255, 255, 0.22);
    margin: 0 4px;
    vertical-align: middle;
    flex-shrink: 0;
}

.nav-admin-label {
    font-size: 10px;
    font-weight: 900;
    letter-spacing: 0.08em;
    color: rgba(255, 255, 255, 0.40);
    vertical-align: middle;
    margin-left: 4px;
    user-select: none;
}

.nav-user-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    margin-left: 4px;
    white-space: nowrap;
}

.nav-role-tag {
    font-size: 10px;
    font-weight: 900;
    letter-spacing: 0.05em;
    padding: 2px 5px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.22);
    text-transform: uppercase;
}

.nav-logout {
    color: rgba(255, 255, 255, 0.65) !important;
}

.nav-logout:hover {
    color: #fff !important;
}

/* =========================================================
   Breadcrumb
   ========================================================= */

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #64748b;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.breadcrumb a {
    color: #1167b1;
    text-decoration: none;
}

.breadcrumb a:hover {
    text-decoration: underline;
}

.breadcrumb-sep {
    color: #cbd5e1;
    font-size: 12px;
}

/* =========================================================
   Section jump bar (document edit)
   ========================================================= */

.section-jump-bar {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.97);
    border-bottom: 1px solid #e5e7eb;
    border-radius: 0 0 14px 14px;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.07);
    margin: 0 -16px 20px;
    backdrop-filter: blur(6px);
}

.jump-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 700;
    color: #475569;
    text-decoration: none;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    white-space: nowrap;
}

.jump-link:hover {
    background: #dbeafe;
    color: #1d4ed8;
    border-color: #93c5fd;
}

.jump-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #cbd5e1;
    flex-shrink: 0;
}

.jump-dot-ok      { background: #16a34a; }
.jump-dot-partial { background: #f97316; }

/* =========================================================
   Document dashboard — status pills
   ========================================================= */

.pill-utkast   { background: #e2e8f0; color: #334155; }
.pill-pagaende { background: #fef3c7; color: #92400e; }
.pill-klar     { background: #dcfce7; color: #166534; }
.pill-arkiverad { background: #f1f5f9; color: #64748b; }

/* =========================================================
   Empty state
   ========================================================= */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 56px 24px;
    text-align: center;
    gap: 10px;
}

.empty-state-icon {
    font-size: 42px;
    line-height: 1;
    opacity: 0.4;
}

.empty-state-title {
    font-size: 18px;
    font-weight: 700;
    color: #334155;
    margin: 0;
}

.empty-state-desc {
    font-size: 14px;
    color: #64748b;
    margin: 0;
    max-width: 320px;
}

/* =========================================================
   Login page
   ========================================================= */

.login-brand {
    text-align: center;
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid #e5e7eb;
}

.login-brand h2 {
    font-size: 22px;
    font-weight: 900;
    color: #0f2942;
    margin: 0 0 6px;
}

.login-brand p {
    color: #64748b;
    font-size: 13px;
    margin: 0;
}

.login-form-gap {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 18px;
}

/* =========================================================
   Site footer
   ========================================================= */

.site-footer {
    text-align: center;
    padding: 18px 20px 28px;
    margin-top: 24px;
    font-size: 12px;
    color: #94a3b8;
    border-top: 1px solid #e5e7eb;
}

/* =========================================================
   Autosave-status
   ========================================================= */

.autosave-status {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    background: #f1f5f9;
    color: #475569;
    border: 1px solid #cbd5e1;
}

.autosave-idle {
    background: #f8fafc;
    color: #475569;
    border-color: #cbd5e1;
}

.autosave-saving {
    background: #dbeafe;
    color: #1d4ed8;
    border-color: #93c5fd;
}

.autosave-ok {
    background: #dcfce7;
    color: #166534;
    border-color: #86efac;
}

.autosave-error {
    background: #fee2e2;
    color: #991b1b;
    border-color: #fca5a5;
}

/* =========================================================
   Clickable table rows
   ========================================================= */
tr[data-href] {
    cursor: pointer;
}

/* =========================================================
   Section collapse toggle — injected by JS into each h2
   ========================================================= */
.section-toggle {
    float: right;
    background: none;
    border: 1px solid var(--color-border-in);
    border-radius: 6px;
    padding: 1px 9px;
    cursor: pointer;
    font-size: 13px;
    color: #64748b;
    line-height: 1.6;
    transition: background 0.15s, color 0.15s;
}
.section-toggle:hover {
    background: #f1f5f9;
    color: #374151;
}

.document-section.section-collapsed > *:not(h2) {
    display: none;
}
.document-section.section-collapsed {
    padding-bottom: 4px;
}

/* =========================================================
   Styled confirm modal
   ========================================================= */
.confirm-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}
.confirm-modal[hidden] {
    display: none;
}
.confirm-modal-box {
    background: #fff;
    border-radius: var(--radius-card);
    padding: 28px 32px;
    max-width: 380px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.18);
}
.confirm-modal-box p {
    margin: 0 0 20px;
    font-size: 15px;
    color: var(--color-text);
    line-height: 1.5;
}
.confirm-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* =========================================================
   KPI cards as filter links
   ========================================================= */
a.kpi-card {
    text-decoration: none;
    display: block;
    transition: transform 0.12s, box-shadow 0.12s;
}
a.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 30px rgba(15, 23, 42, 0.10);
}
a.kpi-card.kpi-active {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}