/* --- INICIO: Estilos para expandir --- */
#main-container {
    transition: max-width 0.5s ease-in-out;
}

#main-container.is-expanded {
    max-width: 98%;
}
/* --- FIN: Estilos para expandir --- */

/* Focus mode */
#main-container > header,
#toolbar {
    max-height: 480px;
    transition: max-height 0.4s ease, opacity 0.3s ease, padding 0.3s ease, margin 0.3s ease, transform 0.3s ease, border-width 0.3s ease;
}

#toolbar {
    max-height: 360px;
}

#focus-mode-toggle .toggle-icon {
    transition: transform 0.25s ease;
}

#main-container.focus-mode > header,
#main-container.focus-mode #toolbar {
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-bottom: 0;
    border-width: 0;
    transform: translateY(-0.75rem);
    overflow: hidden;
    pointer-events: none;
}

#main-container.focus-mode #workspace-shell {
    padding-top: 0;
}

#main-container.focus-mode #editor-container {
    padding-top: 0;
}

#workspace-shell,
#editor-container {
    transition: padding 0.3s ease;
}

#main-container.focus-mode #focus-mode-toggle .toggle-icon {
    transform: rotate(180deg);
}

/* Estilos personalizados */
:root {
    --fs-base: 16px;
    --editor-viewport-offset: 22rem;
} /* Valor por defecto para el tamaño de fuente */

#main-container.focus-mode {
    --editor-viewport-offset: 13rem;
    min-height: calc(100vh - 2rem); /* body p-4 => 1rem arriba + 1rem abajo */
}

@media (min-width: 640px) {
    #main-container.focus-mode {
        min-height: calc(100vh - 3rem); /* sm:p-6 => 1.5rem */
    }
}

@media (min-width: 768px) {
    #main-container.focus-mode {
        min-height: calc(100vh - 4rem); /* md:p-8 => 2rem */
    }
}

body { font-family: 'Inter', sans-serif; background-color: #f1f5f9; }
.dark body { background-color: #0f172a; }

#mobile-toolbar-controls {
    display: none;
}

body.desktop-mode {
    padding: 0 !important;
}
.dark body.desktop-mode {
    background-color: #0f172a;
}

body.desktop-mode #main-container {
    max-width: none;
    margin: 0;
    border-radius: 0;
    box-shadow: none;
    min-height: 100vh;
    border: none;
}

.editor-wrapper { display: flex; }
.panel {
    min-width: 280px;
    overflow: hidden;
}

.CodeMirror, .editor-pane, .markdown-textarea {
    height: calc(100vh - var(--editor-viewport-offset)); /* Ajustado para la zona de pestañas y búsqueda */
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    font-size: var(--fs-base); /* Usa la variable CSS para el tamaño */
}
.dark .CodeMirror, .dark .editor-pane, .dark .markdown-textarea { border-color: #334155; }

.CodeMirror-focused, .markdown-textarea:focus {
    outline: none;
    border-color: #3b82f6 !important;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.4) !important;
}
.dark .CodeMirror-focused, .dark .markdown-textarea:focus { border-color: #60a5fa !important; }

.markdown-textarea {
    width: 100%;
    padding: 1rem;
    resize: none;
    background-color: transparent;
    color: #1f2937;
    font-family: 'Fira Code', 'JetBrains Mono', 'Menlo', monospace;
    line-height: 1.5;
    box-sizing: border-box;
    position: relative;
    z-index: 1;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease, color 0.2s ease;
}
.markdown-textarea::selection {
    background-color: rgba(251, 146, 60, 0.65);
    color: inherit;
}
.markdown-textarea-wrapper {
    position: relative;
    height: 100%;
}

.markdown-textarea-highlights {
    position: absolute;
    inset: 0;
    padding: 1rem;
    border-radius: 0.5rem;
    pointer-events: none;
    white-space: pre-wrap;
    word-break: break-word;
    overflow: hidden;
    font-size: var(--fs-base);
    font-family: 'Fira Code', 'JetBrains Mono', 'Menlo', monospace;
    line-height: 1.5;
    background-color: #ffffff;
    color: transparent;
    z-index: 0;
}
.markdown-textarea-highlights-content {
    margin: 0;
    min-height: 100%;
    white-space: pre-wrap;
    word-break: break-word;
    font: inherit;
    padding: 0;
}
.markdown-textarea-highlights mark {
    background-color: rgba(253, 224, 71, 0.45);
    border-radius: 0.25rem;
    color: transparent;
}
.markdown-textarea-highlights mark.current {
    background-color: #fb923c;
    color: transparent;
}
.dark .markdown-textarea {
    color: #cbd5e1;
}
.markdown-textarea-dark {
    color: #cbd5e1;
}
.markdown-textarea-highlights.markdown-textarea-dark {
    color: transparent;
}
.dark .markdown-textarea::selection,
.markdown-textarea-dark::selection {
    background-color: rgba(14, 165, 233, 0.65);
}
.dark .markdown-textarea-highlights,
.markdown-textarea-highlights.markdown-textarea-dark {
    background-color: #1e293b;
}
.dark .markdown-textarea-highlights mark,
.markdown-textarea-highlights.markdown-textarea-dark mark {
    background-color: rgba(59, 130, 246, 0.35);
}
.dark .markdown-textarea-highlights mark.current,
.markdown-textarea-highlights.markdown-textarea-dark mark.current {
    background-color: rgba(14, 165, 233, 0.5);
}

.editor-pane { padding: 1rem; overflow-y: auto; background-color: #ffffff; }
.dark .editor-pane { background-color: #1e293b; color: #cbd5e1; }
.dark .prose { color: #cbd5e1; }
.dark .prose h1, .dark .prose h2, .dark .prose h3, .dark .prose strong { color: #f1f5f9; }
.dark .prose code { color: #e2e8f0; }
.dark .prose blockquote { border-left-color: #475569; color: #94a3b8;}
.dark .prose a { color: #93c5fd; }
.dark .prose table thead th { color: #f8fafc; }
.dark .prose table thead tr { border-bottom-color: #475569; }
.dark .prose table tbody tr { border-bottom-color: #334155; }

/* Estilo para enlaces con Ctrl/Cmd presionado */
#html-output a.ctrl-hover {
    text-decoration: underline;
    color: #2563eb; /* Tailwind blue-600 */
    cursor: pointer;
}
.dark #html-output a.ctrl-hover {
    color: #60a5fa; /* Tailwind blue-400 */
}

.status-toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -40%) scale(0.95);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 60;
    max-width: min(420px, 90vw);
}

.status-toast.visible {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.status-toast-content {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.9rem 1.5rem;
    border-radius: 1rem;
    background: linear-gradient(135deg, rgba(193, 222, 248, 0.95), rgba(167, 210, 243, 0.95));
    color: #0f172a;
    border: 1px solid rgba(59, 130, 246, 0.35);
    box-shadow: 0 18px 40px rgba(30, 64, 175, 0.18);
    font-size: 0.95rem;
    font-weight: 500;
    backdrop-filter: blur(10px);
}

.dark .status-toast-content {
    background: linear-gradient(135deg, rgba(30, 64, 175, 0.92), rgba(37, 99, 235, 0.88));
    color: #f8fafc;
    border-color: rgba(147, 197, 253, 0.4);
    box-shadow: 0 18px 42px rgba(15, 23, 42, 0.55);
}


.action-btn {
    display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem;
    border-radius: 0.375rem; color: #475569; background-color: transparent;
    transition: background-color 0.2s, color 0.2s;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}
.action-btn:hover { background-color: #f1f5f9; color: #1e293b; }
.dark .action-btn { color: #94a3b8; }
.dark .action-btn:hover { background-color: #1e293b; color: #e2e8f0; }

.panel-counter {
    font-size: 0.75rem;
    font-weight: 500;
    color: #475569;
    border: 1px solid rgba(148, 163, 184, 0.35);
    background: rgba(148, 163, 184, 0.12);
    padding: 0.2rem 0.65rem;
    border-radius: 9999px;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.01em;
}
.dark .panel-counter {
    color: #cbd5f5;
    border-color: rgba(148, 163, 184, 0.25);
    background: rgba(30, 41, 59, 0.7);
}
.dark select.action-btn { background-color: #0f172a; }

.select-trigger {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    min-width: 7rem;
}
.select-trigger.select-focus {
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.4);
}
.dark .select-trigger.select-focus {
    box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.5);
}
.select-trigger-icon,
.select-trigger-label,
.select-trigger-caret {
    pointer-events: none;
    color: inherit;
}
.select-trigger-label {
    font-size: 0.875rem;
    line-height: 1.25rem;
    white-space: nowrap;
}
.select-trigger-caret {
    width: 1rem;
    height: 1rem;
    opacity: 0.7;
}
.select-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    border-radius: inherit;
    background: transparent;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.toolbar-divider {
    width: 1px;
    height: 1.75rem;
    flex-shrink: 0;
    background-color: rgba(148, 163, 184, 0.6);
}
.dark .toolbar-divider {
    background-color: rgba(148, 163, 184, 0.35);
}


.toolbar-btn, .copy-btn {
    padding: 0.5rem; border-radius: 0.375rem; color: #475569;
    transition: background-color 0.2s, color 0.2s;
}
.toolbar-btn:hover, .copy-btn:hover { background-color: #e2e8f0; color: #1e293b; }
.dark .toolbar-btn, .dark .copy-btn { color: #94a3b8; }
.dark .toolbar-btn:hover, .dark .copy-btn:hover { background-color: #334155; color: #e2e8f0; }
.toolbar-btn[disabled], .toolbar-btn[aria-disabled="true"] {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
    background-color: transparent !important;
    color: #94a3b8 !important;
}
.dark .toolbar-btn[disabled], .dark .toolbar-btn[aria-disabled="true"] {
    color: #64748b !important;
}
.toolbar-btn[disabled] i, .toolbar-btn[aria-disabled="true"] i {
    opacity: 0.85;
}

.gutter { background-color: #f1f5f9; background-repeat: no-repeat; background-position: 50%; }
.dark .gutter { background-color: #0f172a; }

.gutter.gutter-horizontal {
    cursor: col-resize;
    background-repeat: no-repeat;
    background-position: 50%;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='30' viewBox='0 0 8 30'%3E%3Cpath d='M3 6h2M3 14h2M3 22h2' stroke='%23cbd5e1' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
}
.dark .gutter.gutter-horizontal {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='30' viewBox='0 0 8 30'%3E%3Cpath d='M3 6h2M3 14h2M3 22h2' stroke='%2360a5fa' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
}
/* Estilos para pestañas */
.tab {
    border: 1px solid transparent;
    border-bottom: 1px solid #e2e8f0;
    background-color: #f1f5f9;
    color: #475569;
    cursor: pointer;
    user-select: none;
    touch-action: pan-y;
}
.dark .tab {
    border-bottom: 1px solid #334155;
    background-color: #1e293b;
    color: #94a3b8;
}
.tab[aria-selected="true"] {
    background-color: white;
    border-color: #e2e8f0;
    border-bottom-color: transparent;
    color: #1e293b;
}
.dark .tab[aria-selected="true"] {
    background-color: #0f172a;
    border-color: #334155;
    border-bottom-color: transparent;
    color: #f1f5f9;
}
.tab-close {
    opacity: 0.5;
    transition: opacity 0.2s;
}
.tab:hover .tab-close {
    opacity: 1;
}

.tab.is-dragging {
    opacity: 0.75;
    cursor: grabbing !important;
}

/* --- INICIO DE ESTILOS PARA LA BÚSQUEDA --- */
.cm-s-eclipse .cm-search-highlight,
.cm-s-material-darker .cm-search-highlight {
    background-color: rgba(253, 224, 71, 0.5); /* Amarillo traslúcido para todas las coincidencias */
    color: inherit !important;
}

/* Estilo para la coincidencia actualmente seleccionada */
.cm-s-eclipse .cm-search-current,
.cm-s-material-darker .cm-search-current {
    background-color: #fb923c; /* Naranja para la coincidencia activa */
}
/* --- FIN DE ESTILOS PARA LA BÚSQUEDA --- */


/* --- INICIO DE LAS CORRECCIONES PARA MÓVIL --- */
@media (max-width: 768px) {
    .editor-wrapper {
        flex-direction: column;
    }

    .panel {
        width: 100% !important;
    }

    .CodeMirror, .editor-pane, .markdown-textarea {
       height: 40vh;
    }
    
    /* Ajustes del contenedor de acciones en cabecera */
    header > div:nth-child(2) {
        width: 100%;
    }
    
    /* Regla para que las pestañas también salten de línea */
    #tab-bar {
        flex-wrap: wrap;
    }

    /* Alinea al inicio el contenedor y el botón nuevo para que no se corte el punto */
    #tab-bar,
    #new-tab-btn {
        align-self: flex-start;
    }

    header {
        flex-direction: column;
        align-items: stretch;
        padding: 1rem 1.25rem;
        gap: 0.75rem;
    }

    header > div:first-child {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        gap: 0.75rem;
    }

    header > div:first-child img {
        width: 2.75rem;
        height: 2.75rem;
    }

    header h1 {
        font-size: 1.1rem;
    }

    #mobile-toolbar-controls {
        display: flex;
        gap: 0.5rem;
        width: 100%;
    }

    #mobile-toolbar-controls button {
        flex: 1 1 0;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 0.4rem;
        padding: 0.55rem 0.75rem;
        border-radius: 0.75rem;
        border: 1px solid rgba(15, 23, 42, 0.08);
        background-color: #f8fafc;
        color: #0f172a;
        font-weight: 600;
        transition: background-color 0.2s, color 0.2s, border-color 0.2s;
    }

    .dark #mobile-toolbar-controls button {
        background-color: #1e293b;
        border-color: rgba(148, 163, 184, 0.25);
        color: #e2e8f0;
    }

    #mobile-toolbar-controls button[aria-expanded="true"] {
        background-color: #e0f2fe;
        border-color: #38bdf8;
        color: #0c4a6e;
    }

    .dark #mobile-toolbar-controls button[aria-expanded="true"] {
        background-color: rgba(56, 189, 248, 0.18);
        border-color: rgba(56, 189, 248, 0.55);
        color: #bae6fd;
    }

    .toolbar-actions,
    #toolbar {
        display: none !important;
    }

    .toolbar-actions.is-open,
    #toolbar.is-open {
        display: grid !important;
        padding: 0.65rem 0.5rem;
        border: 1px solid rgba(15, 23, 42, 0.08);
        border-radius: 0.75rem;
        background-color: rgba(248, 250, 252, 0.95);
        gap: 0.4rem;
    }

    .dark .toolbar-actions.is-open,
    .dark #toolbar.is-open {
        border-color: rgba(148, 163, 184, 0.25);
        background-color: rgba(15, 23, 42, 0.9);
    }

    .toolbar-actions.is-open {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .toolbar-actions .toolbar-group {
        display: contents !important;
    }

    .toolbar-actions .select-trigger,
    .toolbar-actions #preview-copy-container,
    .toolbar-actions #export-menu-container {
        grid-column: span 2;
        min-width: 0;
    }

    .toolbar-actions button,
    .toolbar-actions .select-trigger {
        justify-content: center;
        padding: 0.45rem;
        width: 100%;
    }

    .toolbar-actions #preview-copy-container {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.35rem;
    }

    .toolbar-divider {
        display: none;
    }

    .action-btn,
    .toolbar-btn {
        min-width: 2.4rem;
        min-height: 2.4rem;
    }

    #toolbar.is-open {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    #toolbar > div {
        display: contents !important;
    }

    #toolbar .toolbar-btn,
    #toolbar .action-btn {
        width: 100%;
        justify-content: center;
        padding: 0.35rem;
    }

    #toolbar .border-l {
        display: none;
    }

    #toolbar .toolbar-btn i {
        width: 1.05rem;
        height: 1.05rem;
    }

    .panel-counter {
        font-size: 0.7rem;
        padding: 0.15rem 0.5rem;
    }
}
/* --- FIN DE LAS CORRECCIONES PARA MÓVIL --- */

/* =========================================================
   Indicador visual de arrastre para soltar .md
   ========================================================= */
#drop-backdrop {
    /* No bloquea clics ni selección */
    pointer-events: none;
}

.drop-outline {
    /* Borde visible estilo "marco" alrededor del viewport interior */
    border-style: dashed;
}

.drop-ants {
    /* Sutil patrón animado en el fondo del marco */
    background-image:
        repeating-linear-gradient(90deg, rgba(59,130,246,0.18) 0 12px, transparent 12px 24px),
        repeating-linear-gradient(0deg,  rgba(59,130,246,0.18) 0 12px, transparent 12px 24px);
    background-size: 16px 2px, 2px 16px;
    background-position: 0 0, 0 0;
    animation: drop-ants-move 12s linear infinite;
}

@keyframes drop-ants-move {
    0%   { background-position: 0 0, 0 0; }
    100% { background-position: 480px 0, 0 480px; }
}

.drop-hint {
    text-shadow: 0 1px 2px rgba(0,0,0,0.25);
}

.drop-dim {
    /* Capa que oscurece ligeramente toda la página */
    background: rgba(2,6,23,0.22);
    /* Efecto "por detrás" gracias al blur del fondo */
    backdrop-filter: blur(2px);
}
.dark .drop-dim {
    background: rgba(2,6,23,0.35);
}

/* Controles de búsqueda y modales: respetan el tema de la app */
#search-input, #replace-input,
[id$="-modal-overlay"] input[type="text"],
[id$="-modal-overlay"] input[type="url"],
[id$="-modal-overlay"] input[type="number"],
[id$="-modal-overlay"] textarea {
  color: #0f172a;            /* texto en claro */
  background-color: #ffffff; /* fondo en claro */
  caret-color: #0f172a;      /* cursor visible */
  color-scheme: light;       /* nativo en claro */
}
#search-input::placeholder, #replace-input::placeholder,
[id$="-modal-overlay"] input[type="text"]::placeholder,
[id$="-modal-overlay"] input[type="url"]::placeholder,
[id$="-modal-overlay"] input[type="number"]::placeholder,
[id$="-modal-overlay"] textarea::placeholder {
  color: #64748b; /* slate-500, buena legibilidad en claro */
}

.dark #search-input, .dark #replace-input,
.dark [id$="-modal-overlay"] input[type="text"],
.dark [id$="-modal-overlay"] input[type="url"],
.dark [id$="-modal-overlay"] input[type="number"],
.dark [id$="-modal-overlay"] textarea {
  color: #e2e8f0;            /* texto en oscuro */
  background-color: #1e293b; /* fondo en oscuro */
  caret-color: #e2e8f0;      /* cursor visible */
  color-scheme: dark;        /* nativo en oscuro */
}
.dark #search-input::placeholder, .dark #replace-input::placeholder,
.dark [id$="-modal-overlay"] input[type="text"]::placeholder,
.dark [id$="-modal-overlay"] input[type="url"]::placeholder,
.dark [id$="-modal-overlay"] input[type="number"]::placeholder,
.dark [id$="-modal-overlay"] textarea::placeholder {
  color: #94a3b8; /* slate-300/400, legible en oscuro */
}

code {
  background-color: #f4f4f4;
  padding: 2px 4px;
  border-radius: 4px;
  font-family: monospace;
}

.dark code {
  background-color: #333;
  color: #eee;
}

@media print {
    @page {
        margin: 18mm;
    }
    html, body {
        background: #ffffff !important;
        color: #000000 !important;
        padding: 0 !important;
        margin: 0 !important;
        height: auto !important;
    }
    body {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    body.desktop-mode {
        padding: 0 !important;
    }
    #main-container {
        max-width: none !important;
        margin: 0 !important;
        border: none !important;
        box-shadow: none !important;
        border-radius: 0 !important;
    }
    header,
    #toolbar,
    #tab-bar,
    #new-tab-btn,
    #status-toast,
    #markdown-panel,
    .gutter {
        display: none !important;
    }
    #editor-container {
        display: block !important;
        padding-top: 0 !important;
    }
    #html-panel {
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
    }
    #html-panel > .flex:first-child {
        display: none !important;
    }
    .editor-pane,
    #html-output {
        display: block !important;
        height: auto !important;
        overflow: visible !important;
        border: none !important;
        box-shadow: none !important;
        background: transparent !important;
        color: inherit !important;
        padding: 0 !important;
    }
    .markdown-textarea,
    .markdown-textarea-wrapper,
    .CodeMirror {
        display: none !important;
    }
}
