:root {
    --orange: #e16a03;
    --orange-dark: #bd5500;
    --green: #2f6b3d;
    --red: #b42318;
    --yellow: #a15c00;
    --blue: #3538cd;
    --purple: #6941c6;
    --text: #172033;
    --muted: #667085;
    --line: #e4e7ec;
    --soft: #f7f8fa;
    --white: #ffffff;
    --shadow: 0 10px 26px rgba(16, 24, 40, 0.07);
    --radius: 16px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Montserrat', Arial, sans-serif;
    color: var(--text);
    background: var(--soft);
    line-height: 1.5;
    overflow-x: hidden;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input {
    font-family: inherit;
}

.flash-messages {
    position: fixed;
    top: 78px;
    right: 20px;
    z-index: 100;
    max-width: min(420px, calc(100vw - 40px));
}

.flash-message {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    margin-bottom: 10px;
    border-radius: 14px;
    color: var(--white);
    font-weight: 700;
    box-shadow: var(--shadow);
}

.flash-message.success {
    background: var(--green);
}

.flash-message.error {
    background: #101828;
}

/* Toppfelt */

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(228, 231, 236, 0.9);
}

.topbar-inner {
    max-width: 1240px;
    margin: 0 auto;
    padding: 12px 24px;
    display: grid;
    grid-template-columns: auto minmax(280px, 1fr);
    gap: 16px;
    align-items: center;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    letter-spacing: -0.03em;
    white-space: nowrap;
}

.brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 11px;
    background: var(--orange);
    display: grid;
    place-items: center;
    color: var(--white);
    font-weight: 800;
    box-shadow: 0 7px 16px rgba(225, 106, 3, 0.24);
}

.search-box {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 5px 5px 5px 17px;
    box-shadow: 0 3px 12px rgba(16, 24, 40, 0.04);
    min-width: 0;
}

.search-box input[type="text"] {
    border: 0;
    outline: 0;
    flex: 1;
    font-size: 15px;
    min-width: 0;
    color: var(--text);
    background: transparent;
}

.search-box input[type="text"]:focus {
    outline: none;
}

.search-box button {
    border: 0;
    background: var(--orange);
    color: var(--white);
    font-weight: 700;
    border-radius: 999px;
    padding: 10px 18px;
    cursor: pointer;
    box-shadow: 0 7px 16px rgba(225, 106, 3, 0.22);
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.search-box button:hover {
    background: var(--orange-dark);
}

/* Statuslinje */

.statusbar {
    position: sticky;
    top: 59px;
    z-index: 25;
    background: rgba(247, 248, 250, 0.96);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(228, 231, 236, 0.9);
}

.statusbar-inner {
    max-width: 1240px;
    margin: 0 auto;
    padding: 10px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.result-context {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    min-width: 0;
}

.context-label {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.context-query {
    font-weight: 800;
    letter-spacing: -0.025em;
}

.status-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.mini-stat {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 13px;
    color: var(--muted);
    white-space: nowrap;
}

.mini-stat strong {
    color: var(--text);
}

.mini-stat.ok strong {
    color: var(--green);
}

/* Layout */

.page {
    max-width: 1240px;
    margin: 0 auto;
    padding: 18px 24px 72px;
}

.panel {
    background: rgba(255, 255, 255, 0.97);
    border: 1px solid rgba(228, 231, 236, 0.95);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

/* Startside */

.start-page {
    display: grid;
    gap: 18px;
}

.start-panel {
    display: grid;
    align-items: center;
    padding: 34px 36px;
    background:
        radial-gradient(circle at top left, rgba(225, 106, 3, 0.14), transparent 32rem),
        linear-gradient(180deg, #ffffff 0%, #fffaf5 100%);
}

.start-content {
    max-width: 820px;
}

.eyebrow {
    margin: 0 0 12px;
    color: var(--orange-dark);
    font-weight: 800;
    font-size: 13px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.start-panel h1 {
    margin: 0 0 12px;
    font-size: clamp(32px, 5vw, 52px);
    line-height: 1.04;
    letter-spacing: -0.06em;
}

.start-lead {
    margin: 0;
    color: var(--muted);
    font-size: 17px;
    max-width: 74ch;
}

.start-examples {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 9px;
    margin-top: 22px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
}

.start-examples button {
    border: 1px solid #ffd6a8;
    background: #fff3e6;
    color: var(--orange-dark);
    border-radius: 999px;
    padding: 8px 12px;
    font-weight: 800;
    cursor: pointer;
}

.start-examples button:hover {
    background: #fff7ed;
    border-color: rgba(225, 106, 3, 0.45);
}

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

.info-card {
    padding: 20px;
}

.info-icon {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: #fff3e6;
    color: var(--orange-dark);
    border: 1px solid #ffd6a8;
    font-weight: 800;
    margin-bottom: 12px;
}

.info-card h2 {
    margin: 0 0 8px;
    font-size: 18px;
    letter-spacing: -0.03em;
}

.info-card p {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
}

/* Resultatoverskrift */

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin: 0 0 12px;
}

.results-header h1 {
    margin: 0;
    font-size: 24px;
    letter-spacing: -0.045em;
    line-height: 1.15;
}

.results-header p {
    margin: 3px 0 0;
    color: var(--muted);
    font-size: 14px;
}

/* Resultatkort */

.company-group {
    position: relative;
    overflow: hidden;
    margin-top: 14px;
}

.company-main {
    padding: 18px 20px;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 18px;
    align-items: start;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(180deg, #ffffff 0%, #fffaf5 100%);
}

.company-main.match-main {
    background: #fff7ed;
    box-shadow: inset 4px 0 0 var(--orange);
}

.main-title-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 9px;
    margin-bottom: 7px;
}

.company-name {
    font-size: 21px;
    font-weight: 800;
    letter-spacing: -0.035em;
    line-height: 1.2;
}

.meta-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 18px;
    color: var(--muted);
    font-size: 14px;
}

.meta-grid strong {
    color: var(--text);
}

.main-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    cursor: default;
}

/* Underliggende enheter */

.children-area {
    padding: 14px 20px 18px;
    background: var(--white);
}

.children-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.children-title {
    margin: 0;
    font-size: 16px;
    letter-spacing: -0.025em;
}

.hint {
    color: var(--muted);
    font-size: 13px;
    background: var(--soft);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 6px 10px;
    white-space: nowrap;
}

.child-list {
    display: grid;
    gap: 8px;
}

.child-node {
    display: grid;
    gap: 8px;
}

.child-row {
    position: relative;
    display: grid;
    grid-template-columns: 24px minmax(190px, 1.2fr) minmax(150px, 0.9fr) minmax(250px, auto);
    gap: 10px 12px;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 11px 12px;
    background: var(--white);
}

.child-row:hover {
    background: #fff7ed;
    border-color: rgba(225, 106, 3, 0.28);
}

.child-row.match-row {
    background: #fff7ed;
    border-color: rgba(225, 106, 3, 0.55);
    box-shadow: 0 0 0 3px rgba(225, 106, 3, 0.10);
}

.child-row.nested-row {
    background: #fcfcfd;
}

.child-row.nested-row:hover {
    background: #fff7ed;
}

.tree-mark {
    width: 20px;
    height: 29px;
    border-left: 2px solid #d0d5dd;
    border-bottom: 2px solid #d0d5dd;
    border-bottom-left-radius: 8px;
    transform: translateY(-7px);
}

.child-name {
    font-weight: 800;
    line-height: 1.25;
}

.orgnr {
    font-variant-numeric: tabular-nums;
    color: var(--muted);
    font-size: 13px;
    margin-top: 2px;
}

.address {
    color: var(--muted);
    font-size: 14px;
    min-width: 0;
}

.child-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 7px;
    min-width: 220px;
}

.child-actions .type-pill,
.child-actions .match-label,
.child-actions .ehf-status,
.child-actions .nested-toggle {
    flex: 0 0 auto;
}

/* Nøstede underliggende enheter */

.nested-children {
    display: grid;
    gap: 8px;
    margin-left: 34px;
    padding-left: 14px;
    border-left: 2px solid #eaecf0;
}

.nested-children[hidden] {
    display: none;
}

.child-depth-2 > .child-row {
    margin-left: 0;
}

.child-depth-3 > .child-row {
    margin-left: 0;
}

.child-depth-2 .tree-mark,
.child-depth-3 .tree-mark {
    border-left-color: #cfd4dc;
    border-bottom-color: #cfd4dc;
}

.nested-empty {
    margin-top: 2px;
    margin-bottom: 2px;
}

/* Klikkbare søkeresultater */

[data-search-orgnr] {
    cursor: pointer;
}

/* Direkte treff */

.direct-match-banner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 11px 20px;
    background: #fff7ed;
    border-bottom: 1px solid #ffd6a8;
    color: var(--orange-dark);
    font-size: 14px;
    font-weight: 700;
}

.direct-match-banner span {
    color: var(--muted);
    font-weight: 600;
}

/* Badges */

.ehf-status,
.match-label,
.type-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 13px;
    font-weight: 800;
    white-space: nowrap;
}

.ehf-status.grønn {
    color: var(--green);
    background: #ecfdf3;
    border: 1px solid #abefc6;
}

.ehf-status.rød {
    color: var(--red);
    background: #fef3f2;
    border: 1px solid #fecdca;
}

.ehf-status.gul,
.ehf-status.spinner {
    color: var(--yellow);
    background: #fffaeb;
    border: 1px solid #fedf89;
    animation: puls 1s infinite;
}

@keyframes puls {
    0% {
        opacity: 0.72;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.72;
    }
}

.match-label {
    color: var(--orange-dark);
    background: #fff3e6;
    border: 1px solid #ffd6a8;
}

.type-pill.main {
    background: #fff3e6;
    color: var(--orange-dark);
    border: 1px solid #ffd6a8;
}

.type-pill.child {
    background: #eef4ff;
    color: var(--blue);
    border: 1px solid #c7d7fe;
}

/* Relasjonstype-badges */

.relation-pill {
    justify-self: start;
}

.relation-underenhet {
    background: #eef4ff;
    color: var(--blue);
    border: 1px solid #c7d7fe;
}

.relation-tilknyttet {
    background: #f4f3ff;
    color: var(--purple);
    border: 1px solid #d9d6fe;
}

.relation-ukjent {
    background: #f2f4f7;
    color: var(--muted);
    border: 1px solid var(--line);
}

/* Pluss/minus for hovedkort */

.toggle-children {
    border: 1px solid var(--line);
    background: var(--white);
    color: var(--orange-dark);
    border-radius: 999px;
    padding: 8px 12px;
    font-weight: 800;
    cursor: pointer;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.toggle-children:hover {
    border-color: rgba(225, 106, 3, 0.45);
    background: #fff7ed;
}

.toggle-icon {
    width: 18px;
    height: 18px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #fff3e6;
    border: 1px solid #ffd6a8;
    line-height: 1;
    font-size: 15px;
}

.company-group.is-collapsed .children-area,
.company-group.is-collapsed .direct-match-banner {
    display: none;
}

.company-group.is-collapsed .company-main {
    border-bottom: 0;
}

.company-group.is-collapsed {
    box-shadow: var(--shadow);
}

/* Pluss/minus for tilknyttet enhet */

.nested-toggle {
    border: 1px solid #d9d6fe;
    background: #f4f3ff;
    color: var(--purple);
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    justify-content: center;
}

.nested-toggle:hover {
    background: #ebe9fe;
    border-color: rgba(105, 65, 198, 0.42);
}

.nested-toggle:disabled {
    opacity: 0.7;
    cursor: wait;
}

.nested-toggle-icon {
    width: 16px;
    height: 16px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    border: 1px solid #d9d6fe;
    line-height: 1;
    font-size: 13px;
}

/* Tomtilstand */

.empty-children {
    border: 1px dashed #d0d5dd;
    border-radius: 14px;
    padding: 14px;
    color: var(--muted);
    background: #fcfcfd;
}

/* Paginering for underliggende enheter */

.subunit-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-top: 14px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fcfcfd;
}

.subunit-pagination-info {
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
}

.subunit-pagination-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.pagination-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #ffd6a8;
    background: #fff3e6;
    color: var(--orange-dark);
    border-radius: 999px;
    padding: 8px 12px;
    font-size: 14px;
    font-weight: 800;
    text-decoration: none;
    white-space: nowrap;
}

.pagination-button:hover {
    background: #fff7ed;
    border-color: rgba(225, 106, 3, 0.45);
}

/* Fast tilbakemeldingsknapp */

#feedback-button {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 20;
    background: var(--orange);
    color: var(--white);
    border-radius: 999px;
    padding: 11px 18px;
    font-size: 14px;
    font-weight: 700;
    box-shadow: 0 8px 18px rgba(225, 106, 3, 0.24);
}

#feedback-button:hover {
    background: var(--orange-dark);
}

/* Intranett / smalere desktop-visning */

@media (max-width: 1180px) {
    .child-row {
        grid-template-columns: 22px minmax(190px, 1fr) minmax(160px, 0.75fr) minmax(220px, auto);
    }

    .child-actions {
        justify-content: flex-start;
        min-width: 200px;
    }
}

@media (max-width: 1040px) {
    .child-row {
        grid-template-columns: 22px minmax(0, 1fr) minmax(220px, auto);
    }

    .address {
        grid-column: 2 / 3;
    }

    .child-actions {
        grid-column: 3 / 4;
        justify-content: flex-start;
        min-width: 210px;
    }
}

/* Tablet */

@media (max-width: 860px) {
    .info-grid {
        grid-template-columns: 1fr;
    }

    .topbar-inner {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .statusbar {
        top: 111px;
    }

    .statusbar-inner,
    .results-header,
    .children-head,
    .direct-match-banner {
        flex-direction: column;
        align-items: flex-start;
    }

    .company-main {
        grid-template-columns: 1fr;
    }

    .main-actions {
        justify-content: flex-start;
    }

    .hint {
        white-space: normal;
    }

    .child-row {
        grid-template-columns: 20px minmax(0, 1fr);
    }

    .address,
    .child-actions {
        grid-column: 2 / -1;
    }

    .child-actions {
        min-width: 0;
        justify-content: flex-start;
    }
}

/* Mobil */

@media (max-width: 560px) {
    .topbar-inner,
    .statusbar-inner,
    .page {
        padding-left: 14px;
        padding-right: 14px;
    }

    .page {
        padding-top: 14px;
        padding-bottom: 60px;
    }

    .search-box {
        border-radius: 16px;
        align-items: stretch;
        flex-direction: column;
        padding: 10px;
    }

    .search-box input[type="text"] {
        padding: 9px;
    }

    .search-box button {
        width: 100%;
        justify-content: center;
    }

    .statusbar {
        position: static;
    }

    .status-stats {
        width: 100%;
    }

    .mini-stat {
        flex: 1;
        justify-content: center;
    }

    .start-panel,
    .info-card,
    .company-main,
    .children-area {
        padding: 16px;
    }

    .nested-children {
        margin-left: 18px;
        padding-left: 10px;
    }

    .toggle-children {
        width: 100%;
        justify-content: center;
    }

    .nested-toggle {
        width: auto;
    }

    .child-actions {
        width: 100%;
    }

    .subunit-pagination {
        align-items: flex-start;
        flex-direction: column;
    }

    .subunit-pagination-actions {
        width: 100%;
    }

    .pagination-button {
        flex: 1;
    }

    #feedback-button {
        right: 14px;
        bottom: 14px;
        padding: 10px 14px;
    }
}
