body { font-family: 'Segoe UI', sans-serif; margin: 0; display: flex; flex-direction: column; height: 100vh; overflow: hidden; background: #f8f9fa; }

/* Toolbars */
.toolbar { background: #f1f3f4; padding: 10px; border-bottom: 1px solid #ccc; display: flex; gap: 20px; flex-shrink: 0; align-items: center; }
.group { display: flex; gap: 8px; align-items: center; }
.formula-bar { display: flex; background: white; border-bottom: 1px solid #ccc; padding: 5px; align-items: center; flex-shrink: 0; }
.cell-address { width: 60px; font-weight: bold; text-align: center; border-right: 1px solid #ccc; color: #1a73e8; }
#formulaInput { flex-grow: 1; border: none; outline: none; padding: 5px 10px; font-size: 14px; }

/* Grid Core */
#spreadsheet-container { flex-grow: 1; overflow: auto; background: #fff; position: relative; }
table {
    border-collapse: separate;
    border-spacing: 1px;
    background-color: #c0c0c0;
    table-layout: fixed;
    min-width: 100%;
}

/* Columnas fijas: las celdas no expanden el ancho al ingresar datos */
td {
    padding: 0;
    box-sizing: border-box;
    vertical-align: top;
    position: relative;
    background-color: #fff;
}
.cell-editor {
    min-height: 25px; padding: 2px 5px;
    outline: none; font-size: 13px;
    white-space: normal;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    box-sizing: border-box;
    width: 100%;
    text-align: left;
}

.row-header, .col-header {
    background-color: #f1f3f4; color: #5f6368; text-align: center;
    font-size: 11px; font-weight: bold;
    position: sticky; z-index: 5; user-select: none;
}
.col-header { top: 0; height: 30px; position: relative; overflow: visible; }
.row-header { left: 0; width: 50px; min-width: 50px; z-index: 6; }

/* Redimensionamiento Columnas */
.resizer { position: absolute; right: 0; top: 0; width: 6px; height: 100%; cursor: col-resize; z-index: 10; }
.resizer:hover, .resizing { background: #1a73e8; width: 4px; }

/* Redimensionamiento Filas */
.row-resizer { position: absolute; bottom: -5px; left: 0; width: 100%; height: 10px; cursor: row-resize; z-index: 10; background: transparent; }
.row-resizer:hover, .row-resizer.resizing { background: #1a73e8; }

.cell-selected { background-color: rgba(26, 115, 232, 0.1) !important; box-shadow: inset 0 0 0 2px #1a73e8; z-index: 2; }

/* Gráficos Flotantes */
.floating-chart-wrapper {
    position: absolute; width: 350px; height: 250px;
    background: white; border: 1px solid #1a73e8;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15); z-index: 100;
    padding: 10px; padding-top: 25px; touch-action: none;
}
.chart-handle {
    position: absolute; top: 0; left: 0; right: 0; height: 22px;
    background: #1a73e8; cursor: move; display: flex; justify-content: flex-end;
}
.btn-close-chart { background: none; border: none; color: white; font-weight: bold; cursor: pointer; padding: 0 8px; }

/* Tabs: debajo de la barra de fórmulas y encima del grid */
.tab-bar {
    display: flex;
    background: #f1f3f4;
    border-bottom: 2px solid #ccc;
    height: 38px;
    min-height: 38px;
    overflow-x: auto;
    overflow-y: hidden;
    flex-shrink: 0;
    align-items: flex-end;
    padding: 0 4px;
    gap: 2px;
}
.tab {
    padding: 0 18px;
    height: 30px;
    line-height: 30px;
    cursor: pointer;
    border: 1px solid #ccc;
    border-bottom: none;
    border-radius: 4px 4px 0 0;
    font-size: 12px;
    background: #e8eaed;
    white-space: nowrap;
    color: #5f6368;
    user-select: none;
}
.tab:hover { background: #d2e3fc; color: #1a73e8; }
.tab.active {
    background: white;
    border-bottom: 2px solid white;
    font-weight: bold;
    color: #1a73e8;
    margin-bottom: -2px;
    z-index: 1;
}

/* Modales */
.modal { display: none; position: fixed; z-index: 200; left: 0; top: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.4); }
.modal-content { background: white; margin: 12% auto; padding: 20px; width: 280px; border-radius: 8px; text-align: center; }
.preset-colors { display: flex; justify-content: center; gap: 8px; margin: 15px 0; }
.color-dot { width: 24px; height: 24px; border-radius: 50%; cursor: pointer; border: 1px solid #ddd; }
.modal-buttons { margin-top: 20px; display: flex; justify-content: space-between; }

button { cursor: pointer; padding: 6px 12px; border: 1px solid #ccc; border-radius: 4px; background: white; }
.btn-primary { background: #1a73e8; color: white; border: none; }
.btn-chart { background: #e8f0fe; color: #1a73e8; font-weight: bold; }
.no-select { user-select: none; }
@media (pointer: coarse) {
  .col-header .resizer { width: 12px; right: -6px; }
}
.resizer, .row-resizer { touch-action: none; -webkit-user-select: none; }
@media (pointer:coarse){ 
  .resizer{ width:50px!important; right:-10px!important; }
  .row-resizer{ height:40px!important; bottom:-14px!important; } 
}

/* ═══════════════════════════════════════════
   ANTI-PEGADO ANDROID - CSS Layer (v2)
   ═══════════════════════════════════════════ */

/* Base: cell-editor como el reference app (.editor-content) */
.cell-editor {
    -webkit-touch-callout: none !important;
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    user-select: text !important;
    -webkit-tap-highlight-color: transparent !important;
    -webkit-text-size-adjust: none !important;
    touch-action: manipulation !important;
}

.cell-editor ::selection {
    background: rgba(26, 115, 232, 0.15);
}
.cell-editor ::-moz-selection {
    background: rgba(26, 115, 232, 0.15);
}

/* Dispositivos táctiles (Android/iOS) */
@media (hover: none) and (pointer: coarse) {
    .cell-editor {
        -webkit-touch-callout: none !important;
        -webkit-user-select: text !important;
        user-select: text !important;
        -webkit-tap-highlight-color: transparent !important;
        -webkit-text-size-adjust: none !important;
        touch-action: manipulation !important;
    }
    .cell-editor:focus {
        outline: none !important;
        -webkit-focus-ring-color: transparent !important;
    }
}

/* Android específico */
@supports (-webkit-touch-callout: none) {
    .cell-editor {
        -webkit-touch-callout: none !important;
        -webkit-user-select: text !important;
        -webkit-tap-highlight-color: transparent !important;
        -webkit-appearance: none !important;
    }
}

/* iOS Safari específico */
@supports (-webkit-overflow-scrolling: touch) {
    .cell-editor {
        -webkit-touch-callout: none !important;
        -webkit-user-select: text !important;
        -webkit-tap-highlight-color: transparent !important;
        -webkit-text-size-adjust: none !important;
    }
}

/* Bloquear selección en headers */
.row-header, .col-header {
    -webkit-touch-callout: none !important;
    -webkit-user-select: none !important;
    user-select: none !important;
}

/* Overlay anti long-press (se muestra dinámicamente) */
#anti-paste-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: transparent;
    z-index: 10;
    display: none;
    pointer-events: none;
}
#anti-paste-overlay.active {
    display: block;
}

/* Evitar que el navegador muestre menú de pegado en inputs de la barra */
#formulaInput, #cellAddress {
    -webkit-user-select: none !important;
    user-select: none !important;
    -webkit-touch-callout: none !important;
}

/* ═══════════════════════════════════════════
   MODAL DE EVALUACIÓN IA
   ═══════════════════════════════════════════ */
.eval-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
}
.eval-header h3 { margin: 0; font-size: 18px; color: #333; }
.eval-nota-general {
    text-align: center;
    padding: 18px;
    margin: 15px 20px;
    border-radius: 10px;
    font-size: 22px;
    font-weight: 800;
    letter-spacing: 1px;
}
.eval-nota-general.nota-superior { background: #D4EDDA; color: #155724; }
.eval-nota-general.nota-alto { background: #FFF3CD; color: #856404; }
.eval-nota-general.nota-basico { background: #CCE5FF; color: #004085; }
.eval-nota-general.nota-bajo { background: #DC3545; color: #fff; }
.eval-texto {
    padding: 0 20px;
    font-size: 14px;
    color: #555;
    line-height: 1.5;
    margin-bottom: 12px;
}
#evalDetalle { padding: 0 20px 10px; }
.eval-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    margin-bottom: 6px;
    border-radius: 8px;
    background: #f8f9fa;
    border-left: 4px solid #ccc;
}
.eval-item.aprobado { border-left-color: #28a745; }
.eval-item.no-aprobado { border-left-color: #dc3545; }
.eval-item-nombre {
    font-weight: 700;
    font-size: 13px;
    min-width: 100px;
    color: #333;
}
.eval-item-texto {
    flex: 1;
    font-size: 13px;
    color: #555;
    line-height: 1.4;
}
.eval-badge {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 12px;
    white-space: nowrap;
    flex-shrink: 0;
}
.eval-badge.aprobado { background: #D4EDDA; color: #155724; }
.eval-badge.no-aprobado { background: #f8d7da; color: #721c24; }
.eval-footer {
    padding: 15px 20px;
    border-top: 1px solid #eee;
    text-align: right;
}
#evalCargando .spinner {
    width: 36px;
    height: 36px;
    border: 4px solid #e0e0e0;
    border-top-color: #7c3aed;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }