/* =====================================================================
   Widget-Editor – Drag & Drop Grafik-Builder
   ===================================================================== */

/* ---- Seitenlayout ---- */
.widget-editor-page {
    position: relative;
    padding: 0 0 40px;
}

.widget-editor-page h1 {
    font-size: 1.5rem;
    color: #2a5f1e;
    margin: 0 0 6px;
}

.widget-editor-intro {
    color: #555;
    font-size: 0.9rem;
    margin: 0 0 20px;
}

/* ---- Haupt-Layout: Palette | Canvas | Properties ---- */
.we-layout {
    display: grid;
    grid-template-columns: 160px 1fr 200px;
    grid-template-rows: auto 1fr;
    gap: 12px;
    align-items: start;
}

.we-canvas-area {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;    /* Wrapper horizontal in der Spalte zentrieren */
}

/* ---- Canvas-Einstellungen (Toolbar oben) ---- */
.we-canvas-settings {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 8px 12px;
    flex-wrap: wrap;
    font-size: 0.82rem;
}

.we-canvas-settings label {
    display: flex;
    align-items: center;
    gap: 5px;
    color: #444;
    font-weight: 600;
}

.we-canvas-settings input[type="number"] {
    width: 62px;
    padding: 3px 6px;
    border: 1px solid #bbb;
    border-radius: 4px;
    font-size: 0.82rem;
}

.we-canvas-settings input[type="color"] {
    width: 36px;
    height: 26px;
    border: 1px solid #bbb;
    border-radius: 4px;
    padding: 1px;
    cursor: pointer;
}

.we-canvas-settings select {
    padding: 3px 6px;
    border: 1px solid #bbb;
    border-radius: 4px;
    font-size: 0.82rem;
}

/* ---- Wertebasis / Datenquelle ---- */
.we-datasource {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #eef3fb;
    border: 1px solid #c5d8f0;
    border-radius: 6px;
    padding: 7px 12px;
    flex-wrap: wrap;
    font-size: 0.82rem;
    margin-top: 6px;
}

.we-ds-title {
    font-weight: 700;
    color: #2c5f9e;
    white-space: nowrap;
}

.we-datasource label {
    display: flex;
    align-items: center;
    gap: 5px;
    color: #444;
    font-weight: 600;
}

.we-datasource select,
.we-datasource input[type="text"] {
    padding: 3px 6px;
    border: 1px solid #9ab5d8;
    border-radius: 4px;
    font-size: 0.82rem;
    background: #fff;
}

.we-datasource input[type="text"] {
    width: 160px;
}

.we-gebiet-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.we-ds-hint {
    font-size: 0.75rem;
    color: #5580aa;
    font-style: italic;
    margin-left: auto;
}

.we-ds-hint--live {
    color: #c0392b;
    font-style: normal;
    font-weight: 600;
}

/* ---- Canvas (Zeichenfläche) ---- */
.we-canvas-wrapper {
    position: relative;
    width: 420px;
    height: 420px;
    overflow: auto;            /* scrollbar wenn Canvas größer als der Rahmen */
    display: flex;
    justify-content: center;   /* Canvas horizontal zentrieren */
    align-items: center;       /* Canvas vertikal zentrieren */
    flex-shrink: 0;            /* Wrapper darf nicht schrumpfen */
    border: 2px solid #8bc34a;
    border-radius: 6px;        /* Startwert; wird per JS synchronisiert */
    background: #fff;
    cursor: default;
    user-select: none;
    /* Schachbrettmuster für Transparenz-Hinweis */
    background-image:
        linear-gradient(45deg, #e8e8e8 25%, transparent 25%),
        linear-gradient(-45deg, #e8e8e8 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #e8e8e8 75%),
        linear-gradient(-45deg, transparent 75%, #e8e8e8 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
}

/* Das eigentliche Canvas-Rechteck (Benutzer-Hintergrundfarbe) */
#we-canvas {
    position: relative;
    overflow: hidden;
}

/* Drag-over Highlight */
#we-canvas.we-dragover {
    outline: 3px dashed #8bc34a;
    outline-offset: -3px;
}

/* Canvas leerer Zustand */
.we-canvas-empty {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    color: rgba(0,0,0,0.18);
    font-size: 0.9rem;
    font-style: italic;
}

/* ---- Elemente auf dem Canvas ---- */
.we-element {
    position: absolute;
    cursor: move;
    border: 1px dashed transparent;
    border-radius: 2px;
    padding: 2px 4px;
    box-sizing: border-box;
    white-space: nowrap;
    line-height: 1.2;
    transition: border-color 0.1s;
}

.we-element:hover {
    border-color: rgba(139, 195, 74, 0.7);
}

.we-element.selected {
    border-color: #2a9d8f !important;
    border-style: solid;
    outline: 1px solid rgba(42, 157, 143, 0.4);
}

.we-element .we-resize-handle {
    position: absolute;
    right: -5px;
    bottom: -5px;
    width: 9px;
    height: 9px;
    background: #2a9d8f;
    border-radius: 50%;
    cursor: se-resize;
    opacity: 0;
    transition: opacity 0.15s;
}

.we-element.selected .we-resize-handle {
    opacity: 1;
}

/* Typ-Badge auf Elementen */
.we-element-badge {
    position: absolute;
    top: -16px;
    left: 0;
    background: #2a9d8f;
    color: #fff;
    font-size: 9px;
    padding: 1px 4px;
    border-radius: 3px 3px 0 0;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
}

.we-element.selected .we-element-badge,
.we-element:hover .we-element-badge {
    opacity: 1;
}

/* ---- Palette (links) ---- */
.we-palette {
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 10px;
}

.we-palette h3 {
    font-size: 0.78rem;
    text-transform: uppercase;
    color: #888;
    letter-spacing: 0.05em;
    margin: 0 0 10px;
}

.we-palette-group {
    margin-bottom: 12px;
}

.we-palette-group h4 {
    font-size: 0.72rem;
    text-transform: uppercase;
    color: #aaa;
    letter-spacing: 0.04em;
    margin: 0 0 6px;
    border-top: 1px solid #e8e8e8;
    padding-top: 8px;
}

.we-palette-group:first-child h4 {
    border-top: none;
    padding-top: 0;
}

.we-palette-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 6px 8px;
    margin-bottom: 4px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 0.8rem;
    color: #333;
    cursor: grab;
    text-align: left;
    transition: background 0.15s, border-color 0.15s;
}

.we-palette-btn:active {
    cursor: grabbing;
}

.we-palette-btn:hover {
    background: #eef7e4;
    border-color: #8bc34a;
    color: #2a5f1e;
}

.we-palette-btn .we-icon {
    font-size: 1rem;
    line-height: 1;
    flex-shrink: 0;
    width: 18px;
    text-align: center;
}

/* ---- Properties-Panel (rechts) ---- */
.we-properties {
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 12px;
    font-size: 0.82rem;
}

.we-properties h3 {
    font-size: 0.78rem;
    text-transform: uppercase;
    color: #888;
    letter-spacing: 0.05em;
    margin: 0 0 12px;
}

.we-prop-empty {
    color: #aaa;
    font-size: 0.8rem;
    font-style: italic;
    text-align: center;
    padding: 20px 0;
}

.we-prop-group {
    margin-bottom: 10px;
}

.we-prop-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: #666;
    margin-bottom: 3px;
}

.we-prop-group input[type="text"],
.we-prop-group input[type="number"],
.we-prop-group select {
    width: 100%;
    padding: 5px 7px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.82rem;
    box-sizing: border-box;
}

.we-prop-group input[type="color"] {
    width: 100%;
    height: 30px;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 2px;
    cursor: pointer;
    box-sizing: border-box;
}

.we-prop-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.we-prop-delete {
    width: 100%;
    margin-top: 12px;
    padding: 6px;
    background: #fff0f0;
    border: 1px solid #ffaaaa;
    border-radius: 4px;
    color: #cc3333;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.15s;
}

.we-prop-delete:hover {
    background: #ffdddd;
}

/* ---- Ausgabe / URL-Bereich ---- */
.we-output {
    grid-column: 1 / -1;
    background: #f0f7ea;
    border: 1px solid #c5e1a5;
    border-radius: 6px;
    padding: 14px 16px;
    margin-top: 4px;
}

.we-output h3 {
    font-size: 0.9rem;
    color: #2a5f1e;
    margin: 0 0 10px;
    font-weight: 700;
}

.we-output-btns {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.we-btn {
    padding: 8px 16px;
    border-radius: 5px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background 0.15s;
}

.we-btn--primary {
    background: #4caf50;
    color: #fff;
}

.we-btn--primary:hover {
    background: #388e3c;
}

.we-btn--secondary {
    background: #e0e0e0;
    color: #333;
    border: 1px solid #bbb;
}

.we-btn--secondary:hover {
    background: #d0d0d0;
}

.we-output-url-box {
    display: none;
    background: #fff;
    border: 1px solid #c5e1a5;
    border-radius: 5px;
    padding: 10px 12px;
    margin-top: 10px;
}

.we-output-url-box.visible {
    display: block;
}

.we-url-label {
    font-size: 0.78rem;
    font-weight: 700;
    color: #555;
    margin-bottom: 5px;
}

.we-url-row {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-bottom: 8px;
}

.we-url-input {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid #bbb;
    border-radius: 4px;
    font-size: 0.82rem;
    background: #f8f8f8;
    color: #333;
    font-family: monospace;
}

.we-url-copy {
    padding: 6px 10px;
    background: #4caf50;
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 0.78rem;
    cursor: pointer;
}

.we-url-copy:hover {
    background: #388e3c;
}

.we-embed-label {
    font-size: 0.78rem;
    font-weight: 700;
    color: #555;
    margin: 8px 0 4px;
}

.we-embed-code {
    font-family: monospace;
    font-size: 0.78rem;
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 7px 9px;
    word-break: break-all;
    color: #1565c0;
}

/* ---- SVG-Vorschau (direkt im Grid, immer sichtbar) ---- */
.we-preview-inner {
    grid-column: 1 / -1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px;
    border-radius: 6px;
    /* Schachbrettmuster – zeigt Transparenz im Widget sichtbar */
    background-color: #fff;
    background-image:
        linear-gradient(45deg, #ccc 25%, transparent 25%),
        linear-gradient(-45deg, #ccc 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #ccc 75%),
        linear-gradient(-45deg, transparent 75%, #ccc 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

.we-preview-inner svg {
    max-width: 100%;
    height: auto;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

/* ---- Hilfreich: Info-Box ---- */
.we-hint {
    background: #fff8e1;
    border-left: 3px solid #ffc107;
    border-radius: 0 4px 4px 0;
    padding: 8px 12px;
    font-size: 0.8rem;
    color: #555;
    margin-top: 12px;
}

/* ---- Verlauf (Gradient) & Rand-Seiten Controls ---- */

/* Gradient-Opts: als display:contents eingeblendet, damit die Kind-Labels
   direkt in den Flex-Flow der we-canvas-settings integriert werden */
#we-gradient-opts {
    display: none;  /* initial; JS setzt display:contents wenn aktiv */
}

/* Rand-Seiten: ebenfalls display:contents wenn sichtbar */
#we-border-sides-wrap {
    display: none;  /* initial; JS setzt display:contents wenn aktiv */
}

/* Rand-Seiten-Wrapper: horizontale Gruppe */
.we-border-sides {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.82rem;
    font-weight: 600;
    color: #444;
}

.we-border-sides > span {
    white-space: nowrap;
    margin-right: 2px;
}

/* Einzelne Checkbox-Labels für Randseiten (↑↓←→) */
.we-side-cb {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 1rem;
    cursor: pointer;
    font-weight: normal;
    background: #fff;
    border: 1px solid #bbb;
    border-radius: 4px;
    padding: 1px 5px;
    line-height: 1.4;
    transition: background 0.15s, border-color 0.15s;
}

.we-side-cb:has(input:checked) {
    background: #e8f5e9;
    border-color: #4caf50;
    color: #2a5f1e;
}

.we-side-cb input[type="checkbox"] {
    display: none;  /* nur Pfeil-Symbol sichtbar */
}

/* Verlauf-Separator: leichter visueller Trenner nach Border-Sektion */
.we-canvas-settings label:has(+ #we-gradient-opts) {
    margin-right: 4px;
}

/* Beispiel-Gruppe: Select + Laden-Button nebeneinander */
.we-example-group {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;  /* rechtsbündig in der Toolbar */
}

.we-example-group select {
    padding: 4px 6px;
    border: 1px solid #bbb;
    border-radius: 4px;
    font-size: 0.8rem;
    background: #fff;
    max-width: 180px;
}

/* ── Meine-Widgets-Verwaltungsleiste ──────────────────────────────── */
.we-mw-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    margin-bottom: 4px;
    background: #f0f4f8;
    border: 1px solid #ccd6e0;
    border-radius: 6px;
    flex-wrap: wrap;
}

.we-widget-sel {
    flex: 0 1 260px;
    min-width: 140px;
    padding: 4px 6px;
    border: 1px solid #b0bec5;
    border-radius: 4px;
    font-size: 0.8rem;
    background: #fff;
    color: #333;
}

.we-widget-name-input {
    flex: 1 1 180px;
    min-width: 120px;
    padding: 4px 8px;
    border: 1px solid #b0bec5;
    border-radius: 4px;
    font-size: 0.82rem;
    color: #333;
    background: #fff;
}

.we-widget-name-input::placeholder {
    color: #aaa;
    font-style: italic;
}

/* ── Int-Optionen: Währung + Einheit ──────────────────────────────────── */
.we-int-options {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
    flex-wrap: wrap;
}

.we-int-options label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8rem;
    color: #555;
}

.we-int-options select {
    padding: 3px 6px;
    border: 1px solid #b0bec5;
    border-radius: 4px;
    font-size: 0.8rem;
    background: #fff;
    max-width: 200px;
}

.we-int-unit-toggle {
    display: flex;
    gap: 0;
}

.we-int-unit-toggle .we-btn--unit {
    border-radius: 0;
    border-right-width: 0;
    background: #e8edf2;
    color: #444;
    border-color: #b0bec5;
    transition: background 0.15s, color 0.15s;
}

.we-int-unit-toggle .we-btn--unit:first-child {
    border-radius: 4px 0 0 4px;
}

.we-int-unit-toggle .we-btn--unit:last-child {
    border-radius: 0 4px 4px 0;
    border-right-width: 1px;
}

.we-int-unit-toggle .we-btn--unit.active {
    background: #1565c0;
    color: #fff;
    border-color: #0d47a1;
}

/* ---- Gebiet-Textzeile mit Picker-Button ---- */
.we-gebiet-text-row {
    display: flex;
    gap: 6px;
    align-items: center;
}
.we-gebiet-text-row .we-input {
    flex: 1;
    min-width: 0;
}

/* ---- Picker-Modal ---- */
.we-picker-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.we-picker-modal.open {
    display: flex;
}
.we-picker-box {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,.22);
    width: min(480px, 94vw);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.we-picker-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px 10px;
    border-bottom: 1px solid #e0e0e0;
    background: #f5f5f5;
}
.we-picker-title {
    font-weight: 600;
    font-size: 1rem;
    color: #333;
}
.we-picker-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: #888;
    line-height: 1;
    padding: 0 4px;
}
.we-picker-close:hover { color: #333; }
.we-picker-search-wrap {
    padding: 10px 14px 8px;
    border-bottom: 1px solid #e0e0e0;
}
.we-picker-search {
    width: 100%;
    box-sizing: border-box;
    padding: 7px 10px;
    border: 1px solid #bdbdbd;
    border-radius: 6px;
    font-size: 0.93rem;
}
.we-picker-search:focus {
    outline: none;
    border-color: #1565c0;
    box-shadow: 0 0 0 2px rgba(21,101,192,.18);
}
.we-picker-results {
    overflow-y: auto;
    flex: 1;
    padding: 6px 0;
}
.we-picker-hint {
    padding: 10px 16px;
    color: #888;
    font-size: 0.88rem;
    font-style: italic;
}
.we-picker-row {
    display: flex;
    align-items: baseline;
    gap: 10px;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    cursor: pointer;
    padding: 7px 18px;
    font-size: 0.93rem;
    color: #222;
    transition: background .12s;
}
.we-picker-row:hover { background: #e3f2fd; }
.we-picker-code {
    font-family: monospace;
    font-size: 0.85rem;
    color: #1565c0;
    min-width: 72px;
    flex-shrink: 0;
}
.we-picker-label {
    color: #444;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Extra-kleine Schaltfläche */
.we-btn--xs {
    padding: 4px 9px;
    font-size: 0.78rem;
    min-width: 0;
}

/* Gefahren-Schaltfläche (Löschen) */
.we-btn--danger {
    background: #e53935;
    color: #fff;
    border-color: #c62828;
}

.we-btn--danger:hover {
    background: #c62828;
    border-color: #b71c1c;
}

/* ---- Responsive ---- */
@media (max-width: 900px) {
    .we-layout {
        grid-template-columns: 1fr;
    }

    .we-palette {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
    }

    .we-palette h3 {
        width: 100%;
    }

    .we-palette-group {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        margin-bottom: 4px;
    }

    .we-palette-group h4 {
        width: 100%;
        border-top: 1px solid #e8e8e8;
    }

    .we-palette-btn {
        width: auto;
    }
}
