/*--------------------------- TEMAS ---------------------------*/

body[data-theme="dark"] {
    --bg-primary:      #1a1a1a;
    --bg-secondary:    #252525;
    --bg-tertiary:     #2d2d2d;
    --border-color:    #3d3d3d;
    --text-primary:    #ffffff;
    --text-secondary:  #9ca3af;
    --text-muted:      #6b7280;
    --text-faint:      #4b5563;
    --scrollbar-thumb: #3d3d3d;
    --scrollbar-track: #1a1a1a;
    --table-row-hover: #252525;
    --table-count-bg:  #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;
    --text-muted:      #9ca3af;
    --text-faint:      #d1d5db;
    --scrollbar-thumb: #d1d5db;
    --scrollbar-track: #f3f4f6;
    --table-row-hover: #f9fafb;
    --table-count-bg:  #e5e7eb;
    --cm-bg:           #f8f8f8;
}

/*--------------------------- BASE ---------------------------*/

* { margin: 0; padding: 0; box-sizing: border-box; }

::-webkit-scrollbar             { width: 12px; height: 12px; }
::-webkit-scrollbar-track       { background: var(--scrollbar-track); }
::-webkit-scrollbar-corner      { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb       { background: var(--scrollbar-thumb); border-radius: 6px; border: 2px solid var(--scrollbar-track); }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

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 ---------------------------*/

.toolbar {
    background: linear-gradient(135deg, #2d2d2d 0%, #1a1a1a 100%);
    border-bottom: 1px solid var(--border-color);
    border-top: 3px solid #00758F;
    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;
}

.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;
}

.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;      /* ← subí esto, probá 20px o 22px */
    justify-content: center;
    align-items: center;  /* ← agregá esto */
}
#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;
}

/*--------------------------- PANELS ---------------------------*/

.panels {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.panel {
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100%;
}

.editor-panel { flex: 1; }

.divider,
.divider-h {
    background-color: var(--border-color);
    flex-shrink: 0;
    transition: background-color .2s;
    touch-action: none;
    user-select: none;
}

.divider   { width: 8px;  cursor: col-resize; }
.divider-h { height: 8px; cursor: row-resize; }

.divider:hover,   .divider.dragging,
.divider-h:hover, .divider-h.dragging { background-color: #4f46e5; }

/*--------------------------- CODEMIRROR ---------------------------*/

.sql-editor-area {
    flex: 0 0 38vh;
    overflow: hidden;
    min-height: 80px;
}

.sql-editor-area .CodeMirror {
    height: 100%;
    min-height: 80px;
    font-size: 14px;
    font-family: 'Consolas', 'Monaco', 'JetBrains Mono', monospace;
    background: var(--cm-bg);
}

.sql-editor-area .CodeMirror-gutters {
    background: var(--bg-secondary);
}

body[data-theme="light"] .sql-editor-area .CodeMirror { color: #1f2937; }

.sql-editor-area .CodeMirror-scrollbar-filler,
.sql-editor-area .CodeMirror-gutter-filler { background-color: var(--scrollbar-track); }

/*--------------------------- RESULTADO ---------------------------*/

.result-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.result-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.result-label {
    color: var(--text-faint);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
}

.result-meta          { margin-left: auto; display: flex; align-items: center; gap: 6px; }

.result-badge         { font-size: 11px; padding: 2px 9px; border-radius: 10px; font-weight: 500; }
.result-badge.success { color: #a78bfa; background: rgba(167,139,250,0.12); }
.result-badge.error   { color: #ef4444; background: rgba(239,68,68,0.12); }

.result-body {
    flex: 1;
    overflow: auto;
    background: var(--bg-primary);
}

.result-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 14px;
    padding: 40px;
    text-align: center;
}

.result-placeholder svg    { opacity: 0.15; color: var(--text-secondary); }
.result-placeholder p      { font-size: 13px; line-height: 1.8; color: var(--text-faint); }
.result-placeholder strong { color: var(--text-muted); }
.result-placeholder kbd {
    display: inline-block;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 11px;
    color: var(--text-muted);
    font-family: monospace;
}

.sql-result-table { width: 100%; border-collapse: collapse; font-size: 13px; }

.sql-result-table thead th {
    background: var(--bg-secondary);
    color: #a78bfa;
    padding: 10px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    letter-spacing: 0.5px;
    border-bottom: 2px solid rgba(79,70,229,0.3);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 2;
}

.sql-result-table tbody tr       { border-bottom: 1px solid var(--bg-secondary); transition: background .1s; }
.sql-result-table tbody tr:hover { background: var(--table-row-hover); }

.sql-result-table tbody td {
    padding: 9px 16px;
    color: var(--text-primary);
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sql-result-table tbody td.null-val { color: var(--text-faint); font-style: italic; font-size: 12px; }

.write-result         { padding: 28px 24px; display: flex; align-items: flex-start; gap: 16px; }
.write-result-icon    { font-size: 28px; line-height: 1; }
.write-result-info h4 { color: #22c55e; font-size: 15px; font-weight: 600; margin-bottom: 8px; }
.write-result-info p  { color: var(--text-secondary); font-size: 13px; line-height: 1.7; margin-bottom: 8px; }

.time-badge { display: inline-block; background: var(--bg-secondary); color: var(--text-muted); font-size: 11px; padding: 2px 9px; border-radius: 8px; }

.error-box    { margin: 16px; padding: 18px 20px; background: rgba(239,68,68,0.07); border-left: 4px solid #ef4444; border-radius: 0 6px 6px 0; }
.error-box h4 { color: #ef4444; font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.error-box p  { color: #fca5a5; font-size: 13px; line-height: 1.7; }

.no-rows { padding: 48px 24px; text-align: center; color: var(--text-faint); font-size: 13px; line-height: 1.8; }

/*--------------------------- DB EXPLORER ---------------------------*/

.db-explorer {
    width: 220px;
    min-width: 160px;
    max-width: 320px;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.db-explorer-header { padding: 12px 16px; border-bottom: 1px solid var(--border-color); }
.db-header-row      { display: flex; align-items: center; gap: 8px; }
.db-header-icon     { color: var(--text-muted); flex-shrink: 0; }

.db-name {
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.db-engine {
    background: rgba(79,70,229,0.15);
    color: #a78bfa;
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    letter-spacing: 0.5px;
    font-weight: 500;
    flex-shrink: 0;
}

.db-section-label {
    padding: 10px 16px 4px;
    color: var(--text-faint);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1.2px;
    text-transform: uppercase;
}

.db-tables-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) transparent;
}

.db-tables-list::-webkit-scrollbar             { width: 4px; }
.db-tables-list::-webkit-scrollbar-track       { background: transparent; }
.db-tables-list::-webkit-scrollbar-thumb       { background: var(--scrollbar-thumb); border-radius: 99px; }
.db-tables-list::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

.db-loading { padding: 16px; color: var(--text-faint); font-size: 12px; }

.table-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    cursor: pointer;
    transition: background .15s, border-color .15s;
    border-left: 3px solid transparent;
    user-select: none;
}

.table-item:hover  { background: var(--bg-tertiary); border-left-color: #4f46e5; }
.table-item.active { background: rgba(79,70,229,0.1); border-left-color: #4f46e5; }

.table-item-left { display: flex; align-items: center; gap: 8px; }

.table-icon { width: 13px; height: 13px; color: var(--text-faint); flex-shrink: 0; transition: color .15s; }
.table-item:hover  .table-icon,
.table-item.active .table-icon { color: #a78bfa; }

.table-name { color: var(--text-secondary); font-size: 12px; font-weight: 500; }
.table-item:hover  .table-name,
.table-item.active .table-name { color: var(--text-primary); }

.table-rows {
    color: var(--text-muted);
    font-size: 10px;
    background: var(--table-count-bg);
    padding: 2px 7px;
    border-radius: 8px;
    font-weight: 500;
}

/*--------------------------- 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; }

/*--------------------------- RESPONSIVE ---------------------------*/

@media (max-width: 768px) {
    /* Ocultar explorador y divider vertical — no tienen sentido en mobile */
    .db-explorer, .divider, .keyboard-tip, .result-dimensions, .shortcut { display: none; }

    /* Editor SQL más compacto en mobile */
    .sql-editor-area { flex: 0 0 40vh; min-height: 100px; }

    /* CodeMirror más compacto en mobile */
    .sql-editor-area .CodeMirror { font-size: 13px; }

    /* Divider horizontal — touch-action evita conflicto con scroll de página */
    .divider-h { touch-action: none; }

    /* Contener el scroll del resultado sin que escape al body */
    .result-body { overscroll-behavior: contain; }

    /* Tabla de resultados más compacta */
    .sql-result-table thead th { padding: 8px 10px; font-size: 11px; }
    .sql-result-table tbody td { padding: 7px 10px; font-size: 12px; max-width: 200px; }

    .btn           { padding: 6px 10px; font-size: 12px; }
    .toolbar-right { gap: 4px; }

    /* Botón volver — visible solo en mobile */
    #btnBack { display: inline-flex !important; align-items: center; gap: 4px; }

    /* btnTheme mismo tamaño que el resto */
    #btnTheme { width: auto; height: auto; padding: 6px 10px; font-size: 20px; }

    /* 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; }
}

@keyframes spin { to { transform: rotate(360deg); } }
.spin { display: inline-block; animation: spin 1s linear infinite; }
