/* Konsernstruktur: the group and company detail pages, and the ownership diagram (StructureDiagram). */

:root {
    --structure-node-default: var(--ms-structure-node);
    --structure-node-highlight: var(--ms-structure-node-here);
    --structure-node-source-deleted: var(--ms-structure-node-gone);
    --structure-parent-edge: var(--ms-structure-parent);
    /* Transient feedback rather than a data colour, so it stays out of the legend's palette and
       follows the theme's text colour to stay visible in both light and dark mode. */
    --structure-node-active: var(--mud-palette-text-primary);
}

/* ---- Detail forms (Konserndetaljer, a group company's Detaljer) ---- */

/* A form tab in a page that fills the window: the panel scrolls rather than the page. */
.ms-fill .ms-tab-fill.struct-tab-scroll {
    overflow-y: auto;
}

.struct-details {
    display: flex;
    flex-direction: column;
    gap: 28px;
    max-width: 880px;
    padding: 20px 24px 24px;
}

.struct-details__group + .struct-details__group {
    padding-top: 24px;
    border-top: 1px solid var(--mud-palette-lines-default);
}

.struct-details__title {
    margin: 0 0 14px;
    color: var(--mud-palette-text-primary);
    font-family: var(--ms-font-ui);
    font-size: 1rem;
    font-weight: 600;
}

.struct-details__text {
    margin: 0 0 14px;
    color: var(--mud-palette-text-secondary);
    font-size: .875rem;
}

.mud-form.struct-details__grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
    gap: 16px 24px;
}

.struct-details__grid > .mud-input-control {
    margin: 0;
}

.struct-details__grid > .struct-details__wide {
    grid-column: 1 / -1;
}

@media (max-width: 700px) {
    .mud-form.struct-details__grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

.struct-details__actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 18px;
}

/* ---- A group company's Eierskap: the switch, then the two lists or the diagram ---- */

.struct-ownership {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.struct-ownership__bar {
    flex: 0 0 auto;
    padding: 14px 24px;
    border-bottom: 1px solid var(--mud-palette-lines-default);
}

.struct-ownership__lists {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 32px;
    padding: 20px 24px 24px;
}

.struct-ownership > .structure-paper {
    flex: 1 1 0;
    min-height: 0;
}

.struct-list__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 16px;
    margin-bottom: 10px;
}

.struct-list__head .struct-details__title {
    margin: 0;
}

.struct-list__grid {
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: var(--mud-default-borderradius);
    overflow: hidden;
}

.struct-list__grid .struct-list__center {
    text-align: center;
}

/* The footer only says what is unregistered, and draws an empty row when nothing is. */
.struct-list__grid .mud-table-foot:not(:has(span)) {
    display: none;
}

/* ---- Importer fra Aksjonærregisteret ---- */

/* One width through the steps, so the dialog does not jump between them. */
.struct-import {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 360px;
}

.struct-import__text {
    margin: 0;
    color: var(--mud-palette-text-secondary);
    font-size: .875rem;
}

/* The first step: the details on the left, what the import will do on the right. */
.struct-import__start {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(260px, 1fr);
    align-items: start;
    gap: 24px 40px;
}

@media (max-width: 900px) {
    .struct-import__start {
        grid-template-columns: minmax(0, 1fr);
    }
}

.struct-import__form {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.struct-import__fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
    gap: 16px 24px;
}

.struct-import__how {
    padding: 18px 20px 20px;
    border-radius: var(--mud-default-borderradius);
    background-color: var(--ms-surface-2);
}

.struct-import__how-title {
    margin: 0 0 14px;
    color: var(--mud-palette-text-primary);
    font-family: var(--ms-font-ui);
    font-size: .9375rem;
    font-weight: 600;
}

.struct-import__how-steps {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin: 0;
    padding: 0;
    list-style: none;
    counter-reset: import-step;
}

.struct-import__how-steps li {
    display: grid;
    grid-template-columns: 26px minmax(0, 1fr);
    column-gap: 12px;
    counter-increment: import-step;
}

.struct-import__how-steps li::before {
    content: counter(import-step);
    grid-row: 1 / span 2;
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background-color: var(--mud-palette-primary-lighten);
    color: var(--mud-palette-primary);
    font-size: .8125rem;
    font-weight: 600;
}

.struct-import__how-steps strong {
    color: var(--mud-palette-text-primary);
    font-size: .875rem;
    font-weight: 600;
}

.struct-import__how-steps span {
    color: var(--mud-palette-text-secondary);
    font-size: .8125rem;
    line-height: 1.45;
}

.struct-import__fields > .mud-input-control {
    margin: 0;
}

/* MudSelect puts its Class on an inner element, so the grid item is the one that holds it. */
.struct-import__fields > .struct-import__wide,
.struct-import__fields > :has(.struct-import__wide) {
    grid-column: 1 / -1;
}

.struct-import__tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 14px;
}

.struct-import__tools > .mud-input-control {
    flex: 0 1 380px;
    margin: 0;
}

.struct-import__count {
    margin-left: auto;
    color: var(--mud-palette-text-secondary);
    font-size: .875rem;
}

.struct-import__count strong {
    color: var(--mud-palette-text-primary);
    font-weight: 600;
}

.struct-import__more {
    color: var(--mud-palette-primary);
    font-size: .8125rem;
    font-weight: 600;
}

.struct-import__muted {
    color: var(--mud-palette-text-secondary);
}

.struct-import__owners {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 16px 10px 112px;
    font-size: .8125rem;
}

.struct-import__owners-title {
    color: var(--mud-palette-text-secondary);
    font-weight: 600;
}

/* The picker fills the owner's cell, with whether the owner is new or already in the group after it. */
.struct-import__owner-cell {
    display: flex;
    align-items: center;
    gap: 12px;
}

.struct-import__owner-cell > .mud-input-control,
.struct-import__owner-cell > :has(.struct-import__owner-pick) {
    flex: 1 1 auto;
    min-width: 220px;
    margin: 0;
}

.struct-import__owner-cell > .ms-status {
    flex: 0 0 auto;
}

.struct-import__row-end {
    display: flex;
    justify-content: flex-end;
}

.struct-import__owners-foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 14px;
    padding: 8px 16px 12px;
    font-size: .8125rem;
}

.struct-import__result {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 260px;
    text-align: center;
}

.struct-import__result p {
    margin: 0;
    max-width: 620px;
}

.struct-import__result-icon {
    color: var(--ms-tone-ink);
    font-size: 48px;
}

/* ---- The ownership diagram ---- */

/* Drawn flush in the card or tab around it; fills its parent's height when the parent is a filling panel. */
.structure-paper {
    display: flex;
    flex-direction: column;
    width: 100%;
    position: relative;
    overflow: hidden;
}

.ms-tab-fill > .structure-paper {
    flex: 1 1 0;
    min-height: 0;
}

.structure-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 16px;
    padding: 8px 12px 8px 16px;
    border-bottom: 1px solid var(--mud-palette-lines-default);
    background-color: var(--ms-surface-2);
}

.structure-bar__count {
    margin-left: auto;
    color: var(--mud-palette-text-secondary);
    font-size: .8125rem;
}

/* The canvas sizes itself to its parent, so it needs whatever the header row leaves. */
.structure-canvas-host {
    flex: 1;
    min-height: 0;
    position: relative;
}

.structure-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 18px;
    margin: 0;
    padding: 0;
    list-style: none;
    color: var(--mud-palette-text-secondary);
    font-family: var(--ms-font-ui);
    font-size: .8125rem;
}

.structure-legend li {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.structure-legend span {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.structure-legend .structure-legend-highlighted {
    background-color: var(--structure-node-highlight);
}

.structure-legend .structure-legend-parent {
    width: 16px;
    height: 3px;
    border-radius: 2px;
    background-color: var(--structure-parent-edge);
}

.structure-legend .structure-legend-source-deleted {
    background-color: var(--structure-node-source-deleted);
}

.structure-node {
    --structure-node-color: var(--structure-node-default);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    overflow: hidden;
    font-family: var(--mud-typography-default-family);
    color: var(--mud-palette-text-primary);
}

/* Declared before the highlight so the company you are on keeps its colour either way. */
.structure-node-source-deleted {
    --structure-node-color: var(--structure-node-source-deleted);
}

.structure-node-highlighted {
    --structure-node-color: var(--structure-node-highlight);
}

/* Wraps the node's whole box, so it reads the same around a full node and a compact one. */
.structure-node-active {
    outline: 3px solid var(--structure-node-active);
    outline-offset: 2px;
    border-radius: 8px;
}

.structure-node-icon {
    fill: var(--structure-node-color);
    flex: none;
}

.structure-node-name {
    margin-top: -4px;
    padding: 0 8px;
    font-size: 0.85rem;
    font-weight: 500;
    line-height: 1.15;
    text-align: center;
    /* Two lines of company name, then an ellipsis; the full name is on the node's tooltip. */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.structure-node-orgno {
    font-size: 0.7rem;
    opacity: 0.7;
}

/* Zoomed out the name is all that fits, so the node itself carries the colour. */
.structure-node-compact {
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    padding: 12px 18px;
    border-radius: 8px;
    background-color: var(--structure-node-color);
    color: var(--ms-structure-node-ink);
    overflow: hidden;
}

.structure-node-compact-text {
    font-size: 1.5rem;
    font-weight: 500;
    line-height: 1.15;
    text-align: center;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* The label's foreignObject is 1px wide with the content overflowing it, so without this the
   percent sign wraps onto its own line. */
.structure-canvas-host .diagram-link div.default-link-label {
    white-space: nowrap;
    padding: 0.2rem 0.45rem;
}

/* The percentages are below reading size here, and there is one per ownership row. */
.structure-compact .diagram-link-label {
    display: none;
}
