html, body {
    margin: 0;
    height: 100vh;
    width: 100vw;
    overflow: hidden !important;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', sans-serif;
    background: #0b0f1a;
    color: white;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    overflow: hidden !important;
}

.topbar {
    min-height: 82px;
    background: #111827;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    gap: 16px;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 18px;
    min-width: 0;
    flex: 1;
}

.brand-block {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.brand-home-link {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
    flex: 0 0 auto;
}

.brand-logo-frame {
    width: 74px;
    height: 50px;
    overflow: visible;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
}

.brand-logo {
    width: 74px;
    height: 50px;
    object-fit: contain;
    filter: none;
    flex: 0 0 auto;
    transform: none;
}

.brand-copy {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar-message {
    margin: 0;
    color: #9ca3af;
    font-size: 14px;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 520px;
}

.top-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    overflow-x: auto;
    padding-bottom: 2px;
}

.nav-tab {
    margin: 0;
    background: rgba(148, 163, 184, 0.12);
    color: #e2e8f0;
    border: 1px solid transparent;
    white-space: nowrap;
}

.nav-tab.active {
    background: rgba(37, 99, 235, 0.16);
    border-color: rgba(96, 165, 250, 0.4);
}

button {
    border: none;
    padding: 10px 15px;
    margin-left: 10px;
    border-radius: 8px;
    cursor: pointer;
    height: 42px;
    line-height: 1;
}

.top-actions a,
.btn-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.top-actions {
    display: flex;
    align-items: center;
}

.mirror-btn {
    width: 42px;
    height: 42px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.mirror-icon {
    position: relative;
    width: 24px;
    height: 32px;
    display: inline-block;
}

.mirror-icon::before,
.mirror-icon::after {
    content: '';
    position: absolute;
    width: 5px;
    height: 24px;
    background: #9ca3af;
    border-radius: 3px;
    top: 4px;
}

.mirror-icon::before {
    left: 0;
}

.mirror-icon::after {
    right: 0;
}

.mirror-icon-line {
    position: absolute;
    left: 50%;
    top: 4px;
    transform: translateX(-50%);
    width: 2px;
    height: 24px;
    background: #9ca3af;
    border-radius: 1px;
}

.btn-action.active {
    background: rgba(37, 99, 235, 0.15);
    border: 1px solid #2563eb;
}

.btn-primary {
    background: #2563eb;
    color: white;
}

.btn-download {
    background: #00c853;
    color: black;
    font-weight: bold;
}

.workspace {
    display: flex;
    flex: 1 1 0;
    min-height: 0;
    min-width: 0;
    height: 100%;
    width: 100%;
    overflow: hidden !important;
}

.page-section {
    display: none;
    flex: 1 1 0;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
}

.page-section.active {
    display: flex;
    flex-direction: column;
}

.tool-page {
    background: linear-gradient(180deg, #f3f4f6, #e5e7eb);
}

.tool-frame-shell {
    flex: 1 1 0;
    min-height: 0;
    padding: 12px;
    box-sizing: border-box;
}

.tool-frame {
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 18px;
    background: white;
    box-shadow: 0 20px 40px rgba(15, 23, 42, 0.16);
}

.sidebar {
    position: relative;
    width: 428px;
    flex: 0 0 428px;
    background: #111827;
    padding: 0;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    transition: width 0.28s ease, flex-basis 0.28s ease, opacity 0.2s ease;
    height: 100%;
    min-height: 0;
    border-right: 1px solid rgba(255,255,255,0.08);
}

.sidebar.hidden {
    width: 0;
    flex-basis: 0;
    min-width: 0;
    opacity: 0;
    border-right-color: transparent;
    pointer-events: none;
}

.canvas-area {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 0;
    min-width: 0;
    height: 100%;
    width: 100%;
    overflow: hidden !important;
    padding: 0;
}

#progress-container {
    width: 50%;
    height: 20px;
    background: rgba(255,255,255,0.1);
    border-radius: 10px;
    margin: 10px;
    display: none;
    position: relative;
    overflow: hidden;
}

#progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #00e5ff, #00b0ff);
    transition: width 0.2s;
}

#progress-bar.error {
    background: red !important;
}

#progress-bar.success {
    background: linear-gradient(90deg, #4caf50, #81c784) !important;
}

#progress-text {
    position: absolute;
    right: 10px;
    top: 0;
    font-size: 12px;
}

#dual-preview {
    display: flex;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    gap: 10px;
}

.preview-box {
    flex: 1;
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    background: none;
}

.preview-box.active-bg {
    background-color: #ccc;
    background-image:
        linear-gradient(45deg, #e5e5e5 25%, transparent 25%),
        linear-gradient(-45deg, #e5e5e5 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #e5e5e5 75%),
        linear-gradient(-45deg, transparent 75%, #e5e5e5 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

.preview {
    width: 100%;
    height: 100%;
    cursor: grab;
}

.preview-label {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
    color: #9ca3af;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: none;
    text-shadow: 0 0 8px rgba(255,255,255,0.7), 0 0 2px rgba(0,0,0,0.3);
    pointer-events: none;
}

.preview-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transform-origin: top left;
    user-select: none;
    pointer-events: none;
    cursor: grab;
}

/* PALETA DE COLORES A LA DERECHA */
.color-palette {
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: linear-gradient(180deg, rgba(17,24,39,0.98), rgba(15,23,42,0.98));
    padding: 16px 14px;
    border-radius: 0;
    box-sizing: border-box;
    box-shadow: none;
    transition: opacity 0.3s;
    opacity: 1;
    height: auto;
    min-height: 100%;
    overflow: visible;
    min-width: 0;
}

.palette-header {
    display: flex;
    align-items: center;
    min-height: 28px;
}

.palette-header h3 {
    margin: 0;
    font-size: 17px;
}

#paletteColors {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
    min-height: auto;
    overflow: visible !important;
    padding-right: 2px;
}

.palette-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.palette-section-title {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.palette-section-title h4 {
    margin: 0;
    font-size: 13px;
    font-weight: 700;
    color: #f8fafc;
}

.palette-helper {
    margin: 0;
    color: #94a3b8;
    font-size: 12px;
    line-height: 1.4;
}

.palette-cluster-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
    gap: 20px;
    padding: 4px 2px;
    overflow: visible !important;
}

.palette-present-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
    gap: 8px;
    overflow: visible !important;
}

.color-box {
    aspect-ratio: 1 / 1;
    min-height: 84px;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    border: 2px solid rgba(255,255,255,0.12);
    box-shadow: 0 6px 16px rgba(0,0,0,0.25);
    padding: 12px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 12px;
    position: relative;
    overflow: hidden;
}

.color-box:hover {
    transform: scale(1.03);
}

.color-box.selected {
    border: 2px solid #facc15;
    transform: scale(1.02);
}

.color-box.dragging {
    opacity: 0.45;
}

.color-box.drop-target {
    border-color: #38bdf8;
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.25);
}

.color-box::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(255,255,255,0.12), transparent 36%, rgba(15,23,42,0.2));
    pointer-events: none;
}

.color-box-strip,
.color-box-corner {
    position: relative;
    z-index: 1;
}

.color-box-corner {
    position: absolute;
    top: 8px;
    right: 8px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.72);
    border: 1px solid rgba(255,255,255,0.24);
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.25);
    color: #f8fafc;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
}

.color-box-strip {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

.color-box-chip {
    width: 20px;
    height: 20px;
    border-radius: 5px;
    border: 1px solid rgba(255,255,255,0.35);
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.2);
    cursor: grab;
}

.present-colors-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
    gap: 8px;
}

.present-color-box {
    width: 38px;
    height: 38px;
    cursor: pointer;
    border: 2px solid rgba(255,255,255,0.18);
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    border-radius: 10px;
}

.present-color-box:hover {
    transform: scale(1.06);
}

.present-color-box.selected {
    border-color: #facc15;
    box-shadow: 0 0 0 3px rgba(250, 204, 21, 0.2);
}

.palette-reset {
    width: 100%;
    border-radius: 12px;
    background: rgba(37, 99, 235, 0.16);
    color: #e2e8f0;
    border: 1px solid rgba(96, 165, 250, 0.35);
    margin: 0;
}

.palette-empty {
    color: #94a3b8;
    font-size: 14px;
    line-height: 1.5;
}

.color-palette.hidden {
    display: none;
    opacity: 0;
}

@media (max-width: 900px) {
    .sidebar {
        width: 348px;
        flex-basis: 348px;
    }
}

.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.65);
    z-index: 1100;
}

.modal.hidden {
    display: none;
}

.modal-content {
    width: min(400px, 90%);
    background: #111827;
    border-radius: 16px;
    padding: 20px;
    color: white;
    box-shadow: 0 30px 60px rgba(0,0,0,0.35);
    max-height: 85vh;
    overflow-y: auto;
}

.modal-content label {
    display: block;
    margin-top: 12px;
    margin-bottom: 6px;
    color: #cbd5e1;
    font-size: 14px;
}

.modal-content input,
.modal-content select {
    width: 100%;
    background: #0f172a;
    color: #e2e8f0;
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: 10px;
    padding: 10px 12px;
    box-sizing: border-box;
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 18px;
    font-size: 24px;
    cursor: pointer;
}

.format-options {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.format-options.hidden {
    display: none;
}

.advanced-mode-note {
    margin: 8px 0 0;
    color: #94a3b8;
    font-size: 13px;
    line-height: 1.5;
}

.advanced-preset-bar {
    margin-top: 12px;
}

.advanced-preset-bar label {
    margin-top: 0;
}

.advanced-download-options details {
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: 12px;
    padding: 10px 12px;
    background: rgba(15, 23, 42, 0.65);
}

.advanced-download-options summary {
    cursor: pointer;
    font-weight: 600;
    color: #e2e8f0;
}

.option-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-top: 12px;
}

.option-grid label {
    margin: 0;
}

.option-grid label span {
    display: block;
    margin-bottom: 6px;
    color: #cbd5e1;
    font-size: 13px;
}

.checkbox-option {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 42px;
    background: rgba(30, 41, 59, 0.5);
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: 10px;
    padding: 8px 10px;
}

.checkbox-option input {
    width: auto;
    margin: 0;
}

.checkbox-option span {
    margin: 0;
}

.advanced-preview-actions {
    margin-top: 12px;
}

.advanced-summary {
    margin-top: 12px;
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: 14px;
    padding: 12px;
    background: rgba(15, 23, 42, 0.65);
}

.advanced-summary.hidden {
    display: none;
}

.advanced-summary h4 {
    margin: 0 0 10px;
    font-size: 14px;
    color: #e2e8f0;
}

.advanced-summary-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.advanced-summary-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(59, 130, 246, 0.12);
    border: 1px solid rgba(96, 165, 250, 0.24);
    color: #dbeafe;
    font-size: 12px;
}

.btn-secondary {
    width: 100%;
    background: rgba(14, 165, 233, 0.14);
    color: #e0f2fe;
    border: 1px solid rgba(56, 189, 248, 0.35);
}

.advanced-preview {
    margin-top: 12px;
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: 14px;
    padding: 12px;
    background: rgba(15, 23, 42, 0.65);
}

.advanced-preview p {
    margin: 0 0 10px;
    color: #cbd5e1;
    font-size: 13px;
}

.advanced-preview img {
    width: 100%;
    max-height: 220px;
    object-fit: contain;
    border-radius: 10px;
    background-color: #ccc;
    background-image:
        linear-gradient(45deg, #e5e5e5 25%, transparent 25%),
        linear-gradient(-45deg, #e5e5e5 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #e5e5e5 75%),
        linear-gradient(-45deg, transparent 75%, #e5e5e5 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

.advanced-preview.hidden,
.advanced-preview-actions.hidden,
.advanced-mode-note.hidden {
    display: none;
}

@media (max-width: 720px) {
    .topbar {
        flex-direction: column;
        align-items: stretch;
        padding: 14px 12px;
    }

    .topbar-left {
        flex-direction: column;
        align-items: stretch;
    }

    .brand-block {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    .topbar-message {
        max-width: none;
        white-space: normal;
    }

    .top-actions {
        flex-wrap: wrap;
        justify-content: flex-start;
    }

    .option-grid {
        grid-template-columns: 1fr;
    }
}
