/*--------------------------- TEMAS ---------------------------*/

body[data-theme="dark"] {
    --bg-primary:      #1a1a1a;
    --bg-secondary:    #252525;
    --bg-tertiary:     #2d2d2d;
    --border-color:    #3d3d3d;
    --text-primary:    #ffffff;
    --text-secondary:  #9ca3af;
    --scrollbar-thumb: #3d3d3d;
    --scrollbar-track: #1a1a1a;
    --cm-bg:           #1a1a1a;
}

body[data-theme="light"] {
    --bg-primary:      #ffffff;
    --bg-secondary:    #f3f4f6;
    --bg-tertiary:     #e9eaec;
    --border-color:    #e5e7eb;
    --text-primary:    #1f2937;
    --text-secondary:  #6b7280;
    --scrollbar-thumb: #d1d5db;
    --scrollbar-track: #f3f4f6;
    --cm-bg:           #f8f8f8;
}

/*--------------------------- BASE ---------------------------*/

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    transition: background-color .3s, color .3s;
}

/*--------------------------- LAYOUT ---------------------------*/

.editor-wrapper {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

.toolbar {
    background: linear-gradient(135deg, #2d2d2d 0%, #1a1a1a 100%);
    border-bottom: 1px solid var(--border-color);
    border-top: 3px solid var(--lang-color, #777BB4);
    padding: 0 12px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-shrink: 0;
}

body[data-theme="light"] .toolbar { background: var(--bg-secondary); }

.toolbar-left  { display: flex; align-items: center; gap: 12px; }
.toolbar-right { display: flex; align-items: center; gap: 8px; }

/* Botón volver — solo mobile, es un <a> */
#btnBack {
    display: none;
    text-decoration: none;
    gap: 4px;
}

.panels {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.panel {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    height: 100%;
}

.editor-panel { flex: 1 1 0; }
.result-panel { flex: 1 1 0; }

.divider {
    width: 8px;
    background-color: var(--border-color);
    cursor: col-resize;
    flex-shrink: 0;
    transition: background-color .2s;
    touch-action: none;
    user-select: none;
}

.divider:hover, .divider.dragging { background-color: #4f46e5; }

.keyboard-tip,
.result-dimensions,
.editor-stats {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
    white-space: nowrap;
}

.editor-stats { transition: color .2s; }
.editor-stats.changed { color: #f59e0b; }

/*--------------------------- BOTONES ---------------------------*/

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color .2s;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    /*gap: 6px;*/
}

.btn-primary          { background-color: #4f46e5; color: white; border: 1px solid #4f46e5; }
.btn-primary:hover    { background-color: #4338ca; border-color: #4338ca; transform: translateY(-1px); }
.btn-primary:active   { transform: translateY(0); }
.btn-primary:disabled { background: var(--bg-tertiary); color: var(--text-secondary); cursor: not-allowed; transform: none; border-color: var(--border-color); }

.btn-secondary        { background-color: #2d2d2d; color: #fff; border: 1px solid #404040; }
.btn-secondary:hover  { background-color: #3d3d3d; border-color: #4f46e5; transform: translateY(-1px); }
.btn-secondary:active { transform: translateY(0); }

body[data-theme="light"] .btn-secondary       { background-color: var(--bg-secondary); color: var(--text-primary); border: 1px solid var(--border-color); }
body[data-theme="light"] .btn-secondary:hover { background-color: var(--border-color); border-color: #4f46e5; }

#btnTheme {
    padding: 0;
    width: 35px;
    height: 35px;
    min-width: auto;
    font-size: 22px;
    justify-content: center;
    align-items: center;
}
#btnTheme .theme-icon--dark  { color: #e2e8f0; }
#btnTheme .theme-icon--light { color: #f59e0b; }

.shortcut {
    padding: 2px 6px;
    background-color: rgba(255,255,255,.15);
    border-radius: 3px;
    font-size: 11px;
    line-height: 1;
}

/*--------------------------- EDITOR ---------------------------*/

.editor-content { flex: 1; overflow: hidden; }

.CodeMirror {
    height: 100%;
    font-size: 14px;
    font-family: 'Consolas', 'Monaco', 'JetBrains Mono', monospace;
    background: var(--cm-bg);
}

.CodeMirror-scrollbar-filler,
.CodeMirror-gutter-filler { background-color: var(--bg-primary); }

.CodeMirror-vscrollbar::-webkit-scrollbar,
.CodeMirror-hscrollbar::-webkit-scrollbar { width: 12px; height: 12px; }

.CodeMirror-vscrollbar::-webkit-scrollbar-track,
.CodeMirror-hscrollbar::-webkit-scrollbar-track { background: var(--bg-primary); }

.CodeMirror-vscrollbar::-webkit-scrollbar-thumb,
.CodeMirror-hscrollbar::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 6px;
    border: 2px solid var(--bg-primary);
}

.CodeMirror-vscrollbar::-webkit-scrollbar-thumb:hover,
.CodeMirror-hscrollbar::-webkit-scrollbar-thumb:hover { background: #4f46e5; }

/*--------------------------- RESULTADO ---------------------------*/

.result-content { flex: 1; overflow: hidden; background-color: var(--bg-primary); }

#resultFrame { width: 100%; height: 100%; border: none; background-color: var(--bg-primary); }

/*--------------------------- TOAST ---------------------------*/

.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    background-color: #10b981;
    color: white;
    box-shadow: 0 4px 12px rgba(0,0,0,.3);
    opacity: 0;
    transform: translateY(20px);
    transition: all .3s;
    z-index: 10000;
}

.toast.show  { opacity: 1; transform: translateY(0); }
.toast.error { background-color: #ef4444; }
.toast.info  { background-color: #4f46e5; }

@keyframes spin { to { transform: rotate(360deg); } }
.spin { display: inline-block; animation: spin 1s linear infinite; }

/*--------------------------- RESPONSIVE ---------------------------*/

@media (max-width: 768px) {
    /* Paneles apilados verticalmente — flex para que el JS pueda controlar el resize */
    .panels        { flex-direction: column; }
    .editor-panel  { width: 100%; flex: 1 1 45%; min-height: 90px; }
    .result-panel  { width: 100%; flex: 1 1 55%; min-height: 90px; }

    /* Divider horizontal — área de toque generosa, touch-action none para no competir con scroll */
    .divider {
        width: 100%;
        height: 12px;
        cursor: row-resize;
        touch-action: none;
        background-color: #3d3d3d;
        flex-shrink: 0;
    }

    /* Touch-action en el área del editor para evitar conflicto con drag del divider */
    .editor-content { touch-action: pan-y; }

    /* Iframe resultado: overflow horizontal dentro del iframe */
    #resultFrame { overflow-x: auto; }

    .shortcut, .keyboard-tip, .result-dimensions { display: none; }
    .btn           { padding: 6px 10px; font-size: 12px; }
    .toolbar-right { gap: 4px; }

    /* btnTheme — tamaño normal */
    #btnTheme {
        width: auto;
        height: auto;
        padding: 6px 10px;
        font-size: 20px;
    }

    /* Botón volver — visible solo en mobile */
    #btnBack { display: inline-flex !important; align-items: center; gap: 4px; }

    /* CodeMirror más compacto en mobile */
    .CodeMirror { font-size: 13px; }

    /* Toast full-width en mobile */
    .toast {
        left: 10px;
        right: 10px;
        bottom: 10px;
        text-align: center;
    }
}

@media (max-width: 480px) {
    .toolbar      { padding: 0 8px; height: 48px; }
    .editor-stats { display: none; }
    .btn          { padding: 5px 8px; font-size: 11px; }
    #btnCopy      { display: none; }
    /* Ocultar texto "Restaurar", dejar solo el botón */
    #btnClear     { font-size: 0; padding: 5px 8px; }
    #btnClear::after { content: '↺'; font-size: 14px; }
    /* btnTheme consistente con el resto en 480px */
    #btnTheme     { padding: 5px 8px; font-size: 15px; }
}
