.bead-tool-page { background: linear-gradient(135deg, #fff9e9 0%, #fff 48%, #f6f1ff 100%); }
.app-shell { width: min(1240px, calc(100% - 32px)); margin: 0 auto; }
.workspace { display: grid; gap: 22px; }
.generator-workspace.section { padding-bottom: clamp(54px, 8vw, 84px); }

.app-shell *, .app-shell *::before, .app-shell *::after { box-sizing: border-box; }
.app-shell button, .app-shell input, .app-shell select { font: inherit; }
.app-shell h2, .app-shell h3, .app-shell h4 { margin: 0; color: var(--ink); font-family: "Arial Rounded MT Bold", "Trebuchet MS", "Segoe UI", sans-serif; line-height: 1.15; }
.app-shell h2 { font-size: 1.2rem; }
.app-shell h3 { font-size: 1.05rem; }
.app-shell h4 { font-size: .95rem; }

.controls, .pattern-card, .materials-panel { background: rgba(255,255,255,.96); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow-sm); }
.controls { display: grid; grid-template-columns: minmax(280px, 1fr) minmax(150px, 200px) minmax(180px, 230px); gap: 16px; align-items: start; padding: 20px; }
.field { display: grid; gap: 7px; align-content: start; }
.field > label, .field-label { color: var(--ink); font-weight: 900; font-size: .92rem; line-height: 1.25; min-height: 1.25em; }
.app-shell input[type="file"], .app-shell select, .app-shell input[type="search"] { width: 100%; min-height: 44px; color: var(--ink); background: #fbfaff; border: 1px solid #dcd4ef; border-radius: 12px; outline: none; }
.app-shell input[type="file"] { padding: 8px; }
.app-shell select, .app-shell input[type="search"] { padding: 0 12px; }
.app-shell input:focus, .app-shell select:focus { border-color: var(--violet); box-shadow: 0 0 0 3px rgba(111,75,216,.1); }
.hint, .status, .empty-state { margin: 0; color: var(--muted); font-size: .86rem; line-height: 1.45; }
.status { grid-column: 1 / -1; min-height: 20px; }
.status.is-error { color: #c43e48; font-weight: 800; }

.segmented-control { min-height: 44px; display: grid; grid-template-columns: 1fr 1fr; overflow: hidden; background: #fbfaff; border: 1px solid #dcd4ef; border-radius: 12px; }
.segmented-control label { position: relative; min-width: 0; display: grid; place-items: center; color: var(--muted); cursor: pointer; font-weight: 800; font-size: .9rem; }
.segmented-control label + label { border-left: 1px solid var(--line); }
.segmented-control input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.segmented-control span { position: relative; z-index: 1; width: 100%; height: 100%; display: grid; place-items: center; padding: 0 8px; text-align: center; white-space: nowrap; }
.segmented-control input:checked + span { color: #fff; background: var(--violet); }

.app-shell [hidden] { display: none !important; }
.app-shell button:not(.material-item):not(.palette-library-item):not(.bead),
.app-shell .button-link { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; padding: 0 17px; color: #fff; background: linear-gradient(135deg, var(--violet), #8450e8); border: 2px solid transparent; border-radius: 999px; box-shadow: 0 9px 22px rgba(111,75,216,.2); cursor: pointer; font-weight: 900; text-decoration: none; transition: transform .2s, box-shadow .2s, background .2s; }
.app-shell button:not(.material-item):not(.palette-library-item):not(.bead):hover:not(:disabled),
.app-shell .button-link:hover { background: var(--violet-dark); box-shadow: 0 12px 26px rgba(111,75,216,.28); transform: translateY(-1px); }
.app-shell button:not(.material-item):not(.palette-library-item):not(.bead):disabled { color: #fff; background: #b8b1c3; box-shadow: none; cursor: not-allowed; transform: none; }
.app-shell .button-outline { color: var(--violet-dark); background: #fff; border-color: var(--violet); box-shadow: none; }
.app-shell .button-outline:hover:not(:disabled) { color: #fff; background: var(--violet-dark); }
.app-shell .button-danger { color: #b53b48; background: #fff1f2; border-color: #efbbc0; box-shadow: none; }
.app-shell .button-danger:hover:not(:disabled) { color: #fff; background: #b53b48; }

.editor-layout {
    display: grid;
    grid-template-columns: max-content minmax(280px, 1fr);
    gap: 14px;
    align-items: start;
    justify-content: stretch;
}
.pattern-column {
    display: grid;
    gap: 14px;
    width: max-content;
    max-width: 100%;
    min-width: 0;
}

.edit-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    width: 100%;
    max-width: 100%;
    padding: 12px 14px;
    background: rgba(255,255,255,.96);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: var(--shadow-sm);
}
.active-edit-color { min-width: 150px; display: flex; align-items: center; gap: 10px; }
.active-edit-color small, .active-edit-color strong { display: block; }
.active-edit-color small { color: var(--muted); font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.active-edit-color strong { font-size: .92rem; overflow-wrap: anywhere; }
.active-edit-swatch { flex: 0 0 36px; width: 36px; height: 36px; border-radius: 10px; background: repeating-conic-gradient(#e9e5ed 0 25%, #fff 0 50%) 50% / 10px 10px; border: 1px solid #d5cedd; }

.edit-tools { display: flex; align-items: center; gap: 6px; }
.tool-toggle { position: relative; width: 42px; height: 42px; display: grid; place-items: center; margin: 0; color: var(--violet-dark); background: #fff; border: 1px solid #d7caee; border-radius: 11px; cursor: pointer; }
.tool-toggle input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.tool-toggle:has(input:checked) { color: #fff; background: var(--violet); border-color: var(--violet); }
.tool-icon { display: grid; place-items: center; pointer-events: none; }
.tool-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.toolbar-clear { min-height: 42px; margin-left: auto; padding: 0 14px; font-size: .88rem; }

.swap-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    max-width: 100%;
    padding: 12px 14px;
    background: #fff5e8;
    border: 1px solid #f0d3ae;
    border-radius: 14px;
}
.swap-bar[hidden] {
    display: none !important;
}
.swap-bar-text {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    color: #5c4a32;
    font-size: .9rem;
    line-height: 1.45;
}
.swap-bar-swatch {
    flex: 0 0 28px;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, .15);
}
.swap-bar .button-outline {
    flex-shrink: 0;
    min-height: 40px;
    padding: 0 14px;
    font-size: .88rem;
}

.pattern-card {
    width: max-content;
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
    padding: 16px;
}
.pattern-card-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.pattern-card-heading span { color: var(--violet); font-size: .8rem; font-weight: 900; }
.pattern-area { min-width: 0; overflow: auto; }
.pattern-grid {
    --cell-size: min(2.4vw, 22px);
    width: max-content;
    max-width: 100%;
    display: grid;
    grid-template-columns: repeat(29, var(--cell-size));
    grid-template-rows: repeat(29, var(--cell-size));
    overflow: auto;
    background: #ded9e5;
    border: 1px solid #d4cddd;
    border-radius: 0;
}
.bead { position: relative; width: var(--cell-size); height: var(--cell-size); min-height: 0 !important; overflow: hidden; padding: 0 !important; color: inherit !important; background: #fff !important; border: 1px solid rgba(58,48,74,.16) !important; border-radius: 0 !important; box-shadow: none !important; transform: none !important; }
.bead::before, .bead::after { content: ""; position: absolute; }
.bead::before { inset: 0; background: var(--bead-color); }
.bead::after { inset: 22%; border-radius: 50%; background: rgba(255,255,255,.42); box-shadow: inset 0 1px 2px rgba(0,0,0,.22); }
.pattern-grid.is-round .bead::before { inset: 10%; border-radius: 50%; box-shadow: inset 0 -2px 4px rgba(0,0,0,.18); }
.pattern-grid.is-square .bead::before { inset: 0; border-radius: 0; }
.pattern-grid.is-square .bead::after { display: none; }
.pattern-grid.is-editable .bead { cursor: pointer; }
.pattern-grid.is-editable.is-picker .bead { cursor: crosshair; }
.pattern-grid.is-editable.is-swapper .bead { cursor: crosshair; }
.pattern-grid.is-editable .bead:hover { z-index: 1; outline: 2px solid var(--coral); outline-offset: -2px; }
.bead.is-swap-source { z-index: 1; outline: 2px solid var(--coral); outline-offset: -2px; }
.bead.is-empty::before, .bead.is-empty::after { display: none; }

/* Sidebar – 1:1 an Admin-Werkstatt (ohne Motiv-Miniatur) */
.app-shell .materials-panel {
    width: 100%;
    min-width: 0;
    padding: 18px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: var(--shadow-sm);
    display: grid;
    gap: 0;
    align-content: start;
    max-height: calc(100vh - 120px);
    overflow: auto;
}
.app-shell .materials-download {
    padding-bottom: 16px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: center;
}
.app-shell .materials-download button:not(.material-item):not(.palette-library-item):not(.bead) {
    width: 60%;
    max-width: 100%;
    gap: 8px;
}
.app-shell .materials-download .button-icon {
    display: inline-flex;
    flex-shrink: 0;
}
.app-shell .materials-download .button-icon svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.app-shell .materials-title {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: baseline;
    margin-bottom: 12px;
}
.app-shell .materials-title h3 {
    margin: 0;
    font-size: 18px;
    color: var(--ink);
}
.app-shell .materials-title strong {
    color: var(--violet);
    font-size: 13px;
    white-space: nowrap;
}
.app-shell .material-list {
    display: grid;
    gap: 8px;
    max-height: 240px;
    overflow-y: auto;
    padding-right: 4px;
}
.app-shell button.material-item {
    all: unset;
    box-sizing: border-box;
    width: 100%;
    display: grid;
    grid-template-columns: 17px minmax(0, 1fr) auto;
    gap: 9px;
    align-items: center;
    padding: 6px;
    color: var(--ink);
    text-align: left;
    font-size: 14px;
    line-height: 1.35;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 9px;
    cursor: pointer;
}
.app-shell button.material-item:hover {
    background: rgba(112, 71, 235, .07);
}
.app-shell button.material-item.is-active {
    background: #eee7ff;
    border-color: #bfa9eb;
}
.app-shell button.material-item.is-swap-source-row {
    background: #fff5e8;
    border-color: #f0c88a;
}
.app-shell button.material-item strong {
    font-weight: 700;
}
.app-shell .material-swatch {
    width: 17px;
    height: 17px;
    border-radius: 5px;
    border: 1px solid rgba(0, 0, 0, .13);
    flex-shrink: 0;
}
.app-shell .material-code {
    color: var(--muted);
    font-size: 14px;
}

.app-shell .palette-library-panel {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
    display: grid;
    gap: 0;
    min-height: 0;
}
.app-shell .palette-library-panel h4 {
    margin: 0 0 4px;
    font-size: 15px;
    color: var(--ink);
}
.app-shell .palette-library-panel p {
    margin: 0 0 10px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.4;
}
.app-shell .palette-library-panel input[type="search"] {
    width: 100%;
    min-height: 40px;
    margin: 0;
    padding: 0 11px;
    color: var(--ink);
    background: #fff;
    border: 1px solid #ddd2bd;
    border-radius: 10px;
    outline: none;
    font-size: 14px;
}
.app-shell .palette-library-panel input[type="search"]:focus {
    border-color: var(--violet);
    box-shadow: 0 0 0 3px rgba(112, 71, 235, .12);
}
.app-shell .palette-library {
    max-height: 280px;
    margin-top: 10px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    overflow-y: auto;
    padding-right: 4px;
}
.app-shell button.palette-library-item {
    all: unset;
    box-sizing: border-box;
    min-width: 0;
    min-height: 36px;
    display: grid;
    grid-template-columns: 18px minmax(0, 1fr);
    align-items: center;
    gap: 7px;
    padding: 7px;
    color: var(--ink);
    background: #fff;
    border: 1px solid #e2dac2;
    border-radius: 9px;
    text-align: left;
    font-size: 12px;
    line-height: 1.3;
    cursor: pointer;
}
.app-shell button.palette-library-item span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.app-shell button.palette-library-item strong {
    font-weight: 700;
}
.app-shell button.palette-library-item:hover {
    border-color: #bfa9eb;
    background: #f7f3ff;
}
.app-shell button.palette-library-item.is-active {
    color: var(--violet-dark);
    border-color: var(--violet);
    background: #eee7ff;
}

.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; overflow: hidden !important; clip: rect(0,0,0,0) !important; white-space: nowrap !important; clip-path: inset(50%) !important; }

@media (max-width: 980px) {
    .editor-layout { grid-template-columns: 1fr; }
    .pattern-column,
    .pattern-card { width: 100%; max-width: 100%; }
    .pattern-grid { margin-inline: auto; }
    .app-shell .materials-panel { max-height: none; }
    .app-shell .material-list { max-height: 180px; }
    .app-shell .palette-library { max-height: 240px; }
    .toolbar-clear { margin-left: 0; width: 100%; }
}

@media (max-width: 760px) {
    .controls { grid-template-columns: 1fr; }
    .edit-toolbar { gap: 10px; }
    .active-edit-color { min-width: 100%; }
    .edit-tools { flex-wrap: wrap; }
    .swap-bar { flex-direction: column; align-items: stretch; }
    .swap-bar .button-outline { width: 100%; min-height: 44px; }
    .pattern-grid { --cell-size: min(calc((100vw - 72px) / 29), 20px); }
}

@media (max-width: 520px) {
    .app-shell { width: min(100% - 18px, 1240px); }
    .controls, .pattern-card, .edit-toolbar { padding: 13px; border-radius: 16px; }
    .app-shell .materials-panel { padding: 14px; border-radius: 16px; }
    .pattern-grid { --cell-size: calc((100vw - 50px) / 29); }
    .app-shell .palette-library { grid-template-columns: 1fr; max-height: 220px; }
}
