/* Port 360: bildeeditor for skjermbilder (port360_editor.js).
   Alt er avgrenset til #p360_editor så ingenting lekker til resten av siden. */

#p360_editor {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 100000;
    display: none;
    flex-direction: column;
    background: #111827;
    color: #1f2937;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 13px;
    line-height: 1.4;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
}
#p360_editor.p360e-open {
    display: flex;
}
#p360_editor *,
#p360_editor *::before,
#p360_editor *::after {
    box-sizing: border-box;
}
#p360_editor [hidden] {
    display: none !important;
}
#p360_editor button {
    font: inherit;
    color: inherit;
    background: none;
    border: 0;
    margin: 0;
    padding: 0;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    line-height: 1;
}
#p360_editor button:disabled {
    opacity: .35;
    cursor: default;
}
#p360_editor button:focus-visible {
    outline: 2px solid #0284c7;
    outline-offset: 1px;
}
#p360_editor i {
    pointer-events: none;
}

/* ---- Ikonknapper --------------------------------------------------- */
#p360_editor .p360e-ib,
#p360_editor .p360e-tool,
#p360_editor .p360e-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    font-size: 15px;
    flex: none;
    transition: background-color .12s;
}
#p360_editor .p360e-ib:hover:not(:disabled),
#p360_editor .p360e-tool:hover,
#p360_editor .p360e-close:hover,
#p360_editor .p360e-zoom:hover {
    background: rgba(0,0,0,.05);
}
#p360_editor .p360e-tool.active {
    background: rgba(2,132,199,.12);
    color: #0284c7;
}

/* ---- Topplinje ----------------------------------------------------- */
#p360_editor .p360e-top {
    position: relative;
    z-index: 5;
    flex: none;
    display: flex;
    align-items: center;
    gap: 8px;
    height: calc(48px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) calc(12px + env(safe-area-inset-right)) 0 calc(12px + env(safe-area-inset-left));
    background: rgba(255,255,255,.96);
    box-shadow: 0 1px 2px rgba(60,64,67,.15), 0 1px 3px 1px rgba(60,64,67,.07);
}
#p360_editor .p360e-top-left {
    flex: 1;
    min-width: 0;
}
#p360_editor .p360e-title {
    display: block;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#p360_editor .p360e-top-center {
    display: flex;
    align-items: center;
    gap: 2px;
}
#p360_editor .p360e-sep {
    width: 1px;
    height: 22px;
    margin: 0 6px;
    background: rgba(0,0,0,.12);
}
#p360_editor .p360e-zoom {
    min-width: 56px;
    height: 32px;
    padding: 0 6px;
    border-radius: 8px;
    font-variant-numeric: tabular-nums;
}
#p360_editor .p360e-top-right {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}
#p360_editor .p360e-close {
    font-size: 24px;
    color: #4b5563;
}

/* Nedlasting: hovedknapp med liten meny for format. */
#p360_editor .p360e-dl {
    position: relative;
    display: flex;
    align-items: stretch;
}
#p360_editor .p360e-dl-main,
#p360_editor .p360e-dl-caret {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 36px;
    background: #0284c7;
    color: #ffffff;
    font-weight: 600;
    transition: background-color .12s;
}
#p360_editor .p360e-dl-main {
    gap: 8px;
    padding: 0 14px;
    border-radius: 10px 0 0 10px;
}
#p360_editor .p360e-dl-caret {
    width: 32px;
    border-left: 1px solid rgba(255,255,255,.35);
    border-radius: 0 10px 10px 0;
    font-size: 12px;
}
#p360_editor .p360e-dl-main:hover,
#p360_editor .p360e-dl-caret:hover {
    background: #0369a1;
}
#p360_editor .p360e-dl-menu {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 200px;
    padding: 6px;
    background: #ffffff;
    border-radius: 10px;
    box-shadow: 0 1px 2px rgba(60,64,67,.15), 0 4px 16px rgba(60,64,67,.25);
}
#p360_editor .p360e-dl-menu.open {
    display: block;
}
#p360_editor .p360e-dl-menu button {
    display: block;
    width: 100%;
    padding: 9px 10px;
    border-radius: 6px;
    text-align: left;
    white-space: nowrap;
}
#p360_editor .p360e-dl-menu button:hover {
    background: rgba(0,0,0,.05);
}

/* ---- Alternativlinje ----------------------------------------------- */
#p360_editor .p360e-options {
    position: relative;
    z-index: 4;
    flex: none;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px 16px;
    min-height: 44px;
    padding: 4px calc(12px + env(safe-area-inset-right)) 4px calc(12px + env(safe-area-inset-left));
    background: #ffffff;
    border-bottom: 1px solid rgba(0,0,0,.08);
}
#p360_editor .p360e-opt {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 34px;
}
#p360_editor .p360e-opt-label {
    color: #6b7280;
    font-size: 12px;
    white-space: nowrap;
}
#p360_editor .p360e-swatches {
    display: flex;
    gap: 4px;
}
#p360_editor .p360e-swatch {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid rgba(0,0,0,.14);
    transition: transform .1s;
}
#p360_editor .p360e-swatch:hover {
    transform: scale(1.12);
}
#p360_editor .p360e-swatch.active {
    border-color: #ffffff;
    box-shadow: 0 0 0 2px #0284c7;
}
#p360_editor .p360e-colorwrap {
    position: relative;
    display: block;
    width: 26px;
    height: 26px;
    border-radius: 8px;
    border: 2px solid rgba(0,0,0,.14);
    background: var(--p360e-swatch, #e11d48);
    overflow: hidden;
    cursor: pointer;
    flex: none;
}
#p360_editor .p360e-colorwrap::after {
    content: "";
    position: absolute;
    right: 2px;
    bottom: 2px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,.9);
    background: conic-gradient(#f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00);
}
#p360_editor .p360e-colorwrap input {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    opacity: 0;
    cursor: pointer;
}
#p360_editor .p360e-range {
    width: 110px;
    height: 24px;
    margin: 0;
    accent-color: #0284c7;
    cursor: pointer;
}
#p360_editor .p360e-val {
    min-width: 28px;
    text-align: right;
    color: #374151;
    font-variant-numeric: tabular-nums;
}
#p360_editor .p360e-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 30px;
    padding: 0 10px;
    border: 1px solid rgba(0,0,0,.14);
    border-radius: 8px;
    white-space: nowrap;
}
#p360_editor .p360e-toggle:hover {
    background: rgba(0,0,0,.05);
}
#p360_editor .p360e-toggle.active {
    background: rgba(2,132,199,.12);
    border-color: rgba(2,132,199,.45);
    color: #0284c7;
}
#p360_editor .p360e-opt[data-opt="fill"].off .p360e-colorwrap,
#p360_editor .p360e-opt[data-opt="fill"].off .p360e-range,
#p360_editor .p360e-opt[data-opt="fill"].off .p360e-val {
    opacity: .4;
}

/* ---- Hoveddel: verktøyrekke, scene og paneler ----------------------- */
#p360_editor .p360e-body {
    position: relative;
    flex: 1;
    display: flex;
    min-height: 0;
}
#p360_editor .p360e-rail {
    flex: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    width: calc(48px + env(safe-area-inset-left));
    padding: 8px 0 8px env(safe-area-inset-left);
    background: #ffffff;
    box-shadow: 1px 0 0 rgba(0,0,0,.08);
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-width: none;
}
#p360_editor .p360e-rail::-webkit-scrollbar {
    display: none;
}
#p360_editor .p360e-rail-sep {
    flex: none;
    width: 24px;
    height: 1px;
    margin: 4px 0;
    background: rgba(0,0,0,.12);
}
#p360_editor .p360e-mobile-only {
    display: none;
}
#p360_editor .p360e-main {
    position: relative;
    flex: 1;
    display: flex;
    min-width: 0;
    min-height: 0;
}
#p360_editor .p360e-stage {
    position: relative;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    background: #111827;
}
#p360_editor .p360e-canvas {
    position: absolute;
    top: 0;
    left: 0;
    display: block;
    touch-action: none;
}

/* Tekstfelt over lerretet. Innholdsboks: polstring settes fra JS. */
#p360_editor .p360e-textedit {
    position: absolute;
    z-index: 2;
    margin: 0;
    border: 1px dashed rgba(2,132,199,.9);
    outline: none;
    resize: none;
    overflow: hidden;
    white-space: pre;
    box-sizing: content-box;
    background: transparent;
    -webkit-user-select: text;
    user-select: text;
    caret-color: currentColor;
}
#p360_editor .p360e-textedit::placeholder {
    color: rgba(156,163,175,.8);
}

#p360_editor .p360e-panel {
    flex: none;
    display: flex;
    flex-direction: column;
    width: 260px;
    min-height: 0;
    background: #ffffff;
    border-left: 1px solid rgba(0,0,0,.08);
}
#p360_editor .p360e-panel-head {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 44px;
    padding: 0 6px 0 14px;
    font-weight: 600;
    border-bottom: 1px solid rgba(0,0,0,.08);
}
#p360_editor .p360e-layers {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 6px;
    -webkit-overflow-scrolling: touch;
}
#p360_editor .p360e-empty {
    margin: 12px 8px;
    color: #6b7280;
}
#p360_editor .p360e-layer {
    margin-bottom: 2px;
    padding: 2px 4px;
    border-radius: 8px;
    cursor: pointer;
}
#p360_editor .p360e-layer:hover {
    background: rgba(0,0,0,.04);
}
#p360_editor .p360e-layer.sel {
    background: rgba(2,132,199,.12);
}
#p360_editor .p360e-layer-main {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 36px;
}
#p360_editor .p360e-layer-icon {
    flex: none;
    width: 22px;
    text-align: center;
    color: #6b7280;
}
#p360_editor .p360e-layer-name {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#p360_editor .p360e-layer.off .p360e-layer-name,
#p360_editor .p360e-layer.off .p360e-layer-icon {
    opacity: .45;
}
#p360_editor .p360e-layer.locked .p360e-layer-name {
    color: #6b7280;
}
#p360_editor .p360e-layer .p360e-ib {
    width: 30px;
    height: 30px;
    font-size: 13px;
    color: #6b7280;
}
#p360_editor .p360e-layer.sel .p360e-ib {
    color: #1f2937;
}
#p360_editor .p360e-layer-actions {
    display: flex;
    gap: 2px;
    padding: 0 0 4px 26px;
}
#p360_editor .p360e-rename {
    flex: 1;
    min-width: 0;
    height: 28px;
    padding: 0 6px;
    border: 1px solid #0284c7;
    border-radius: 6px;
    font: inherit;
    color: inherit;
    background: #ffffff;
    outline: none;
    -webkit-user-select: text;
    user-select: text;
}
#p360_editor .p360e-adjust {
    padding: 14px;
    overflow-y: auto;
}
#p360_editor .p360e-adj-row {
    margin-bottom: 14px;
}
#p360_editor .p360e-adj-label {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
    color: #374151;
}
#p360_editor .p360e-adjust .p360e-range {
    display: block;
    width: 100%;
}
#p360_editor .p360e-btn {
    height: 34px;
    padding: 0 14px;
    border: 1px solid rgba(0,0,0,.14);
    border-radius: 8px;
    background: #ffffff;
}
#p360_editor .p360e-btn:hover {
    background: rgba(0,0,0,.05);
}

/* ---- Smale skjermer: verktøyrekke nederst, paneler som bunnark ------- */
@media (max-width: 899px) {
    #p360_editor .p360e-top-center {
        display: none;
    }
    #p360_editor .p360e-top {
        gap: 6px;
    }
    #p360_editor .p360e-title {
        font-size: 13px;
    }
    #p360_editor .p360e-ib,
    #p360_editor .p360e-close {
        width: 40px;
        height: 40px;
    }
    #p360_editor .p360e-dl-main,
    #p360_editor .p360e-dl-caret {
        height: 40px;
    }
    #p360_editor .p360e-options {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        gap: 4px 14px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    #p360_editor .p360e-options::-webkit-scrollbar {
        display: none;
    }
    #p360_editor .p360e-opt {
        flex: none;
        min-height: 40px;
    }
    #p360_editor .p360e-swatch {
        width: 26px;
        height: 26px;
    }
    #p360_editor .p360e-colorwrap {
        width: 30px;
        height: 30px;
    }
    #p360_editor .p360e-range {
        height: 32px;
    }
    #p360_editor .p360e-toggle {
        height: 34px;
    }
    #p360_editor .p360e-body {
        flex-direction: column-reverse;
    }
    #p360_editor .p360e-rail {
        flex-direction: row;
        justify-content: flex-start;
        width: auto;
        gap: 2px;
        padding: 6px calc(8px + env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) calc(8px + env(safe-area-inset-left));
        box-shadow: 0 -1px 0 rgba(0,0,0,.08);
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
    }
    #p360_editor .p360e-tool {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }
    #p360_editor .p360e-rail-sep {
        align-self: center;
        width: 1px;
        height: 24px;
        margin: 0 4px;
    }
    #p360_editor .p360e-mobile-only {
        display: inline-flex;
    }
    #p360_editor .p360e-panel {
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 3;
        width: auto;
        max-height: 45vh;
        border-left: 0;
        border-radius: 14px 14px 0 0;
        box-shadow: 0 -4px 20px rgba(0,0,0,.25);
    }
    #p360_editor .p360e-layer .p360e-ib {
        width: 36px;
        height: 36px;
    }
}
