:root {
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-full: 999px;
    --shadow-1: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-2: 0 4px 12px rgba(0, 0, 0, 0.15);
    --transition-fast: 0.15s ease;
    --transition-medium: 0.3s ease;
    --z-nav: 900;
    --z-modal: 1000;
    --z-toast: 9999;
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --danger-color: #dc2626;
    --danger-hover: #b91c1c;
    --success-color: #16a34a;
    --warning-color: #d97706;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --app-bg: var(--gray-100);
    --app-text: var(--gray-900);
    --surface: #ffffff;
    --border-color: var(--gray-200);

    /* Semantic status colors */
    --color-success-bg: #dcfce7;
    --color-success-text: #166534;
    --color-success-border: #bbf7d0;
    --color-error-bg: #fee2e2;
    --color-error-text: #991b1b;
    --color-error-border: #fecaca;
    --color-warning-bg: #fef3c7;
    --color-warning-text: #92400e;
    --color-warning-border: #fde68a;
    --color-info-bg: #dbeafe;
    --color-info-text: #1e40af;
    --color-info-border: #bfdbfe;

    /* Document type colors */
    --color-doc-cert-bg: #eff6ff;
    --color-doc-cert-text: #1d4ed8;
    --color-doc-inspection-bg: #fefce8;
    --color-doc-inspection-text: #854d0e;
    --color-doc-decl-bg: #f0fdf4;
    --color-doc-decl-text: #166534;
    --color-doc-risk-bg: #fdf4ff;
    --color-doc-risk-text: #7e22ce;
    --color-doc-sg-bg: rgba(16,185,129,0.1);
    --color-doc-sg-border: rgba(16,185,129,0.3);
    --color-doc-sg-text: #059669;
}

html[data-theme="dark"],
body[data-theme="dark"] {
    --primary-color: #60a5fa;
    --primary-hover: #3b82f6;
    --danger-color: #f87171;
    --danger-hover: #ef4444;
    --success-color: #22c55e;
    --warning-color: #f59e0b;
    --gray-50: #0b1220;
    --gray-100: #0f172a;
    --gray-200: #1e293b;
    --gray-300: #334155;
    --gray-400: #64748b;
    --gray-500: #94a3b8;
    --gray-600: #a1adc0;
    --gray-700: #cbd5e1;
    --gray-800: #e2e8f0;
    --gray-900: #f8fafc;
    --app-bg: #0b1120;
    --app-text: #e2e8f0;
    --surface: #111827;
    --border-color: #1f2937;

    /* Semantic status colors — dark mode */
    --color-success-bg: rgba(34, 197, 94, 0.1);
    --color-success-text: #86efac;
    --color-success-border: rgba(34, 197, 94, 0.2);
    --color-error-bg: rgba(248, 113, 113, 0.1);
    --color-error-text: #fca5a5;
    --color-error-border: rgba(248, 113, 113, 0.2);
    --color-warning-bg: rgba(245, 158, 11, 0.1);
    --color-warning-text: #fcd34d;
    --color-warning-border: rgba(245, 158, 11, 0.2);
    --color-info-bg: rgba(96, 165, 250, 0.1);
    --color-info-text: #93c5fd;
    --color-info-border: rgba(96, 165, 250, 0.2);

    /* Document type colors — dark mode */
    --color-doc-cert-bg: rgba(96, 165, 250, 0.15);
    --color-doc-cert-text: #93c5fd;
    --color-doc-inspection-bg: rgba(245, 158, 11, 0.15);
    --color-doc-inspection-text: #fcd34d;
    --color-doc-decl-bg: rgba(34, 197, 94, 0.15);
    --color-doc-decl-text: #86efac;
    --color-doc-risk-bg: rgba(168, 85, 247, 0.15);
    --color-doc-risk-text: #d8b4fe;
    --color-doc-sg-bg: rgba(16,185,129,0.15);
    --color-doc-sg-border: rgba(16,185,129,0.25);
    --color-doc-sg-text: #6ee7b7;

    /* Fuse-box spinner — dark mode */
    --fuse-box-bg: #374151;
    --fuse-box-border: #4b5563;
    --fuse-breaker-bg: #1f2937;
    --fuse-slot: #e2e8f0;
    --fuse-lever: #9ca3af;
    --fuse-trip: #f87171;
}
        * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--app-bg);
    color: var(--app-text);
    line-height: 1.5;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-4);
}

.card {
    background: var(--surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-1);
    margin-bottom: var(--space-4);
}

.card-header {
    padding: var(--space-4) var(--space-6);
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    font-size: 1.125rem;
}

.card-body {
    padding: var(--space-6);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    border: none;
    transition: all var(--transition-fast);
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-danger {
    background-color: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background-color: var(--danger-hover);
}

.btn-secondary {
    background-color: var(--gray-200);
    color: var(--gray-700);
}

.btn-secondary:hover {
    background-color: var(--gray-300);
}

.btn-sm {
    padding: var(--space-1) var(--space-2);
    font-size: 0.75rem;
}

.form-group {
    margin-bottom: var(--space-4);
}

.form-label {
    display: block;
    margin-bottom: var(--space-1);
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--gray-700);
}

.form-input {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    background-color: var(--surface);
    color: var(--app-text);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input::placeholder {
    color: var(--gray-500);
}

.form-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

textarea.form-input {
    min-height: 80px;
    resize: vertical;
}

.alert {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-4);
    font-size: 0.875rem;
}

.alert-success {
    background-color: var(--color-success-bg);
    color: var(--color-success-text);
    border: 1px solid var(--color-success-border);
}

.alert-error {
    background-color: var(--color-error-bg);
    color: var(--color-error-text);
    border: 1px solid var(--color-error-border);
}

.alert-warning {
    background-color: var(--color-warning-bg);
    color: var(--color-warning-text);
    border: 1px solid var(--color-warning-border);
}

.alert-info {
    background-color: var(--color-info-bg);
    color: var(--color-info-text);
    border: 1px solid var(--color-info-border);
}

.form-error {
    color: var(--danger-color);
    font-size: 0.8rem;
    margin-top: var(--space-1);
}

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

.table th,
.table td {
    padding: var(--space-3);
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
}

.table th {
    background-color: var(--gray-50);
    font-weight: 600;
    color: var(--gray-700);
}

.table tbody tr:hover {
    background-color: var(--gray-50);
}

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.grid {
    display: grid;
    gap: var(--space-4);
}

.grid-2 {
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

.grid-3 {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

/* ── Unified tab system ─────────────────────────────────── */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--gray-200);
    margin-bottom: 1rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
    padding: var(--space-3) var(--space-6);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-500);
    background: transparent;
    border: none;
    font-family: inherit;
    text-decoration: none;
    border-bottom: 2px solid transparent;
    transition: all var(--transition-fast);
    white-space: nowrap;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: -1px;
}

.tab:hover {
    color: var(--gray-700);
}

.tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.tab-content {
    display: none;
}

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

/* Tab count badge (works in all tab variants) */
.tab-count {
    background: var(--gray-100);
    color: var(--gray-500);
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.1rem 0.45rem;
    border-radius: 9999px;
}
.tab.active .tab-count {
    background: color-mix(in srgb, var(--primary-color) 12%, transparent);
    color: var(--primary-color);
}

/* Modifier: padded (dashboard/org navigation tabs) */
.tabs--padded {
    padding: 0 1.25rem;
}

/* Modifier: small (sub-tabs inside panels) */
.tabs--sm .tab {
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
}

/* Modifier: pill on mobile (converts to pill buttons on small screens) */
@media (max-width: 768px) {
    .tabs--pill {
        border-bottom: none;
        gap: 0.5rem;
        padding: 0.5rem 1rem;
    }
    .tabs--pill .tab {
        border-radius: 9999px;
        border: 1px solid var(--border-color);
        background: var(--gray-100);
        padding: 0.4rem 1rem;
        border-bottom: none;
        margin-bottom: 0;
    }
    .tabs--pill .tab.active {
        background: var(--primary-color);
        color: white;
        border-color: var(--primary-color);
    }
    .tabs--pill .tab:hover:not(.active) {
        background: var(--gray-200);
    }
    .tabs--pill .tab.active .tab-count {
        background: rgba(255,255,255,0.25);
        color: white;
    }

    /* Small pill variant: wrap + tighter */
    .tabs--sm.tabs--pill {
        gap: 0.4rem;
        padding: 0 0 0.75rem;
        flex-wrap: wrap;
    }
    .tabs--sm.tabs--pill .tab {
        padding: 0.35rem 0.85rem;
        font-size: 0.78rem;
    }
}

.badge {
    display: inline-block;
    padding: calc(var(--space-1) / 2) var(--space-2);
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: var(--radius-full);
}

.badge-success {
    background-color: var(--color-success-bg);
    color: var(--color-success-text);
}

.badge-warning {
    background-color: var(--color-warning-bg);
    color: var(--color-warning-text);
}

.badge-danger {
    background-color: var(--color-error-bg);
    color: var(--color-error-text);
}

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

.badge-secondary {
    background-color: var(--gray-200);
    color: var(--gray-600);
}

/* Dark mode: dropdown menus (inline-styled dropdowns) */
body[data-theme="dark"] .dropdown-menu {
    background: var(--surface) !important;
    border-color: var(--border-color) !important;
}
body[data-theme="dark"] .dropdown-menu .dropdown-item {
    color: var(--app-text) !important;
}
body[data-theme="dark"] .dropdown-menu .dropdown-item:hover {
    background: var(--gray-200) !important;
}

.theme-toggle {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-color);
    background: var(--surface);
    color: var(--app-text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.theme-toggle:hover {
    background: var(--gray-100);
}

.text-center { text-align: center; }
.text-muted { color: var(--gray-500); }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-4 { gap: var(--space-4); }
.hidden { display: none !important; }
.font-mono { font-family: 'Monaco', 'Consolas', monospace; }

/* ── Layout utilities ──────────────────────────────────── */
.flex-center { display: flex; align-items: center; }
.flex-col { display: flex; flex-direction: column; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.inline-flex { display: inline-flex; align-items: center; }
.flex-1 { flex: 1; }
.flex-shrink-0 { flex-shrink: 0; }
.w-full { width: 100%; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.whitespace-nowrap { white-space: nowrap; }
.text-truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.flex-wrap { flex-wrap: wrap; }
.text-center { text-align: center; }
.inline { display: inline; }
.link-plain { color: inherit; text-decoration: none; }

/* Gap utilities */
.gap-1 { gap: var(--space-1); }
.gap-3 { gap: var(--space-3); }
.gap-6 { gap: var(--space-6); }
.gap-8 { gap: var(--space-8); }

/* Padding utilities */
.p-2 { padding: var(--space-2); }
.p-3 { padding: var(--space-3); }
.p-4 { padding: var(--space-4); }
.p-6 { padding: var(--space-6); }
.px-4 { padding-left: var(--space-4); padding-right: var(--space-4); }
.py-2 { padding-top: var(--space-2); padding-bottom: var(--space-2); }
.py-3 { padding-top: var(--space-3); padding-bottom: var(--space-3); }

/* Margin utilities */
.ml-2 { margin-left: var(--space-2); }
.mr-2 { margin-right: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-6 { margin-bottom: var(--space-6); }
.mt-3 { margin-top: var(--space-3); }

/* ── Badge code (monospace, high contrast, easy copy) ── */
.badge-code {
    display: inline-block;
    padding: calc(var(--space-1) / 2) var(--space-2);
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    background: var(--gray-200);
    color: var(--gray-800);
    user-select: all;
    letter-spacing: 0.05em;
}

@media (max-width: 640px) {
    .badge-code { font-size: 1rem; }
}

/* ── Icon mask utilities ──────────────────────────────── */
.icon-view { -webkit-mask-image: url('/icons/view.svg'); mask-image: url('/icons/view.svg'); }
.icon-edit { -webkit-mask-image: url('/icons/edit.svg'); mask-image: url('/icons/edit.svg'); }
.icon-delete { -webkit-mask-image: url('/icons/delete.svg'); mask-image: url('/icons/delete.svg'); }
.icon-share { -webkit-mask-image: url('/icons/share.svg'); mask-image: url('/icons/share.svg'); }
.icon-favorite { -webkit-mask-image: url('/icons/favorite.svg'); mask-image: url('/icons/favorite.svg'); }
.icon-duplicate { -webkit-mask-image: url('/icons/duplicate.svg'); mask-image: url('/icons/duplicate.svg'); }
.icon-archive { -webkit-mask-image: url('/icons/archive.svg'); mask-image: url('/icons/archive.svg'); }
.icon-pdf { -webkit-mask-image: url('/icons/file-pdf.svg'); mask-image: url('/icons/file-pdf.svg'); }

/* ── Button loading state ──────────────────────────────── */
/* ── Fuse-box spinner (sikringsskap) ──────────────────── */
@keyframes tripBreaker {
    0%, 25%  { top: 2px; background-color: var(--fuse-lever, #374151); }
    30%, 70% { top: 9px; background-color: var(--fuse-trip, #ef4444); }
    75%, 100%{ top: 2px; background-color: var(--fuse-lever, #374151); }
}

.btn-loading {
    pointer-events: none;
    opacity: 0.8;
    position: relative;
}

.btn-loading .btn-text {
    visibility: hidden;
}

.btn-spinner {
    display: none;
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
}
.btn-loading .btn-spinner { display: block; }

.fuse-box {
    display: flex; gap: 2px;
    background: var(--fuse-box-bg, #d1d5db);
    padding: 3px; border-radius: 3px;
    border: 1px solid var(--fuse-box-border, #9ca3af);
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.2);
}
.fuse-box .breaker {
    width: 10px; height: 18px;
    background: var(--fuse-breaker-bg, #f3f4f6);
    border-radius: 1px; position: relative;
    display: flex; justify-content: center;
    box-shadow: inset 0 1px 1px rgba(0,0,0,0.2);
}
.fuse-box .breaker::before {
    content: ''; position: absolute;
    top: 2px; bottom: 2px; width: 4px;
    background: var(--fuse-slot, #111827);
    border-radius: 1px;
}
.fuse-box .lever {
    position: absolute; width: 6px; height: 7px;
    background: var(--fuse-lever, #374151);
    top: 2px; border-radius: 1px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.2);
    animation: tripBreaker 1.5s infinite;
}
.fuse-box .breaker:nth-child(1) .lever { animation-delay: 0s; }
.fuse-box .breaker:nth-child(2) .lever { animation-delay: 0.2s; }
.fuse-box .breaker:nth-child(3) .lever { animation-delay: 0.4s; }

/* Large standalone fuse-box spinner (for loading states) */
.fuse-box-lg {
    transform: scale(2.2);
    margin: 1rem auto;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: var(--z-modal);
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface);
    color: var(--app-text);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    padding: var(--space-4) var(--space-6);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-weight: 600;
    font-size: 1.125rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--gray-500);
}

.modal-body {
    padding: var(--space-6);
}

.modal-footer {
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
}

@media (max-width: 640px) {
    .container {
        padding: var(--space-2);
    }

    .card-body {
        padding: var(--space-4);
    }

    .btn {
        padding: var(--space-2) var(--space-3);
    }

    .grid-2 {
        grid-template-columns: 1fr !important;
    }
}

/* =====================================================
   Mobile global improvements (< 768px)
   ===================================================== */

/* Bottom navigation bar: hidden on desktop, styled on mobile */
.mobile-bottom-nav {
    display: none;
}

/* Topbar hamburger: hidden on desktop */
.topbar-hamburger {
    display: none;
}

@media (max-width: 768px) {

    /* Body padding so content is not hidden behind fixed bottom nav */
    body:has(.mobile-bottom-nav) {
        padding-bottom: calc(60px + env(safe-area-inset-bottom));
    }

    /* Robust fallback uten :has() (eldre mobilnettlesere): gi selve innholdet
       bunnplass, ubetinget. Litt ekstra luft på sider uten bunnlinje er ufarlig —
       knapper skjult bak bunnlinjen er det ikke. */
    main#main-content {
        padding-bottom: calc(70px + env(safe-area-inset-bottom));
    }

    /* iOS auto-zoom fix: all text inputs must be ≥ 16px */
    input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
    select,
    textarea {
        font-size: 1rem !important;
    }

    /* Minimum touch targets */
    .btn {
        min-height: 44px;
    }

    .btn-sm {
        min-height: 40px;
    }

    /* Dropdowns: never overflow viewport */
    .account-menu,
    .hamburger-menu {
        max-width: min(95vw, 320px);
        right: 0;
        left: auto;
    }

    /* Bottom navigation bar */
    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: calc(60px + env(safe-area-inset-bottom));
        padding-bottom: env(safe-area-inset-bottom);
        background: var(--surface);
        border-top: 1px solid var(--border-color);
        z-index: 950;
        align-items: center;
        justify-content: space-around;
        box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
    }

    .mbn-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.2rem;
        flex: 1;
        height: 60px;
        text-decoration: none;
        color: var(--gray-500);
        background: none;
        border: none;
        cursor: pointer;
        font-size: 0.75rem;
        font-weight: 500;
        font-family: inherit;
        padding: 0;
        -webkit-tap-highlight-color: transparent;
        transition: color 0.15s ease;
    }

    .mbn-item:hover,
    .mbn-item.mbn-active {
        color: var(--primary-color);
    }

    .mbn-item svg {
        width: 22px;
        height: 22px;
        flex-shrink: 0;
    }

    /* FAB center button */
    .mbn-fab {
        flex: 0 0 56px;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background: var(--primary-color);
        color: white !important;
        box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
        transform: translateY(-12px);
        transition: transform 0.15s ease, box-shadow 0.15s ease;
    }

    .mbn-fab:hover {
        transform: translateY(-14px);
        box-shadow: 0 6px 16px rgba(37, 99, 235, 0.5);
    }

    .mbn-fab svg {
        width: 26px;
        height: 26px;
    }

    /* Badge on bottom nav items (notifications) */
    .mbn-icon-wrap {
        position: relative;
        display: inline-flex;
    }

    .mbn-badge {
        position: absolute;
        top: -4px;
        right: -8px;
        min-width: 16px;
        height: 16px;
        padding: 0 4px;
        border-radius: 9999px;
        background: var(--danger-color, #ef4444);
        color: white;
        font-size: 0.625rem;
        font-weight: 700;
        line-height: 16px;
        text-align: center;
    }

    /* Topbar: show hamburger, hide notification + account on mobile */
    .topbar-hamburger {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        background: none;
        border: 1px solid var(--border-color);
        border-radius: 0.375rem;
        cursor: pointer;
        color: var(--gray-600);
        -webkit-tap-highlight-color: transparent;
    }

    .notification-wrapper { display: none !important; }
    .account-wrapper { display: none !important; }
    .topbar-dash-btn { display: none !important; }

    /* ── Fase E: Touch targets & contrast ─────────────── */

    /* Form inputs: 44px minimum touch target */
    .form-input,
    .form-select {
        min-height: 44px;
    }

    /* Search field: larger touch target */
    .form-input[type="search"],
    .form-input[name="q"] {
        min-height: 48px;
    }

    /* Tab touch targets */
    .tab {
        min-height: 44px;
    }

    /* Contrast: improve muted text readability in varying light */
    .text-muted {
        color: var(--gray-600);
    }

    /* Metadata/secondary text in cards and lists */
    .rv-card .text-xs,
    .board-card .text-xs,
    .table td .text-muted {
        color: var(--gray-600);
        font-weight: 500;
    }

    /* Theme toggle: ensure 44px touch target */
    .theme-toggle {
        width: 44px;
        height: 44px;
    }
}

/* ── Mer-meny bottom sheet ─────────────────────────── */
.mer-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 990;
    align-items: flex-end;
}

.mer-overlay.active {
    display: flex;
}

.mer-sheet {
    background: var(--surface);
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    border-radius: 1.25rem 1.25rem 0 0;
    animation: merSlideUp 0.25s ease-out;
}

@keyframes merSlideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.mer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    font-size: 1rem;
}

.mer-nav {
    padding: 0.5rem 0;
}

.mer-nav a,
.mer-nav button {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.875rem 1.25rem;
    font-size: 0.9375rem;
    color: var(--app-text);
    text-decoration: none;
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.1s;
}

.mer-nav a:hover,
.mer-nav button:hover {
    background: var(--gray-50);
}

.mer-nav a svg,
.mer-nav button svg {
    flex-shrink: 0;
    color: var(--gray-500);
}

.mer-nav hr {
    margin: 0.25rem 0;
    border: none;
    border-top: 1px solid var(--border-color);
}

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

/* =====================================================
   Print styles
   ===================================================== */
@media print {
    /* ── Page setup ──────────────────────────────────── */
    @page {
        margin: 15mm 12mm 20mm 12mm;
        size: A4;
    }

    /* Template: landscape orientation */
    body.print-template-compact {
        /* Set via JS before print */
    }
    @page compact { size: A4 landscape; margin: 10mm; }
    body.print-template-compact { page: compact; }

    /* ── Reset colors & background ───────────────────── */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    body {
        background: white !important;
        color: #111 !important;
        font-size: 10pt;
        line-height: 1.4;
    }

    body.print-template-compact {
        font-size: 9pt;
    }

    /* ── Hide non-content elements ───────────────────── */
    .topbar,
    .mobile-bottom-nav,
    .mer-overlay,
    .modal,
    .contact-sticky-btn,
    .theme-toggle,
    .toast,
    #cookieNotice,
    .notification-wrapper,
    .notification-panel,
    .account-wrapper,
    .topbar-hamburger,
    .topbar-dash-btn,
    .topbar-login,
    .topbar-right,
    .sr-only,
    .print-hide {
        display: none !important;
    }

    /* Hide action buttons, edit/unlock buttons */
    .header-actions .btn,
    .header-actions button,
    .show-header-mobile__actions,
    .show-header-mobile__bottom .btn,
    .show-header-mobile__branding,
    #circuitPagination,
    .btn-primary,
    .btn-secondary,
    .btn-danger {
        display: none !important;
    }

    /* Hide tabs bar — show only active tab content */
    .tabs[role="tablist"] {
        display: none !important;
    }

    .tab-content {
        display: block !important;
    }

    /* Template compact: hide customer/installer info */
    body.print-template-compact .print-section-customer,
    body.print-template-compact .print-section-installer {
        display: none !important;
    }

    /* Template compact: hide QR code */
    body.print-template-compact .header-qr,
    body.print-template-compact .qr-container {
        display: none !important;
    }

    /* Template standard: show QR code */
    body.print-template-standard .header-qr,
    body.print-template-standard .qr-container {
        display: block !important;
    }

    /* ── Print dropdown itself should be hidden ──────── */
    .print-dropdown-wrap {
        display: none !important;
    }

    /* ── Layout resets ───────────────────────────────── */
    .container {
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    .header {
        border-bottom: 2px solid #333 !important;
        padding: 0 0 0.5rem 0 !important;
        margin-bottom: 0.75rem !important;
        background: none !important;
    }

    .header-content {
        display: flex !important;
    }

    /* Always show desktop header on print, hide mobile */
    .show-header-desktop {
        display: flex !important;
    }
    .show-header-mobile {
        display: none !important;
    }

    .card {
        box-shadow: none !important;
        border: none !important;
        margin-bottom: 0.5rem !important;
        break-inside: avoid;
    }

    .card-body {
        padding: 0.25rem 0 !important;
    }

    .card-header {
        border-bottom: 1px solid #ccc !important;
        padding: 0.25rem 0 !important;
        background: none !important;
    }

    /* ── Header: board name & address ────────────────── */
    .header-title {
        font-size: 16pt !important;
        color: #111 !important;
    }

    .header-subtitle {
        font-size: 10pt !important;
        color: #444 !important;
    }

    /* QR code in header: compact for print */
    .header-qr {
        margin-right: 1rem !important;
    }
    .header-qr .qr-container {
        padding: 4px !important;
        cursor: default !important;
    }
    .header-qr svg {
        width: 80px !important;
        height: 80px !important;
    }

    /* ── Branding/logo: show inline in print ─────────── */
    .header-actions {
        display: flex !important;
        flex-direction: column !important;
        align-items: flex-end !important;
    }
    .header-actions button[onclick*="brandingModal"] {
        display: flex !important;
        border: none !important;
        padding: 0 !important;
        cursor: default !important;
    }
    .header-actions button[onclick*="brandingModal"] img {
        height: 32px !important;
    }
    /* Hide other action buttons but keep branding visible */
    .header-actions .flex-center {
        display: none !important;
    }

    /* ── Circuit table ───────────────────────────────── */
    .table-responsive {
        overflow: visible !important;
    }

    .table {
        width: 100% !important;
        border-collapse: collapse !important;
        font-size: inherit !important;
        page-break-inside: auto;
    }

    .table th,
    .table td {
        border: 1px solid #999 !important;
        padding: 4px 6px !important;
        text-align: left !important;
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: clip !important;
        color: #111 !important;
        background: none !important;
    }

    .table th {
        background: #f0f0f0 !important;
        font-weight: 700 !important;
        font-size: inherit !important;
    }

    .table tbody tr {
        /* Undo mobile card layout */
        display: table-row !important;
        border: none !important;
        border-radius: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        background: none !important;
    }

    .table tbody td {
        display: table-cell !important;
    }

    .table thead {
        display: table-header-group !important;
    }

    .table tbody {
        display: table-row-group !important;
    }

    /* Remove mobile ::before labels */
    .table tbody td::before {
        content: none !important;
    }

    /* Remove mobile ::after suffixes */
    .table tbody td::after {
        content: none !important;
    }

    /* Ensure all rows visible (override pagination) */
    .table tbody tr {
        display: table-row !important;
    }

    /* Table page breaks */
    .table tr {
        page-break-inside: avoid;
    }
    .table thead {
        display: table-header-group;
    }

    /* ── Notes card ──────────────────────────────────── */
    .text-muted {
        color: #555 !important;
    }

    /* ── Document tables ─────────────────────────────── */
    .table-docs-mobile thead {
        display: table-header-group !important;
    }
    .table-docs-mobile tbody tr {
        display: table-row !important;
        border: none !important;
        border-radius: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    .table-docs-mobile tbody td {
        display: table-cell !important;
        border: 1px solid #999 !important;
    }
    .table-docs-mobile tbody td::before {
        content: none !important;
    }
    /* Hide download buttons in document tables */
    .table-docs-mobile tbody td:last-child .btn {
        display: none !important;
    }

    /* ── Section breaks ──────────────────────────────── */
    #documents-tab {
        page-break-before: auto;
        margin-top: 1rem;
    }

    #documents-tab h3 {
        page-break-after: avoid;
    }

    #links-tab {
        page-break-before: auto;
        margin-top: 1rem;
    }

    /* ── Links ────────────────────────────────────────── */
    a {
        color: #111 !important;
        text-decoration: none !important;
    }

    /* ── Print footer ────────────────────────────────── */
    body::after {
        content: "Utskrift fra QR-Live \2014  qrlive.no";
        display: block;
        text-align: center;
        font-size: 8pt;
        color: #999;
        margin-top: 2rem;
        padding-top: 0.5rem;
        border-top: 1px solid #ddd;
        position: relative;
    }

    /* ── Grid resets ─────────────────────────────────── */
    .grid-2 {
        grid-template-columns: 1fr 1fr !important;
    }
}

        .icon {
            display: inline-block;
            background-color: currentColor;
            -webkit-mask-size: contain;
            mask-size: contain;
            -webkit-mask-repeat: no-repeat;
            mask-repeat: no-repeat;
            -webkit-mask-position: center;
            mask-position: center;
        }

        .icon-sm { width: 14px; height: 14px; }
        .icon-md { width: 18px; height: 18px; }
        .icon-lg { width: 24px; height: 24px; }

        .btn-icon {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 0.375rem;
        }

        .btn-icon.btn-sm {
            padding: 0.3rem 0.45rem;
        }

        .form-input-code {
            font-family: 'Monaco', 'Consolas', monospace;
            font-size: 1.5rem;
            text-align: center;
            letter-spacing: 0.5rem;
            padding: 1rem;
        }

        .form-input-error {
            border-color: var(--danger-color);
        }

        .form-input-error:focus {
            box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
        }


        .header {
            background: var(--surface);
            border-bottom: 1px solid var(--border-color);
            padding: 1rem 0;
            margin-bottom: 1.5rem;
        }

        /* Global topbar */
        .topbar {
            background: var(--surface);
            border-bottom: 1px solid var(--border-color);
            position: sticky;
            top: 0;
            z-index: 900;
        }

        .topbar-content {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 1rem;
            display: flex;
            align-items: center;
            justify-content: space-between;
            height: 48px;
        }

        .topbar-brand {
            display: flex;
            align-items: center;
            line-height: 0;
            text-decoration: none;
        }

        .topbar-brand img {
            height: 32px;
            width: auto;
        }

        .topbar-brand:hover {
            opacity: 0.85;
        }

        .topbar-right {
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .topbar-login {
            color: var(--gray-500);
            text-decoration: none;
            font-size: 0.875rem;
            padding: 0.375rem 0.75rem;
            border-radius: 0.375rem;
            transition: color 0.15s ease;
        }

        .topbar-login:hover {
            color: var(--app-text);
        }

        .topbar-dash-btn {
            display: inline-flex;
            align-items: center;
            gap: 0.4rem;
            padding: 0.3rem 0.7rem;
            border: 1px solid var(--border-color);
            border-radius: 0.375rem;
            background: var(--surface);
            color: var(--gray-700);
            font-size: 0.8125rem;
            font-weight: 500;
            text-decoration: none;
            transition: background 0.15s, color 0.15s;
            white-space: nowrap;
        }
        .topbar-dash-btn:hover {
            background: var(--gray-100);
            color: var(--app-text);
        }
        .topbar-dash-btn svg {
            flex-shrink: 0;
        }
        .topbar-dash-btn .dash-btn-label {
            display: none;
        }
        @media (min-width: 480px) {
            .topbar-dash-btn .dash-btn-label {
                display: inline;
            }
        }

        .account-wrapper {
            position: relative;
        }

        .account-btn {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            padding: 0.25rem 0.625rem 0.25rem 0.375rem;
            border: 1px solid var(--border-color);
            border-radius: 0.375rem;
            background: var(--surface);
            color: var(--app-text);
            cursor: pointer;
            font-size: 0.875rem;
            transition: background 0.15s ease;
        }

        .account-btn:hover {
            background: var(--gray-100);
        }

        .account-avatar {
            width: 32px;
            height: 32px;
            border-radius: 50%;
            background: var(--primary-color);
            color: #fff;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: 700;
            font-size: 0.875rem;
            overflow: hidden;
            flex-shrink: 0;
        }

        .account-avatar img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        .account-info {
            display: flex;
            flex-direction: column;
            align-items: flex-start;
            line-height: 1.25;
            text-align: left;
        }

        .account-user-name {
            font-size: 0.8rem;
            font-weight: 600;
            max-width: 130px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .account-company {
            font-size: 0.7rem;
            color: var(--gray-500);
            max-width: 130px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .account-menu {
            display: none;
            position: absolute;
            top: 100%;
            right: 0;
            margin-top: 0.25rem;
            min-width: 200px;
            background: var(--surface);
            border: 1px solid var(--border-color);
            border-radius: 0.5rem;
            box-shadow: 0 4px 12px rgba(0,0,0,0.15);
            padding: 0.25rem 0;
            z-index: 1000;
        }

        .account-menu.open {
            display: block;
        }

        .account-menu a,
        .account-menu button {
            display: block;
            width: 100%;
            padding: 0.5rem 0.75rem;
            text-align: left;
            text-decoration: none;
            color: var(--app-text);
            font-size: 0.85rem;
            background: none;
            border: none;
            cursor: pointer;
            white-space: nowrap;
        }

        .account-menu a:hover,
        .account-menu button:hover {
            background: var(--gray-100);
        }

        .account-menu hr {
            margin: 0.25rem 0;
            border: none;
            border-top: 1px solid var(--border-color);
        }

        .header-content {
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
            gap: 1rem;
        }

        .header-title {
            font-size: 1.5rem;
            font-weight: 700;
            color: var(--gray-900);
        }

        .header-subtitle {
            font-size: 0.875rem;
            color: var(--gray-500);
        }

        .header-actions {
            display: flex;
            gap: 0.5rem;
            flex-wrap: wrap;
        }

        @media (max-width: 640px) {
            .account-info {
                display: none;
            }

            .table-mobile-cards thead {
                display: none;
            }

            .table-mobile-cards tbody tr {
                display: block;
                padding: 0.875rem;
                margin-bottom: 0.625rem;
                border: 1px solid var(--border-color);
                border-radius: 0.5rem;
            }

            .table-mobile-cards tbody tr:hover {
                background: transparent;
            }

            .table-mobile-cards tbody td {
                display: block;
                border: none;
                padding: 0;
            }

            /* Action cell (last column in all table variants) */
            .table-mobile-cards tbody td:last-child {
                display: flex;
                flex-wrap: wrap;
                gap: 0.5rem;
                margin-top: 0.75rem;
                padding-top: 0.625rem;
                border-top: 1px solid var(--border-color);
            }

            .table-mobile-cards tbody td:last-child .btn {
                flex: 1;
                min-height: 40px;
                min-width: 40px;
                padding: 0.5rem;
                justify-content: center;
            }

            .table-mobile-cards tbody td:last-child .icon {
                width: 18px !important;
                height: 18px !important;
            }

            /* === Mine tavler-specific card layout === */
            .table-boards-main tbody td:nth-child(1) {
                font-weight: 700;
                font-size: 0.9375rem;
                padding-bottom: 0.2rem;
            }

            .table-boards-main tbody td:nth-child(2) {
                font-size: 0.8125rem;
                color: var(--gray-500);
                padding-bottom: 0.35rem;
            }

            /* Type · Kurser · Oppdatert as inline meta row */
            .table-boards-main tbody td:nth-child(3),
            .table-boards-main tbody td:nth-child(4),
            .table-boards-main tbody td:nth-child(5) {
                display: inline;
                font-size: 0.75rem;
                color: var(--gray-500);
            }

            .table-boards-main tbody td:nth-child(4)::before,
            .table-boards-main tbody td:nth-child(5)::before {
                content: " · ";
            }

            /* === Board action buttons: fill full card width on mobile === */
            .table-boards-main tbody td:last-child .board-actions {
                display: flex;
                width: 100%;
                gap: 0.5rem;
            }

            .table-boards-main tbody td:last-child .board-actions .btn {
                flex: 1;
                min-height: 44px;
                justify-content: center;
                padding: 0.5rem;
            }

            .table-boards-main tbody td:last-child .board-actions .icon {
                width: 20px !important;
                height: 20px !important;
            }
        }

        /* Notification bell */
        .notification-wrapper { position: relative; }
        .notification-btn {
            display: flex; align-items: center; justify-content: center;
            width: 36px; height: 36px;
            border: 1px solid var(--border-color); border-radius: 0.375rem;
            background: var(--surface); color: var(--gray-600); cursor: pointer;
            position: relative; transition: background 0.15s;
        }
        .notification-btn:hover { background: var(--gray-100); color: var(--app-text); }
        .notification-badge {
            position: absolute; top: -4px; right: -4px;
            min-width: 18px; height: 18px; padding: 0 4px;
            background: #dc2626; color: white; font-size: 0.6875rem; font-weight: 700;
            border-radius: 9999px; display: flex; align-items: center; justify-content: center;
            line-height: 1;
        }
        .notification-panel {
            display: none; position: absolute; top: 100%; right: 0; margin-top: 0.25rem;
            width: 340px; max-height: 420px;
            background: var(--surface); border: 1px solid var(--border-color);
            border-radius: 0.5rem; box-shadow: 0 4px 16px rgba(0,0,0,0.15);
            z-index: 1000; overflow: hidden;
        }
        .notification-panel.open { display: flex; flex-direction: column; }
        .notification-panel-header {
            display: flex; align-items: center; justify-content: space-between;
            padding: 0.75rem 1rem; border-bottom: 1px solid var(--border-color);
            font-size: 0.875rem;
        }
        .notification-mark-all {
            background: none; border: none; color: var(--primary-color);
            font-size: 0.75rem; cursor: pointer; padding: 0;
        }
        .notification-mark-all:hover { text-decoration: underline; }
        .notification-list { overflow-y: auto; flex: 1; }
        .notification-item {
            display: block; padding: 0.75rem 1rem;
            border-bottom: 1px solid var(--gray-100);
            text-decoration: none; color: var(--app-text);
            transition: background 0.1s;
        }
        .notification-item:hover { background: var(--gray-50); }
        .notification-item.unread { background: #eff6ff; }
        .notification-item.unread:hover { background: #dbeafe; }
        .notification-item-text { font-size: 0.8125rem; line-height: 1.4; }
        .notification-item-time { font-size: 0.6875rem; color: var(--gray-500); margin-top: 0.25rem; }
        .notification-empty { padding: 2rem 1rem; text-align: center; color: var(--gray-500); font-size: 0.875rem; }
        @media (max-width: 400px) { .notification-panel { width: calc(100vw - 1rem); right: -3rem; } }

        /* Hamburger menu */
        .hamburger-wrapper {
            position: relative;
        }

        .hamburger-btn {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 40px;
            height: 40px;
            border: 1px solid var(--border-color);
            border-radius: 0.375rem;
            background: var(--surface);
            color: var(--app-text);
            font-size: 1.25rem;
            cursor: pointer;
        }

        .hamburger-menu {
            display: none;
            position: absolute;
            top: 100%;
            right: 0;
            margin-top: 0.25rem;
            min-width: 180px;
            background: var(--surface);
            border: 1px solid var(--border-color);
            border-radius: 0.5rem;
            box-shadow: 0 4px 12px rgba(0,0,0,0.15);
            padding: 0.25rem 0;
            z-index: 1000;
        }

        .hamburger-menu.open {
            display: block;
        }

        .hamburger-menu a,
        .hamburger-menu button {
            display: block;
            width: 100%;
            padding: 0.5rem 0.75rem;
            text-align: left;
            text-decoration: none;
            color: var(--app-text);
            font-size: 0.85rem;
            background: none;
            border: none;
            cursor: pointer;
            white-space: nowrap;
        }

        .hamburger-menu a:hover,
        .hamburger-menu button:hover {
            background: var(--gray-100);
        }

        .hamburger-menu hr {
            margin: 0.25rem 0;
            border: none;
            border-top: 1px solid var(--border-color);
        }

        /* Toast notification */
        .toast {
            position: fixed;
            bottom: 2rem;
            left: 50%;
            transform: translateX(-50%) translateY(100px);
            background: var(--gray-900);
            color: #fff;
            padding: 0.75rem 1.5rem;
            border-radius: 0.5rem;
            font-size: 0.875rem;
            z-index: 9999;
            opacity: 0;
            transition: transform 0.3s ease, opacity 0.3s ease;
            pointer-events: none;
        }

        body[data-theme="dark"] .toast {
            background: var(--gray-300);
            color: var(--gray-900);
        }

        .toast.show {
            transform: translateX(-50%) translateY(0);
            opacity: 1;
        }

        .toast.toast-success {
            background: #16a34a;
        }

        .toast.toast-error {
            background: #dc2626;
        }

        .toast.toast-info {
            background: #2563eb;
        }

        body[data-theme="dark"] .toast.toast-success {
            background: #22c55e;
            color: #052e16;
        }

        body[data-theme="dark"] .toast.toast-error {
            background: #f87171;
            color: #450a0a;
        }

        body[data-theme="dark"] .toast.toast-info {
            background: #60a5fa;
            color: #172554;
        }

        /* On mobile with bottom nav, lift toast above it */
        @media (max-width: 768px) {
            body:has(.mobile-bottom-nav) .toast {
                bottom: calc(60px + env(safe-area-inset-bottom) + 0.75rem);
            }
        }

