/* ============================================================
   Layout — shell, sidebar, header, footer, content-areas
   ============================================================ */

/* Body/html holder seg innenfor viewport — wide tables får intern scroll */
html, body { max-width: 100vw; overflow-x: hidden; }

/* === SHELL === Header dekker full bredde, sidebar under header */
.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: 0 1fr auto;
    grid-template-areas:
        "header  header"
        "sidebar main"
        "footer  footer";
    min-height: 100vh;
    transition: grid-template-columns var(--transition-base);
}
.app-shell.sidebar-collapsed { grid-template-columns: var(--sidebar-collapsed) 1fr; }
.app-shell > .app-header { grid-area: header; }
.app-shell > .sidebar { grid-area: sidebar; }
.app-shell > .app-main, .app-shell > .app-content { grid-area: main; min-width: 0; max-width: 100%; overflow-x: auto; box-sizing: border-box; }
.app-content > *, .app-content .admin-card, .app-content section { max-width: 100%; box-sizing: border-box; }
.app-content table { max-width: 100%; }
.app-content .table-wrap, .app-content .matrix-table, .app-content .data-table-wrap { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* Wide tabeller (admin-table) — fortsatt synlig men scroll-bar inni innholdet, ikke side */
.app-content table.admin-table { display: block; max-width: 100%; overflow-x: auto; white-space: nowrap; }
.app-content table.admin-table thead, .app-content table.admin-table tbody, .app-content table.admin-table tr { display: table; width: 100%; table-layout: auto; }
.app-shell > .app-footer { grid-area: footer; position: static !important; }

@media (max-width: 1024px) {
    .app-shell { grid-template-columns: 1fr; grid-template-areas: "header" "main" "footer"; }
    .sidebar { position: fixed; left: -100%; transition: left var(--transition-base); z-index: var(--z-modal); top: var(--header-height); height: calc(100vh - var(--header-height)); }
    .sidebar.is-open { left: 0; box-shadow: var(--shadow-xl); }
    .sidebar-overlay { display: none; }
    .sidebar-overlay.is-open {
        display: block; position: fixed; inset: 0;
        background: var(--bg-overlay); backdrop-filter: blur(4px);
        z-index: calc(var(--z-modal) - 1);
    }
}

/* === SIDEBAR === */
.sidebar {
    background: var(--chrome-bg, var(--bg-elevated));
    border: 0;
    display: flex;
    flex-direction: column;
    overflow-y: hidden;
    overflow-x: hidden;
    height: calc(100vh - var(--header-height) - 40px);
    position: fixed;
    top: var(--header-height);
    bottom: 40px;
    left: 0;
    width: var(--sidebar-width);
    z-index: 40;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.sidebar::-webkit-scrollbar { display: none; width: 0; height: 0; }
.sidebar-header {
    padding: var(--space-5) var(--space-5) var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    text-decoration: none;
    color: var(--text-primary);
}
.sidebar-brand-mark {
    width: 36px; height: 36px;
    background: linear-gradient(135deg, var(--brand-500) 0%, var(--brand-700) 100%);
    border-radius: var(--radius-md);
    display: grid;
    place-items: center;
    color: white;
    font-weight: var(--weight-bold);
    font-size: var(--text-lg);
    box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255,255,255,0.2);
    flex-shrink: 0;
}
.sidebar-brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
    overflow: hidden;
    transition: opacity var(--transition-base);
}
.sidebar-brand-name { font-size: var(--text-md); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-tight); }
.sidebar-brand-tagline { font-size: var(--text-xs); color: var(--text-muted); margin-top: 2px; }

.sidebar-collapsed .sidebar-brand-text,
.sidebar-collapsed .sidebar-section-title,
.sidebar-collapsed .sidebar-nav-link span,
.sidebar-collapsed .sidebar-footer-text { opacity: 0; pointer-events: none; }

.sidebar-nav {
    flex: 1;
    padding: var(--space-4) var(--space-3);
    overflow-y: auto;
    overflow-x: hidden;
}
.sidebar-section { margin-bottom: var(--space-5); }
.sidebar-section-title {
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wider);
    color: var(--text-muted);
    padding: 0 var(--space-3);
    margin-bottom: var(--space-2);
    transition: opacity var(--transition-fast);
}
.sidebar-nav-list { list-style: none; padding: 0; margin: 0; }
.sidebar-nav-link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 0 var(--space-3);
    height: 38px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    position: relative;
    margin-bottom: 1px;
    white-space: nowrap;
    overflow: hidden;
}
.sidebar-nav-link:hover {
    background: var(--bg-glass);
    color: var(--text-primary);
}
.sidebar-nav-link.is-active {
    background: linear-gradient(90deg, rgba(108,99,255,0.12) 0%, rgba(108,99,255,0.04) 100%);
    color: var(--text-primary);
}
.sidebar-nav-link.is-active::before {
    content: '';
    position: absolute;
    left: 0; top: 50%; transform: translateY(-50%);
    width: 3px; height: 60%;
    background: var(--brand-500);
    border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
}
.sidebar-nav-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    color: var(--text-muted);
    transition: color var(--transition-fast);
}
.sidebar-nav-link:hover .sidebar-nav-icon,
.sidebar-nav-link.is-active .sidebar-nav-icon { color: var(--brand-400); }
.sidebar-nav-badge {
    margin-left: auto;
    font-size: 10px;
    font-weight: var(--weight-semibold);
    padding: 1px 6px;
    border-radius: var(--radius-full);
    background: var(--brand-500);
    color: white;
    line-height: 1.4;
    min-width: 18px;
    text-align: center;
}

.sidebar-footer {
    padding: var(--space-3) var(--space-3);
    border-top: 1px solid var(--border-subtle);
}
.sidebar-toggle {
    width: 100%;
    height: 36px;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 0 var(--space-3);
    background: transparent;
    border: 0;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    transition: all var(--transition-fast);
}
.sidebar-toggle:hover { background: var(--bg-glass); color: var(--text-primary); }

/* === MAIN === */
.app-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 100vh;
}

/* === HEADER === */
.app-header {
    height: var(--header-height);
    background: var(--chrome-bg, var(--bg-base));
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 0;
    display: flex !important;
    align-items: center;
    padding: 0 var(--space-6);
    gap: var(--space-4);
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 9998 !important;
    visibility: visible !important;
    opacity: 1 !important;
}
/* Header er fixed — grid-row 1 (header-height) er allerede reservert som tom plass */
.app-shell > .sidebar { top: var(--header-height) !important; }
.app-header-left { display: flex; align-items: center; gap: var(--space-4); flex: 1; min-width: 0; }
.app-header-right { display: flex; align-items: center; gap: var(--space-2); }

.page-title-block { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.page-title {
    font-size: var(--text-md);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.page-subtitle {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: 2px;
}

/* Header-search (Cmd-K) */
.header-search {
    display: flex; align-items: center; gap: var(--space-2);
    height: 36px;
    padding: 0 var(--space-3);
    background: var(--chrome-bg);
    border: 1px solid var(--chrome-border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: var(--text-sm);
    cursor: pointer;
    min-width: 240px;
    transition: all var(--transition-fast);
}
.header-search:hover { border-color: var(--border-default); }
.header-search > span { color: var(--text-muted) }
[data-theme="light"] .header-search { color: #0f1525 }
.header-search kbd {
    margin-left: auto;
    padding: 1px 6px;
    font-size: 10px;
    font-family: var(--font-mono);
    color: var(--text-muted);
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xs);
}

.header-action {
    width: 36px; height: 36px;
    display: grid; place-items: center;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
}
.header-action:hover {
    background: var(--bg-card);
    color: var(--text-primary);
    border-color: var(--border-subtle);
}
.header-action-badge {
    position: absolute;
    top: 6px; right: 6px;
    width: 8px; height: 8px;
    background: var(--danger-fg);
    border-radius: 50%;
    border: 2px solid var(--bg-base);
}

/* Bruker-meny */
.user-menu {
    display: flex; align-items: center; gap: var(--space-2);
    padding: var(--space-1) var(--space-2) var(--space-1) var(--space-1);
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: all var(--transition-fast);
}
.user-menu:hover { border-color: var(--border-default); }
.user-menu-info { display: flex; flex-direction: column; line-height: 1.2; }
.user-menu-name { font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--text-primary); }
.user-menu-role { font-size: 10px; color: var(--text-muted); }

/* === CONTENT === */
.app-content {
    flex: 1;
    padding: var(--space-6) var(--space-8);
    max-width: var(--content-max);
    width: 100%;
    margin: 0 auto;
}

@media (max-width: 768px) {
    .app-content { padding: var(--space-4); }
    .header-search { display: none; }
}

@media (max-width: 1024px) {
    .app-shell > .sidebar {
        left: -100%;
        width: min(320px, 85vw);
    }
    .app-shell > .sidebar.is-open {
        left: 0;
    }
}

/* === FOOTER === */
.app-footer {
    padding: 10px var(--space-6);
    border: 0;
    background: var(--chrome-bg, var(--bg-elevated));
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    font-size: 12px;
    color: var(--text-muted);
    min-height: 40px !important;
    line-height: 1.3;
    position: fixed !important;
    left: 0 !important; right: 0 !important; bottom: 0 !important;
    z-index: 9999 !important;
    visibility: visible !important;
    opacity: 1 !important;
}
.app-shell .app-content,
.app-shell > main { padding-bottom: 56px; padding-top: calc(var(--header-height) + var(--space-3)); }
.app-shell > .sidebar { padding-top: var(--space-3); }
body { padding-bottom: 0 !important; }
.public-shell .public-main { padding-bottom: 56px; }

/* Footer-alignment: copyright venstre, alt annet høyre */
.app-footer > :first-child { margin-right: auto; }
.app-footer { justify-content: flex-start !important; }
.app-footer-links, .app-footer-status { margin-left: 0; }

/* Brand i header (innloggede sider) — bredde matcher sidebar */
.app-header .header-brand {
    display: flex; align-items: center; gap: 10px;
    color: inherit; text-decoration: none;
    padding: 0 var(--space-5);
    margin-right: 0;
    height: 100%;
    width: var(--sidebar-width, 240px);
    box-sizing: border-box;
    flex-shrink: 0;
}
.app-shell.sidebar-collapsed .app-header .header-brand { width: var(--sidebar-collapsed, 72px); padding: 0 var(--space-3); }
.app-shell.sidebar-collapsed > .sidebar { width: var(--sidebar-collapsed, 72px); }
.app-shell.sidebar-collapsed .app-header .header-brand .header-brand-text { display: none }
.app-header .header-brand-mark {
    width: 32px; height: 32px; border-radius: 8px;
    background: linear-gradient(135deg, var(--accent, #6c63ff), #8b80ff);
    color: #fff; display: inline-flex; align-items: center; justify-content: center;
    font-weight: 700;
}
.app-header .header-brand-text { display: flex; flex-direction: column; line-height: 1.1 }
.app-header .header-brand-name { font-weight: 600; font-size: 14px; color: var(--text-primary) }
.app-header .header-brand-tagline { font-size: 11px; color: var(--text-muted) }

/* Skjul gammel brand-blokk i sidebar (flyttet til header) */
.app-shell .sidebar > .sidebar-header { display: none !important; }
.app-footer-links { display: flex; align-items: center; gap: var(--space-4); }
.app-footer-links a { color: var(--text-muted); transition: color var(--transition-fast); }
.app-footer-links a:hover { color: var(--text-primary); }
.app-footer-status { display: flex; align-items: center; gap: var(--space-2); }
.status-indicator {
    display: inline-flex; align-items: center; gap: var(--space-1);
}

/* === BREADCRUMBS === */
.breadcrumbs {
    display: flex; align-items: center; gap: var(--space-2);
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-bottom: var(--space-2);
}
.breadcrumbs a { color: var(--text-muted); }
.breadcrumbs a:hover { color: var(--text-primary); }
.breadcrumb-separator { opacity: 0.5; }

/* === PAGE-HEADER (under app-header, før content) === */
.page-hero {
    margin-bottom: var(--space-6);
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--space-6);
    flex-wrap: wrap;
}
.page-hero h1 {
    font-size: var(--text-2xl);
    margin: 0 0 var(--space-1);
}
.page-hero-text { font-size: var(--text-sm); color: var(--text-muted); max-width: 600px; }
.page-hero-actions { display: flex; gap: var(--space-2); }

/* === PUBLIC LAYOUT === */
.public-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: radial-gradient(ellipse at top, rgba(108,99,255,0.08) 0%, transparent 50%),
                radial-gradient(ellipse at bottom, rgba(20,184,166,0.05) 0%, transparent 50%),
                var(--bg-base);
    padding-bottom: 44px;
}
@media (max-width: 900px) {
    body { padding-bottom: 90px; }
}
.public-header {
    height: var(--header-height);
    padding: 0 var(--space-8);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-subtle);
    backdrop-filter: blur(12px);
    background: var(--bg-elevated);
    position: sticky; top: 0; z-index: var(--z-sticky);
}
.public-header .sidebar-brand-text { display: flex; }
.public-header-nav { display: flex; align-items: center; gap: var(--space-2); }
.public-header-nav a {
    padding: var(--space-2) var(--space-3);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    transition: all var(--transition-fast);
}
.public-header-nav a:hover { color: var(--text-primary); background: var(--bg-glass); }

.public-main { flex: 1; }

.public-footer {
    padding: var(--space-2) var(--space-6);
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-elevated);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: var(--z-sticky);
}
.public-footer-row {
    max-width: var(--content-max);
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-5);
    flex-wrap: wrap;
}
.public-footer-meta {
    color: var(--text-muted);
    font-size: var(--text-xs);
    white-space: nowrap;
}
.public-footer-links {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    flex-wrap: wrap;
}
.public-footer-links a {
    color: var(--text-secondary);
    font-size: var(--text-xs);
    text-decoration: none;
}
.public-footer-links a:hover { color: var(--text-primary); }
@media (max-width: 900px) {
    .public-footer-row { flex-direction: column; align-items: flex-start; gap: var(--space-2); }
}

/* === HERO (landingsside) === */
.hero {
    padding: var(--space-24) var(--space-8) var(--space-16);
    text-align: center;
    position: relative;
}
.hero h1 {
    font-family: var(--font-display);
    font-size: clamp(2.5rem, 6vw, 4.5rem);
    line-height: 0.98;
    letter-spacing: -0.035em;
    font-weight: var(--weight-bold);
    margin-bottom: var(--space-5);
    color: var(--text-primary);
    max-width: 920px;
    margin-left: auto;
    margin-right: auto;
}
.hero p {
    font-size: var(--text-lg);
    color: var(--text-secondary);
    max-width: 640px;
    margin: 0 auto var(--space-8);
    line-height: var(--leading-relaxed);
}
.hero-cta { display: flex; justify-content: center; gap: var(--space-3); flex-wrap: wrap; }

.hero-eyebrow {
    display: inline-flex; align-items: center; gap: var(--space-2);
    padding: var(--space-1) var(--space-3);
    background: var(--bg-glass);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    color: var(--brand-300);
    margin-bottom: var(--space-6);
}

/* Trust-row (logoer eller compliance-badges) */
.trust-row {
    max-width: var(--content-max);
    margin: 0 auto;
    padding: var(--space-8) var(--space-8);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--space-12);
    flex-wrap: wrap;
    opacity: 0.7;
}
.trust-item { font-size: var(--text-xs); color: var(--text-muted); display: flex; align-items: center; gap: var(--space-2); }

/* Feature-grid */
.features-section { padding: var(--space-16) var(--space-8); max-width: var(--content-max); margin: 0 auto; }
.features-header { text-align: center; margin-bottom: var(--space-12); }
.features-header h2 { font-size: var(--text-3xl); margin-bottom: var(--space-3); }
.features-header p { font-size: var(--text-md); color: var(--text-secondary); max-width: 640px; margin: 0 auto; }
.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--space-5);
}
.feature {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    transition: all var(--transition-base);
}
.feature:hover {
    transform: translateY(-3px);
    border-color: var(--border-default);
    box-shadow: var(--shadow-lg);
}
.feature-icon {
    width: 40px; height: 40px;
    display: grid; place-items: center;
    background: linear-gradient(135deg, rgba(108,99,255,0.18), rgba(20,184,166,0.12));
    border: 1px solid rgba(108,99,255,0.30);
    color: var(--brand-300);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-4);
}
.feature h3 { font-size: var(--text-md); margin-bottom: var(--space-2); }
.feature p { font-size: var(--text-sm); color: var(--text-secondary); line-height: var(--leading-relaxed); }

/* CTA-block */
.cta-block {
    max-width: var(--content-max);
    margin: var(--space-16) auto;
    padding: var(--space-12) var(--space-8);
    text-align: center;
    background: linear-gradient(135deg, rgba(108,99,255,0.10), rgba(20,184,166,0.06));
    border: 1px solid rgba(108,99,255,0.30);
    border-radius: var(--radius-xl);
}
.cta-block h2 { font-size: var(--text-3xl); margin-bottom: var(--space-3); }
.cta-block p { color: var(--text-secondary); margin-bottom: var(--space-6); max-width: 540px; margin-left: auto; margin-right: auto; }

/* === LOGIN / AUTH === */
.auth-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: var(--bg-base);
}
@media (max-width: 768px) { .auth-shell { grid-template-columns: 1fr; } .auth-aside { display: none; } }

.auth-aside {
    background: linear-gradient(135deg, var(--brand-700) 0%, var(--brand-900) 60%, #0a0e1a 100%);
    padding: var(--space-12);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
}
.auth-aside::before {
    content: '';
    position: absolute;
    top: -20%; right: -20%;
    width: 70%; height: 70%;
    background: radial-gradient(circle, rgba(108,99,255,0.30) 0%, transparent 70%);
    filter: blur(40px);
}
.auth-aside-quote {
    position: relative;
    color: var(--text-primary);
    font-size: var(--text-2xl);
    font-weight: var(--weight-medium);
    line-height: var(--leading-snug);
    max-width: 420px;
    letter-spacing: var(--tracking-tight);
}
.auth-aside-cite { position: relative; color: var(--text-secondary); margin-top: var(--space-3); font-size: var(--text-sm); }

.auth-form-area {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-8);
}
.auth-form {
    width: 100%;
    max-width: 420px;
}
.auth-form h1 { font-size: var(--text-2xl); margin-bottom: var(--space-2); }
.auth-form-text { color: var(--text-secondary); margin-bottom: var(--space-6); font-size: var(--text-sm); }
.auth-divider {
    display: flex; align-items: center; gap: var(--space-3);
    margin: var(--space-6) 0;
    color: var(--text-muted);
    font-size: var(--text-xs);
}
.auth-divider::before, .auth-divider::after {
    content: ''; flex: 1; height: 1px; background: var(--border-subtle);
}
.auth-meta {
    margin-top: var(--space-6);
    text-align: center;
    color: var(--text-muted);
    font-size: var(--text-sm);
}
