/*
 * BrawlTier Studio — distribución profesional del Diseñador de Pins.
 * Inspiración: editores de escritorio con dockers (p. ej. Krita), sin copiar
 * sus elementos de marca ni cambiar la lógica del editor.
 * Se carga al final para conservar todos los identificadores y eventos actuales.
 */

/* En modo creador, el área de trabajo utiliza la ventana completa. */
main:has(#creator-view:not(.hidden)) {
    max-width: none !important;
    width: 100% !important;
    height: 100vh;
    min-height: 0;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden;
    box-sizing: border-box;
}

body:has(#creator-view:not(.hidden)) {
    overflow: hidden;
    background: #202124;
}

#creator-view {
    --studio-surface: #292c31;
    --studio-panel: #30343a;
    --studio-panel-raised: #373b42;
    --studio-line: #454a52;
    --studio-text: #e6e8eb;
    --studio-muted: #a8afb8;
    --studio-accent: #5b9bea;
    width: 100%;
    max-width: none;
    height: 100vh;
    min-height: 0;
    max-height: 100vh;
    margin: 0;
    padding: 8px 10px 10px;
    display: flex;
    flex-direction: column;
    gap: 0;
    overflow: hidden;
    color: var(--studio-text);
    background: #25282d;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    box-sizing: border-box;
    font-size: 13px;
}

#creator-view *,
#creator-view *::before,
#creator-view *::after {
    box-sizing: border-box;
}

/* Encabezado de documento: acción de regreso, nombre y exportaciones. */
#creator-view .creator-header {
    flex: 0 0 auto;
    min-height: 54px;
    display: grid;
    grid-template-columns: minmax(160px, 1fr) minmax(170px, auto) minmax(180px, 1fr);
    align-items: center;
    gap: 12px;
    margin: 0;
    padding: 0 4px 8px;
    background: #25282d;
    border: 0;
    border-bottom: 1px solid #41454c;
    border-radius: 0;
}

#creator-view .creator-header > #closeCreatorBtn {
    justify-self: start;
    white-space: nowrap;
    min-height: 34px;
    padding: 7px 11px;
    color: #e8eaed;
    background: #3a3e45;
    border: 1px solid #535861;
    border-radius: 5px;
    box-shadow: none;
}

#creator-view .creator-header h2 {
    justify-self: center;
    margin: 0;
    padding: 0 8px;
    color: #f0f1f3;
    font-size: 18px;
    font-weight: 650;
    letter-spacing: .15px;
    white-space: nowrap;
}

#creator-view .creator-header-actions {
    justify-self: end;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 7px;
    min-width: 0;
}

#creator-view .creator-header-actions .menu-art-button > img {
    height: 38px;
    max-width: 132px;
}

/* Cuatro zonas de un editor de escritorio:
   categorías/herramientas | recursos | lienzo | capas e inspector. */
#creator-view .creator-workspace {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    height: auto;
    width: 100%;
    display: grid;
    grid-template-columns: 48px minmax(205px, clamp(220px, 19vw, 300px)) minmax(320px, 1fr) minmax(245px, clamp(255px, 20vw, 330px));
    grid-template-rows: auto minmax(0, 1fr) minmax(170px, 215px);
    grid-template-areas:
        "categories assets toolbar layers"
        "categories assets canvas layers"
        "categories assets canvas properties";
    align-items: stretch;
    gap: 8px;
    padding-top: 9px;
    overflow: hidden;
}

/* Los paneles son envoltorios semánticos; los docks se distribuyen en la rejilla. */
#creator-view .creator-left-panel,
#creator-view .creator-right-panel {
    display: contents;
}

/* Caja de herramientas estrecha como la barra vertical de un editor gráfico. */
#creator-view .gacha-tabs-bar {
    grid-area: categories;
    display: flex;
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-start;
    gap: 5px;
    width: 100%;
    min-width: 0;
    max-height: none;
    height: 100%;
    padding: 6px 4px;
    overflow-x: hidden;
    overflow-y: auto;
    background: #2b2e33;
    border: 1px solid #41454b;
    border-radius: 5px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.025);
    scrollbar-width: thin;
    scrollbar-color: #59616b #2b2e33;
}

#creator-view .gacha-tab-btn {
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    min-width: 40px;
    padding: 0;
    color: #d9dde2;
    background: #34383e;
    border: 1px solid #4b5058;
    border-radius: 5px;
    font-size: 19px;
    box-shadow: none;
    transform: none;
}

#creator-view .gacha-tab-btn:hover {
    background: #41464e;
    border-color: #707984;
    transform: none;
}

#creator-view .gacha-tab-btn.active {
    color: #fff;
    background: #3b5f88;
    border-color: #7eb6f4;
    box-shadow: inset 0 0 0 1px rgba(126,182,244,.15);
}

/* Navegador de recursos: las miniaturas pueden desplazarse sin mover el editor. */
#creator-view .gacha-options-container {
    grid-area: assets;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: 100%;
    padding: 10px;
    margin: 0;
    overflow: hidden;
    background: var(--studio-surface);
    border: 1px solid var(--studio-line);
    border-radius: 5px;
    box-shadow: none;
}

#creator-view .options-header-row {
    flex: 0 0 auto;
    gap: 8px;
    min-height: 34px;
    padding: 0 0 9px;
    margin: 0 0 8px;
    border-bottom: 1px solid #454950;
}

#creator-view .options-header-row h3 {
    margin: 0;
    color: #e5e8ec;
    font-size: 13px;
    font-weight: 650;
}

#creator-view .options-header-row .btn {
    min-height: 29px;
    padding: 5px 8px;
    color: #dfe3e8;
    background: #3a3e45;
    border: 1px solid #555b64;
    border-radius: 4px;
    font-size: 11px;
    box-shadow: none;
}

#creator-view .gacha-grid {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    align-content: start;
    gap: 6px;
    margin: 0;
    padding: 1px 4px 4px 0;
    overflow: auto;
    scrollbar-width: thin;
    scrollbar-color: #59616b #2b2e33;
}

#creator-view .gacha-item-card {
    height: clamp(62px, 8.5vh, 94px);
    min-height: 58px;
    padding: 5px;
    background: #22252a;
    border: 1px solid #454a52;
    border-radius: 4px;
    box-shadow: none;
    transition: border-color .12s ease, background .12s ease;
}

#creator-view .gacha-item-card:hover {
    background: #303640;
    border-color: #79aee9;
    transform: none;
}

#creator-view .gacha-item-card img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Barra de herramientas de edición, alineada sobre el área de trabajo. */
#creator-view .pin-editor-toolbar {
    grid-area: toolbar;
    align-self: stretch;
    display: flex;
    align-items: center;
    align-content: center;
    flex-wrap: wrap;
    gap: 5px;
    min-width: 0;
    margin: 0;
    padding: 6px 8px;
    background: #2d3035;
    border: 1px solid #454a52;
    border-radius: 5px;
    box-shadow: none;
}

#creator-view .pin-editor-toolbar .btn {
    min-height: 29px;
    padding: 5px 8px;
    color: #e4e7eb;
    background: #3b3f46;
    border: 1px solid #575d66;
    border-radius: 4px;
    box-shadow: none;
    font-size: 11px;
    line-height: 1.2;
    white-space: nowrap;
}

#creator-view .pin-editor-toolbar .btn:hover:not(:disabled) {
    background: #484e57;
    border-color: #737b86;
    transform: none;
}

#creator-view .pin-editor-toolbar .btn:disabled {
    color: #7b828b;
    background: #303339;
    border-color: #42464c;
    opacity: .7;
}

#creator-view .pin-editor-toolbar select {
    width: 75px;
    min-height: 29px;
    padding: 5px;
    color: #e7e9ec;
    background: #202328;
    border: 1px solid #575d66;
    border-radius: 4px;
    font-size: 11px;
}

#creator-view .pin-toolbar-separator {
    height: 22px;
    background: #555a62;
    margin: 0 2px;
}

#creator-view .pin-editor-status {
    margin-left: auto;
    color: #aeb5be;
    font-size: 10px;
    white-space: nowrap;
}

#creator-view .pin-editor-toolbar .pin-tool-select.active {
    color: #fff;
    background: #3d6087;
    border-color: #91bff0;
    box-shadow: inset 0 0 0 1px rgba(145,191,240,.15);
}

/* Área gris de navegación como un editor de escritorio; el tablero de transparencia
   está solo debajo del lienzo, no en todo el espacio de trabajo. */
#creator-view .canvas-container {
    grid-area: canvas;
    position: relative;
    display: flex;
    flex-direction: row;
    justify-content: center;
    justify-content: safe center;
    align-items: center;
    align-items: safe center;
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 24px;
    overflow: auto;
    overscroll-behavior: contain;
    background: #474a4f;
    background-image: none;
    border: 1px solid #17191d;
    border-radius: 4px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.04);
    scrollbar-width: thin;
    scrollbar-color: #707782 #373a3f;
}

#creator-view .canvas-container::before {
    content: "ÁREA DE TRABAJO";
    position: absolute;
    top: 8px;
    left: 12px;
    z-index: 0;
    color: rgba(238,241,244,.46);
    font-size: 9px;
    font-weight: 650;
    letter-spacing: .11em;
    pointer-events: none;
}

#creator-view #pinCanvas {
    display: block;
    flex: 0 0 auto;
    max-width: none;
    height: auto;
    margin: auto;
    border: 1px solid #17191d;
    border-radius: 1px;
    background-color: #d1d4d9;
    background-image:
        linear-gradient(45deg, #adb3bb 25%, transparent 25%, transparent 75%, #adb3bb 75%, #adb3bb),
        linear-gradient(45deg, #adb3bb 25%, transparent 25%, transparent 75%, #adb3bb 75%, #adb3bb);
    background-position: 0 0, 9px 9px;
    background-size: 18px 18px;
    box-shadow: 0 5px 16px rgba(0,0,0,.36), 0 0 0 1px rgba(255,255,255,.06);
    touch-action: none;
    user-select: none;
    -webkit-user-drag: none;
}

/* Capas a la derecha; listado expansible y controles anclados al fondo. */
#creator-view .layers-manager-container {
    grid-area: layers;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: 100%;
    max-height: none;
    margin: 0;
    padding: 10px;
    overflow: hidden;
    background: var(--studio-surface);
    border: 1px solid var(--studio-line);
    border-radius: 5px;
    box-shadow: none;
}

#creator-view .layers-manager-container h3 {
    flex: 0 0 auto;
    margin: 0 0 8px;
    padding: 0 0 8px;
    color: #e5e8ec;
    font-size: 13px;
    border-bottom: 1px solid #454950;
}

#creator-view .layers-list {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    margin: 0 0 8px;
    padding: 1px 3px 3px 0;
    overflow: auto;
    scrollbar-width: thin;
    scrollbar-color: #59616b #2b2e33;
}

#creator-view .layer-item {
    min-height: 43px;
    padding: 6px 8px;
    background: #26292e;
    border: 1px solid #454a52;
    border-radius: 4px;
}

#creator-view .layer-item.selected {
    background: #35465a;
    border-color: #80b4ef;
    box-shadow: inset 0 0 0 1px rgba(128,180,239,.14);
}

#creator-view .layer-actions-bar {
    flex: 0 0 auto;
    display: flex;
    gap: 6px;
    margin-top: 0;
}

#creator-view .layer-actions-bar .btn,
#creator-view .element-properties-box .btn {
    min-height: 29px;
    padding: 5px 8px;
    color: #e3e6ea;
    background: #3b3f46;
    border: 1px solid #555b64;
    border-radius: 4px;
    box-shadow: none;
    font-size: 11px;
}

#creator-view .layer-actions-bar .btn:hover,
#creator-view .element-properties-box .btn:hover {
    background: #494e56;
    transform: none;
}

/* Inspector de propiedades: dock compacto debajo del panel de capas. */
#creator-view .element-properties-box {
    grid-area: properties;
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: 100%;
    max-height: none;
    margin: 0;
    padding: 10px;
    gap: 8px;
    overflow: auto;
    background: var(--studio-surface);
    border: 1px solid var(--studio-line);
    border-radius: 5px;
    box-shadow: none;
    scrollbar-width: thin;
    scrollbar-color: #59616b #2b2e33;
}

#creator-view .element-properties-box h4 {
    margin: 0;
    padding: 0 0 7px;
    color: #e5e8ec;
    font-size: 13px;
    border-bottom: 1px solid #454950;
}

#creator-view .prop-row {
    gap: 7px;
    align-items: stretch;
}

#creator-view .prop-row label {
    min-width: 0;
    color: #bfc5cd;
    font-size: 11px;
    gap: 4px;
}

#creator-view .prop-row input[type="number"] {
    min-width: 0;
    min-height: 29px;
    padding: 5px 7px;
    color: #edf0f3;
    background: #202328;
    border: 1px solid #50565f;
    border-radius: 4px;
    font-size: 11px;
}

#creator-view .prop-row input[type="color"] {
    min-height: 29px;
    height: 29px;
    padding: 2px;
    background: #202328;
    border: 1px solid #50565f;
    border-radius: 4px;
}

#creator-view .prop-row .prop-check {
    flex-direction: row;
    align-items: center;
    gap: 6px;
    line-height: 1.35;
}

/* Panel de dimensiones con el mismo lenguaje visual de los dockers. */
#creator-view .pin-canvas-size-dialog {
    color: #e6e8eb;
    background: #2c3036;
    border: 1px solid #5c626b;
    border-radius: 7px;
    box-shadow: 0 18px 48px rgba(0,0,0,.55);
}

#creator-view .pin-canvas-size-dialog::backdrop {
    background: rgba(6,8,12,.72);
    backdrop-filter: blur(3px);
}

#creator-view .pin-canvas-size-dialog input,
#creator-view .pin-canvas-size-dialog select {
    color: #e6e8eb;
    background: #202328;
    border: 1px solid #555b64;
    border-radius: 4px;
}

/* Coherencia de foco, desplazamiento y contraste. */
#creator-view button:focus-visible,
#creator-view select:focus-visible,
#creator-view input:focus-visible {
    outline: 2px solid #8bbcf0;
    outline-offset: 2px;
}

#creator-view ::-webkit-scrollbar { width: 10px; height: 10px; }
#creator-view ::-webkit-scrollbar-track { background: #2b2e33; }
#creator-view ::-webkit-scrollbar-thumb { background: #59616b; border: 2px solid #2b2e33; border-radius: 10px; }
#creator-view ::-webkit-scrollbar-thumb:hover { background: #737d89; }

/* En tablets, la biblioteca se convierte en una fila superior y los docks pasan
   debajo del lienzo para no aplastar el área de trabajo. */
@media (min-width: 760px) and (max-width: 1099px) {
    #creator-view {
        height: auto;
        min-height: 100vh;
        max-height: none;
        overflow: visible;
        padding: 8px;
    }
    #creator-view .creator-workspace {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(230px, 34%);
        grid-template-rows: auto auto minmax(360px, 60vh) minmax(170px, auto) auto;
        grid-template-areas:
            "categories categories"
            "assets toolbar"
            "assets canvas"
            "layers canvas"
            "properties properties";
        overflow: visible;
    }
    #creator-view .gacha-tabs-bar {
        height: auto;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: flex-start;
    }
    #creator-view .gacha-options-container { height: auto; max-height: 440px; }
    #creator-view .gacha-grid { max-height: 370px; }
    #creator-view .canvas-container { min-height: 360px; height: 60vh; }
    #creator-view .layers-manager-container { min-height: 220px; }
    #creator-view .element-properties-box { height: auto; min-height: 180px; }
}

@media (max-width: 759px) {
    main:has(#creator-view:not(.hidden)) { height: auto; min-height: 100vh; overflow: visible; }
    body:has(#creator-view:not(.hidden)) { overflow: auto; }
    #creator-view {
        width: 100%;
        height: auto;
        min-height: 100vh;
        max-height: none;
        padding: 8px;
        overflow: visible;
    }
    #creator-view .creator-header {
        grid-template-columns: 1fr auto;
        gap: 8px;
        min-height: 0;
        padding-bottom: 9px;
    }
    #creator-view .creator-header h2 { grid-column: 1 / -1; grid-row: 1; justify-self: start; font-size: 16px; }
    #creator-view .creator-header > #closeCreatorBtn { grid-column: 1; grid-row: 2; }
    #creator-view .creator-header-actions { grid-column: 2; grid-row: 2; }
    #creator-view .creator-header-actions .menu-art-button > img { height: 34px; max-width: 110px; }
    #creator-view .creator-workspace {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto auto auto minmax(300px, 62vh) auto auto;
        grid-template-areas:
            "categories"
            "assets"
            "toolbar"
            "canvas"
            "layers"
            "properties";
        gap: 7px;
        overflow: visible;
    }
    #creator-view .gacha-tabs-bar {
        height: auto;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: flex-start;
    }
    #creator-view .gacha-tab-btn { flex-basis: 36px; width: 36px; height: 36px; min-width: 36px; }
    #creator-view .gacha-options-container { height: auto; max-height: 270px; }
    #creator-view .gacha-grid { grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); max-height: 210px; }
    #creator-view .gacha-item-card { height: 62px; }
    #creator-view .pin-editor-toolbar { position: static; }
    #creator-view .pin-editor-status { flex-basis: 100%; margin-left: 0; white-space: normal; }
    #creator-view .canvas-container { width: 100%; height: 62vh; min-height: 300px; max-height: 600px; padding: 18px; }
    #creator-view .layers-manager-container { min-height: 220px; height: auto; }
    #creator-view .layers-list { max-height: 260px; }
    #creator-view .element-properties-box { height: auto; max-height: none; }
}

@media (prefers-reduced-motion: reduce) {
    #creator-view *,
    #creator-view *::before,
    #creator-view *::after { transition: none !important; animation: none !important; }
}
