/* ─── RESET & BASE ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --white:     #ffffff;
    --gray-50:   #f9fafb;
    --gray-100:  #f3f4f6;
    --gray-200:  #e5e7eb;
    --gray-300:  #d1d5db;
    --gray-400:  #9ca3af;
    --gray-500:  #6b7280;
    --gray-600:  #4b5563;
    --gray-700:  #374151;
    --gray-800:  #1f2937;
    --gray-900:  #111827;
    --black:     #000000;
    --blue-500:  #3b82f6;
    --blue-600:  #2563eb;
    --red-500:   #ef4444;
    --red-100:   #fee2e2;
    --green-500: #22c55e;
    --green-100: #dcfce7;
    --amber-500: #f59e0b;
    --amber-100: #fef3c7;
    --font:      'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --radius:    6px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
    --shadow:    0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1);
}

body {
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--gray-900);
    background: var(--gray-200);
}

/* ─── APP SHELL (sidebar SaaS) ─── */
.app-body {
    display: flex;
    min-height: 100vh;
    background: var(--gray-100);
}
.app-sidebar {
    width: 260px;
    min-height: 100vh;
    background: var(--gray-900);
    color: var(--gray-300);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    align-self: flex-start;
    z-index: 200;
}
.sidebar-brand {
    padding: 18px 16px;
    border-bottom: 1px solid var(--gray-800);
}
.sidebar-brand-link {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    font-weight: 700;
    color: var(--white);
    text-decoration: none;
}
.sidebar-brand-link:hover { color: var(--white); text-decoration: none; opacity: 0.92; }
.sidebar-brand-link i { font-size: 18px; opacity: 0.9; }
.sidebar-nav {
    flex: 1;
    padding: 12px 10px;
    overflow-y: auto;
}
.sidebar-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--gray-500);
    padding: 16px 10px 6px;
}
.sidebar-label:first-child { padding-top: 4px; }
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--gray-300);
    text-decoration: none;
    margin-bottom: 2px;
    transition: background .12s, color .12s;
}
.sidebar-link i {
    width: 20px;
    text-align: center;
    font-size: 15px;
    opacity: 0.85;
}
.sidebar-link:hover {
    background: rgba(255,255,255,.06);
    color: var(--white);
    text-decoration: none;
}
.sidebar-link.active {
    background: rgba(59, 130, 246, .18);
    color: var(--white);
}
.sidebar-link.sidebar-link-sub {
    padding-left: 22px;
    font-size: 12px;
}
.sidebar-footer {
    padding: 14px 12px;
    border-top: 1px solid var(--gray-800);
}
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--gray-400);
    margin-bottom: 10px;
}
.sidebar-user i { font-size: 18px; opacity: 0.7; }
.sidebar-user-email {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar-logout-form { margin: 0; }
.sidebar-logout {
    border-color: var(--gray-600);
    color: var(--gray-300);
    background: transparent;
}
.sidebar-logout:hover {
    background: rgba(255,255,255,.08);
    border-color: var(--gray-500);
    color: var(--white);
}
.app-shell {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.app-topbar {
    display: none;
    align-items: center;
    gap: 12px;
    min-height: 52px;
    padding: 0 16px;
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    position: sticky;
    top: 0;
    z-index: 50;
}
.sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    background: var(--white);
    color: var(--gray-700);
    cursor: pointer;
}
.sidebar-toggle:hover { background: var(--gray-50); }
.app-page-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--gray-700);
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
@media (max-width: 900px) {
    .app-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: var(--shadow-md);
    }
    .app-sidebar.open,
    body.sidebar-open .app-sidebar { transform: translateX(0); }
    .app-topbar { display: flex; }
    .app-shell { padding-top: 0; }
}

a { color: var(--blue-600); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── TOPBAR ─── */
.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    height: 52px;
    padding: 0 24px;
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    position: sticky;
    top: 0;
    z-index: 100;
}
.topbar-left { display: flex; align-items: center; }
.logo { font-size: 16px; font-weight: 700; color: var(--gray-900); letter-spacing: -0.3px; }
.topbar-nav { display: flex; align-items: center; gap: 4px; margin-left: 32px; }
.nav-link {
    padding: 6px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    color: var(--gray-600);
    transition: all .15s;
}
.nav-link:hover { background: var(--gray-100); color: var(--gray-900); text-decoration: none; }
.nav-link.active { background: var(--gray-100); color: var(--gray-900); }

/* Nav Dropdown */
.nav-dropdown { position: relative; display: flex; align-items: center; }
.nav-dropdown > .nav-link { cursor: pointer; user-select: none; display: inline-flex; align-items: center; }
.dropdown-arrow { font-size: 10px; margin-left: 2px; }
.nav-dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% - 4px);
    left: 0;
    margin-top: 0;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    min-width: 140px;
    padding: 4px;
    z-index: 200;
}
/* Puente invisible: el ratón no pierde el hover al cruzar el espacio entre “Constructor” y el panel */
.nav-dropdown-menu::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 100%;
    height: 16px;
}
.nav-dropdown:hover .nav-dropdown-menu { display: block; }
.dropdown-item {
    display: block;
    padding: 7px 14px;
    font-size: 13px;
    color: var(--gray-700);
    border-radius: 4px;
    transition: all .12s;
    text-decoration: none;
}
.dropdown-item:hover { background: var(--gray-100); color: var(--gray-900); text-decoration: none; }
.dropdown-item.active { font-weight: 600; color: var(--gray-900); }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user-email { font-size: 13px; color: var(--gray-500); }

/* ─── MAIN ─── */
.main-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
    width: 100%;
}
.form-hint { font-size: 12px; margin-top: 6px; }

.openai-status {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 8px;
    padding: 6px 10px;
    border-radius: var(--radius);
}
.openai-status--ok {
    background: var(--green-100);
    color: #166534;
    border: 1px solid #bbf7d0;
}
.openai-status--empty {
    background: var(--gray-100);
    color: var(--gray-600);
    border: 1px solid var(--gray-200);
}
.openai-status--warn {
    background: var(--amber-100);
    color: #92400e;
    border: 1px solid #fde68a;
}
.input-api-key::placeholder {
    color: var(--gray-500);
    opacity: 1;
}
.input-api-key[type="password"]::placeholder {
    color: var(--gray-600);
}

/* ─── BUTTONS ─── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    background: var(--white);
    color: var(--gray-700);
    transition: all .15s;
    white-space: nowrap;
}
.btn:hover { background: var(--gray-50); border-color: var(--gray-400); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--gray-800); color: var(--white); border-color: var(--gray-800); }
.btn-primary:hover { background: var(--gray-700); }
.btn-danger { color: var(--red-500); border-color: var(--red-500); }
.btn-danger:hover { background: var(--red-100); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-outline { background: transparent; }
.btn-group { display: flex; gap: 6px; }
.btn-icon {
    padding: 8px 10px;
    min-width: 38px;
    font-size: 15px;
    color: var(--gray-600);
}
.btn-icon:hover { color: var(--gray-900); }

/* ─── FORMS ─── */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.input, input[type="text"], input[type="email"], input[type="password"], select, textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: var(--font);
    color: var(--gray-900);
    background: var(--white);
    transition: border-color .15s;
}
.input:focus, input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--gray-500);
    box-shadow: 0 0 0 3px rgba(107,114,128,.1);
}
.form-row { display: flex; gap: 12px; align-items: flex-end; }
.flex-1 { flex: 1; }

/* ─── ALERTS ─── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 16px;
}
.alert-error { background: var(--red-100); color: #991b1b; border: 1px solid #fecaca; }
.alert-warn { background: var(--amber-100); color: #92400e; border: 1px solid #fde68a; }
.alert-success { background: var(--green-100); color: #166534; border: 1px solid #bbf7d0; }

/* ─── LOGIN ─── */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--gray-100);
}
.login-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-md);
}
.login-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: 4px;
}
.login-subtitle {
    font-size: 13px;
    color: var(--gray-500);
    margin-bottom: 28px;
}
.login-form .form-group { margin-bottom: 18px; }
.login-form .btn { margin-top: 8px; }

/* ─── PAGE HEADER ─── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}
.page-header h2 { font-size: 20px; font-weight: 700; color: var(--gray-900); }
.page-header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.page-header.compact { margin-bottom: 16px; }

/* ─── MODAL ─── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(15, 23, 42, 0.45);
}
/* Cerrado: no debe capturar clics (p. ej. si otro CSS altera display) */
.modal-backdrop.hidden {
    display: none !important;
    pointer-events: none !important;
    visibility: hidden;
}
.modal-panel {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.12);
    width: 100%;
    max-width: 440px;
    padding: 24px;
}
.modal-panel--wide { max-width: 640px; }
.modal-panel kbd {
    display: inline-block;
    padding: 1px 6px;
    font-size: 11px;
    font-family: inherit;
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
    border-radius: 4px;
}
.input-textarea-bulk {
    width: 100%;
    min-height: 220px;
    resize: vertical;
    font-family: ui-monospace, 'Cascadia Code', 'Consolas', monospace;
    font-size: 13px;
    line-height: 1.45;
}
.cell-prompt { min-width: 320px; }
.input-prompt {
    width: 100%;
    min-height: 64px;
    padding: 6px 8px;
    border: 1px solid var(--gray-200);
    border-radius: 4px;
    resize: vertical;
    font-family: ui-monospace, 'Cascadia Code', 'Consolas', monospace;
    font-size: 12.5px;
    line-height: 1.4;
}
.modal-title { font-size: 17px; font-weight: 700; color: var(--gray-900); margin: 0 0 8px; }
.modal-hint { margin: 0 0 18px; font-size: 13px; }
.modal-panel .form-group { margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.modal-error { color: #b91c1c; font-size: 13px; margin: 0 0 12px; }
.modal-error.hidden { display: none !important; }
.text-muted { color: var(--gray-500); font-size: 13px; }
.text-center { text-align: center; }

/* ─── TABS ─── */
.tabs {
    display: flex;
    gap: 2px;
    background: var(--gray-100);
    border-radius: var(--radius);
    padding: 3px;
    width: fit-content;
    margin-bottom: 20px;
}
.tab {
    padding: 6px 18px;
    border: none;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    background: transparent;
    color: var(--gray-600);
    transition: all .15s;
    text-decoration: none;
}
.tab:hover { color: var(--gray-900); text-decoration: none; }
.tab.active { background: var(--white); color: var(--gray-900); box-shadow: var(--shadow-sm); }

/* ─── CARDS ─── */
.card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    overflow: hidden;
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
    background: var(--gray-50);
}
.card-header h3 { font-size: 15px; font-weight: 600; }
.card-body { padding: 20px; }

.grid-3 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 20px;
}

/* ─── TEMPLATE BLOCKS ─── */
.template-block { margin-bottom: 16px; }
.template-block h4 { font-size: 13px; font-weight: 600; margin-bottom: 8px; color: var(--gray-700); }
.template-status {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}
.template-status-meta { flex: 1; min-width: 0; }
.template-download {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    margin-left: auto;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    color: var(--gray-600);
    background: var(--white);
    text-decoration: none;
}
.template-download:hover {
    color: var(--gray-900);
    background: var(--gray-50);
    border-color: var(--gray-400);
    text-decoration: none;
}
.template-upload-form { display: flex; flex-direction: column; gap: 8px; }
.file-input-wrap.compact { }
.file-input-sm { font-size: 12px; padding: 4px; width: 100%; }
.divider { height: 1px; background: var(--gray-200); margin: 16px 0; }
.section-divider { height: 1px; background: var(--gray-200); margin: 28px 0; }

/* ─── BADGES ─── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.badge-pending { background: var(--gray-200); color: var(--gray-600); }
.badge-ok { background: var(--green-100); color: #166534; }
.badge-warn { background: var(--amber-100); color: #92400e; }
.badge-error { background: var(--red-100); color: #991b1b; }

.table-wrap { overflow-x: auto; }
.users-form-grid {
    display: grid;
    grid-template-columns: 1.4fr 1fr 180px;
    gap: 12px;
    align-items: end;
    margin-bottom: 8px;
}
.chip-you {
    display: inline-flex;
    align-items: center;
    margin-left: 6px;
    padding: 1px 7px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    background: var(--gray-200);
    color: var(--gray-600);
}
.badge-role-admin { background: #dbeafe; color: #1e40af; }
.badge-role-user { background: var(--gray-200); color: var(--gray-700); }
@media (max-width: 800px) {
    .users-form-grid { grid-template-columns: 1fr; }
}

/* ─── DATA TABLE ─── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.data-table th {
    text-align: left;
    padding: 8px 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--gray-50);
    background: var(--gray-500);
    border-bottom: 1px solid var(--gray-200);
}
.data-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--gray-100);
    color: var(--gray-800);
}
.data-table tr:hover td { background: var(--gray-50); }
.data-table.compact th, .data-table.compact td { padding: 6px 10px; font-size: 12px; }
.data-table input {
    padding: 4px 8px;
    font-size: 12px;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    width: 100%;
}

/* ─── CONVERT ─── */
.upload-zone {
    background: var(--white);
    border: 2px dashed var(--gray-300);
    border-radius: 8px;
    padding: 32px;
    text-align: center;
}
.file-input-wrap { margin-bottom: 16px; }
.file-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 16px;
}
.file-icon { font-size: 32px; }
.file-text { font-size: 13px; color: var(--gray-500); }
.file-input-hidden { display: none; }
.convert-result { margin-top: 20px; padding: 20px; background: var(--white); border: 1px solid var(--gray-200); border-radius: 8px; }
.convert-result h3 { font-size: 15px; margin-bottom: 12px; }
.result-summary {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}
.result-stat {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 12px;
    text-align: center;
}
.result-stat .stat-value { font-size: 24px; font-weight: 700; }
.result-stat .stat-label { font-size: 11px; color: var(--gray-500); text-transform: uppercase; }
.result-actions { display: flex; gap: 8px; }

/* ─── TABLES (DICCIONARIOS) ─── */
.tables-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 20px;
    min-height: 500px;
}
.tables-sidebar {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 12px;
}
.tables-list { display: flex; flex-direction: column; gap: 2px; }
.table-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    color: var(--gray-700);
    transition: all .15s;
}
.table-item:hover { background: var(--gray-100); }
.table-item.active { background: var(--gray-100); font-weight: 600; color: var(--gray-900); }
.table-item .row-count { font-size: 11px; color: var(--gray-400); }
.tables-editor {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 20px;
}
.empty-state { display: flex; align-items: center; justify-content: center; min-height: 200px; color: var(--gray-400); }
.editor-header { margin-bottom: 0; }
.editor-rows-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.editor-rows-header h4 { font-size: 14px; font-weight: 600; }

/* ─── CONSTRUCTOR ─── */
.constructor-toolbar {
    margin-bottom: 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}
.btn-file-wrap {
    cursor: pointer;
    margin: 0;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn-file-wrap .input-file-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
input.input-file-hidden {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
}
.constructor-layout {
    display: grid;
    grid-template-columns: 200px 1fr 1fr;
    gap: 16px;
    min-height: 600px;
}
.constructor-sidebar {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 12px;
    overflow-y: auto;
    max-height: calc(100vh - 130px);
    position: sticky;
    top: 68px;
}
.sidebar-section { margin-bottom: 16px; }
.sidebar-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--gray-500);
    margin-bottom: 6px;
    padding: 0 8px;
}
.sidebar-items { display: flex; flex-direction: column; gap: 1px; }
.sidebar-item {
    padding: 5px 10px;
    font-size: 12px;
    color: var(--gray-700);
    border-radius: 4px;
    cursor: grab;
    border: 1px solid transparent;
    background: var(--gray-50);
    transition: all .15s;
    user-select: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-item:hover { background: var(--gray-100); border-color: var(--gray-300); }
.sidebar-item.dragging { opacity: .5; }
.sidebar-item[data-type="origen"]  { border-left: 3px solid var(--blue-500); }
.sidebar-item[data-type="destino"] { border-left: 3px solid var(--green-500); }
.sidebar-item[data-type="table"]   { border-left: 3px solid var(--amber-500); }

.constructor-center {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 16px;
    overflow-y: auto;
    max-height: calc(100vh - 130px);
}
.constructor-preview {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 16px;
    overflow-y: auto;
    max-height: calc(100vh - 130px);
}
.section-title { font-size: 14px; font-weight: 600; margin-bottom: 12px; }

/* ─── ACCORDION ─── */
.accordion { display: flex; flex-direction: column; gap: 4px; }
.accordion-item {
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    overflow: hidden;
}
.accordion-item[draggable="true"] { cursor: grab; }
.accordion-item.is-dragging { opacity: .7; }
.accordion-item.drop-target { outline: 2px dashed var(--blue-500); outline-offset: -2px; }
.accordion-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--gray-50);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--gray-800);
    transition: background .15s;
    user-select: none;
}
.accordion-header:hover { background: var(--gray-100); }
.accordion-header .drag-handle { color: var(--gray-400); margin-right: 8px; cursor: grab; }
.accordion-header .drag-handle:hover { color: var(--gray-600); }
.accordion-header .acc-title { flex: 1; min-width: 0; }
.accordion-header .arrow { transition: transform .2s; font-size: 10px; color: var(--gray-400); }
.accordion-item.open .accordion-header .arrow { transform: rotate(90deg); }
.accordion-header .rule-status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-left: auto;
    margin-right: 8px;
}
.rule-status.has-rule  { background: var(--green-500); }
.rule-status.no-rule   { background: var(--gray-300); }
.rule-status.has-error { background: var(--red-500); }

.accordion-body {
    display: none;
    padding: 14px;
    border-top: 1px solid var(--gray-200);
}
.accordion-item.open .accordion-body { display: block; }

.mapping-field-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}
.mapping-field-row label { font-size: 12px; font-weight: 600; color: var(--gray-600); white-space: nowrap; }
.mapping-field-row select { max-width: 220px; font-size: 13px; padding: 5px 8px; }
.mapping-hint { font-size: 12px; color: var(--gray-600); margin: 0 0 8px 0; }
.section-subtitle { font-weight: normal; font-size: 0.85em; color: var(--gray-600); }

.dsl-help { margin-bottom: 12px; border: 1px solid var(--gray-300); border-radius: 6px; background: var(--gray-50); }
.dsl-help summary { padding: 8px 12px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--gray-700); }
.dsl-help-content { padding: 0 12px 12px; font-size: 12px; color: var(--gray-700); }
.dsl-help-content p { margin: 8px 0 4px 0; }
.dsl-help-content ul { margin: 4px 0 8px 0; padding-left: 20px; }
.dsl-help-content code { background: var(--gray-200); padding: 1px 4px; border-radius: 3px; font-size: 11px; }
.dsl-example { display: block; margin: 4px 0 8px 0; padding: 8px 10px; background: var(--gray-800); color: var(--gray-100); border-radius: 4px; font-size: 12px; overflow-x: auto; }

/* ─── GUÍA DE USO ─── */
.guide-page { max-width: 900px; margin: 0 auto; padding-bottom: 2rem; }
.guide-section { margin-bottom: 2rem; }
.guide-section h3 { font-size: 1.15rem; margin-bottom: 0.75rem; color: var(--gray-800); display: flex; align-items: center; gap: 8px; }
.guide-section h3 i { color: var(--blue-600); }
.guide-section p { margin: 0 0 0.5rem 0; font-size: 14px; line-height: 1.6; color: var(--gray-700); }
.guide-section ul { margin: 0.5rem 0 1rem 1.25rem; font-size: 14px; color: var(--gray-700); line-height: 1.6; }
.guide-section code { background: var(--gray-200); padding: 2px 6px; border-radius: 4px; font-size: 12px; }
.guide-card { background: var(--gray-50); border: 1px solid var(--gray-200); border-radius: 8px; padding: 1rem 1.25rem; margin-bottom: 1rem; }
.guide-card h4 { font-size: 0.95rem; margin: 0 0 0.5rem 0; display: flex; align-items: center; gap: 8px; }
.guide-card h4 i { color: var(--gray-500); font-size: 0.9rem; }
.guide-card.compact { padding: 0.75rem 1rem; }
.guide-card.compact h4 { margin-bottom: 0.5rem; }
.guide-code { display: block; margin: 0.5rem 0 0 0; padding: 12px 14px; background: var(--gray-800); color: #e5e7eb; border-radius: 6px; font-size: 13px; font-family: 'JetBrains Mono', 'Consolas', monospace; overflow-x: auto; white-space: pre; }
.guide-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 0.75rem; }
@media (max-width: 640px) { .guide-grid { grid-template-columns: 1fr; } }
.guide-fn-list { list-style: none; padding-left: 0; margin: 0; font-size: 12px; }
.guide-fn-list li { margin: 0.25rem 0; }
.guide-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 0.5rem; }
.guide-table th, .guide-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--gray-200); }
.guide-table th { background: var(--gray-100); font-weight: 600; color: var(--gray-800); }
.guide-table code { font-size: 11px; white-space: nowrap; }

/* ─── CODE EDITOR (Night mode textarea) ─── */
.code-editor {
    width: 100%;
    min-height: 80px;
    padding: 12px 14px;
    font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 13px;
    line-height: 1.6;
    background: var(--gray-900);
    color: #e5e7eb;
    border: 1px solid var(--gray-700);
    border-radius: var(--radius);
    resize: vertical;
    tab-size: 2;
}
.code-editor:focus {
    outline: none;
    border-color: var(--blue-500);
    box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
.code-editor::placeholder { color: var(--gray-500); }

.mapping-actions {
    display: flex;
    gap: 6px;
    margin-top: 10px;
    align-items: center;
}
.mapping-actions .validation-msg {
    font-size: 11px;
    margin-left: auto;
}
.validation-msg.valid { color: var(--green-500); }
.validation-msg.invalid { color: var(--red-500); }

/* ─── PREVIEW ─── */
.preview-panel { }
.preview-pagination {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 10px;
}
.preview-page-info {
    font-size: 12px;
    color: var(--gray-600);
    min-width: 170px;
    text-align: center;
}
.preview-row-error { color: var(--red-500); font-size: 11px; }
.preview-col-hint {
    margin-top: 6px;
    font-size: 11px;
    color: var(--gray-500);
    line-height: 1.4;
}
.preview-col-hint .preview-col-k { color: var(--gray-600); font-weight: 600; }
.preview-col-hint .preview-col-miss { color: var(--amber-500); }
.preview-hint-warn {
    margin-top: 8px;
    font-size: 11px;
    color: var(--gray-700);
    padding: 8px 10px;
    background: var(--amber-100);
    border-radius: var(--radius);
    border: 1px solid var(--amber-500);
}
.preview-hint-warn code { font-size: 10px; }

/* ─── UTILITY ─── */
.hidden { display: none !important; }
.loading { opacity: .6; pointer-events: none; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mb-8 { margin-bottom: 8px; }
.gap-8 { gap: 8px; }

/* ─── HISTORY TABLE ─── */
.history-section { margin-top: 8px; }
.history-section h3 { font-size: 16px; font-weight: 600; margin-bottom: 12px; }

/* ─── RESPONSIVE ─── */
@media (max-width: 1100px) {
    .constructor-layout { grid-template-columns: 180px 1fr; }
    .constructor-preview { grid-column: 1 / -1; }
}
@media (max-width: 768px) {
    .grid-3 { grid-template-columns: 1fr; }
    .tables-layout { grid-template-columns: 1fr; }
    .constructor-layout { grid-template-columns: 1fr; }
    .result-summary { grid-template-columns: repeat(2, 1fr); }
}

/* ─── AUTOMATIZADOR ─── */
.auto-setup-card { margin-bottom: 24px; }
.auto-upload-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}
.auto-upload-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 24px 16px;
    border: 2px dashed var(--gray-300);
    border-radius: 8px;
    background: var(--gray-50);
    cursor: pointer;
    text-align: center;
    transition: border-color .15s, background .15s;
}
.auto-upload-zone:hover,
.auto-upload-zone.has-file {
    border-color: var(--gray-500);
    background: var(--white);
}
.auto-upload-zone i { font-size: 22px; color: var(--gray-500); }
.auto-upload-zone strong { font-size: 14px; color: var(--gray-800); }
.auto-file-name {
    font-size: 12px;
    color: var(--gray-600);
    margin-top: 4px;
    word-break: break-all;
}
.auto-setup-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.auto-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.auto-meta-item {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 12px 14px;
}
.auto-meta-item span {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--gray-500);
    margin-bottom: 4px;
}
.auto-meta-item strong {
    display: block;
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.auto-meta-item em {
    display: block;
    font-style: normal;
    font-size: 12px;
    color: var(--gray-500);
    margin-top: 2px;
}
.auto-meta-join code {
    font-size: 12px;
    background: var(--gray-100);
    padding: 1px 5px;
    border-radius: 3px;
}
.auto-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}
.auto-filter { width: 280px; max-width: 100%; }
.auto-filter-tabs { margin-bottom: 0; }
.auto-col-list { display: flex; flex-direction: column; gap: 10px; }
.auto-col-item {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 14px 16px;
}
.auto-col-item.is-done { border-color: #bbf7d0; }
.auto-col-item.is-busy { opacity: .85; }
.auto-col-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.auto-col-title {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex-wrap: wrap;
}
.auto-col-idx {
    font-size: 11px;
    font-weight: 700;
    color: var(--gray-400);
    min-width: 22px;
}
.auto-col-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 8px;
    font-size: 12px;
    color: var(--gray-500);
}
.auto-samples { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.auto-existing {
    margin-top: 8px;
    font-size: 12px;
    color: var(--gray-600);
}
.auto-existing code {
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
}
.auto-col-body { margin-top: 12px; }
.auto-expr-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: 4px;
}
.auto-expr-input {
    width: 100%;
    font-family: 'JetBrains Mono', 'Consolas', monospace;
    font-size: 12px;
    line-height: 1.45;
    background: var(--gray-800);
    color: #e5e7eb;
    border: 1px solid var(--gray-800);
    border-radius: 6px;
    padding: 10px 12px;
    resize: vertical;
    min-height: 64px;
}
.auto-result-meta { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.badge-conf-high { background: var(--green-100); color: #166534; }
.badge-conf-medium { background: var(--amber-100); color: #92400e; }
.badge-conf-low { background: var(--gray-200); color: var(--gray-600); }
.auto-rationale { font-size: 13px; color: var(--gray-700); margin: 4px 0 0; }
.auto-notes { font-size: 12px; color: var(--gray-500); margin: 4px 0 0; }
.auto-col-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

@media (max-width: 768px) {
    .auto-upload-grid { grid-template-columns: 1fr; }
    .auto-toolbar { flex-direction: column; align-items: stretch; }
    .auto-col-head { flex-direction: column; align-items: stretch; }
    .auto-filter { width: 100%; }
}

/* ─── LOGS ─── */
.logs-filters {
    display: grid;
    grid-template-columns: 1.4fr 1.3fr 1fr 1fr auto;
    gap: 12px;
    align-items: end;
}
.logs-filters .form-group { margin-bottom: 0; }
.logs-filters-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    padding-bottom: 1px;
}
.logs-meta {
    font-size: 12px;
    color: var(--gray-500);
    margin-bottom: 10px;
}
.logs-detail { color: var(--gray-700); }
@media (max-width: 960px) {
    .logs-filters { grid-template-columns: 1fr 1fr; }
}
