:root {
    --ss-black: #1c1c14;
    --ss-yellow: #f6c404;
    --ss-white: #ffffff;
    --ss-yellow-light: #fef9e7;
    --ss-yellow-dark: #d4a803;
    --ss-gray-light: #f5f5f3;
    --ss-gray: #888;
    --ss-gray-dark: #444;
    --ss-border: #e8e8e4;
    --ss-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    --ss-radius: 16px;
}

.so-app {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1rem;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--ss-black);
}

/* ── Header ──────────────────────── */
.so-header {
    text-align: center;
    padding: 1.5rem 1rem;
    background: var(--ss-white);
    border-radius: var(--ss-radius);
    margin-bottom: 1rem;
    border: 2px solid var(--ss-border);
    border-top: 4px solid var(--ss-yellow);
    box-shadow: var(--ss-shadow);
}

.so-header h2 {
    font-size: 1.5rem;
    margin: 0 0 0.5rem 0;
    color: var(--ss-black);
}

.so-header p {
    color: var(--ss-gray);
    font-size: 0.9rem;
    margin: 0;
}

/* ── Info-felt ───────────────────── */
.so-info-bar {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.so-field {
    flex: 1;
    min-width: 200px;
}

.so-field-small {
    flex: 0 0 200px;
    min-width: 150px;
}

.so-info-bar label,
.so-merknader-wrap label {
    display: block;
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 4px;
    color: var(--ss-gray-dark);
}

.so-info-bar input,
.so-merknader-wrap textarea {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: 2px solid var(--ss-border);
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.so-info-bar input:focus,
.so-merknader-wrap textarea:focus {
    outline: none;
    border-color: var(--ss-yellow);
}

.so-merknader-wrap {
    margin-top: 1rem;
    max-width: 100%;
}

.so-merknader-wrap textarea {
    resize: vertical;
    min-height: 60px;
}

/* ── Tooltip ─────────────────────── */
.so-tooltip {
    background: var(--ss-yellow-light);
    border: 1px solid var(--ss-border);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    font-size: 0.8rem;
    color: var(--ss-gray-dark);
    margin-bottom: 1rem;
    text-align: center;
}

/* ── Hovedlayout ─────────────────── */
.so-main {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}

/* ── Verktøylinje ────────────────── */
.so-toolbar {
    width: 180px;
    flex-shrink: 0;
    background: var(--ss-white);
    border-radius: var(--ss-radius);
    padding: 1rem;
    border: 2px solid var(--ss-border);
    position: sticky;
    top: 1rem;
    box-shadow: var(--ss-shadow);
}

.so-toolbar h3 {
    font-size: 0.8rem;
    color: var(--ss-gray);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0 0 0.75rem 0;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--ss-yellow);
}

.so-tool {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.6rem;
    margin-bottom: 0.3rem;
    border-radius: 8px;
    cursor: grab;
    font-size: 0.8rem;
    font-weight: 500;
    transition: all 0.15s;
    border: 2px solid transparent;
    user-select: none;
    -webkit-user-select: none;
}

.so-tool:hover {
    background: var(--ss-yellow-light);
    border-color: var(--ss-yellow);
}

.so-tool:active {
    cursor: grabbing;
}

.so-tool-icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.so-tool-icon svg {
    width: 100%;
    height: 100%;
}

.so-tool-sep {
    height: 1px;
    background: var(--ss-border);
    margin: 0.5rem 0;
}

/* ── Scene-canvas ────────────────── */
.so-canvas-wrap {
    flex: 1;
    background: var(--ss-white);
    border-radius: var(--ss-radius);
    border: 2px solid var(--ss-border);
    overflow: hidden;
    box-shadow: var(--ss-shadow);
}

.so-scene-header {
    padding: 0.5rem 1rem;
    background: var(--ss-yellow-light);
    border-bottom: 1px solid var(--ss-border);
    font-size: 0.8rem;
    color: var(--ss-gray);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.so-canvas-container {
    position: relative;
    width: 100%;
    padding-bottom: 70%;
    background: var(--ss-white);
    overflow: hidden;
}

.so-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.so-scenekant {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 40px;
    background: var(--ss-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: #666;
    letter-spacing: 0.05em;
    z-index: 5;
}

.so-dirigent-area {
    position: absolute;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    width: 100px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    color: #aaa;
    border-top: 2px dashed #ddd;
    z-index: 5;
    pointer-events: none;
}

.so-grid {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 40px;
    background-image: radial-gradient(circle, #e8e8e4 1px, transparent 1px);
    background-size: 30px 30px;
    pointer-events: none;
    z-index: 1;
    opacity: 0.4;
}

/* ── Plasserte elementer ─────────── */
.so-placed-item {
    position: absolute;
    z-index: 10;
    cursor: move;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
    transition: box-shadow 0.15s;
}

.so-placed-item:hover {
    z-index: 20;
}

.so-placed-item.so-dragging {
    opacity: 0.8;
    z-index: 100;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.so-placed-item .so-item-label {
    font-size: 0.55rem;
    color: #999;
    margin-top: 1px;
    white-space: nowrap;
    pointer-events: none;
}

.so-placed-item .so-delete-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 18px;
    height: 18px;
    background: #dc3232;
    color: #fff;
    border: 2px solid #fff;
    border-radius: 50%;
    font-size: 10px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    line-height: 1;
    z-index: 30;
    padding: 0;
    font-family: inherit;
}

.so-placed-item:hover .so-delete-btn {
    display: flex;
}

.so-item-shape {
    display: flex;
    align-items: center;
    justify-content: center;
}

.so-item-shape svg {
    width: 100%;
    height: 100%;
}

/* Elementstørrelser */
.so-placed-item[data-type="stol"] .so-item-shape,
.so-placed-item[data-type="stol-stativ"] .so-item-shape {
    width: 22px;
    height: 22px;
}

.so-placed-item[data-type="dirigentstativ"] .so-item-shape,
.so-placed-item[data-type="soliststativ"] .so-item-shape {
    width: 26px;
    height: 26px;
}

.so-placed-item[data-type="trommesett"] .so-item-shape {
    width: 52px;
    height: 40px;
}

.so-placed-item[data-type="pauker"] .so-item-shape {
    width: 48px;
    height: 36px;
}

.so-placed-item[data-type="xylofon"] .so-item-shape,
.so-placed-item[data-type="klokkespill"] .so-item-shape,
.so-placed-item[data-type="stikkebrett"] .so-item-shape {
    width: 50px;
    height: 30px;
}

.so-placed-item[data-type="konsertstortromme"] .so-item-shape {
    width: 48px;
    height: 42px;
}

/* ── Tellere ─────────────────────── */
.so-counts {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    padding: 0.75rem 1rem;
    background: var(--ss-yellow-light);
    font-size: 0.8rem;
    border-top: 1px solid var(--ss-border);
}

.so-count-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.so-count-num {
    font-weight: 700;
    color: var(--ss-black);
}

.so-count-label {
    color: var(--ss-gray);
}

/* ── Knapper ─────────────────────── */
.so-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
    justify-content: center;
}

.so-btn {
    padding: 0.7rem 1.5rem;
    border: 2px solid var(--ss-border);
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
    background: var(--ss-white);
    color: var(--ss-black);
}

.so-btn:hover {
    border-color: var(--ss-yellow);
    background: var(--ss-yellow-light);
}

.so-btn-primary {
    background: var(--ss-yellow);
    border-color: var(--ss-yellow-dark);
    color: var(--ss-black);
}

.so-btn-primary:hover {
    background: var(--ss-yellow-dark);
}

.so-btn-danger {
    color: #dc3232;
    border-color: #dc3232;
}

.so-btn-danger:hover {
    background: #dc3232;
    color: #fff;
}

.so-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ── Meldinger ───────────────────── */
.so-success-msg {
    display: none;
    background: #d4edda;
    color: #155724;
    padding: 1rem 1.5rem;
    border-radius: 10px;
    text-align: center;
    margin-top: 1rem;
    font-weight: 600;
    border: 1px solid #c3e6cb;
}

.so-error-msg {
    display: none;
    background: #f8d7da;
    color: #721c24;
    padding: 1rem 1.5rem;
    border-radius: 10px;
    text-align: center;
    margin-top: 1rem;
    font-weight: 600;
    border: 1px solid #f5c6cb;
}

/* ── Responsiv ───────────────────── */
@media (max-width: 768px) {
    .so-main {
        flex-direction: column;
    }

    .so-toolbar {
        width: 100%;
        position: static;
        display: flex;
        flex-wrap: wrap;
        gap: 0.3rem;
        padding: 0.75rem;
    }

    .so-toolbar h3 {
        width: 100%;
        margin-top: 0.5rem;
    }

    .so-toolbar h3:first-child {
        margin-top: 0;
    }

    .so-tool {
        flex: 0 0 auto;
        padding: 0.4rem 0.5rem;
        font-size: 0.75rem;
    }

    .so-tool-icon {
        width: 22px;
        height: 22px;
    }

    .so-tool-sep {
        display: none;
    }

    .so-canvas-container {
        padding-bottom: 85%;
    }

    .so-info-bar .so-field {
        min-width: 100%;
    }

    .so-field-small {
        flex: 1;
        min-width: 100%;
    }
}

@media (max-width: 480px) {
    .so-canvas-container {
        padding-bottom: 100%;
    }

    .so-placed-item .so-item-label {
        display: none;
    }

    .so-actions {
        flex-direction: column;
    }

    .so-btn {
        width: 100%;
    }
}

/* ══════════════════════════════════════
   CODA-INTEGRASJON STILER
   ══════════════════════════════════════ */

/* Coda-banner øverst */
.so-coda-banner {
    background: linear-gradient(135deg, #e8f4fd 0%, #d1ecf1 100%);
    border: 1px solid #bee5eb;
    border-left: 4px solid #17a2b8;
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 0.95em;
    color: #0c5460;
}

.so-coda-banner strong {
    color: #0a4a54;
}

.so-coda-banner small {
    color: #5a8a93;
}

/* Låst felt (readonly) */
input.so-readonly {
    background-color: #f0f0f0 !important;
    border-color: #ccc !important;
    color: #555 !important;
    cursor: not-allowed;
    font-weight: 600;
}
/* ============================================
   EGENDEFINERTE ELEMENTER
   ============================================ */

.so-custom-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.so-custom-header h3 {
    margin: 0;
}

.so-btn-add-custom {
    background: #4CAF50;
    color: white;
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.so-btn-add-custom:hover {
    background: #45a049;
}

#soCustomElementsContainer {
    min-height: 40px;
}

.so-custom-empty {
    color: #999;
    font-size: 13px;
    font-style: italic;
    margin: 8px 0;
}

.so-tool.custom-element {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    position: relative;
}

.so-tool.custom-element .so-remove-custom {
    position: absolute;
    top: 2px;
    right: 2px;
    background: rgba(255,255,255,0.9);
    color: #d63638;
    border: none;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    display: none;
}

.so-tool.custom-element:hover .so-remove-custom {
    display: block;
}

/* ============================================
   MODAL FOR EGENDEFINERT ELEMENT
   ============================================ */

.so-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    z-index: 10000;
    align-items: center;
    justify-content: center;
}

.so-modal.active {
    display: flex;
}

.so-modal-content {
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.so-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #e0e0e0;
}

.so-modal-header h3 {
    margin: 0;
    font-size: 18px;
}

.so-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: #666;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
}

.so-modal-close:hover {
    background: #f0f0f0;
}

.so-modal-body {
    padding: 20px;
}

.so-modal-footer {
    padding: 16px 20px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* ============================================
   CUSTOM FORM
   ============================================ */

.so-custom-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.so-form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.so-form-group label {
    font-weight: 600;
    font-size: 14px;
    color: #333;
}

.so-form-group input[type="text"] {
    padding: 10px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 15px;
    transition: border-color 0.2s;
}

.so-form-group input[type="text"]:focus {
    outline: none;
    border-color: #667eea;
}

.so-shape-options {
    display: flex;
    gap: 12px;
}

.so-shape-option {
    flex: 1;
    cursor: pointer;
}

.so-shape-option input[type="radio"] {
    display: none;
}

.so-shape-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    transition: all 0.2s;
}

.so-shape-option input[type="radio"]:checked + .so-shape-preview {
    border-color: #667eea;
    background: #f0f4ff;
}

.so-shape-preview:hover {
    border-color: #999;
}

.so-shape-preview span {
    font-size: 13px;
    color: #666;
    font-weight: 500;
}

.so-custom-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 20px;
    background: #f9f9f9;
    border-radius: 8px;
    border: 2px dashed #ddd;
}

.so-custom-preview-icon svg {
    display: block;
}

.so-custom-preview-label {
    font-size: 13px;
    color: #666;
    font-weight: 500;
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 600px) {
    .so-shape-options {
        flex-direction: column;
    }
}

/* ============================================
   SCROLLBAR PÅ VERKTØYLINJE - ULTRA FIX
   ============================================ */

/* Fjern all konflikterende styling */
@media (min-width: 769px) {
    body .so-app .so-main .so-toolbar,
    body .so-app .so-main #soToolbar,
    .so-app .so-main .so-toolbar,
    .so-app .so-main #soToolbar,
    #soToolbar {
        position: relative !important;
        top: auto !important;
        max-height: 600px !important;
        min-height: 400px !important;
        overflow-y: scroll !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
    }

    /* ALWAYS show scrollbar (Chrome/Safari) */
    body .so-app .so-main .so-toolbar::-webkit-scrollbar,
    body .so-app .so-main #soToolbar::-webkit-scrollbar,
    #soToolbar::-webkit-scrollbar {
        width: 12px !important;
        -webkit-appearance: none !important;
        display: block !important;
    }

    body .so-app .so-main .so-toolbar::-webkit-scrollbar-track,
    body .so-app .so-main #soToolbar::-webkit-scrollbar-track,
    #soToolbar::-webkit-scrollbar-track {
        background: #e8e8e4 !important;
        border-radius: 6px !important;
    }

    body .so-app .so-main .so-toolbar::-webkit-scrollbar-thumb,
    body .so-app .so-main #soToolbar::-webkit-scrollbar-thumb,
    #soToolbar::-webkit-scrollbar-thumb {
        background: #666 !important;
        border-radius: 6px !important;
        border: 2px solid #e8e8e4 !important;
    }

    body .so-app .so-main .so-toolbar::-webkit-scrollbar-thumb:hover,
    body .so-app .so-main #soToolbar::-webkit-scrollbar-thumb:hover,
    #soToolbar::-webkit-scrollbar-thumb:hover {
        background: #333 !important;
    }

    /* Firefox - ALWAYS show scrollbar */
    body .so-app .so-main .so-toolbar,
    body .so-app .so-main #soToolbar,
    #soToolbar {
        scrollbar-width: auto !important;
        scrollbar-color: #666 #e8e8e4 !important;
    }
}

/* Mobil */
@media (max-width: 768px) {
    .so-toolbar,
    #soToolbar {
        max-height: 300px !important;
        overflow-y: scroll !important;
    }
}
/* ============================================
   CUSTOM ELEMENTS STØRRELSE PÅ CANVAS
   ============================================ */

.so-placed-item[data-type^="custom_"] .so-item-shape {
    width: 50px;
    height: 50px;
}

.so-placed-item[data-type^="custom_"] .so-item-shape svg {
    max-width: 48px;
    max-height: 48px;
}