/* Eikekveik — eige utvalde stilar (utvidar neobrutalisme.css) */

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
    justify-content: flex-start;
}

.toolbar-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.toolbar-group:not(:last-child) {
    padding-right: 16px;
    border-right: 2px solid var(--border);
}

.toolbar .btn svg {
    vertical-align: -3px;
    margin-right: 4px;
}

/* Lerret og panel side om side. Panelet fell under lerretet på smal skjerm. */
.editor {
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(250px, 22vw, 320px);
    gap: 16px;
    align-items: start;
}

@media (max-width: 900px) {
    .editor {
        grid-template-columns: minmax(0, 1fr);
    }
}

.editor [hidden] {
    display: none !important;
}

/* Lerret */
.canvas-wrapper {
    position: relative;
    padding: 0;
    overflow: hidden;
}

.canvas {
    position: relative;
    height: clamp(400px, 72vh, 1000px);
    background-image:
        radial-gradient(circle, var(--border) 1px, transparent 1px);
    background-size: 24px 24px;
    background-position: 12px 12px;
    overflow: hidden;
    touch-action: none;
    cursor: grab;
}

.canvas.panning {
    cursor: grabbing;
}

/* Under om lag 40 % zoom står prikkane så tett at dei blir eit grått teppe. */
.canvas.grid-off {
    background-image: none;
}

/* Verda er eit punkt i øvre venstre hjørne. Nodane ligg absolutt i henne,
   og heile flata blir flytt og skalert med éin transform. */
.world {
    position: absolute;
    left: 0;
    top: 0;
    width: 0;
    height: 0;
    transform-origin: 0 0;
}

.edges {
    position: absolute;
    left: 0;
    top: 0;
    width: 1px;
    height: 1px;
    overflow: visible;
    pointer-events: none;
    z-index: 1;
}

.edges .edge-hit {
    fill: none;
    stroke: transparent;
    stroke-width: 18;
    pointer-events: stroke;
    cursor: pointer;
}

.edges .edge-line.selected {
    stroke-width: 5;
    stroke-dasharray: 8 7;
}

.edges .edge-hit:focus-visible {
    outline: none;
}

.edges .edge-hit:focus-visible + .edge-line {
    stroke-width: 5;
    stroke-dasharray: 8 7;
}

.edges path {
    fill: none;
    stroke: var(--border);
    stroke-width: 3;
    stroke-linecap: round;
}

.edges marker path {
    fill: var(--border);
    stroke: none;
}

/* Nodar */
.node {
    --node-fill: #FFD166;
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: #1a1a1a;
    padding: 0.65em 1em;
    /* Verda er 0 px brei, så utan max-content ville ein absolutt plassert
       node krympe til den smalaste breidda teksten tåler — eitt ord per linje. */
    width: max-content;
    min-width: 80px;
    max-width: 220px;
    cursor: grab;
    user-select: none;
    z-index: 2;
    transition: transform 0.1s;
    font-weight: 600;
    text-align: center;
    overflow-wrap: break-word;
}

/* Forma blir teikna i JS etter at storleiken er kjend (sjå render.js).
   z-index -1 legg henne bak teksten men inne i noden sin stabel. */
.node-shape {
    position: absolute;
    left: 0;
    top: 0;
    overflow: visible;
    z-index: -1;
    pointer-events: none;
}

.shape-fill {
    fill: var(--node-fill);
    stroke: var(--border);
    stroke-width: 3;
    stroke-linejoin: round;
}

.shape-shadow {
    fill: var(--border);
    stroke: var(--border);
    stroke-width: 3;
    stroke-linejoin: round;
    transform: translate(4px, 4px);
    transition: transform 0.1s;
}

.shape-detail {
    fill: none;
    stroke: var(--border);
    stroke-width: 3;
}

.node:hover {
    transform: translate(-1px, -1px);
}

.node:hover .shape-shadow {
    transform: translate(5px, 5px);
}

.node:active,
.node.dragging {
    cursor: grabbing;
    transform: translate(2px, 2px);
}

.node:active .shape-shadow,
.node.dragging .shape-shadow {
    transform: translate(2px, 2px);
}

.node.selected {
    outline: 3px dashed var(--accent2, #ff6b6b);
    outline-offset: 6px;
}

.node.root {
    font-size: 1.2em;
}

/* Luft per form. I em, så rotnoden får meir luft av seg sjølv. */
.node[data-shape="terminal"]    { padding: 0.65em 1.4em; }
.node[data-shape="ellipse"]     { padding: 0.9em 1.6em; min-width: 100px; }
.node[data-shape="cloud"]       { padding: 1.3em 1.8em; min-width: 120px; }
.node[data-shape="decision"]    { padding: 1.5em 2.2em; min-width: 130px; max-width: 260px; }
.node[data-shape="io"]          { padding: 0.65em 1.8em; }
.node[data-shape="subprocess"]  { padding: 0.65em 1.5em; }
.node[data-shape="document"]    { padding: 0.6em 1em 1.1em; }
.node[data-shape="database"]    { padding: 1.2em 1em 0.8em; }
.node[data-shape="preparation"] { padding: 0.65em 1.8em; }
.node[data-shape="manualInput"] { padding: 1.1em 1em 0.65em; }
.node[data-shape="delay"]       { padding: 0.65em 1.6em 0.65em 1em; }
.node[data-shape="connector"]   { padding: 0.5em; min-width: 56px; max-width: 140px; aspect-ratio: 1; border-radius: 50%; }

.node-text {
    pointer-events: none;
    display: block;
    line-height: 1.3;
}

.node-text:empty {
    display: none;
}

.node-icon {
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.7em;
    line-height: 1.1;
    font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
}

.node-icon svg {
    width: 1em;
    height: 1em;
}

.node-edit {
    width: 100%;
    min-width: 120px;
    border: none;
    background: transparent;
    color: inherit;
    font: inherit;
    font-weight: 600;
    text-align: center;
    outline: none;
}

.node-actions {
    position: absolute;
    top: -14px;
    right: -14px;
    display: none;
    gap: 4px;
}

.node.selected .node-actions {
    display: flex;
}

.node-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--surface, #ffffff);
    color: #1a1a1a;
    cursor: pointer;
    font-size: 16px;
    font-weight: 700;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    box-shadow: 2px 2px 0 var(--border);
}

.node-btn:hover {
    transform: translate(-1px, -1px);
    box-shadow: 3px 3px 0 var(--border);
}

.node-btn.add {
    background: var(--accent3, #BAFCA2);
}

.node-btn.delete {
    background: var(--accent5, #FF6B6B);
    color: #1a1a1a;
}

/* Zoom */
.zoom-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 4;
    display: flex;
    gap: 6px;
}

.zoom-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    height: 38px;
    padding: 0 8px;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    box-shadow: 2px 2px 0 var(--border);
    font: inherit;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
}

.zoom-btn:hover:not(:disabled) {
    transform: translate(-1px, -1px);
    box-shadow: 3px 3px 0 var(--border);
}

.zoom-btn:disabled {
    opacity: 0.45;
    cursor: default;
}

.zoom-level {
    min-width: 64px;
    font-variant-numeric: tabular-nums;
}

/* Hint under lerretet */
.canvas-hint {
    position: absolute;
    bottom: 8px;
    left: 8px;
    right: 8px;
    text-align: center;
    pointer-events: none;
    z-index: 3;
}

.canvas-hint p {
    display: inline-block;
    max-width: 78ch;
    background: var(--surface);
    color: var(--text);
    padding: 6px 12px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 0.85em;
    margin: 0;
    opacity: 0.85;
}

.canvas-hint kbd {
    background: var(--border);
    color: var(--surface);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.9em;
}

/* Eigenskapspanelet */
.props-panel {
    color: var(--text);
}

.props-panel .heading4 {
    margin-bottom: 8px;
}

.panel-empty {
    margin: 0;
    opacity: 0.85;
}

.color-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.color-swatch {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 3px solid var(--border);
    cursor: pointer;
    box-shadow: 3px 3px 0 var(--border);
    padding: 0;
}

.color-swatch:hover {
    transform: translate(-1px, -1px);
    box-shadow: 4px 4px 0 var(--border);
}

.color-swatch[aria-pressed="true"] {
    outline: 3px dashed var(--border);
    outline-offset: 3px;
}

.icon-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.icon-preview {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
    color: #1a1a1a;
    font-size: 28px;
    font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
}

.icon-preview svg {
    width: 28px;
    height: 28px;
}

.icon-preview.empty {
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 0.7rem;
    line-height: 1.1;
    text-align: center;
}

.panel-btn {
    padding: 6px 12px;
    font-size: 0.95rem;
    box-shadow: 3px 3px 0 var(--shadow);
}

.panel-btn:disabled {
    opacity: 0.5;
    pointer-events: none;
}

.shape-group-title {
    margin: 12px 0 6px;
    font-size: 0.8rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.shape-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
    gap: 6px;
}

.shape-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 40px;
    padding: 4px 8px 4px 4px;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.15;
    text-align: left;
    cursor: pointer;
}

.shape-btn:hover {
    transform: translate(-1px, -1px);
    box-shadow: 2px 2px 0 var(--border);
}

/* Invertert, ikkje aksentfylt — sjå AGENTS.md §3.2 om kontrast i dei mørke temaa. */
.shape-btn[aria-pressed="true"] {
    background: var(--text);
    color: var(--surface);
}

.shape-preview {
    flex: 0 0 auto;
    width: 36px;
    height: 23px;
}

.shape-preview path {
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linejoin: round;
}

.panel-help {
    margin: 0 0 12px;
    line-height: 1.4;
}

.edge-ending-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.edge-ending-btn {
    min-height: 42px;
    padding: 6px 8px;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.edge-ending-btn:hover {
    transform: translate(-1px, -1px);
    box-shadow: 2px 2px 0 var(--border);
}

.edge-ending-btn[aria-pressed="true"] {
    background: var(--text);
    color: var(--surface);
}

.edge-ending-btn:focus-visible {
    outline: 3px dashed var(--text);
    outline-offset: 2px;
}

/* Ikonveljaren */
.picker {
    max-width: 640px;
}

.picker-search {
    display: block;
    width: 100%;
    box-sizing: border-box;
    margin: 8px 0 12px;
    padding: 10px 12px;
    border: 3px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

.picker-box {
    margin-bottom: 0;
}

.picker-box .box-tabs {
    flex-wrap: wrap;
}

.picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
    gap: 6px;
    max-height: min(50vh, 360px);
    overflow-y: auto;
    padding: 4px;
}

.picker-item {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 48px;
    padding: 0;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
    color: #1a1a1a;
    font-size: 26px;
    font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
    cursor: pointer;
}

.picker-item:hover {
    transform: translate(-1px, -1px);
    box-shadow: 2px 2px 0 var(--border);
}

.picker-item[aria-pressed="true"] {
    outline: 3px dashed var(--border);
    outline-offset: 2px;
}

.picker-empty {
    grid-column: 1 / -1;
    margin: 8px 0;
    color: var(--text);
}

/* Lagra liste */
.saved-list {
    max-height: 320px;
    overflow-y: auto;
    margin-top: 8px;
}

.saved-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border: 2px solid var(--border);
    border-radius: 8px;
    margin-bottom: 8px;
    background: var(--surface, #ffffff);
    color: #1a1a1a;
}

.saved-item-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.saved-item-name {
    font-weight: 700;
}

.saved-item-meta {
    font-size: 0.85em;
    opacity: 0.7;
}

.saved-item-actions {
    display: flex;
    gap: 6px;
}

.saved-empty {
    padding: 12px;
    text-align: center;
    opacity: 0.7;
}

/* Print */
@page {
    size: A4 portrait;
    margin: 1.5cm;
}

@media print {
    neo-header,
    .hero-box,
    .toolbar,
    .props-panel,
    .zoom-controls,
    .canvas-hint,
    .node-actions {
        display: none !important;
    }

    body, .page-wrapper, .main-content {
        background: white !important;
    }

    .editor {
        display: block;
    }

    .canvas-wrapper {
        border: none;
        box-shadow: none;
        overflow: visible;
        page-break-inside: avoid;
    }

    .canvas {
        background-image: none !important;
    }

    .edges path {
        stroke: #1a1a1a;
    }

    .edges marker path {
        fill: #1a1a1a;
    }

    .shape-fill,
    .shape-detail {
        stroke: #1a1a1a;
    }

    .shape-shadow {
        fill: #1a1a1a;
        stroke: #1a1a1a;
    }

    .node {
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }

    .node.selected {
        outline: none;
    }
}
